@deessejs/type-testing
Advanced tools
| /** | ||
| * Runtime comparison utilities. | ||
| */ | ||
| /** | ||
| * Result of checking if a value matches a type. | ||
| */ | ||
| export interface TypeCheckResult<T> { | ||
| matches: boolean; | ||
| value: T; | ||
| typeName: string; | ||
| } | ||
| /** | ||
| * Check if a value is a string. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isString('hello') | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isString(value: unknown): TypeCheckResult<string>; | ||
| /** | ||
| * Check if a value is a number. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isNumber(42) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isNumber(value: unknown): TypeCheckResult<number>; | ||
| /** | ||
| * Check if a value is a boolean. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isBoolean(true) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isBoolean(value: unknown): TypeCheckResult<boolean>; | ||
| /** | ||
| * Check if a value is an object. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isObject({ a: 1 }) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isObject(value: unknown): TypeCheckResult<object>; | ||
| /** | ||
| * Check if a value is an array. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isArray([1, 2, 3]) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isArray(value: unknown): TypeCheckResult<unknown[]>; | ||
| /** | ||
| * Check if a value is null. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isNull(null) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isNull(value: unknown): TypeCheckResult<null>; | ||
| /** | ||
| * Check if a value is undefined. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isUndefined(undefined) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export declare function isUndefined(value: unknown): TypeCheckResult<undefined>; | ||
| /** | ||
| * Type guard that returns true if the value is a string. | ||
| */ | ||
| export declare function isStringGuard(value: unknown): value is string; | ||
| /** | ||
| * Type guard that returns true if the value is a number. | ||
| */ | ||
| export declare function isNumberGuard(value: unknown): value is number; | ||
| /** | ||
| * Type guard that returns true if the value is a boolean. | ||
| */ | ||
| export declare function isBooleanGuard(value: unknown): value is boolean; | ||
| /** | ||
| * Type guard that returns true if the value is an object (not null, not array). | ||
| */ | ||
| export declare function isObjectGuard(value: unknown): value is object; | ||
| /** | ||
| * Type guard that returns true if the value is an array. | ||
| */ | ||
| export declare function isArrayGuard(value: unknown): value is unknown[]; | ||
| /** | ||
| * Type guard that returns true if the value is null. | ||
| */ | ||
| export declare function isNullGuard(value: unknown): value is null; | ||
| /** | ||
| * Type guard that returns true if the value is undefined. | ||
| */ | ||
| export declare function isUndefinedGuard(value: unknown): value is undefined; | ||
| /** | ||
| * Type guard that returns true if the value is a symbol. | ||
| */ | ||
| export declare function isSymbolGuard(value: unknown): value is symbol; | ||
| /** | ||
| * Type guard that returns true if the value is a bigint. | ||
| */ | ||
| export declare function isBigIntGuard(value: unknown): value is bigint; | ||
| /** | ||
| * Type guard that returns true if the value is a function. | ||
| */ | ||
| export declare function isFunctionGuard(value: unknown): value is Function; | ||
| //# sourceMappingURL=comparison.d.ts.map |
| {"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../../src/runtime/comparison.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,CAAC,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAMhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,C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wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;GAEG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAEjE"} |
| /** | ||
| * Runtime comparison utilities. | ||
| */ | ||
| /** | ||
| * Check if a value is a string. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isString('hello') | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isString(value) { | ||
| return { | ||
| matches: typeof value === 'string', | ||
| value: value, | ||
| typeName: typeof value, | ||
| }; | ||
| } | ||
| /** | ||
| * Check if a value is a number. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isNumber(42) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isNumber(value) { | ||
| return { | ||
| matches: typeof value === 'number', | ||
| value: value, | ||
| typeName: typeof value, | ||
| }; | ||
| } | ||
| /** | ||
| * Check if a value is a boolean. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isBoolean(true) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isBoolean(value) { | ||
| return { | ||
| matches: typeof value === 'boolean', | ||
| value: value, | ||
| typeName: typeof value, | ||
| }; | ||
| } | ||
| /** | ||
| * Check if a value is an object. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isObject({ a: 1 }) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isObject(value) { | ||
| return { | ||
| matches: typeof value === 'object' && value !== null, | ||
| value: value, | ||
| typeName: typeof value, | ||
| }; | ||
| } | ||
| /** | ||
| * Check if a value is an array. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isArray([1, 2, 3]) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isArray(value) { | ||
| return { | ||
| matches: Array.isArray(value), | ||
| value: value, | ||
| typeName: Array.isArray(value) ? 'array' : typeof value, | ||
| }; | ||
| } | ||
| /** | ||
| * Check if a value is null. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isNull(null) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isNull(value) { | ||
| return { | ||
| matches: value === null, | ||
| value: value, | ||
| typeName: value === null ? 'null' : typeof value, | ||
| }; | ||
| } | ||
| /** | ||
| * Check if a value is undefined. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = isUndefined(undefined) | ||
| * result.matches // true | ||
| * ``` | ||
| */ | ||
| export function isUndefined(value) { | ||
| return { | ||
| matches: value === undefined, | ||
| value: value, | ||
| typeName: value === undefined ? 'undefined' : typeof value, | ||
| }; | ||
| } | ||
| // ============================================ | ||
| // Simple boolean type guards | ||
| // ============================================ | ||
| /** | ||
| * Type guard that returns true if the value is a string. | ||
| */ | ||
| export function isStringGuard(value) { | ||
| return typeof value === 'string'; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is a number. | ||
| */ | ||
| export function isNumberGuard(value) { | ||
| return typeof value === 'number'; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is a boolean. | ||
| */ | ||
| export function isBooleanGuard(value) { | ||
| return typeof value === 'boolean'; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is an object (not null, not array). | ||
| */ | ||
| export function isObjectGuard(value) { | ||
| return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is an array. | ||
| */ | ||
| export function isArrayGuard(value) { | ||
| return Array.isArray(value); | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is null. | ||
| */ | ||
| export function isNullGuard(value) { | ||
| return value === null; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is undefined. | ||
| */ | ||
| export function isUndefinedGuard(value) { | ||
| return value === undefined; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is a symbol. | ||
| */ | ||
| export function isSymbolGuard(value) { | ||
| return typeof value === 'symbol'; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is a bigint. | ||
| */ | ||
| export function isBigIntGuard(value) { | ||
| return typeof value === 'bigint'; | ||
| } | ||
| /** | ||
| * Type guard that returns true if the value is a function. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type | ||
| export function isFunctionGuard(value) { | ||
| return typeof value === 'function'; | ||
| } | ||
| //# sourceMappingURL=comparison.js.map |
| {"version":3,"file":"comparison.js","sourceRoot":"","sources":["../../src/runtime/comparison.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,QAAQ;QAClC,KAAK,EAAE,KAAe;QACtB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,QAAQ;QAClC,KAAK,EAAE,KAAe;QACtB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,SAAS;QACnC,KAAK,EAAE,KAAgB;QACvB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QACpD,KAAK,EAAE,KAAe;QACtB,QAAQ,EAAE,OAAO,KAAK;KACvB,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC7B,KAAK,E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AAO,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,KAAK,IAAI,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,KAAK,SAAS,CAAA;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,UAAU,CAAA;AACpC,CAAC"} |
| /** | ||
| * Runtime type testing utilities. | ||
| */ | ||
| export * from './comparison.js'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAA"} |
| /** | ||
| * Runtime type testing utilities. | ||
| */ | ||
| export * from './comparison.js'; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAA"} |
+7
-1
| # @deessejs/type-testing | ||
| ## 0.2.0 | ||
| ### Minor Changes | ||
| - Add runtime type checking utilities with boolean type guards | ||
| ## 0.1.2 | ||
@@ -7,3 +13,3 @@ | ||
| - Fix ESM exports by adding explicit .js extensions to imports and exports | ||
| - Fix .npmignore to include dist folder in published package | ||
@@ -10,0 +16,0 @@ ## 0.1.1 |
+1
-0
@@ -9,2 +9,3 @@ /** | ||
| export * from './utils.js'; | ||
| export * from './runtime/index.js'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAA;AAGhC,cAAc,gBAAgB,CAAA;AAG9B,cAAc,YAAY,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAA;AAGhC,cAAc,gBAAgB,CAAA;AAG9B,cAAc,YAAY,CAAA;AAG1B,cAAc,oBAAoB,CAAA"} |
+2
-0
@@ -12,2 +12,4 @@ /** | ||
| export * from './utils.js'; | ||
| // Re-export runtime utilities | ||
| export * from './runtime/index.js'; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,kBAAkB,CAAA;AAEhC,gBAAgB;AAChB,cAAc,gBAAgB,CAAA;AAE9B,sBAAsB;AACtB,cAAc,YAAY,CAAA"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+BAA+B;AAC/B,cAAc,kBAAkB,CAAA;AAEhC,gBAAgB;AAChB,cAAc,gBAAgB,CAAA;AAE9B,sBAAsB;AACtB,cAAc,YAAY,CAAA;AAE1B,8BAA8B;AAC9B,cAAc,oBAAoB,CAAA"} |
+2
-1
| { | ||
| "name": "@deessejs/type-testing", | ||
| "version": "0.1.5", | ||
| "version": "0.2.0", | ||
| "type": "module", | ||
@@ -19,2 +19,3 @@ "main": "./dist/index.js", | ||
| "test": "vitest run", | ||
| "test:coverage": "vitest run --coverage", | ||
| "test:watch": "vitest", | ||
@@ -21,0 +22,0 @@ "clean": "rm -rf dist" |
+40
-0
@@ -167,2 +167,42 @@ # @deessejs/type-testing | ||
| ## Runtime Type Checking | ||
| The library also provides runtime type checking utilities: | ||
| ```typescript | ||
| import { | ||
| // Type check functions returning TypeCheckResult objects | ||
| isString, | ||
| isNumber, | ||
| isBoolean, | ||
| isObject, | ||
| isArray, | ||
| isNull, | ||
| isUndefined, | ||
| // Boolean type guards (for use in conditionals) | ||
| isStringGuard, | ||
| isNumberGuard, | ||
| isBooleanGuard, | ||
| isObjectGuard, | ||
| isArrayGuard, | ||
| isNullGuard, | ||
| isUndefinedGuard, | ||
| isSymbolGuard, | ||
| isBigIntGuard, | ||
| isFunctionGuard | ||
| } from '@deessejs/type-testing' | ||
| // TypeCheckResult objects | ||
| const stringResult = isString('hello') | ||
| stringResult.matches // true | ||
| stringResult.value // 'hello' | ||
| stringResult.typeName // 'string' | ||
| // Boolean type guards | ||
| if (isStringGuard(value)) { | ||
| // value is narrowed to string here | ||
| } | ||
| ``` | ||
| ## Chainable API | ||
@@ -169,0 +209,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
224330
6.03%69
13.11%844
58.35%345
13.11%0
-100%