@xyo-network/object 2.79.4 → 2.79.5

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.
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger';
1
+ import { Logger } from '@xylabs/logger';
2
2
  import { ObjectTypeShape } from './isType';
3
3
  export interface ObjectTypeConfig {
4
4
  log?: boolean | Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
1
+ {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger';
1
+ import { Logger } from '@xylabs/logger';
2
2
  import { ObjectTypeShape } from './isType';
3
3
  export interface ObjectTypeConfig {
4
4
  log?: boolean | Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
1
+ {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger';
1
+ import { Logger } from '@xylabs/logger';
2
2
  import { ObjectTypeShape } from './isType';
3
3
  export interface ObjectTypeConfig {
4
4
  log?: boolean | Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
1
+ {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
@@ -1 +1 @@
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 './JsonObject'\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,O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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"]}
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 './JsonObject'\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 '@xylabs/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;AAA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-1 +1 @@
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.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A0D;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,SAEN,kBAAkB,OAAO,CAAC,MAAM,UAAU,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,KAAK;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"]}
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 '@xylabs/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,YAA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BAAkB,OAAO,CAAC,MAAM,UAAU,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,KAAK;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"]}
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger';
1
+ import { Logger } from '@xylabs/logger';
2
2
  import { ObjectTypeShape } from './isType';
3
3
  export interface ObjectTypeConfig {
4
4
  log?: boolean | Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
1
+ {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger';
1
+ import { Logger } from '@xylabs/logger';
2
2
  import { ObjectTypeShape } from './isType';
3
3
  export interface ObjectTypeConfig {
4
4
  log?: boolean | Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
1
+ {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger';
1
+ import { Logger } from '@xylabs/logger';
2
2
  import { ObjectTypeShape } from './isType';
3
3
  export interface ObjectTypeConfig {
4
4
  log?: boolean | Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
1
+ {"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,EAAU,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACvB;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,KAAK,GAAG,IAAI,CAAC,CAAA;AAGlG,qBAAa,eAAe,CAAC,CAAC,SAAS,EAAE;IACvC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;CAoB1F"}
@@ -1,5 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
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
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+
1
32
  // src/AsObjectFactory.ts
2
- import { assertEx } from "@xylabs/assert";
33
+ var import_assert = require("@xylabs/assert");
3
34
  var AsObjectFactory = {
4
35
  // eslint-disable-next-line @typescript-eslint/ban-types
5
36
  create: (typeCheck) => {
@@ -17,7 +48,7 @@ var AsObjectFactory = {
17
48
  const resolvedConfig = typeof assertOrConfig === "object" ? assertOrConfig : config;
18
49
  const result = typeCheck(obj, resolvedConfig) ? obj : void 0;
19
50
  if (noUndefined(resolvedAssert)) {
20
- return assertEx(result, typeof resolvedAssert === "function" ? resolvedAssert() : resolvedAssert);
51
+ return (0, import_assert.assertEx)(result, typeof resolvedAssert === "function" ? resolvedAssert() : resolvedAssert);
21
52
  } else {
22
53
  return result;
23
54
  }
@@ -88,12 +119,13 @@ var ObjectWrapper = class {
88
119
  return this.obj;
89
120
  }
90
121
  };
91
- export {
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
92
124
  AsObjectFactory,
93
125
  IsObjectFactory,
94
126
  ObjectWrapper,
95
127
  asObject,
96
128
  isObject,
97
129
  isType
98
- };
99
- //# sourceMappingURL=index.mjs.map
130
+ });
131
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
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 './JsonObject'\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 '@xylabs/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,KAE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A;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"]}
@@ -1,36 +1,5 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
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
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
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
- });
30
- module.exports = __toCommonJS(src_exports);
31
-
32
1
  // src/AsObjectFactory.ts
33
- var import_assert = require("@xylabs/assert");
2
+ import { assertEx } from "@xylabs/assert";
34
3
  var AsObjectFactory = {
35
4
  // eslint-disable-next-line @typescript-eslint/ban-types
36
5
  create: (typeCheck) => {
@@ -48,7 +17,7 @@ var AsObjectFactory = {
48
17
  const resolvedConfig = typeof assertOrConfig === "object" ? assertOrConfig : config;
49
18
  const result = typeCheck(obj, resolvedConfig) ? obj : void 0;
50
19
  if (noUndefined(resolvedAssert)) {
51
- return (0, import_assert.assertEx)(result, typeof resolvedAssert === "function" ? resolvedAssert() : resolvedAssert);
20
+ return assertEx(result, typeof resolvedAssert === "function" ? resolvedAssert() : resolvedAssert);
52
21
  } else {
53
22
  return result;
54
23
  }
@@ -119,13 +88,12 @@ var ObjectWrapper = class {
119
88
  return this.obj;
120
89
  }
121
90
  };
122
- // Annotate the CommonJS export names for ESM import in node:
123
- 0 && (module.exports = {
91
+ export {
124
92
  AsObjectFactory,
125
93
  IsObjectFactory,
126
94
  ObjectWrapper,
127
95
  asObject,
128
96
  isObject,
129
97
  isType
130
- });
98
+ };
131
99
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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 './JsonObject'\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,K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AAA;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"]}
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 '@xylabs/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,WAA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AAkE;AAAA,EAC9D;AAAA,EACT,YAAY,KAAQ;AAClB,SAAK,MAAM;AAAA,EACb;AAAA,EACA,IAAc,eAAe;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;","names":["resolvedAssert"]}
package/package.json CHANGED
@@ -11,15 +11,14 @@
11
11
  },
12
12
  "description": "Primary SDK for using XYO Protocol 2.0",
13
13
  "dependencies": {
14
- "@xylabs/assert": "^2.13.3",
15
- "@xyo-network/logger": "~2.79.4"
14
+ "@xylabs/assert": "^2.13.8",
15
+ "@xylabs/logger": "^2.13.8"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@xylabs/ts-scripts-yarn3": "^3.1.21",
19
19
  "@xylabs/tsconfig": "^3.1.21",
20
20
  "typescript": "^5.2.2"
21
21
  },
22
- "docs": "dist/docs.json",
23
22
  "exports": {
24
23
  ".": {
25
24
  "browser": {
@@ -34,19 +33,21 @@
34
33
  },
35
34
  "node": {
36
35
  "require": {
37
- "types": "./dist/node/index.d.ts",
38
- "default": "./dist/node/index.js"
36
+ "types": "./dist/node/index.d.cts",
37
+ "default": "./dist/node/index.cjs"
39
38
  },
40
39
  "import": {
41
40
  "types": "./dist/node/index.d.mts",
42
- "default": "./dist/node/index.mjs"
41
+ "default": "./dist/node/index.js"
43
42
  }
44
43
  }
45
44
  },
46
45
  "./package.json": "./package.json"
47
46
  },
48
- "main": "dist/node/index.js",
49
- "module": "dist/node/index.mjs",
47
+ "main": "dist/node/index.cjs",
48
+ "module": "dist/node/index.js",
49
+ "types": "dist/node/index.d.mts",
50
+ "type": "module",
50
51
  "homepage": "https://xyo.network",
51
52
  "license": "LGPL-3.0-or-later",
52
53
  "publishConfig": {
@@ -57,6 +58,5 @@
57
58
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
58
59
  },
59
60
  "sideEffects": false,
60
- "types": "dist/node/index.d.ts",
61
- "version": "2.79.4"
61
+ "version": "2.79.5"
62
62
  }
@@ -1,4 +1,4 @@
1
- import { Logger } from '@xyo-network/logger'
1
+ import { Logger } from '@xylabs/logger'
2
2
 
3
3
  import { isType, ObjectTypeShape } from './isType'
4
4
 
@@ -1 +0,0 @@
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,QA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