@xylabs/promise 4.4.18 → 4.4.19

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.
@@ -3,6 +3,5 @@ export { fulfilledValues } from './fulfilledValues.ts';
3
3
  export * from './isPromise.ts';
4
4
  export * from './PromiseEx.ts';
5
5
  export { rejected } from './rejected.ts';
6
- export * from './Typed.ts';
7
6
  export * from './types.ts';
8
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,cAAc,YAAY,CAAA"}
@@ -44,54 +44,11 @@ var PromiseEx = class extends Promise {
44
44
  var rejected = (val) => {
45
45
  return val.status === "rejected";
46
46
  };
47
-
48
- // src/Typed.ts
49
- import { isType } from "@xylabs/typeof";
50
- var isTypedKey = (value) => {
51
- switch (typeof value) {
52
- case "string":
53
- case "bigint":
54
- case "number":
55
- case "symbol": {
56
- return true;
57
- }
58
- default: {
59
- return false;
60
- }
61
- }
62
- };
63
- var isTypedValue = (value) => {
64
- switch (typeof value) {
65
- case "string":
66
- case "number":
67
- case "boolean": {
68
- return true;
69
- }
70
- default: {
71
- return value === null || isTypedObject(value) || isTypedArray(value);
72
- }
73
- }
74
- };
75
- var isTypedArray = (value) => {
76
- return Array.isArray(value) && !value.some((item) => !isTypedValue(item));
77
- };
78
- var isValidTypedFieldPair = (pair) => {
79
- const [key, value] = pair;
80
- return isTypedKey(key) && isTypedValue(value);
81
- };
82
- var isTypedObject = (value) => {
83
- return isType(value, "object") && !Object.entries(value).some((item) => !isValidTypedFieldPair(item));
84
- };
85
47
  export {
86
48
  PromiseEx,
87
49
  fulfilled,
88
50
  fulfilledValues,
89
51
  isPromise,
90
- isTypedArray,
91
- isTypedKey,
92
- isTypedObject,
93
- isTypedValue,
94
- isValidTypedFieldPair,
95
52
  rejected
96
53
  };
97
54
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fulfilled.ts","../../src/fulfilledValues.ts","../../src/isPromise.ts","../../src/PromiseEx.ts","../../src/rejected.ts","../../src/Typed.ts"],"sourcesContent":["/**\n * For use with Promise.allSettled to filter only successful results\n * @param val\n * @returns\n */\nexport const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {\n return val.status === 'fulfilled'\n}\n","/**\n * For use with Promise.allSettled to reduce to only successful result values\n * @example <caption>Casting the initialValue provided to reduce</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce(fulfilledValues, [] as string[])\n * // results === [ 'resolved' ]\n * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce<string[]>(fulfilledValues, [])\n * // results === [ 'resolved' ]\n * @param previousValue\n * @param currentValue\n * @returns\n */\nexport const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {\n if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)\n return previousValue\n}\n","import type { TypedValue } from './Typed.ts'\n\nexport interface PromiseType {\n then: () => unknown\n}\n\nexport type AnyNonPromise = Exclude<TypedValue, Promise<unknown>>\n\nexport const isPromise = (value: unknown): value is Promise<unknown> => {\n if (typeof value === 'object' && !Array.isArray(value)) {\n return typeof (value as PromiseType).then === 'function'\n }\n return false\n}\n\n// type test\n/*\nconst x = Promise.resolve()\n\nconst f = (x: AnyNonPromise) => {\n return x\n}\n\nf(x)\n*/\n","export type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult\nexport type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void\nexport type PromiseExValueFunc<V> = (value?: V) => boolean\n\nexport class PromiseEx<T, V = void> extends Promise<T> {\n cancelled?: boolean\n private _value?: V\n\n constructor(func: PromiseExFunc<T>, value?: V) {\n super(func)\n this._value = value\n }\n\n // eslint-disable-next-line unicorn/no-thenable\n override then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n onvalue?: (value?: V) => boolean,\n ): Promise<TResult1 | TResult2> {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return super.then(onfulfilled, onrejected)\n }\n\n value(onvalue?: (value?: V) => boolean) {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return this\n }\n}\n","/**\n * For use with Promise.allSettled to filter only rejected results\n * @param val\n * @returns\n */\nexport const rejected = <T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult => {\n return val.status === 'rejected'\n}\n","import { isType } from '@xylabs/typeof'\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport type TypedValue = bigint | string | number | boolean | null | TypedObject | TypedArray | Function | symbol | undefined\nexport type TypedKey<T extends string | void = void> = T extends string ? T : string | number | symbol\nexport type TypedObject = { [key: TypedKey]: TypedValue } | object\nexport type TypedArray = TypedValue[]\n\nexport const isTypedKey = (value: unknown): value is TypedKey => {\n switch (typeof value) {\n case 'string':\n case 'bigint':\n case 'number':\n case 'symbol': {\n return true\n }\n default: {\n return false\n }\n }\n}\n\nexport const isTypedValue = (value: unknown): value is TypedValue => {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean': {\n return true\n }\n default: {\n return value === null || isTypedObject(value) || isTypedArray(value)\n }\n }\n}\n\nexport const isTypedArray = (value: unknown): value is TypedArray => {\n return Array.isArray(value) && !value.some(item => !isTypedValue(item))\n}\n\nexport const isValidTypedFieldPair = (pair: [key: unknown, value: unknown]): pair is [key: TypedKey, value: TypedValue] => {\n const [key, value] = pair\n return isTypedKey(key) && isTypedValue(value)\n}\n\nexport const isTypedObject = (value: unknown): value is TypedObject => {\n return (\n isType(value, 'object')\n // check if all keys are strings\n && !Object.entries(value as object).some(item => !isValidTypedFieldPair(item))\n )\n}\n\n// Object Type Test\n/*\ninterface TestObject {\n value: number\n}\n\nconst x: TestObject = { value: 1 }\n\nconst f = (p: TypedValue): void => {\n console.log(p)\n}\n\nf(x)\n*/\n"],"mappings":";AAKO,IAAM,YAAY,CAAI,QAAmE;AAC9F,SAAO,IAAI,WAAW;AACxB;;;ACWO,IAAM,kBAAkB,CAAI,eAAoB,iBAA+C;AACpG,MAAI,aAAa,WAAW,YAAa,eAAc,KAAK,aAAa,KAAK;AAC9E,SAAO;AACT;;;ACbO,IAAM,YAAY,CAAC,UAA8C;AACtE,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,GAAG;AACtD,WAAO,OAAQ,MAAsB,SAAS;AAAA,EAChD;AACA,SAAO;AACT;;;ACTO,IAAM,YAAN,cAAqC,QAAW;AAAA,EACrD;AAAA,EACQ;AAAA,EAER,YAAY,MAAwB,OAAW;AAC7C,UAAM,IAAI;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGS,KACP,aACA,YACA,SAC8B;AAC9B,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO,MAAM,KAAK,aAAa,UAAU;AAAA,EAC3C;AAAA,EAEA,MAAM,SAAkC;AACtC,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO;AAAA,EACT;AACF;;;AC1BO,IAAM,WAAW,CAAI,QAA+D;AACzF,SAAO,IAAI,WAAW;AACxB;;;ACPA,SAAS,cAAc;AAQhB,IAAM,aAAa,CAAC,UAAsC;AAC/D,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,UAAU;AACb,aAAO;AAAA,IACT;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,IAAM,eAAe,CAAC,UAAwC;AACnE,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,WAAW;AACd,aAAO;AAAA,IACT;AAAA,IACA,SAAS;AACP,aAAO,UAAU,QAAQ,cAAc,KAAK,KAAK,aAAa,KAAK;AAAA,IACrE;AAAA,EACF;AACF;AAEO,IAAM,eAAe,CAAC,UAAwC;AACnE,SAAO,MAAM,QAAQ,KAAK,KAAK,CAAC,MAAM,KAAK,UAAQ,CAAC,aAAa,IAAI,CAAC;AACxE;AAEO,IAAM,wBAAwB,CAAC,SAAqF;AACzH,QAAM,CAAC,KAAK,KAAK,IAAI;AACrB,SAAO,WAAW,GAAG,KAAK,aAAa,KAAK;AAC9C;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SACE,OAAO,OAAO,QAAQ,KAEnB,CAAC,OAAO,QAAQ,KAAe,EAAE,KAAK,UAAQ,CAAC,sBAAsB,IAAI,CAAC;AAEjF;","names":[]}
1
+ {"version":3,"sources":["../../src/fulfilled.ts","../../src/fulfilledValues.ts","../../src/isPromise.ts","../../src/PromiseEx.ts","../../src/rejected.ts"],"sourcesContent":["/**\n * For use with Promise.allSettled to filter only successful results\n * @param val\n * @returns\n */\nexport const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {\n return val.status === 'fulfilled'\n}\n","/**\n * For use with Promise.allSettled to reduce to only successful result values\n * @example <caption>Casting the initialValue provided to reduce</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce(fulfilledValues, [] as string[])\n * // results === [ 'resolved' ]\n * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce<string[]>(fulfilledValues, [])\n * // results === [ 'resolved' ]\n * @param previousValue\n * @param currentValue\n * @returns\n */\nexport const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {\n if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)\n return previousValue\n}\n","import type { TypedValue } from '@xylabs/typeof'\n\nexport interface PromiseType {\n then: () => unknown\n}\n\nexport type AnyNonPromise = Exclude<TypedValue, Promise<unknown>>\n\nexport const isPromise = (value: unknown): value is Promise<unknown> => {\n if (typeof value === 'object' && !Array.isArray(value)) {\n return typeof (value as PromiseType).then === 'function'\n }\n return false\n}\n\n// type test\n/*\nconst x = Promise.resolve()\n\nconst f = (x: AnyNonPromise) => {\n return x\n}\n\nf(x)\n*/\n","export type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult\nexport type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void\nexport type PromiseExValueFunc<V> = (value?: V) => boolean\n\nexport class PromiseEx<T, V = void> extends Promise<T> {\n cancelled?: boolean\n private _value?: V\n\n constructor(func: PromiseExFunc<T>, value?: V) {\n super(func)\n this._value = value\n }\n\n // eslint-disable-next-line unicorn/no-thenable\n override then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n onvalue?: (value?: V) => boolean,\n ): Promise<TResult1 | TResult2> {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return super.then(onfulfilled, onrejected)\n }\n\n value(onvalue?: (value?: V) => boolean) {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return this\n }\n}\n","/**\n * For use with Promise.allSettled to filter only rejected results\n * @param val\n * @returns\n */\nexport const rejected = <T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult => {\n return val.status === 'rejected'\n}\n"],"mappings":";AAKO,IAAM,YAAY,CAAI,QAAmE;AAC9F,SAAO,IAAI,WAAW;AACxB;;;ACWO,IAAM,kBAAkB,CAAI,eAAoB,iBAA+C;AACpG,MAAI,aAAa,WAAW,YAAa,eAAc,KAAK,aAAa,KAAK;AAC9E,SAAO;AACT;;;ACbO,IAAM,YAAY,CAAC,UAA8C;AACtE,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,GAAG;AACtD,WAAO,OAAQ,MAAsB,SAAS;AAAA,EAChD;AACA,SAAO;AACT;;;ACTO,IAAM,YAAN,cAAqC,QAAW;AAAA,EACrD;AAAA,EACQ;AAAA,EAER,YAAY,MAAwB,OAAW;AAC7C,UAAM,IAAI;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGS,KACP,aACA,YACA,SAC8B;AAC9B,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO,MAAM,KAAK,aAAa,UAAU;AAAA,EAC3C;AAAA,EAEA,MAAM,SAAkC;AACtC,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO;AAAA,EACT;AACF;;;AC1BO,IAAM,WAAW,CAAI,QAA+D;AACzF,SAAO,IAAI,WAAW;AACxB;","names":[]}
@@ -1,4 +1,4 @@
1
- import type { TypedValue } from './Typed.ts';
1
+ import type { TypedValue } from '@xylabs/typeof';
2
2
  export interface PromiseType {
3
3
  then: () => unknown;
4
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"isPromise.d.ts","sourceRoot":"","sources":["../../src/isPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAEjE,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,KAAK,IAAI,OAAO,CAAC,OAAO,CAKlE,CAAA"}
1
+ {"version":3,"file":"isPromise.d.ts","sourceRoot":"","sources":["../../src/isPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAEjE,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,KAAK,IAAI,OAAO,CAAC,OAAO,CAKlE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/promise",
3
- "version": "4.4.18",
3
+ "version": "4.4.19",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "promise",
@@ -36,12 +36,12 @@
36
36
  "module": "./dist/neutral/index.mjs",
37
37
  "types": "./dist/neutral/index.d.ts",
38
38
  "dependencies": {
39
- "@xylabs/typeof": "^4.4.18"
39
+ "@xylabs/typeof": "^4.4.19"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@xylabs/ts-scripts-yarn3": "^4.2.4",
43
43
  "@xylabs/tsconfig": "^4.2.4",
44
- "@xylabs/vitest-extended": "^4.4.18",
44
+ "@xylabs/vitest-extended": "^4.4.19",
45
45
  "typescript": "^5.7.2",
46
46
  "vitest": "^2.1.8"
47
47
  },
package/src/index.ts CHANGED
@@ -3,5 +3,4 @@ export { fulfilledValues } from './fulfilledValues.ts'
3
3
  export * from './isPromise.ts'
4
4
  export * from './PromiseEx.ts'
5
5
  export { rejected } from './rejected.ts'
6
- export * from './Typed.ts'
7
6
  export * from './types.ts'
package/src/isPromise.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TypedValue } from './Typed.ts'
1
+ import type { TypedValue } from '@xylabs/typeof'
2
2
 
3
3
  export interface PromiseType {
4
4
  then: () => unknown
@@ -1,12 +0,0 @@
1
- export type TypedValue = bigint | string | number | boolean | null | TypedObject | TypedArray | Function | symbol | undefined;
2
- export type TypedKey<T extends string | void = void> = T extends string ? T : string | number | symbol;
3
- export type TypedObject = {
4
- [key: TypedKey]: TypedValue;
5
- } | object;
6
- export type TypedArray = TypedValue[];
7
- export declare const isTypedKey: (value: unknown) => value is TypedKey;
8
- export declare const isTypedValue: (value: unknown) => value is TypedValue;
9
- export declare const isTypedArray: (value: unknown) => value is TypedArray;
10
- export declare const isValidTypedFieldPair: (pair: [key: unknown, value: unknown]) => pair is [key: TypedKey, value: TypedValue];
11
- export declare const isTypedObject: (value: unknown) => value is TypedObject;
12
- //# sourceMappingURL=Typed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Typed.d.ts","sourceRoot":"","sources":["../../src/Typed.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;AAC7H,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AACtG,MAAM,MAAM,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,QAAQ,GAAG,UAAU,CAAA;CAAE,GAAG,MAAM,CAAA;AAClE,MAAM,MAAM,UAAU,GAAG,UAAU,EAAE,CAAA;AAErC,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,KAAK,IAAI,QAYpD,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,UAWtD,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,UAEtD,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAG,IAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAGrH,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,KAAK,IAAI,WAMvD,CAAA"}
package/src/Typed.ts DELETED
@@ -1,66 +0,0 @@
1
- import { isType } from '@xylabs/typeof'
2
-
3
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
4
- export type TypedValue = bigint | string | number | boolean | null | TypedObject | TypedArray | Function | symbol | undefined
5
- export type TypedKey<T extends string | void = void> = T extends string ? T : string | number | symbol
6
- export type TypedObject = { [key: TypedKey]: TypedValue } | object
7
- export type TypedArray = TypedValue[]
8
-
9
- export const isTypedKey = (value: unknown): value is TypedKey => {
10
- switch (typeof value) {
11
- case 'string':
12
- case 'bigint':
13
- case 'number':
14
- case 'symbol': {
15
- return true
16
- }
17
- default: {
18
- return false
19
- }
20
- }
21
- }
22
-
23
- export const isTypedValue = (value: unknown): value is TypedValue => {
24
- switch (typeof value) {
25
- case 'string':
26
- case 'number':
27
- case 'boolean': {
28
- return true
29
- }
30
- default: {
31
- return value === null || isTypedObject(value) || isTypedArray(value)
32
- }
33
- }
34
- }
35
-
36
- export const isTypedArray = (value: unknown): value is TypedArray => {
37
- return Array.isArray(value) && !value.some(item => !isTypedValue(item))
38
- }
39
-
40
- export const isValidTypedFieldPair = (pair: [key: unknown, value: unknown]): pair is [key: TypedKey, value: TypedValue] => {
41
- const [key, value] = pair
42
- return isTypedKey(key) && isTypedValue(value)
43
- }
44
-
45
- export const isTypedObject = (value: unknown): value is TypedObject => {
46
- return (
47
- isType(value, 'object')
48
- // check if all keys are strings
49
- && !Object.entries(value as object).some(item => !isValidTypedFieldPair(item))
50
- )
51
- }
52
-
53
- // Object Type Test
54
- /*
55
- interface TestObject {
56
- value: number
57
- }
58
-
59
- const x: TestObject = { value: 1 }
60
-
61
- const f = (p: TypedValue): void => {
62
- console.log(p)
63
- }
64
-
65
- f(x)
66
- */