botbuilder-stdlib
Advanced tools
| import { Nil } from './types'; | ||
| /** | ||
| * Check if a string is nil or empty. | ||
| * | ||
| * @param val a value that may be a string | ||
| * @returns true if the string is nil or empty | ||
| */ | ||
| export declare function isNilOrEmpty(val: string | Nil): boolean; | ||
| //# sourceMappingURL=stringExt.d.ts.map |
| import { Nil } from './types'; | ||
| /** | ||
| * Check if a string is nil or empty. | ||
| * | ||
| * @param val a value that may be a string | ||
| * @returns true if the string is nil or empty | ||
| */ | ||
| export declare function isNilOrEmpty(val: string | Nil): boolean; | ||
| //# sourceMappingURL=stringExt.d.ts.map |
| {"version":3,"file":"stringExt.d.ts","sourceRoot":"","sources":["../src/stringExt.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAEvD"} |
| "use strict"; | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isNilOrEmpty = void 0; | ||
| /** | ||
| * Check if a string is nil or empty. | ||
| * | ||
| * @param val a value that may be a string | ||
| * @returns true if the string is nil or empty | ||
| */ | ||
| function isNilOrEmpty(val) { | ||
| return val == null || val === ''; | ||
| } | ||
| exports.isNilOrEmpty = isNilOrEmpty; | ||
| //# sourceMappingURL=stringExt.js.map |
| {"version":3,"file":"stringExt.js","sourceRoot":"","sources":["../src/stringExt.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,GAAiB;IAC1C,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;AACrC,CAAC;AAFD,oCAEC"} |
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| import { Nil } from './types'; | ||
| /** | ||
| * Check if a string is nil or empty. | ||
| * | ||
| * @param val a value that may be a string | ||
| * @returns true if the string is nil or empty | ||
| */ | ||
| export function isNilOrEmpty(val: string | Nil): boolean { | ||
| return val == null || val === ''; | ||
| } |
@@ -1,4 +0,4 @@ | ||
| import * as assertExt_1 from './assertExt'; | ||
| export { assertExt_1 as assertExt }; | ||
| export * from './types'; | ||
| import * as stringExt_1 from './stringExt'; | ||
| export { stringExt_1 as stringExt }; | ||
| export { delay } from './delay'; | ||
@@ -5,0 +5,0 @@ export { maybeCast } from './maybeCast'; |
+0
-475
@@ -1,2 +0,1 @@ | ||
| import { NewableError } from './assertExt'; | ||
| export declare type Nil = null | undefined; | ||
@@ -8,476 +7,2 @@ export declare type Maybe<T> = T | Nil; | ||
| }; | ||
| export declare type Dictionary<V = unknown, K extends string | number = string | number> = Record<K, V>; | ||
| export declare type Test<T> = (val: unknown) => val is T; | ||
| export declare type Assertion<T> = (val: unknown, path: string[]) => void; | ||
| /** | ||
| * An error that indicates that the source of the error was an undefined value | ||
| */ | ||
| export declare class UndefinedError extends Error { | ||
| } | ||
| /** | ||
| * Asserts `cond` to the typescript compiler | ||
| * | ||
| * @param {any} cond a condition to assert | ||
| * @param {string[]} path the accumulated path for the assertion | ||
| * @param {string} message an error message to use | ||
| * @param {NewableError} errorCtor an optional error constructor | ||
| */ | ||
| declare function condition(cond: unknown, path: string[], message: string, errorCtor?: NewableError): void; | ||
| /** | ||
| * Construct an assertion function | ||
| * | ||
| * @template T the type to assert | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Test<T>} test a method to test if an unknown value is of type `T` | ||
| * @param {boolean} acceptNil true if null or undefined values are acceptable | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| declare function makeAssertion<T>(typeName: string, test: Test<T>, acceptNil?: boolean): Assertion<T>; | ||
| /** | ||
| * Constructs a type assertion that is enforced if the value is not null or undefined | ||
| * | ||
| * @template T the type to assert | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T` or `Nil` | ||
| */ | ||
| declare function makeMaybeAssertion<T>(assertion: Assertion<T>): Assertion<Maybe<T>>; | ||
| /** | ||
| * Takes an assertion for type `T` and returns an assertion for type `Partial<T>`. The implementation | ||
| * expects that the assertion throws `UndefinedError` if an expected value is undefined. All the assertions | ||
| * exported by this package satisfy that requirement. | ||
| * | ||
| * @template T a type extending from `Dictionary` | ||
| * @param {Assertion<T>} assertion an assertion that asserts an unknown value is of type `T` | ||
| * @returns {Assertion<Partial<T>>} an assertion that asserts an unknown value is of type `Partial<T>` | ||
| */ | ||
| declare function makePartialAssertion<T extends Dictionary>(assertion: Assertion<T>): Assertion<Partial<T>>; | ||
| /** | ||
| * Test if `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `any` | ||
| */ | ||
| declare function isAny(val: unknown): val is any; | ||
| /** | ||
| * Assert that `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function any(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `any`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeAny(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `array` | ||
| */ | ||
| declare function isArray(val: unknown): val is unknown[]; | ||
| /** | ||
| * Assert that `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function array(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `array`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeArray(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `boolean` | ||
| */ | ||
| declare function isBoolean(val: unknown): val is boolean; | ||
| /** | ||
| * Assert that `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function boolean(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `boolean`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeBoolean(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Date` | ||
| */ | ||
| declare function isDate(val: unknown): val is Date; | ||
| /** | ||
| * Assert that `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function date(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `Date`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeDate(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Dictionary` | ||
| */ | ||
| declare function isDictionary(val: unknown): val is Dictionary; | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function dictionary(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeDictionary(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Error` | ||
| */ | ||
| declare function isError(val: unknown): val is Error; | ||
| /** | ||
| * Assert that `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function error(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `TypeError` | ||
| */ | ||
| declare function isTypeError(val: unknown): val is TypeError; | ||
| /** | ||
| * Assert that `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function typeError(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `UndefinedError` | ||
| */ | ||
| declare function isUndefinedError(val: unknown): val is UndefinedError; | ||
| /** | ||
| * Assert that `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function undefinedError(val: unknown, path: string[]): void; | ||
| export declare type Func<T extends unknown[] = unknown[], R = unknown> = (...args: T) => R; | ||
| /** | ||
| * Test if `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| declare function isFunc(val: unknown): val is Func; | ||
| /** | ||
| * Assert that `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function func(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `Func`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeFunc(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| declare function isNil(val: unknown): val is Nil; | ||
| /** | ||
| * Assert that `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function nil(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `string` | ||
| */ | ||
| declare function isString(val: unknown): val is string; | ||
| /** | ||
| * Test if `val` is of type `string` with zero length or `Nil`. | ||
| * | ||
| * @remarks | ||
| * Implementation of string.IsNullOrEmpty(): https://docs.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=netcore-3.1 | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of `string` with zero length or `Nil` | ||
| */ | ||
| declare function isStringNullOrEmpty(val: unknown): val is Maybe<string>; | ||
| /** | ||
| * Assert that `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function string(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `string`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeString(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `number` | ||
| */ | ||
| declare function isNumber(val: unknown): val is number; | ||
| /** | ||
| * Assert that `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function number(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `number`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeNumber(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| declare function isObject(val: unknown): val is object; | ||
| /** | ||
| * Assert that `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function object(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `object`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeObject(val: unknown, path: string[]): void; | ||
| /** | ||
| * Test if `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `unknown` | ||
| */ | ||
| declare function isUnknown(val: unknown): val is unknown; | ||
| /** | ||
| * Assert that `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function unknown(val: unknown, path: string[]): void; | ||
| /** | ||
| * Assert that `val` is of type `unknown`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeUnknown(val: unknown, path: string[]): void; | ||
| /** | ||
| * Make a type test function out of an assertion | ||
| * | ||
| * @template T the type to test | ||
| * @param {Assertion<T>} assertion an assertion | ||
| * @returns {Test<T>} a type test that returns true if an unknown value is of type `T` | ||
| */ | ||
| declare function makeTest<T>(assertion: Assertion<T>): Test<T>; | ||
| /** | ||
| * **UNSAFE** | ||
| * Test if `val` is of type `object`. | ||
| * This test does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| declare function isObjectAs<T>(val: unknown): val is T; | ||
| export declare const tests: { | ||
| isAny: typeof isAny; | ||
| isArray: typeof isArray; | ||
| isBoolean: typeof isBoolean; | ||
| isDate: typeof isDate; | ||
| isDictionary: typeof isDictionary; | ||
| isFunc: typeof isFunc; | ||
| isNil: typeof isNil; | ||
| isNumber: typeof isNumber; | ||
| isObject: typeof isObject; | ||
| isString: typeof isString; | ||
| isStringNullOrEmpty: typeof isStringNullOrEmpty; | ||
| isUnknown: typeof isUnknown; | ||
| isError: typeof isError; | ||
| isTypeError: typeof isTypeError; | ||
| isUndefinedError: typeof isUndefinedError; | ||
| fromAssertion: typeof makeTest; | ||
| toAssertion: typeof makeAssertion; | ||
| unsafe: { | ||
| isObjectAs: typeof isObjectAs; | ||
| }; | ||
| }; | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Array<T>>} an assertion that asserts an unknown value is an array with items of type `T` | ||
| */ | ||
| declare function arrayOf<T>(assertion: Assertion<T>): Assertion<Array<T>>; | ||
| /** | ||
| * Assert that `val` is of type `string[]`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function arrayOfString(val: unknown, path: string[]): void; | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T`, or `Nil` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<Array<T>>>} an assertion that asserts an unknown value is an array with | ||
| * items of type `T`, or `Nil` | ||
| */ | ||
| declare function maybeArrayOf<T>(assertion: Assertion<T>): Assertion<Maybe<Array<T>>>; | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is an instance of type `T` | ||
| */ | ||
| declare function instanceOf<T>(typeName: string, ctor: Newable<T> | Extends<T>): Assertion<T>; | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T`, or `Nil` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is an instance of type `T`, or `Nil` | ||
| */ | ||
| declare function maybeInstanceOf<T>(typeName: string, ctor: Newable<T> | Extends<T>): Assertion<Maybe<T>>; | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| declare function oneOf<T>(...tests: Array<Test<T>>): Assertion<T>; | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type, or `Nil` | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T`, or `Nil` | ||
| */ | ||
| declare function maybeOneOf<T>(...tests: Array<Test<T>>): Assertion<Maybe<T>>; | ||
| /** | ||
| * **UNSAFE** | ||
| * This assertion does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val the unknown value | ||
| * @param {string[]} path the accumulated assertion path | ||
| */ | ||
| declare function castObjectAs<T>(val: unknown, path: string[]): void; | ||
| export declare const assert: { | ||
| condition: typeof condition; | ||
| any: typeof any; | ||
| maybeAny: typeof maybeAny; | ||
| array: typeof array; | ||
| maybeArray: typeof maybeArray; | ||
| boolean: typeof boolean; | ||
| maybeBoolean: typeof maybeBoolean; | ||
| date: typeof date; | ||
| maybeDate: typeof maybeDate; | ||
| dictionary: typeof dictionary; | ||
| maybeDictionary: typeof maybeDictionary; | ||
| error: typeof error; | ||
| undefinedError: typeof undefinedError; | ||
| typeError: typeof typeError; | ||
| func: typeof func; | ||
| maybeFunc: typeof maybeFunc; | ||
| nil: typeof nil; | ||
| number: typeof number; | ||
| maybeNumber: typeof maybeNumber; | ||
| object: typeof object; | ||
| maybeObject: typeof maybeObject; | ||
| string: typeof string; | ||
| maybeString: typeof maybeString; | ||
| unknown: typeof unknown; | ||
| maybeUnknown: typeof maybeUnknown; | ||
| arrayOf: typeof arrayOf; | ||
| maybeArrayOf: typeof maybeArrayOf; | ||
| arrayOfString: typeof arrayOfString; | ||
| instanceOf: typeof instanceOf; | ||
| maybeInstanceOf: typeof maybeInstanceOf; | ||
| oneOf: typeof oneOf; | ||
| maybeOneOf: typeof maybeOneOf; | ||
| fromTest: typeof makeAssertion; | ||
| makeMaybe: typeof makeMaybeAssertion; | ||
| makePartial: typeof makePartialAssertion; | ||
| toTest: typeof makeTest; | ||
| unsafe: { | ||
| castObjectAs: typeof castObjectAs; | ||
| }; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=types.d.ts.map |
+1
-1
@@ -1,3 +0,3 @@ | ||
| export * as assertExt from './assertExt'; | ||
| export * from './types'; | ||
| export * as stringExt from './stringExt'; | ||
| export { delay } from './delay'; | ||
@@ -4,0 +4,0 @@ export { maybeCast } from './maybeCast'; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"} |
+5
-5
@@ -16,2 +16,5 @@ "use strict"; | ||
| }); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -24,9 +27,6 @@ if (mod && mod.__esModule) return mod; | ||
| }; | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.retry = exports.maybeCast = exports.delay = exports.assertExt = void 0; | ||
| exports.assertExt = __importStar(require("./assertExt")); | ||
| exports.retry = exports.maybeCast = exports.delay = exports.stringExt = void 0; | ||
| __exportStar(require("./types"), exports); | ||
| exports.stringExt = __importStar(require("./stringExt")); | ||
| var delay_1 = require("./delay"); | ||
@@ -33,0 +33,0 @@ Object.defineProperty(exports, "delay", { enumerable: true, get: function () { return delay_1.delay; } }); |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;AAElC,yDAAyC;AACzC,0CAAwB;AACxB,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;AAElC,0CAAwB;AACxB,yDAAyC;AAEzC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"} |
+0
-475
@@ -1,2 +0,1 @@ | ||
| import { NewableError } from './assertExt'; | ||
| export declare type Nil = null | undefined; | ||
@@ -8,476 +7,2 @@ export declare type Maybe<T> = T | Nil; | ||
| }; | ||
| export declare type Dictionary<V = unknown, K extends string | number = string | number> = Record<K, V>; | ||
| export declare type Test<T> = (val: unknown) => val is T; | ||
| export declare type Assertion<T> = (val: unknown, path: string[]) => asserts val is T; | ||
| /** | ||
| * An error that indicates that the source of the error was an undefined value | ||
| */ | ||
| export declare class UndefinedError extends Error { | ||
| } | ||
| /** | ||
| * Asserts `cond` to the typescript compiler | ||
| * | ||
| * @param {any} cond a condition to assert | ||
| * @param {string[]} path the accumulated path for the assertion | ||
| * @param {string} message an error message to use | ||
| * @param {NewableError} errorCtor an optional error constructor | ||
| */ | ||
| declare function condition(cond: unknown, path: string[], message: string, errorCtor?: NewableError): asserts cond; | ||
| /** | ||
| * Construct an assertion function | ||
| * | ||
| * @template T the type to assert | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Test<T>} test a method to test if an unknown value is of type `T` | ||
| * @param {boolean} acceptNil true if null or undefined values are acceptable | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| declare function makeAssertion<T>(typeName: string, test: Test<T>, acceptNil?: boolean): Assertion<T>; | ||
| /** | ||
| * Constructs a type assertion that is enforced if the value is not null or undefined | ||
| * | ||
| * @template T the type to assert | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T` or `Nil` | ||
| */ | ||
| declare function makeMaybeAssertion<T>(assertion: Assertion<T>): Assertion<Maybe<T>>; | ||
| /** | ||
| * Takes an assertion for type `T` and returns an assertion for type `Partial<T>`. The implementation | ||
| * expects that the assertion throws `UndefinedError` if an expected value is undefined. All the assertions | ||
| * exported by this package satisfy that requirement. | ||
| * | ||
| * @template T a type extending from `Dictionary` | ||
| * @param {Assertion<T>} assertion an assertion that asserts an unknown value is of type `T` | ||
| * @returns {Assertion<Partial<T>>} an assertion that asserts an unknown value is of type `Partial<T>` | ||
| */ | ||
| declare function makePartialAssertion<T extends Dictionary>(assertion: Assertion<T>): Assertion<Partial<T>>; | ||
| /** | ||
| * Test if `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `any` | ||
| */ | ||
| declare function isAny(val: unknown): val is any; | ||
| /** | ||
| * Assert that `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function any(val: unknown, path: string[]): asserts val is any; | ||
| /** | ||
| * Assert that `val` is of type `any`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeAny(val: unknown, path: string[]): asserts val is Maybe<any>; | ||
| /** | ||
| * Test if `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `array` | ||
| */ | ||
| declare function isArray(val: unknown): val is unknown[]; | ||
| /** | ||
| * Assert that `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function array(val: unknown, path: string[]): asserts val is unknown[]; | ||
| /** | ||
| * Assert that `val` is of type `array`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeArray(val: unknown, path: string[]): asserts val is Maybe<unknown[]>; | ||
| /** | ||
| * Test if `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `boolean` | ||
| */ | ||
| declare function isBoolean(val: unknown): val is boolean; | ||
| /** | ||
| * Assert that `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function boolean(val: unknown, path: string[]): asserts val is boolean; | ||
| /** | ||
| * Assert that `val` is of type `boolean`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeBoolean(val: unknown, path: string[]): asserts val is Maybe<boolean>; | ||
| /** | ||
| * Test if `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Date` | ||
| */ | ||
| declare function isDate(val: unknown): val is Date; | ||
| /** | ||
| * Assert that `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function date(val: unknown, path: string[]): asserts val is Date; | ||
| /** | ||
| * Assert that `val` is of type `Date`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeDate(val: unknown, path: string[]): asserts val is Maybe<Date>; | ||
| /** | ||
| * Test if `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Dictionary` | ||
| */ | ||
| declare function isDictionary(val: unknown): val is Dictionary; | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function dictionary(val: unknown, path: string[]): asserts val is Dictionary; | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeDictionary(val: unknown, path: string[]): asserts val is Maybe<Dictionary>; | ||
| /** | ||
| * Test if `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Error` | ||
| */ | ||
| declare function isError(val: unknown): val is Error; | ||
| /** | ||
| * Assert that `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function error(val: unknown, path: string[]): asserts val is Error; | ||
| /** | ||
| * Test if `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `TypeError` | ||
| */ | ||
| declare function isTypeError(val: unknown): val is TypeError; | ||
| /** | ||
| * Assert that `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function typeError(val: unknown, path: string[]): asserts val is TypeError; | ||
| /** | ||
| * Test if `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `UndefinedError` | ||
| */ | ||
| declare function isUndefinedError(val: unknown): val is UndefinedError; | ||
| /** | ||
| * Assert that `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function undefinedError(val: unknown, path: string[]): asserts val is UndefinedError; | ||
| export declare type Func<T extends unknown[] = unknown[], R = unknown> = (...args: T) => R; | ||
| /** | ||
| * Test if `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| declare function isFunc(val: unknown): val is Func; | ||
| /** | ||
| * Assert that `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function func(val: unknown, path: string[]): asserts val is Func; | ||
| /** | ||
| * Assert that `val` is of type `Func`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeFunc(val: unknown, path: string[]): asserts val is Maybe<Func>; | ||
| /** | ||
| * Test if `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| declare function isNil(val: unknown): val is Nil; | ||
| /** | ||
| * Assert that `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function nil(val: unknown, path: string[]): asserts val is Nil; | ||
| /** | ||
| * Test if `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `string` | ||
| */ | ||
| declare function isString(val: unknown): val is string; | ||
| /** | ||
| * Test if `val` is of type `string` with zero length or `Nil`. | ||
| * | ||
| * @remarks | ||
| * Implementation of string.IsNullOrEmpty(): https://docs.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=netcore-3.1 | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of `string` with zero length or `Nil` | ||
| */ | ||
| declare function isStringNullOrEmpty(val: unknown): val is Maybe<string>; | ||
| /** | ||
| * Assert that `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function string(val: unknown, path: string[]): asserts val is string; | ||
| /** | ||
| * Assert that `val` is of type `string`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeString(val: unknown, path: string[]): asserts val is Maybe<string>; | ||
| /** | ||
| * Test if `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `number` | ||
| */ | ||
| declare function isNumber(val: unknown): val is number; | ||
| /** | ||
| * Assert that `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function number(val: unknown, path: string[]): asserts val is number; | ||
| /** | ||
| * Assert that `val` is of type `number`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeNumber(val: unknown, path: string[]): asserts val is Maybe<number>; | ||
| /** | ||
| * Test if `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| declare function isObject(val: unknown): val is object; | ||
| /** | ||
| * Assert that `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function object(val: unknown, path: string[]): asserts val is object; | ||
| /** | ||
| * Assert that `val` is of type `object`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeObject(val: unknown, path: string[]): asserts val is Maybe<object>; | ||
| /** | ||
| * Test if `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `unknown` | ||
| */ | ||
| declare function isUnknown(val: unknown): val is unknown; | ||
| /** | ||
| * Assert that `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function unknown(val: unknown, path: string[]): asserts val is unknown; | ||
| /** | ||
| * Assert that `val` is of type `unknown`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function maybeUnknown(val: unknown, path: string[]): asserts val is Maybe<unknown>; | ||
| /** | ||
| * Make a type test function out of an assertion | ||
| * | ||
| * @template T the type to test | ||
| * @param {Assertion<T>} assertion an assertion | ||
| * @returns {Test<T>} a type test that returns true if an unknown value is of type `T` | ||
| */ | ||
| declare function makeTest<T>(assertion: Assertion<T>): Test<T>; | ||
| /** | ||
| * **UNSAFE** | ||
| * Test if `val` is of type `object`. | ||
| * This test does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| declare function isObjectAs<T>(val: unknown): val is T; | ||
| export declare const tests: { | ||
| isAny: typeof isAny; | ||
| isArray: typeof isArray; | ||
| isBoolean: typeof isBoolean; | ||
| isDate: typeof isDate; | ||
| isDictionary: typeof isDictionary; | ||
| isFunc: typeof isFunc; | ||
| isNil: typeof isNil; | ||
| isNumber: typeof isNumber; | ||
| isObject: typeof isObject; | ||
| isString: typeof isString; | ||
| isStringNullOrEmpty: typeof isStringNullOrEmpty; | ||
| isUnknown: typeof isUnknown; | ||
| isError: typeof isError; | ||
| isTypeError: typeof isTypeError; | ||
| isUndefinedError: typeof isUndefinedError; | ||
| fromAssertion: typeof makeTest; | ||
| toAssertion: typeof makeAssertion; | ||
| unsafe: { | ||
| isObjectAs: typeof isObjectAs; | ||
| }; | ||
| }; | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Array<T>>} an assertion that asserts an unknown value is an array with items of type `T` | ||
| */ | ||
| declare function arrayOf<T>(assertion: Assertion<T>): Assertion<Array<T>>; | ||
| /** | ||
| * Assert that `val` is of type `string[]`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| declare function arrayOfString(val: unknown, path: string[]): asserts val is string[]; | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T`, or `Nil` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<Array<T>>>} an assertion that asserts an unknown value is an array with | ||
| * items of type `T`, or `Nil` | ||
| */ | ||
| declare function maybeArrayOf<T>(assertion: Assertion<T>): Assertion<Maybe<Array<T>>>; | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is an instance of type `T` | ||
| */ | ||
| declare function instanceOf<T>(typeName: string, ctor: Newable<T> | Extends<T>): Assertion<T>; | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T`, or `Nil` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is an instance of type `T`, or `Nil` | ||
| */ | ||
| declare function maybeInstanceOf<T>(typeName: string, ctor: Newable<T> | Extends<T>): Assertion<Maybe<T>>; | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| declare function oneOf<T>(...tests: Array<Test<T>>): Assertion<T>; | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type, or `Nil` | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T`, or `Nil` | ||
| */ | ||
| declare function maybeOneOf<T>(...tests: Array<Test<T>>): Assertion<Maybe<T>>; | ||
| /** | ||
| * **UNSAFE** | ||
| * This assertion does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val the unknown value | ||
| * @param {string[]} path the accumulated assertion path | ||
| */ | ||
| declare function castObjectAs<T>(val: unknown, path: string[]): asserts val is T; | ||
| export declare const assert: { | ||
| condition: typeof condition; | ||
| any: typeof any; | ||
| maybeAny: typeof maybeAny; | ||
| array: typeof array; | ||
| maybeArray: typeof maybeArray; | ||
| boolean: typeof boolean; | ||
| maybeBoolean: typeof maybeBoolean; | ||
| date: typeof date; | ||
| maybeDate: typeof maybeDate; | ||
| dictionary: typeof dictionary; | ||
| maybeDictionary: typeof maybeDictionary; | ||
| error: typeof error; | ||
| undefinedError: typeof undefinedError; | ||
| typeError: typeof typeError; | ||
| func: typeof func; | ||
| maybeFunc: typeof maybeFunc; | ||
| nil: typeof nil; | ||
| number: typeof number; | ||
| maybeNumber: typeof maybeNumber; | ||
| object: typeof object; | ||
| maybeObject: typeof maybeObject; | ||
| string: typeof string; | ||
| maybeString: typeof maybeString; | ||
| unknown: typeof unknown; | ||
| maybeUnknown: typeof maybeUnknown; | ||
| arrayOf: typeof arrayOf; | ||
| maybeArrayOf: typeof maybeArrayOf; | ||
| arrayOfString: typeof arrayOfString; | ||
| instanceOf: typeof instanceOf; | ||
| maybeInstanceOf: typeof maybeInstanceOf; | ||
| oneOf: typeof oneOf; | ||
| maybeOneOf: typeof maybeOneOf; | ||
| fromTest: typeof makeAssertion; | ||
| makeMaybe: typeof makeMaybeAssertion; | ||
| makePartial: typeof makePartialAssertion; | ||
| toTest: typeof makeTest; | ||
| unsafe: { | ||
| castObjectAs: typeof castObjectAs; | ||
| }; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=types.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAmB,MAAM,aAAa,CAAC;AAG5D,oBAAY,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC;AAGnC,oBAAY,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;AAG/B,oBAAY,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AAGhF,oBAAY,OAAO,CAAC,CAAC,IAAI,QAAQ,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,CAAC;AAGrD,oBAAY,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAGhG,oBAAY,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC;AAGjD,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAK9E;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAE5C;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,G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CAAC,CAAC,IAAI,QAAQ,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,CAAC"} |
+0
-656
@@ -5,658 +5,2 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.assert = exports.tests = exports.UndefinedError = void 0; | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /* eslint-disable @typescript-eslint/ban-types */ | ||
| const assertExt_1 = require("./assertExt"); | ||
| // Formats error messages for assertion failures | ||
| const formatPathAndMessage = (path, message) => `\`${path.join('.')}\` ${message}`; | ||
| /** | ||
| * An error that indicates that the source of the error was an undefined value | ||
| */ | ||
| class UndefinedError extends Error { | ||
| } | ||
| exports.UndefinedError = UndefinedError; | ||
| /** | ||
| * Asserts `cond` to the typescript compiler | ||
| * | ||
| * @param {any} cond a condition to assert | ||
| * @param {string[]} path the accumulated path for the assertion | ||
| * @param {string} message an error message to use | ||
| * @param {NewableError} errorCtor an optional error constructor | ||
| */ | ||
| function condition(cond, path, message, errorCtor = TypeError) { | ||
| assertExt_1.assertCondition(cond, formatPathAndMessage(path, message), errorCtor); | ||
| } | ||
| /** | ||
| * Construct an assertion function | ||
| * | ||
| * @template T the type to assert | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Test<T>} test a method to test if an unknown value is of type `T` | ||
| * @param {boolean} acceptNil true if null or undefined values are acceptable | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| function makeAssertion(typeName, test, acceptNil = false) { | ||
| return (val, path) => { | ||
| if (!acceptNil) { | ||
| condition(!isNil(val), path, 'must be defined', UndefinedError); | ||
| } | ||
| condition(test(val), path, `must be of type "${typeName}"`); | ||
| }; | ||
| } | ||
| /** | ||
| * Constructs a type assertion that is enforced if the value is not null or undefined | ||
| * | ||
| * @template T the type to assert | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T` or `Nil` | ||
| */ | ||
| function makeMaybeAssertion(assertion) { | ||
| return (val, path) => { | ||
| if (!isNil(val)) { | ||
| assertion(val, path); | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Takes an assertion for type `T` and returns an assertion for type `Partial<T>`. The implementation | ||
| * expects that the assertion throws `UndefinedError` if an expected value is undefined. All the assertions | ||
| * exported by this package satisfy that requirement. | ||
| * | ||
| * @template T a type extending from `Dictionary` | ||
| * @param {Assertion<T>} assertion an assertion that asserts an unknown value is of type `T` | ||
| * @returns {Assertion<Partial<T>>} an assertion that asserts an unknown value is of type `Partial<T>` | ||
| */ | ||
| function makePartialAssertion(assertion) { | ||
| return (val, path) => { | ||
| try { | ||
| assertion(val, path); | ||
| } | ||
| catch (err) { | ||
| if (!isUndefinedError(err)) { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Test if `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `any` | ||
| */ | ||
| function isAny(val) { | ||
| return true; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function any(val, path) { | ||
| const assertion = makeAssertion('any', isAny); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `any`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeAny(val, path) { | ||
| const assertion = makeMaybeAssertion(any); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `array` | ||
| */ | ||
| function isArray(val) { | ||
| return Array.isArray(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function array(val, path) { | ||
| const assertion = makeAssertion('array', isArray); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `array`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeArray(val, path) { | ||
| const assertion = makeMaybeAssertion(array); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `boolean` | ||
| */ | ||
| function isBoolean(val) { | ||
| return typeof val === 'boolean'; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function boolean(val, path) { | ||
| const assertion = makeAssertion('boolean', isBoolean); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `boolean`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeBoolean(val, path) { | ||
| const assertion = makeMaybeAssertion(boolean); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Date` | ||
| */ | ||
| function isDate(val) { | ||
| return val instanceof Date; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function date(val, path) { | ||
| const assertion = makeAssertion('Date', isDate); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Date`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeDate(val, path) { | ||
| const assertion = makeMaybeAssertion(date); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Dictionary` | ||
| */ | ||
| function isDictionary(val) { | ||
| return isObject(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function dictionary(val, path) { | ||
| const assertion = makeAssertion('Dictionary', isDictionary); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeDictionary(val, path) { | ||
| const assertion = makeMaybeAssertion(dictionary); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Error` | ||
| */ | ||
| function isError(val) { | ||
| return val instanceof Error; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function error(val, path) { | ||
| const assertion = makeAssertion('Error', isError); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `TypeError` | ||
| */ | ||
| function isTypeError(val) { | ||
| return val instanceof TypeError; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function typeError(val, path) { | ||
| const assertion = makeAssertion('TypeError', isTypeError); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `UndefinedError` | ||
| */ | ||
| function isUndefinedError(val) { | ||
| return val instanceof UndefinedError; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function undefinedError(val, path) { | ||
| const assertion = makeAssertion('UndefinedError', isUndefinedError); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| function isFunc(val) { | ||
| return typeof val === 'function'; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function func(val, path) { | ||
| const assertion = makeAssertion('Function', isFunc); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Func`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeFunc(val, path) { | ||
| const assertion = makeMaybeAssertion(func); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| function isNil(val) { | ||
| return val == null; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function nil(val, path) { | ||
| const assertion = makeAssertion('nil', isNil, true); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `string` | ||
| */ | ||
| function isString(val) { | ||
| return typeof val === 'string'; | ||
| } | ||
| /** | ||
| * Test if `val` is of type `string` with zero length or `Nil`. | ||
| * | ||
| * @remarks | ||
| * Implementation of string.IsNullOrEmpty(): https://docs.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=netcore-3.1 | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of `string` with zero length or `Nil` | ||
| */ | ||
| function isStringNullOrEmpty(val) { | ||
| return exports.tests.isNil(val) || (exports.tests.isString(val) && !val.length); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function string(val, path) { | ||
| const assertion = makeAssertion('string', isString); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `string`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeString(val, path) { | ||
| const assertion = makeMaybeAssertion(string); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `number` | ||
| */ | ||
| function isNumber(val) { | ||
| return typeof val === 'number' && !isNaN(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function number(val, path) { | ||
| const assertion = makeAssertion('number', isNumber); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `number`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeNumber(val, path) { | ||
| const assertion = makeMaybeAssertion(number); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| function isObject(val) { | ||
| return !isNil(val) && typeof val === 'object' && !isArray(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function object(val, path) { | ||
| const assertion = makeAssertion('object', isObject); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `object`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeObject(val, path) { | ||
| const assertion = makeMaybeAssertion(object); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `unknown` | ||
| */ | ||
| function isUnknown(val) { | ||
| return true; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function unknown(val, path) { | ||
| const assertion = makeAssertion('unknown', isUnknown); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `unknown`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeUnknown(val, path) { | ||
| const assertion = makeMaybeAssertion(unknown); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Make a type test function out of an assertion | ||
| * | ||
| * @template T the type to test | ||
| * @param {Assertion<T>} assertion an assertion | ||
| * @returns {Test<T>} a type test that returns true if an unknown value is of type `T` | ||
| */ | ||
| function makeTest(assertion) { | ||
| return (val) => { | ||
| try { | ||
| assertion(val, []); | ||
| return true; | ||
| } | ||
| catch (_err) { | ||
| return false; | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * **UNSAFE** | ||
| * Test if `val` is of type `object`. | ||
| * This test does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| function isObjectAs(val) { | ||
| castObjectAs(val, []); | ||
| return isObject(val); | ||
| } | ||
| exports.tests = { | ||
| isAny, | ||
| isArray, | ||
| isBoolean, | ||
| isDate, | ||
| isDictionary, | ||
| isFunc, | ||
| isNil, | ||
| isNumber, | ||
| isObject, | ||
| isString, | ||
| isStringNullOrEmpty, | ||
| isUnknown, | ||
| isError, | ||
| isTypeError, | ||
| isUndefinedError, | ||
| fromAssertion: makeTest, | ||
| toAssertion: makeAssertion, | ||
| unsafe: { isObjectAs }, | ||
| }; | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Array<T>>} an assertion that asserts an unknown value is an array with items of type `T` | ||
| */ | ||
| function arrayOf(assertion) { | ||
| return (val, path) => { | ||
| const assertArray = array; | ||
| assertArray(val, path); | ||
| val.forEach((val, idx) => assertion(val, path.concat(`[${idx}]`))); | ||
| }; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `string[]`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function arrayOfString(val, path) { | ||
| const assertion = arrayOf(string); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T`, or `Nil` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<Array<T>>>} an assertion that asserts an unknown value is an array with | ||
| * items of type `T`, or `Nil` | ||
| */ | ||
| function maybeArrayOf(assertion) { | ||
| return (val, path) => { | ||
| const assertArrayOf = arrayOf(assertion); | ||
| const assertMaybeArrayOf = makeMaybeAssertion(assertArrayOf); | ||
| assertMaybeArrayOf(val, path); | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is an instance of type `T` | ||
| */ | ||
| function instanceOf(typeName, ctor) { | ||
| return (val, path) => { | ||
| condition(!isNil(val), path, 'must be defined', UndefinedError); | ||
| condition(val instanceof ctor, path, `must be an instance of "${typeName}"`); | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T`, or `Nil` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is an instance of type `T`, or `Nil` | ||
| */ | ||
| function maybeInstanceOf(typeName, ctor) { | ||
| return (val, path) => { | ||
| const assertInstanceOf = instanceOf(typeName, ctor); | ||
| const assertMaybeInstanceOf = makeMaybeAssertion(assertInstanceOf); | ||
| assertMaybeInstanceOf(val, path); | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| function oneOf(...tests) { | ||
| return (val, path) => { | ||
| condition(!isNil(val), path, 'must be defined', UndefinedError); | ||
| if (!tests.some((test) => test(val))) { | ||
| condition(false, path, 'is of wrong type'); | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type, or `Nil` | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T`, or `Nil` | ||
| */ | ||
| function maybeOneOf(...tests) { | ||
| return (val, path) => { | ||
| const assertOneOf = oneOf(...tests); | ||
| const assertMaybeOneOf = makeMaybeAssertion(assertOneOf); | ||
| assertMaybeOneOf(val, path); | ||
| }; | ||
| } | ||
| /** | ||
| * **UNSAFE** | ||
| * This assertion does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val the unknown value | ||
| * @param {string[]} path the accumulated assertion path | ||
| */ | ||
| function castObjectAs(val, path) { | ||
| const assertWithCast = object; | ||
| assertWithCast(val, path); | ||
| } | ||
| exports.assert = { | ||
| condition, | ||
| any, | ||
| maybeAny, | ||
| array, | ||
| maybeArray, | ||
| boolean, | ||
| maybeBoolean, | ||
| date, | ||
| maybeDate, | ||
| dictionary, | ||
| maybeDictionary, | ||
| error, | ||
| undefinedError, | ||
| typeError, | ||
| func, | ||
| maybeFunc, | ||
| nil, | ||
| number, | ||
| maybeNumber, | ||
| object, | ||
| maybeObject, | ||
| string, | ||
| maybeString, | ||
| unknown, | ||
| maybeUnknown, | ||
| arrayOf, | ||
| maybeArrayOf, | ||
| arrayOfString, | ||
| instanceOf, | ||
| maybeInstanceOf, | ||
| oneOf, | ||
| maybeOneOf, | ||
| // Some helpful, well, helpers | ||
| fromTest: makeAssertion, | ||
| makeMaybe: makeMaybeAssertion, | ||
| makePartial: makePartialAssertion, | ||
| toTest: makeTest, | ||
| unsafe: { castObjectAs }, | ||
| }; | ||
| //# sourceMappingURL=types.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uDAAuD;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uCAAuC;AACvC,kCAAkC"} |
+1
-1
@@ -5,3 +5,3 @@ { | ||
| "description": "BotBuilder shared libraries, internal only", | ||
| "version": "4.15.0-internal.dev.e9769e2", | ||
| "version": "4.15.0-rc0.internal", | ||
| "internal": true, | ||
@@ -8,0 +8,0 @@ "license": "MIT", |
+2
-1
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| export * as assertExt from './assertExt'; | ||
| export * from './types'; | ||
| export * as stringExt from './stringExt'; | ||
| export { delay } from './delay'; | ||
| export { maybeCast } from './maybeCast'; | ||
| export { retry } from './retry'; |
+0
-743
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /* eslint-disable @typescript-eslint/ban-types */ | ||
| import { NewableError, assertCondition } from './assertExt'; | ||
| // Nil describes a null or undefined value; | ||
@@ -20,739 +15,1 @@ export type Nil = null | undefined; | ||
| export type Extends<T> = Function & { prototype: T }; // eslint-disable-line @typescript-eslint/ban-types | ||
| // A dictionary type describes a common Javascript object | ||
| export type Dictionary<V = unknown, K extends string | number = string | number> = Record<K, V>; | ||
| // A type test function signature | ||
| export type Test<T> = (val: unknown) => val is T; | ||
| // A type assertion method signature | ||
| export type Assertion<T> = (val: unknown, path: string[]) => asserts val is T; | ||
| // Formats error messages for assertion failures | ||
| const formatPathAndMessage = (path: string[], message: string): string => `\`${path.join('.')}\` ${message}`; | ||
| /** | ||
| * An error that indicates that the source of the error was an undefined value | ||
| */ | ||
| export class UndefinedError extends Error {} | ||
| /** | ||
| * Asserts `cond` to the typescript compiler | ||
| * | ||
| * @param {any} cond a condition to assert | ||
| * @param {string[]} path the accumulated path for the assertion | ||
| * @param {string} message an error message to use | ||
| * @param {NewableError} errorCtor an optional error constructor | ||
| */ | ||
| function condition(cond: unknown, path: string[], message: string, errorCtor: NewableError = TypeError): asserts cond { | ||
| assertCondition(cond, formatPathAndMessage(path, message), errorCtor); | ||
| } | ||
| /** | ||
| * Construct an assertion function | ||
| * | ||
| * @template T the type to assert | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Test<T>} test a method to test if an unknown value is of type `T` | ||
| * @param {boolean} acceptNil true if null or undefined values are acceptable | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| function makeAssertion<T>(typeName: string, test: Test<T>, acceptNil = false): Assertion<T> { | ||
| return (val, path) => { | ||
| if (!acceptNil) { | ||
| condition(!isNil(val), path, 'must be defined', UndefinedError); | ||
| } | ||
| condition(test(val), path, `must be of type "${typeName}"`); | ||
| }; | ||
| } | ||
| /** | ||
| * Constructs a type assertion that is enforced if the value is not null or undefined | ||
| * | ||
| * @template T the type to assert | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T` or `Nil` | ||
| */ | ||
| function makeMaybeAssertion<T>(assertion: Assertion<T>): Assertion<Maybe<T>> { | ||
| return (val, path) => { | ||
| if (!isNil(val)) { | ||
| assertion(val, path); | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Takes an assertion for type `T` and returns an assertion for type `Partial<T>`. The implementation | ||
| * expects that the assertion throws `UndefinedError` if an expected value is undefined. All the assertions | ||
| * exported by this package satisfy that requirement. | ||
| * | ||
| * @template T a type extending from `Dictionary` | ||
| * @param {Assertion<T>} assertion an assertion that asserts an unknown value is of type `T` | ||
| * @returns {Assertion<Partial<T>>} an assertion that asserts an unknown value is of type `Partial<T>` | ||
| */ | ||
| function makePartialAssertion<T extends Dictionary>(assertion: Assertion<T>): Assertion<Partial<T>> { | ||
| return (val, path) => { | ||
| try { | ||
| assertion(val, path); | ||
| } catch (err) { | ||
| if (!isUndefinedError(err)) { | ||
| throw err; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Test if `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `any` | ||
| */ | ||
| function isAny(val: unknown): val is any { | ||
| return true; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `any`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function any(val: unknown, path: string[]): asserts val is any { | ||
| const assertion: Assertion<any> = makeAssertion('any', isAny); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `any`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeAny(val: unknown, path: string[]): asserts val is Maybe<any> { | ||
| const assertion: Assertion<Maybe<any>> = makeMaybeAssertion(any); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `array` | ||
| */ | ||
| function isArray(val: unknown): val is unknown[] { | ||
| return Array.isArray(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `array`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function array(val: unknown, path: string[]): asserts val is unknown[] { | ||
| const assertion: Assertion<unknown[]> = makeAssertion('array', isArray); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `array`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeArray(val: unknown, path: string[]): asserts val is Maybe<unknown[]> { | ||
| const assertion: Assertion<Maybe<unknown[]>> = makeMaybeAssertion(array); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `boolean` | ||
| */ | ||
| function isBoolean(val: unknown): val is boolean { | ||
| return typeof val === 'boolean'; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `boolean`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function boolean(val: unknown, path: string[]): asserts val is boolean { | ||
| const assertion: Assertion<boolean> = makeAssertion('boolean', isBoolean); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `boolean`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeBoolean(val: unknown, path: string[]): asserts val is Maybe<boolean> { | ||
| const assertion: Assertion<Maybe<boolean>> = makeMaybeAssertion(boolean); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Date` | ||
| */ | ||
| function isDate(val: unknown): val is Date { | ||
| return val instanceof Date; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Date`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function date(val: unknown, path: string[]): asserts val is Date { | ||
| const assertion: Assertion<Date> = makeAssertion('Date', isDate); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Date`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeDate(val: unknown, path: string[]): asserts val is Maybe<Date> { | ||
| const assertion: Assertion<Maybe<Date>> = makeMaybeAssertion(date); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Dictionary` | ||
| */ | ||
| function isDictionary(val: unknown): val is Dictionary { | ||
| return isObject(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function dictionary(val: unknown, path: string[]): asserts val is Dictionary { | ||
| const assertion: Assertion<Dictionary> = makeAssertion('Dictionary', isDictionary); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Dictionary`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeDictionary(val: unknown, path: string[]): asserts val is Maybe<Dictionary> { | ||
| const assertion: Assertion<Maybe<Dictionary>> = makeMaybeAssertion(dictionary); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Error` | ||
| */ | ||
| function isError(val: unknown): val is Error { | ||
| return val instanceof Error; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Error`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function error(val: unknown, path: string[]): asserts val is Error { | ||
| const assertion: Assertion<Error> = makeAssertion('Error', isError); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `TypeError` | ||
| */ | ||
| function isTypeError(val: unknown): val is TypeError { | ||
| return val instanceof TypeError; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `TypeError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function typeError(val: unknown, path: string[]): asserts val is TypeError { | ||
| const assertion: Assertion<TypeError> = makeAssertion('TypeError', isTypeError); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `UndefinedError` | ||
| */ | ||
| function isUndefinedError(val: unknown): val is UndefinedError { | ||
| return val instanceof UndefinedError; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `UndefinedError`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function undefinedError(val: unknown, path: string[]): asserts val is UndefinedError { | ||
| const assertion: Assertion<UndefinedError> = makeAssertion('UndefinedError', isUndefinedError); | ||
| assertion(val, path); | ||
| } | ||
| // Represents a generic function | ||
| export type Func<T extends unknown[] = unknown[], R = unknown> = (...args: T) => R; | ||
| /** | ||
| * Test if `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| function isFunc(val: unknown): val is Func { | ||
| return typeof val === 'function'; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Func`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function func(val: unknown, path: string[]): asserts val is Func { | ||
| const assertion: Assertion<Func> = makeAssertion('Function', isFunc); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Func`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeFunc(val: unknown, path: string[]): asserts val is Maybe<Func> { | ||
| const assertion: Assertion<Maybe<Func>> = makeMaybeAssertion(func); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `Func` | ||
| */ | ||
| function isNil(val: unknown): val is Nil { | ||
| return val == null; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function nil(val: unknown, path: string[]): asserts val is Nil { | ||
| const assertion: Assertion<Nil> = makeAssertion('nil', isNil, true); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `string` | ||
| */ | ||
| function isString(val: unknown): val is string { | ||
| return typeof val === 'string'; | ||
| } | ||
| /** | ||
| * Test if `val` is of type `string` with zero length or `Nil`. | ||
| * | ||
| * @remarks | ||
| * Implementation of string.IsNullOrEmpty(): https://docs.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=netcore-3.1 | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of `string` with zero length or `Nil` | ||
| */ | ||
| function isStringNullOrEmpty(val: unknown): val is Maybe<string> { | ||
| return tests.isNil(val) || (tests.isString(val) && !val.length); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `string`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function string(val: unknown, path: string[]): asserts val is string { | ||
| const assertion: Assertion<string> = makeAssertion('string', isString); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `string`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeString(val: unknown, path: string[]): asserts val is Maybe<string> { | ||
| const assertion: Assertion<Maybe<string>> = makeMaybeAssertion(string); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `number` | ||
| */ | ||
| function isNumber(val: unknown): val is number { | ||
| return typeof val === 'number' && !isNaN(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `number`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function number(val: unknown, path: string[]): asserts val is number { | ||
| const assertion: Assertion<number> = makeAssertion('number', isNumber); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `number`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeNumber(val: unknown, path: string[]): asserts val is Maybe<number> { | ||
| const assertion: Assertion<Maybe<number>> = makeMaybeAssertion(number); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| function isObject(val: unknown): val is object { | ||
| return !isNil(val) && typeof val === 'object' && !isArray(val); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `object`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function object(val: unknown, path: string[]): asserts val is object { | ||
| const assertion: Assertion<object> = makeAssertion('object', isObject); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `object`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeObject(val: unknown, path: string[]): asserts val is Maybe<object> { | ||
| const assertion: Assertion<Maybe<object>> = makeMaybeAssertion(object); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Test if `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `unknown` | ||
| */ | ||
| function isUnknown(val: unknown): val is unknown { | ||
| return true; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `unknown`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function unknown(val: unknown, path: string[]): asserts val is unknown { | ||
| const assertion: Assertion<unknown> = makeAssertion('unknown', isUnknown); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `unknown`, or `Nil`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function maybeUnknown(val: unknown, path: string[]): asserts val is Maybe<unknown> { | ||
| const assertion: Assertion<Maybe<unknown>> = makeMaybeAssertion(unknown); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Make a type test function out of an assertion | ||
| * | ||
| * @template T the type to test | ||
| * @param {Assertion<T>} assertion an assertion | ||
| * @returns {Test<T>} a type test that returns true if an unknown value is of type `T` | ||
| */ | ||
| function makeTest<T>(assertion: Assertion<T>): Test<T> { | ||
| return (val): val is T => { | ||
| try { | ||
| assertion(val, []); | ||
| return true; | ||
| } catch (_err) { | ||
| return false; | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * **UNSAFE** | ||
| * Test if `val` is of type `object`. | ||
| * This test does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val value to test | ||
| * @returns {boolean} true if `val` is of type `object` | ||
| */ | ||
| function isObjectAs<T>(val: unknown): val is T { | ||
| castObjectAs<T>(val, []); | ||
| return isObject(val); | ||
| } | ||
| export const tests = { | ||
| isAny, | ||
| isArray, | ||
| isBoolean, | ||
| isDate, | ||
| isDictionary, | ||
| isFunc, | ||
| isNil, | ||
| isNumber, | ||
| isObject, | ||
| isString, | ||
| isStringNullOrEmpty, | ||
| isUnknown, | ||
| isError, | ||
| isTypeError, | ||
| isUndefinedError, | ||
| fromAssertion: makeTest, | ||
| toAssertion: makeAssertion, | ||
| unsafe: { isObjectAs }, | ||
| }; | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Array<T>>} an assertion that asserts an unknown value is an array with items of type `T` | ||
| */ | ||
| function arrayOf<T>(assertion: Assertion<T>): Assertion<Array<T>> { | ||
| return (val, path) => { | ||
| const assertArray: Assertion<unknown[]> = array; | ||
| assertArray(val, path); | ||
| val.forEach((val, idx) => assertion(val, path.concat(`[${idx}]`))); | ||
| }; | ||
| } | ||
| /** | ||
| * Assert that `val` is of type `string[]`. | ||
| * | ||
| * @param {any} val value to assert | ||
| * @param {string[]} path path to val (useful for nested assertions) | ||
| */ | ||
| function arrayOfString(val: unknown, path: string[]): asserts val is string[] { | ||
| const assertion: Assertion<string[]> = arrayOf(string); | ||
| assertion(val, path); | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is an array with items of type `T`, or `Nil` | ||
| * | ||
| * @template T the item type | ||
| * @param {Assertion<T>} assertion the assertion | ||
| * @returns {Assertion<Maybe<Array<T>>>} an assertion that asserts an unknown value is an array with | ||
| * items of type `T`, or `Nil` | ||
| */ | ||
| function maybeArrayOf<T>(assertion: Assertion<T>): Assertion<Maybe<Array<T>>> { | ||
| return (val, path) => { | ||
| const assertArrayOf: Assertion<Array<T>> = arrayOf(assertion); | ||
| const assertMaybeArrayOf: Assertion<Array<T> | Nil> = makeMaybeAssertion(assertArrayOf); | ||
| assertMaybeArrayOf(val, path); | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is an instance of type `T` | ||
| */ | ||
| function instanceOf<T>(typeName: string, ctor: Newable<T> | Extends<T>): Assertion<T> { | ||
| return (val, path) => { | ||
| condition(!isNil(val), path, 'must be defined', UndefinedError); | ||
| condition(val instanceof ctor, path, `must be an instance of "${typeName}"`); | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is an instance of type `T`, or `Nil` | ||
| * | ||
| * @template T the instance type | ||
| * @param {string} typeName the name of type `T` | ||
| * @param {Newable<T> | Extends<T>} ctor a constructor reference for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is an instance of type `T`, or `Nil` | ||
| */ | ||
| function maybeInstanceOf<T>(typeName: string, ctor: Newable<T> | Extends<T>): Assertion<Maybe<T>> { | ||
| return (val, path) => { | ||
| const assertInstanceOf: Assertion<T> = instanceOf(typeName, ctor); | ||
| const assertMaybeInstanceOf: Assertion<T | Nil> = makeMaybeAssertion(assertInstanceOf); | ||
| assertMaybeInstanceOf(val, path); | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<T>} an assertion that asserts an unknown value is of type `T` | ||
| */ | ||
| function oneOf<T>(...tests: Array<Test<T>>): Assertion<T> { | ||
| return (val, path) => { | ||
| condition(!isNil(val), path, 'must be defined', UndefinedError); | ||
| if (!tests.some((test) => test(val))) { | ||
| condition(false, path, 'is of wrong type'); | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Construct an assertion that an unknown value is of type `T`, likely a union type, or `Nil` | ||
| * | ||
| * @template T the type, likely a union of other types | ||
| * @param {Array<Test<T>>} tests a set of tests for type `T` | ||
| * @returns {Assertion<Maybe<T>>} an assertion that asserts an unknown value is of type `T`, or `Nil` | ||
| */ | ||
| function maybeOneOf<T>(...tests: Array<Test<T>>): Assertion<Maybe<T>> { | ||
| return (val, path) => { | ||
| const assertOneOf: Assertion<T> = oneOf(...tests); | ||
| const assertMaybeOneOf: Assertion<T | Nil> = makeMaybeAssertion(assertOneOf); | ||
| assertMaybeOneOf(val, path); | ||
| }; | ||
| } | ||
| /** | ||
| * **UNSAFE** | ||
| * This assertion does not actually verify that `val` is of type `T`. It is useful as the first | ||
| * line in a nested assertion so that remaining assertion calls can leverage helpful intellisense. | ||
| * This method is only exported under the `unsafe` keyword as a constant reminder of this fact. | ||
| * | ||
| * @template T the type to cast `val` to, should extend `Dictionary<unknown>`, i.e. be itself an object | ||
| * @param {any} val the unknown value | ||
| * @param {string[]} path the accumulated assertion path | ||
| */ | ||
| function castObjectAs<T>(val: unknown, path: string[]): asserts val is T { | ||
| const assertWithCast: Assertion<T> = object; | ||
| assertWithCast(val, path); | ||
| } | ||
| export const assert = { | ||
| condition, | ||
| any, | ||
| maybeAny, | ||
| array, | ||
| maybeArray, | ||
| boolean, | ||
| maybeBoolean, | ||
| date, | ||
| maybeDate, | ||
| dictionary, | ||
| maybeDictionary, | ||
| error, | ||
| undefinedError, | ||
| typeError, | ||
| func, | ||
| maybeFunc, | ||
| nil, | ||
| number, | ||
| maybeNumber, | ||
| object, | ||
| maybeObject, | ||
| string, | ||
| maybeString, | ||
| unknown, | ||
| maybeUnknown, | ||
| arrayOf, | ||
| maybeArrayOf, | ||
| arrayOfString, | ||
| instanceOf, | ||
| maybeInstanceOf, | ||
| oneOf, | ||
| maybeOneOf, | ||
| // Some helpful, well, helpers | ||
| fromTest: makeAssertion, | ||
| makeMaybe: makeMaybeAssertion, | ||
| makePartial: makePartialAssertion, | ||
| toTest: makeTest, | ||
| unsafe: { castObjectAs }, | ||
| }; |
| import { Newable } from './types'; | ||
| export declare type NewableError = Newable<Error, [ | ||
| string | ||
| ]>; | ||
| /** | ||
| * Asserts `condition` to the Typescript compiler | ||
| * | ||
| * @param {any} condition a condition to assert | ||
| * @param {string} message error message | ||
| * @param {NewableError} ctor an optional constructor that makes Error instances | ||
| */ | ||
| export declare function assertCondition(condition: unknown, message: string, ctor?: NewableError): void; | ||
| //# sourceMappingURL=assertExt.d.ts.map |
| import { Newable } from './types'; | ||
| export declare type NewableError = Newable<Error, [string]>; | ||
| /** | ||
| * Asserts `condition` to the Typescript compiler | ||
| * | ||
| * @param {any} condition a condition to assert | ||
| * @param {string} message error message | ||
| * @param {NewableError} ctor an optional constructor that makes Error instances | ||
| */ | ||
| export declare function assertCondition(condition: unknown, message: string, ctor?: NewableError): asserts condition; | ||
| //# sourceMappingURL=assertExt.d.ts.map |
| {"version":3,"file":"assertExt.d.ts","sourceRoot":"","sources":["../src/assertExt.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,oBAAY,YAAY,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,YAAoB,GAAG,OAAO,CAAC,SAAS,CAIlH"} |
| "use strict"; | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.assertCondition = void 0; | ||
| /** | ||
| * Asserts `condition` to the Typescript compiler | ||
| * | ||
| * @param {any} condition a condition to assert | ||
| * @param {string} message error message | ||
| * @param {NewableError} ctor an optional constructor that makes Error instances | ||
| */ | ||
| function assertCondition(condition, message, ctor = Error) { | ||
| if (!condition) { | ||
| throw new ctor(message); | ||
| } | ||
| } | ||
| exports.assertCondition = assertCondition; | ||
| //# sourceMappingURL=assertExt.js.map |
| {"version":3,"file":"assertExt.js","sourceRoot":"","sources":["../src/assertExt.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAOlC;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,SAAkB,EAAE,OAAe,EAAE,OAAqB,KAAK;IAC3F,IAAI,CAAC,SAAS,EAAE;QACZ,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;KAC3B;AACL,CAAC;AAJD,0CAIC"} |
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| import { Newable } from './types'; | ||
| // Represents an error constructor | ||
| export type NewableError = Newable<Error, [string]>; | ||
| /** | ||
| * Asserts `condition` to the Typescript compiler | ||
| * | ||
| * @param {any} condition a condition to assert | ||
| * @param {string} message error message | ||
| * @param {NewableError} ctor an optional constructor that makes Error instances | ||
| */ | ||
| export function assertCondition(condition: unknown, message: string, ctor: NewableError = Error): asserts condition { | ||
| if (!condition) { | ||
| throw new ctor(message); | ||
| } | ||
| } |
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
19569
-82.66%357
-86.46%1
Infinity%