@xyo-network/object 2.75.0 → 2.75.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/AnyObject.d.cts +2 -0
- package/dist/browser/AnyObject.d.cts.map +1 -0
- package/dist/browser/AsObjectFactory.d.cts +8 -0
- package/dist/browser/AsObjectFactory.d.cts.map +1 -0
- package/dist/browser/AsObjectFactory.js +1 -2
- package/dist/browser/AsObjectFactory.js.map +1 -1
- package/dist/browser/EmptyObject.d.cts +4 -0
- package/dist/browser/EmptyObject.d.cts.map +1 -0
- package/dist/browser/IsObjectFactory.d.cts +10 -0
- package/dist/browser/IsObjectFactory.d.cts.map +1 -0
- package/dist/browser/IsObjectFactory.js +3 -24
- package/dist/browser/IsObjectFactory.js.map +1 -1
- package/dist/browser/ObjectWrapper.d.cts +8 -0
- package/dist/browser/ObjectWrapper.d.cts.map +1 -0
- package/dist/browser/ObjectWrapper.js +2 -3
- package/dist/browser/ObjectWrapper.js.map +1 -1
- package/dist/browser/StringKeyObject.d.cts +4 -0
- package/dist/browser/StringKeyObject.d.cts.map +1 -0
- package/dist/browser/WithAdditional.d.cts +3 -0
- package/dist/browser/WithAdditional.d.cts.map +1 -0
- package/dist/browser/asObject.d.cts +5 -0
- package/dist/browser/asObject.d.cts.map +1 -0
- package/dist/browser/asObject.js +3 -56
- package/dist/browser/asObject.js.map +1 -1
- package/dist/browser/index.d.cts +11 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.js +10 -98
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/isObject.d.cts +2 -0
- package/dist/browser/isObject.d.cts.map +1 -0
- package/dist/browser/isObject.js +2 -23
- package/dist/browser/isObject.js.map +1 -1
- package/dist/browser/isType.d.cts +4 -0
- package/dist/browser/isType.d.cts.map +1 -0
- package/dist/browser/isType.js +1 -2
- package/dist/browser/isType.js.map +1 -1
- package/dist/docs.json +2101 -0
- package/dist/node/AnyObject.d.cts +2 -0
- package/dist/node/AnyObject.d.cts.map +1 -0
- package/dist/node/AnyObject.js +2 -0
- package/dist/node/AnyObject.js.map +1 -1
- package/dist/node/AsObjectFactory.d.cts +8 -0
- package/dist/node/AsObjectFactory.d.cts.map +1 -0
- package/dist/node/AsObjectFactory.js +3 -1
- package/dist/node/AsObjectFactory.js.map +1 -1
- package/dist/node/AsObjectFactory.mjs +2 -1
- package/dist/node/AsObjectFactory.mjs.map +1 -1
- package/dist/node/EmptyObject.d.cts +4 -0
- package/dist/node/EmptyObject.d.cts.map +1 -0
- package/dist/node/EmptyObject.js +2 -0
- package/dist/node/EmptyObject.js.map +1 -1
- package/dist/node/IsObjectFactory.d.cts +10 -0
- package/dist/node/IsObjectFactory.d.cts.map +1 -0
- package/dist/node/IsObjectFactory.js +29 -5
- package/dist/node/IsObjectFactory.js.map +1 -1
- package/dist/node/IsObjectFactory.mjs +25 -4
- package/dist/node/IsObjectFactory.mjs.map +1 -1
- package/dist/node/ObjectWrapper.d.cts +8 -0
- package/dist/node/ObjectWrapper.d.cts.map +1 -0
- package/dist/node/ObjectWrapper.js +4 -2
- package/dist/node/ObjectWrapper.js.map +1 -1
- package/dist/node/ObjectWrapper.mjs +3 -2
- package/dist/node/ObjectWrapper.mjs.map +1 -1
- package/dist/node/StringKeyObject.d.cts +4 -0
- package/dist/node/StringKeyObject.d.cts.map +1 -0
- package/dist/node/StringKeyObject.js +2 -0
- package/dist/node/StringKeyObject.js.map +1 -1
- package/dist/node/WithAdditional.d.cts +3 -0
- package/dist/node/WithAdditional.d.cts.map +1 -0
- package/dist/node/WithAdditional.js +2 -0
- package/dist/node/WithAdditional.js.map +1 -1
- package/dist/node/asObject.d.cts +5 -0
- package/dist/node/asObject.d.cts.map +1 -0
- package/dist/node/asObject.js +59 -3
- package/dist/node/asObject.js.map +1 -1
- package/dist/node/asObject.mjs +56 -3
- package/dist/node/asObject.mjs.map +1 -1
- package/dist/node/index.d.cts +11 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +111 -21
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +98 -10
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/isObject.d.cts +2 -0
- package/dist/node/isObject.d.cts.map +1 -0
- package/dist/node/isObject.js +27 -3
- package/dist/node/isObject.js.map +1 -1
- package/dist/node/isObject.mjs +23 -2
- package/dist/node/isObject.mjs.map +1 -1
- package/dist/node/isType.d.cts +4 -0
- package/dist/node/isType.d.cts.map +1 -0
- package/dist/node/isType.js +3 -1
- package/dist/node/isType.js.map +1 -1
- package/dist/node/isType.mjs +2 -1
- package/dist/node/isType.mjs.map +1 -1
- package/package.json +6 -6
package/dist/node/index.js
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,31 +15,117 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
15
|
}
|
|
12
16
|
return to;
|
|
13
17
|
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
16
21
|
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AsObjectFactory: () => AsObjectFactory,
|
|
24
|
+
IsObjectFactory: () => IsObjectFactory,
|
|
25
|
+
ObjectWrapper: () => ObjectWrapper,
|
|
26
|
+
asObject: () => asObject,
|
|
27
|
+
isObject: () => isObject,
|
|
28
|
+
isType: () => isType
|
|
29
|
+
});
|
|
17
30
|
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
|
|
32
|
+
// src/AsObjectFactory.ts
|
|
33
|
+
var import_assert = require("@xylabs/assert");
|
|
34
|
+
var AsObjectFactory = {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
36
|
+
create: (typeCheck) => {
|
|
37
|
+
function func(obj, assertOrConfig, config) {
|
|
38
|
+
const noUndefined = (resolvedAssert2) => {
|
|
39
|
+
return !!resolvedAssert2;
|
|
40
|
+
};
|
|
41
|
+
if (obj === void 0) {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
const resolvedAssert = typeof assertOrConfig === "object" ? void 0 : assertOrConfig;
|
|
48
|
+
const resolvedConfig = typeof assertOrConfig === "object" ? assertOrConfig : config;
|
|
49
|
+
const result = typeCheck(obj, resolvedConfig) ? obj : void 0;
|
|
50
|
+
if (noUndefined(resolvedAssert)) {
|
|
51
|
+
return (0, import_assert.assertEx)(result, typeof resolvedAssert === "function" ? resolvedAssert() : resolvedAssert);
|
|
52
|
+
} else {
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return func;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/isType.ts
|
|
61
|
+
var isType = (value, expectedType) => {
|
|
62
|
+
const typeofValue = typeof value;
|
|
63
|
+
switch (expectedType) {
|
|
64
|
+
case "array":
|
|
65
|
+
return Array.isArray(value);
|
|
66
|
+
case "null":
|
|
67
|
+
return value === null;
|
|
68
|
+
case "undefined":
|
|
69
|
+
return value === void 0;
|
|
70
|
+
case "object": {
|
|
71
|
+
if (value === null) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return typeofValue === "object" && !Array.isArray(value);
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
return typeofValue === expectedType;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/isObject.ts
|
|
82
|
+
var isObject = (value) => {
|
|
83
|
+
return isType(value, "object");
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/asObject.ts
|
|
87
|
+
var asObject = (() => AsObjectFactory.create((obj) => isObject(obj)))();
|
|
88
|
+
|
|
89
|
+
// src/IsObjectFactory.ts
|
|
90
|
+
var IsObjectFactory = class {
|
|
91
|
+
create(shape, additionalChecks) {
|
|
92
|
+
return (obj, { log } = {}) => {
|
|
93
|
+
if (!obj || typeof obj !== "object") {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return (
|
|
97
|
+
//do primary check
|
|
98
|
+
Object.entries(shape ?? {}).reduce((prev, [key, type]) => {
|
|
99
|
+
const result = isType(obj[key], type);
|
|
100
|
+
if (!result && log) {
|
|
101
|
+
const logger = typeof log === "object" ? log : console;
|
|
102
|
+
logger.warn(`isType Failed: ${key}: ${type}`);
|
|
103
|
+
}
|
|
104
|
+
return prev && result;
|
|
105
|
+
}, true) && //perform additional checks
|
|
106
|
+
((additionalChecks == null ? void 0 : additionalChecks.reduce((prev, check) => prev && check(obj, { log }), true)) ?? true)
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/ObjectWrapper.ts
|
|
113
|
+
var ObjectWrapper = class {
|
|
114
|
+
obj;
|
|
115
|
+
constructor(obj) {
|
|
116
|
+
this.obj = obj;
|
|
117
|
+
}
|
|
118
|
+
get stringKeyObj() {
|
|
119
|
+
return this.obj;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
28
122
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
123
|
0 && (module.exports = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...require("./isType"),
|
|
37
|
-
...require("./ObjectWrapper"),
|
|
38
|
-
...require("./StringKeyObject"),
|
|
39
|
-
...require("./WithAdditional")
|
|
124
|
+
AsObjectFactory,
|
|
125
|
+
IsObjectFactory,
|
|
126
|
+
ObjectWrapper,
|
|
127
|
+
asObject,
|
|
128
|
+
isObject,
|
|
129
|
+
isType
|
|
40
130
|
});
|
|
41
131
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './AnyObject'\nexport * from './asObject'\nexport * from './AsObjectFactory'\nexport * from './EmptyObject'\nexport * from './isObject'\nexport * from './IsObjectFactory'\nexport * from './isType'\nexport * from './ObjectWrapper'\nexport * from './StringKeyObject'\nexport * from './WithAdditional'\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/AsObjectFactory.ts","../../src/isType.ts","../../src/isObject.ts","../../src/asObject.ts","../../src/IsObjectFactory.ts","../../src/ObjectWrapper.ts"],"sourcesContent":["export * from './AnyObject'\nexport * from './asObject'\nexport * from './AsObjectFactory'\nexport * from './EmptyObject'\nexport * from './isObject'\nexport * from './IsObjectFactory'\nexport * from './isType'\nexport * from './ObjectWrapper'\nexport * from './StringKeyObject'\nexport * from './WithAdditional'\n","import { assertEx } from '@xylabs/assert'\n\nimport { ObjectTypeCheck, ObjectTypeConfig } from './IsObjectFactory'\n\nexport const AsObjectFactory = {\n // eslint-disable-next-line @typescript-eslint/ban-types\n create: <T extends object>(typeCheck: ObjectTypeCheck<T>) => {\n function func<TObject extends T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: object | undefined | null,\n config?: ObjectTypeConfig,\n ): TObject | undefined\n function func<TObject extends T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: object | undefined | null,\n assert: string | (() => string),\n config?: ObjectTypeConfig,\n ): TObject\n function func<TObject extends T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: object | undefined | null,\n assertOrConfig?: string | (() => string) | ObjectTypeConfig,\n config?: ObjectTypeConfig,\n ): TObject | undefined {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const noUndefined = (resolvedAssert: any): resolvedAssert is T => {\n return !!resolvedAssert\n }\n\n if (obj === undefined) {\n return undefined\n }\n\n if (obj === null) {\n return undefined\n }\n const resolvedAssert = typeof assertOrConfig === 'object' ? undefined : assertOrConfig\n const resolvedConfig = typeof assertOrConfig === 'object' ? assertOrConfig : config\n const result = typeCheck(obj, resolvedConfig) ? obj : undefined\n\n if (noUndefined(resolvedAssert)) {\n return assertEx(result, typeof resolvedAssert === 'function' ? resolvedAssert() : resolvedAssert) as TObject\n } else {\n return result as TObject\n }\n }\n return func\n },\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n","import { isType } from './isType'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isObject = (value: any): value is Record<string | number | symbol, any> => {\n return isType(value, 'object')\n}\n","import { AsObjectFactory } from './AsObjectFactory'\nimport { isObject } from './isObject'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const asObject = (() => AsObjectFactory.create(<T>(obj: T): obj is T => isObject(obj)))()\n","import { Logger } from '@xyo-network/logger'\n\nimport { isType, ObjectTypeShape } from './isType'\n\nexport interface ObjectTypeConfig {\n log?: boolean | Logger\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types\nexport type ObjectTypeCheck<T extends {} = {}> = (obj: any, config?: ObjectTypeConfig) => obj is T\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport class IsObjectFactory<T extends {}> {\n create(shape?: ObjectTypeShape, additionalChecks?: ObjectTypeCheck[]): ObjectTypeCheck<T> {\n return (obj, { log } = {}): obj is T => {\n if (!obj || typeof obj !== 'object') {\n return false\n }\n return (\n //do primary check\n Object.entries(shape ?? {}).reduce((prev, [key, type]) => {\n const result = isType(obj[key], type)\n if (!result && log) {\n const logger = typeof log === 'object' ? log : console\n logger.warn(`isType Failed: ${key}: ${type}`)\n }\n return prev && result\n }, true) &&\n //perform additional checks\n (additionalChecks?.reduce((prev, check) => prev && check(obj, { log }), true) ?? true)\n )\n }\n }\n}\n","import { EmptyObject } from './EmptyObject'\nimport { StringKeyObject } from './StringKeyObject'\n\nexport abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {\n readonly obj: T\n constructor(obj: T) {\n this.obj = obj\n }\n protected get stringKeyObj() {\n return this.obj as StringKeyObject\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AAIlB,IAAM,kBAAkB;AAAA;AAAA,EAE7B,QAAQ,CAAmB,cAAkC;AAY3D,aAAS,KAEP,KACA,gBACA,QACqB;AAErB,YAAM,cAAc,CAACA,oBAA6C;AAChE,eAAO,CAAC,CAACA;AAAA,MACX;AAEA,UAAI,QAAQ,QAAW;AACrB,eAAO;AAAA,MACT;AAEA,UAAI,QAAQ,MAAM;AAChB,eAAO;AAAA,MACT;AACA,YAAM,iBAAiB,OAAO,mBAAmB,WAAW,SAAY;AACxE,YAAM,iBAAiB,OAAO,mBAAmB,WAAW,iBAAiB;AAC7E,YAAM,SAAS,UAAU,KAAK,cAAc,IAAI,MAAM;AAEtD,UAAI,YAAY,cAAc,GAAG;AAC/B,mBAAO,wBAAS,QAAQ,OAAO,mBAAmB,aAAa,eAAe,IAAI,cAAc;AAAA,MAClG,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AC1CO,IAAM,SAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA;AACE,aAAO,gBAAgB;AAAA,EAC3B;AACF;;;ACvBO,IAAM,WAAW,CAAC,UAA+D;AACtF,SAAO,OAAO,OAAO,QAAQ;AAC/B;;;ACDO,IAAM,YAAY,MAAM,gBAAgB,OAAO,CAAI,QAAqB,SAAS,GAAG,CAAC,GAAG;;;ACQxF,IAAM,kBAAN,MAAoC;AAAA,EACzC,OAAO,OAAyB,kBAA0D;AACxF,WAAO,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,MAAgB;AACtC,UAAI,CAAC,OAAO,OAAO,QAAQ,UAAU;AACnC,eAAO;AAAA,MACT;AACA;AAAA;AAAA,QAEE,OAAO,QAAQ,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM;AACxD,gBAAM,SAAS,OAAO,IAAI,GAAG,GAAG,IAAI;AACpC,cAAI,CAAC,UAAU,KAAK;AAClB,kBAAM,SAAS,OAAO,QAAQ,WAAW,MAAM;AAC/C,mBAAO,KAAK,kBAAkB,GAAG,KAAK,IAAI,EAAE;AAAA,UAC9C;AACA,iBAAO,QAAQ;AAAA,QACjB,GAAG,IAAI;AAAA,UAEN,qDAAkB,OAAO,CAAC,MAAM,UAAU,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG,UAAS;AAAA;AAAA,IAErF;AAAA,EACF;AACF;;;AC9BO,IAAe,gBAAf,MAAkE;AAAA,EAC9D;AAAA,EACT,YAAY,KAAQ;AAClB,SAAK,MAAM;AAAA,EACb;AAAA,EACA,IAAc,eAAe;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;","names":["resolvedAssert"]}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,11 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
// src/AsObjectFactory.ts
|
|
2
|
+
import { assertEx } from "@xylabs/assert";
|
|
3
|
+
var AsObjectFactory = {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
|
+
create: (typeCheck) => {
|
|
6
|
+
function func(obj, assertOrConfig, config) {
|
|
7
|
+
const noUndefined = (resolvedAssert2) => {
|
|
8
|
+
return !!resolvedAssert2;
|
|
9
|
+
};
|
|
10
|
+
if (obj === void 0) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
if (obj === null) {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
const resolvedAssert = typeof assertOrConfig === "object" ? void 0 : assertOrConfig;
|
|
17
|
+
const resolvedConfig = typeof assertOrConfig === "object" ? assertOrConfig : config;
|
|
18
|
+
const result = typeCheck(obj, resolvedConfig) ? obj : void 0;
|
|
19
|
+
if (noUndefined(resolvedAssert)) {
|
|
20
|
+
return assertEx(result, typeof resolvedAssert === "function" ? resolvedAssert() : resolvedAssert);
|
|
21
|
+
} else {
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return func;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/isType.ts
|
|
30
|
+
var isType = (value, expectedType) => {
|
|
31
|
+
const typeofValue = typeof value;
|
|
32
|
+
switch (expectedType) {
|
|
33
|
+
case "array":
|
|
34
|
+
return Array.isArray(value);
|
|
35
|
+
case "null":
|
|
36
|
+
return value === null;
|
|
37
|
+
case "undefined":
|
|
38
|
+
return value === void 0;
|
|
39
|
+
case "object": {
|
|
40
|
+
if (value === null) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return typeofValue === "object" && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
default:
|
|
46
|
+
return typeofValue === expectedType;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/isObject.ts
|
|
51
|
+
var isObject = (value) => {
|
|
52
|
+
return isType(value, "object");
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/asObject.ts
|
|
56
|
+
var asObject = (() => AsObjectFactory.create((obj) => isObject(obj)))();
|
|
57
|
+
|
|
58
|
+
// src/IsObjectFactory.ts
|
|
59
|
+
var IsObjectFactory = class {
|
|
60
|
+
create(shape, additionalChecks) {
|
|
61
|
+
return (obj, { log } = {}) => {
|
|
62
|
+
if (!obj || typeof obj !== "object") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return (
|
|
66
|
+
//do primary check
|
|
67
|
+
Object.entries(shape ?? {}).reduce((prev, [key, type]) => {
|
|
68
|
+
const result = isType(obj[key], type);
|
|
69
|
+
if (!result && log) {
|
|
70
|
+
const logger = typeof log === "object" ? log : console;
|
|
71
|
+
logger.warn(`isType Failed: ${key}: ${type}`);
|
|
72
|
+
}
|
|
73
|
+
return prev && result;
|
|
74
|
+
}, true) && //perform additional checks
|
|
75
|
+
((additionalChecks == null ? void 0 : additionalChecks.reduce((prev, check) => prev && check(obj, { log }), true)) ?? true)
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/ObjectWrapper.ts
|
|
82
|
+
var ObjectWrapper = class {
|
|
83
|
+
obj;
|
|
84
|
+
constructor(obj) {
|
|
85
|
+
this.obj = obj;
|
|
86
|
+
}
|
|
87
|
+
get stringKeyObj() {
|
|
88
|
+
return this.obj;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
export {
|
|
92
|
+
AsObjectFactory,
|
|
93
|
+
IsObjectFactory,
|
|
94
|
+
ObjectWrapper,
|
|
95
|
+
asObject,
|
|
96
|
+
isObject,
|
|
97
|
+
isType
|
|
98
|
+
};
|
|
11
99
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/AsObjectFactory.ts","../../src/isType.ts","../../src/isObject.ts","../../src/asObject.ts","../../src/IsObjectFactory.ts","../../src/ObjectWrapper.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\nimport { ObjectTypeCheck, ObjectTypeConfig } from './IsObjectFactory'\n\nexport const AsObjectFactory = {\n // eslint-disable-next-line @typescript-eslint/ban-types\n create: <T extends object>(typeCheck: ObjectTypeCheck<T>) => {\n function func<TObject extends T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: object | undefined | null,\n config?: ObjectTypeConfig,\n ): TObject | undefined\n function func<TObject extends T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: object | undefined | null,\n assert: string | (() => string),\n config?: ObjectTypeConfig,\n ): TObject\n function func<TObject extends T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: object | undefined | null,\n assertOrConfig?: string | (() => string) | ObjectTypeConfig,\n config?: ObjectTypeConfig,\n ): TObject | undefined {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const noUndefined = (resolvedAssert: any): resolvedAssert is T => {\n return !!resolvedAssert\n }\n\n if (obj === undefined) {\n return undefined\n }\n\n if (obj === null) {\n return undefined\n }\n const resolvedAssert = typeof assertOrConfig === 'object' ? undefined : assertOrConfig\n const resolvedConfig = typeof assertOrConfig === 'object' ? assertOrConfig : config\n const result = typeCheck(obj, resolvedConfig) ? obj : undefined\n\n if (noUndefined(resolvedAssert)) {\n return assertEx(result, typeof resolvedAssert === 'function' ? resolvedAssert() : resolvedAssert) as TObject\n } else {\n return result as TObject\n }\n }\n return func\n },\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n","import { isType } from './isType'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isObject = (value: any): value is Record<string | number | symbol, any> => {\n return isType(value, 'object')\n}\n","import { AsObjectFactory } from './AsObjectFactory'\nimport { isObject } from './isObject'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const asObject = (() => AsObjectFactory.create(<T>(obj: T): obj is T => isObject(obj)))()\n","import { Logger } from '@xyo-network/logger'\n\nimport { isType, ObjectTypeShape } from './isType'\n\nexport interface ObjectTypeConfig {\n log?: boolean | Logger\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types\nexport type ObjectTypeCheck<T extends {} = {}> = (obj: any, config?: ObjectTypeConfig) => obj is T\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport class IsObjectFactory<T extends {}> {\n create(shape?: ObjectTypeShape, additionalChecks?: ObjectTypeCheck[]): ObjectTypeCheck<T> {\n return (obj, { log } = {}): obj is T => {\n if (!obj || typeof obj !== 'object') {\n return false\n }\n return (\n //do primary check\n Object.entries(shape ?? {}).reduce((prev, [key, type]) => {\n const result = isType(obj[key], type)\n if (!result && log) {\n const logger = typeof log === 'object' ? log : console\n logger.warn(`isType Failed: ${key}: ${type}`)\n }\n return prev && result\n }, true) &&\n //perform additional checks\n (additionalChecks?.reduce((prev, check) => prev && check(obj, { log }), true) ?? true)\n )\n }\n }\n}\n","import { EmptyObject } from './EmptyObject'\nimport { StringKeyObject } from './StringKeyObject'\n\nexport abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {\n readonly obj: T\n constructor(obj: T) {\n this.obj = obj\n }\n protected get stringKeyObj() {\n return this.obj as StringKeyObject\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAIlB,IAAM,kBAAkB;AAAA;AAAA,EAE7B,QAAQ,CAAmB,cAAkC;AAY3D,aAAS,KAEP,KACA,gBACA,QACqB;AAErB,YAAM,cAAc,CAACA,oBAA6C;AAChE,eAAO,CAAC,CAACA;AAAA,MACX;AAEA,UAAI,QAAQ,QAAW;AACrB,eAAO;AAAA,MACT;AAEA,UAAI,QAAQ,MAAM;AAChB,eAAO;AAAA,MACT;AACA,YAAM,iBAAiB,OAAO,mBAAmB,WAAW,SAAY;AACxE,YAAM,iBAAiB,OAAO,mBAAmB,WAAW,iBAAiB;AAC7E,YAAM,SAAS,UAAU,KAAK,cAAc,IAAI,MAAM;AAEtD,UAAI,YAAY,cAAc,GAAG;AAC/B,eAAO,SAAS,QAAQ,OAAO,mBAAmB,aAAa,eAAe,IAAI,cAAc;AAAA,MAClG,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AC1CO,IAAM,SAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA;AACE,aAAO,gBAAgB;AAAA,EAC3B;AACF;;;ACvBO,IAAM,WAAW,CAAC,UAA+D;AACtF,SAAO,OAAO,OAAO,QAAQ;AAC/B;;;ACDO,IAAM,YAAY,MAAM,gBAAgB,OAAO,CAAI,QAAqB,SAAS,GAAG,CAAC,GAAG;;;ACQxF,IAAM,kBAAN,MAAoC;AAAA,EACzC,OAAO,OAAyB,kBAA0D;AACxF,WAAO,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,MAAgB;AACtC,UAAI,CAAC,OAAO,OAAO,QAAQ,UAAU;AACnC,eAAO;AAAA,MACT;AACA;AAAA;AAAA,QAEE,OAAO,QAAQ,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM;AACxD,gBAAM,SAAS,OAAO,IAAI,GAAG,GAAG,IAAI;AACpC,cAAI,CAAC,UAAU,KAAK;AAClB,kBAAM,SAAS,OAAO,QAAQ,WAAW,MAAM;AAC/C,mBAAO,KAAK,kBAAkB,GAAG,KAAK,IAAI,EAAE;AAAA,UAC9C;AACA,iBAAO,QAAQ;AAAA,QACjB,GAAG,IAAI;AAAA,UAEN,qDAAkB,OAAO,CAAC,MAAM,UAAU,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG,UAAS;AAAA;AAAA,IAErF;AAAA,EACF;AACF;;;AC9BO,IAAe,gBAAf,MAAkE;AAAA,EAC9D;AAAA,EACT,YAAY,KAAQ;AAClB,SAAK,MAAM;AAAA,EACb;AAAA,EACA,IAAc,eAAe;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;","names":["resolvedAssert"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isObject.d.ts","sourceRoot":"","sources":["../../src/isObject.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,UAAW,GAAG,mDAElC,CAAA"}
|
package/dist/node/isObject.js
CHANGED
|
@@ -16,14 +16,38 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/isObject.ts
|
|
19
21
|
var isObject_exports = {};
|
|
20
22
|
__export(isObject_exports, {
|
|
21
23
|
isObject: () => isObject
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(isObject_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
// src/isType.ts
|
|
28
|
+
var isType = (value, expectedType) => {
|
|
29
|
+
const typeofValue = typeof value;
|
|
30
|
+
switch (expectedType) {
|
|
31
|
+
case "array":
|
|
32
|
+
return Array.isArray(value);
|
|
33
|
+
case "null":
|
|
34
|
+
return value === null;
|
|
35
|
+
case "undefined":
|
|
36
|
+
return value === void 0;
|
|
37
|
+
case "object": {
|
|
38
|
+
if (value === null) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return typeofValue === "object" && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return typeofValue === expectedType;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/isObject.ts
|
|
49
|
+
var isObject = (value) => {
|
|
50
|
+
return isType(value, "object");
|
|
27
51
|
};
|
|
28
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
53
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isObject.ts"],"sourcesContent":["import { isType } from './isType'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isObject = (value: any): value is Record<string | number | symbol, any> => {\n return isType(value, 'object')\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/isObject.ts","../../src/isType.ts"],"sourcesContent":["import { isType } from './isType'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isObject = (value: any): value is Record<string | number | symbol, any> => {\n return isType(value, 'object')\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,SAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA;AACE,aAAO,gBAAgB;AAAA,EAC3B;AACF;;;ADvBO,IAAM,WAAW,CAAC,UAA+D;AACtF,SAAO,OAAO,OAAO,QAAQ;AAC/B;","names":[]}
|
package/dist/node/isObject.mjs
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/isType.ts
|
|
2
|
+
var isType = (value, expectedType) => {
|
|
3
|
+
const typeofValue = typeof value;
|
|
4
|
+
switch (expectedType) {
|
|
5
|
+
case "array":
|
|
6
|
+
return Array.isArray(value);
|
|
7
|
+
case "null":
|
|
8
|
+
return value === null;
|
|
9
|
+
case "undefined":
|
|
10
|
+
return value === void 0;
|
|
11
|
+
case "object": {
|
|
12
|
+
if (value === null) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return typeofValue === "object" && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
default:
|
|
18
|
+
return typeofValue === expectedType;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/isObject.ts
|
|
23
|
+
var isObject = (value) => {
|
|
3
24
|
return isType(value, "object");
|
|
4
25
|
};
|
|
5
26
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isObject.ts"],"sourcesContent":["import { isType } from './isType'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isObject = (value: any): value is Record<string | number | symbol, any> => {\n return isType(value, 'object')\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/isType.ts","../../src/isObject.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n","import { isType } from './isType'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isObject = (value: any): value is Record<string | number | symbol, any> => {\n return isType(value, 'object')\n}\n"],"mappings":";AAMO,IAAM,SAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA;AACE,aAAO,gBAAgB;AAAA,EAC3B;AACF;;;ACvBO,IAAM,WAAW,CAAC,UAA+D;AACtF,SAAO,OAAO,OAAO,QAAQ;AAC/B;","names":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function';
|
|
2
|
+
export type ObjectTypeShape = Record<string | number | symbol, FieldType>;
|
|
3
|
+
export declare const isType: (value: unknown, expectedType: FieldType) => boolean;
|
|
4
|
+
//# sourceMappingURL=isType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isType.d.ts","sourceRoot":"","sources":["../../src/isType.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAA;AAE1H,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,SAAS,CAAC,CAAA;AAEzE,eAAO,MAAM,MAAM,UAAW,OAAO,gBAAgB,SAAS,YAoB7D,CAAA"}
|
package/dist/node/isType.js
CHANGED
|
@@ -16,12 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/isType.ts
|
|
19
21
|
var isType_exports = {};
|
|
20
22
|
__export(isType_exports, {
|
|
21
23
|
isType: () => isType
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(isType_exports);
|
|
24
|
-
|
|
26
|
+
var isType = (value, expectedType) => {
|
|
25
27
|
const typeofValue = typeof value;
|
|
26
28
|
switch (expectedType) {
|
|
27
29
|
case "array":
|
package/dist/node/isType.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/isType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,SAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA;AACE,aAAO,gBAAgB;AAAA,EAC3B;AACF;","names":[]}
|
package/dist/node/isType.mjs
CHANGED
package/dist/node/isType.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n"],"mappings":"AAMO,
|
|
1
|
+
{"version":3,"sources":["../../src/isType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nexport type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function'\n\nexport type ObjectTypeShape = Record<string | number | symbol, FieldType>\n\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array':\n return Array.isArray(value)\n case 'null':\n return value === null\n case 'undefined':\n return value === undefined\n case 'object': {\n //nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n //arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default:\n return typeofValue === expectedType\n }\n}\n"],"mappings":";AAMO,IAAM,SAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK;AACH,aAAO,UAAU;AAAA,IACnB,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA;AACE,aAAO,gBAAgB;AAAA,EAC3B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
},
|
|
12
12
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@xylabs/assert": "^2.
|
|
15
|
-
"@xyo-network/logger": "~2.75.
|
|
14
|
+
"@xylabs/assert": "^2.12.10",
|
|
15
|
+
"@xyo-network/logger": "~2.75.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@xylabs/ts-scripts-yarn3": "^3.0.
|
|
19
|
-
"@xylabs/tsconfig": "^3.0.
|
|
18
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.77",
|
|
19
|
+
"@xylabs/tsconfig": "^3.0.77",
|
|
20
20
|
"typescript": "^5.2.2"
|
|
21
21
|
},
|
|
22
22
|
"docs": "dist/docs.json",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
".": {
|
|
25
25
|
"browser": {
|
|
26
26
|
"require": {
|
|
27
|
-
"types": "./dist/browser/index.d.
|
|
27
|
+
"types": "./dist/browser/index.d.cts",
|
|
28
28
|
"default": "./dist/browser/index.cjs"
|
|
29
29
|
},
|
|
30
30
|
"import": {
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
},
|
|
62
62
|
"sideEffects": false,
|
|
63
63
|
"types": "dist/node/index.d.ts",
|
|
64
|
-
"version": "2.75.
|
|
64
|
+
"version": "2.75.1"
|
|
65
65
|
}
|