@softwareventures/nullable
Advanced tools
+10
-10
@@ -8,3 +8,3 @@ /** Tests if the specified value is null or undefined. | ||
| * Useful as the predicate of filter functions and similar. */ | ||
| export declare function isNotNull<T>(value: T | null | undefined): value is T; | ||
| export declare function isNotNull<T>(value: T | null | undefined | void): value is T; | ||
| /** Asserts that the specified value is neither null nor undefined, and | ||
@@ -14,3 +14,3 @@ * returns it. | ||
| * @throws TypeError if the value is null or undefined */ | ||
| export declare function notNull<T>(value: T | null | undefined): T; | ||
| export declare function notNull<T>(value: T | null | undefined | void): T; | ||
| /** Returns the specified value, or the default value if the specified value | ||
@@ -21,3 +21,3 @@ * is null or undefined. | ||
| * {@link mapNull} instead. */ | ||
| export declare function defaultValue<T>(nullable: T | undefined | null, defaultValue: T): T; | ||
| export declare function defaultValue<T>(nullable: T | undefined | null | void, defaultValue: T): T; | ||
| /** Returns a function that returns the specified value, or the default value | ||
@@ -28,3 +28,3 @@ * if the specified value is null or undefined. | ||
| * {@link mapNullFn} instead. */ | ||
| export declare function defaultValueFn<T>(defaultValue: T): (nullable: T | undefined | null) => T; | ||
| export declare function defaultValueFn<T>(defaultValue: T): (nullable: T | undefined | null | void) => T; | ||
| /** If the specified value is null or undefined, returns null. | ||
@@ -34,3 +34,3 @@ * | ||
| * the return value of that function. */ | ||
| export declare function map<T, U>(nullable: T | undefined | null, f: (element: T) => U): U | null; | ||
| export declare function map<T, U>(nullable: T | undefined | null | void, f: (element: T) => U): U | null; | ||
| /** Returns a function that takes a nullable value as its argument. | ||
@@ -44,3 +44,3 @@ * | ||
| * Curried variant of {@link map}. */ | ||
| export declare function mapFn<T, U>(f: (element: T) => U): (nullable: T | undefined | null) => U | null; | ||
| export declare function mapFn<T, U>(f: (element: T) => U): (nullable: T | undefined | null | void) => U | null; | ||
| /** If the specified value is null or undefined, returns null. | ||
@@ -52,3 +52,3 @@ * | ||
| * Alias for {@link map}. */ | ||
| export declare function mapNullable<T, U>(nullable: T | undefined | null, f: (element: T) => U): U | null; | ||
| export declare function mapNullable<T, U>(nullable: T | undefined | null | void, f: (element: T) => U): U | null; | ||
| /** Returns a function that takes a nullable value as its argument. | ||
@@ -62,3 +62,3 @@ * | ||
| * Alias for {@link mapFn}, which is a curried variant of {@link map}. */ | ||
| export declare function mapNullableFn<T, U>(f: (element: T) => U): (nullable: T | undefined | null) => U | null; | ||
| export declare function mapNullableFn<T, U>(f: (element: T) => U): (nullable: T | undefined | null | void) => U | null; | ||
| /** Returns the specified value or, if the value is null or undefined, calls | ||
@@ -69,3 +69,3 @@ * the provided callback and returns the result of that function call. | ||
| * expensive to compute. */ | ||
| export declare function mapNull<T, U = T>(nullable: T | undefined | null, f: () => U): T | U; | ||
| export declare function mapNull<T, U = T>(nullable: T | undefined | null | void, f: () => U): T | U; | ||
| /** Returns a function that returns the specified value or, if the value is | ||
@@ -77,2 +77,2 @@ * null or undefined, calls the provided callback and returns the result of | ||
| * expensive to compute. */ | ||
| export declare function mapNullFn<T, U = T>(f: () => U): (nullable: T | undefined | null) => T | U; | ||
| export declare function mapNullFn<T, U = T>(f: () => U): (nullable: T | undefined | null | void) => T | U; |
+10
-1
@@ -14,2 +14,3 @@ "use strict"; | ||
| * Useful as the predicate of filter functions and similar. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function isNotNull(value) { | ||
@@ -23,2 +24,3 @@ return value != null; | ||
| * @throws TypeError if the value is null or undefined */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function notNull(value) { | ||
@@ -36,2 +38,3 @@ if (value == null) { | ||
| * {@link mapNull} instead. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function defaultValue(nullable, defaultValue) { | ||
@@ -46,2 +49,3 @@ return nullable !== null && nullable !== void 0 ? nullable : defaultValue; | ||
| * {@link mapNullFn} instead. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function defaultValueFn(defaultValue) { | ||
@@ -55,2 +59,3 @@ return nullable => nullable !== null && nullable !== void 0 ? nullable : defaultValue; | ||
| * the return value of that function. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function map(nullable, f) { | ||
@@ -69,3 +74,5 @@ var _a; | ||
| * Curried variant of {@link map}. */ | ||
| function mapFn(f) { | ||
| function mapFn(f | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| ) { | ||
| return nullable => map(nullable, f); | ||
@@ -87,2 +94,3 @@ } | ||
| * expensive to compute. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function mapNull(nullable, f) { | ||
@@ -98,2 +106,3 @@ return nullable == null ? f() : nullable; | ||
| * expensive to compute. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| function mapNullFn(f) { | ||
@@ -100,0 +109,0 @@ return nullable => mapNull(nullable, f); |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA;;8DAE8D;AAC9D,SAAgB,MAAM,CAAI,KAAc;IACpC,OAAO,KAAK,IAAI,IAAI,CAAC;AACzB,CAAC;AAFD,wBAEC;AAED;;8DAE8D;AAC9D,SAAgB,SAAS,CAAI,KAA2B;IACpD,OAAO,KAAK,IAAI,IAAI,CAAC;AACzB,CAAC;AAFD,8BAEC;AAED;;;yDAGyD;AACzD,SAAgB,OAAO,CAAI,KAA2B;IAClD,IAAI,KAAK,IAAI,IAAI,EAAE;QACf,MAAM,IAAI,SAAS,CAAC,YAAY,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;KACpD;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAND,0BAMC;AAED;;;;8BAI8B;AAC9B,SAAgB,YAAY,CAAI,QAA8B,EAAE,YAAe;IAC3E,OAAO,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,YAAY,CAAC;AACpC,CAAC;AAFD,oCAEC;AAED;;;;gCAIgC;AAChC,SAAgB,cAAc,CAAI,YAAe;IAC7C,OAAO,QAAQ,CAAC,EAAE,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,YAAY,CAAC;AAChD,CAAC;AAFD,wCAEC;AAED;;;wCAGwC;AACxC,SAAgB,GAAG,CAAO,QAA8B,EAAE,CAAoB;;IAC1E,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAA,CAAC,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC;AACzD,CAAC;AAFD,kBAEC;AAED;;;;;;;qCAOqC;AACrC,SAAgB,KAAK,CAAO,CAAoB;IAC5C,OAAO,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAFD,sBAEC;AAYD,gBAAgB;AAChB,6DAA6D;AAC7D,4EAA4E;AAC/D,QAAA,WAAW,GAAG,GAAG,CAAC;AAgB/B,gBAAgB;AAChB,6DAA6D;AAC7D,4EAA4E;AAC/D,QAAA,aAAa,GAAG,KAAK,CAAC;AAEnC;;;;2BAI2B;AAC3B,SAAgB,OAAO,CAAW,QAA8B,EAAE,CAAU;IACxE,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7C,CAAC;AAFD,0BAEC;AAED;;;;;2BAK2B;AAC3B,SAAgB,SAAS,CAAW,CAAU;IAC1C,OAAO,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AAC5C,CAAC;AAFD,8BAEC","sourcesContent":["/** Tests if the specified value is null or undefined.\n *\n * Useful as the predicate of filter functions and similar. */\nexport function isNull<T>(value: unknown): value is null | undefined {\n return value == null;\n}\n\n/** Tests if the specified value is null or undefined.\n *\n * Useful as the predicate of filter functions and similar. */\nexport function isNotNull<T>(value: T | null | undefined): value is T {\n return value != null;\n}\n\n/** Asserts that the specified value is neither null nor undefined, and\n * returns it.\n *\n * @throws TypeError if the value is null or undefined */\nexport function notNull<T>(value: T | null | undefined): T {\n if (value == null) {\n throw new TypeError(`value is ${String(value)}`);\n }\n\n return value;\n}\n\n/** Returns the specified value, or the default value if the specified value\n * is null or undefined.\n *\n * If the default value is expensive to compute, consider using\n * {@link mapNull} instead. */\nexport function defaultValue<T>(nullable: T | undefined | null, defaultValue: T): T {\n return nullable ?? defaultValue;\n}\n\n/** Returns a function that returns the specified value, or the default value\n * if the specified value is null or undefined.\n *\n * If the default value is expensive to compute, consider using\n * {@link mapNullFn} instead. */\nexport function defaultValueFn<T>(defaultValue: T): (nullable: T | undefined | null) => T {\n return nullable => nullable ?? defaultValue;\n}\n\n/** If the specified value is null or undefined, returns null.\n *\n * Otherwise, passes the specified value to the provided function and returns\n * the return value of that function. */\nexport function map<T, U>(nullable: T | undefined | null, f: (element: T) => U): U | null {\n return nullable == null ? null : f(nullable) ?? null;\n}\n\n/** Returns a function that takes a nullable value as its argument.\n *\n * If the function is called with null or undefined, it returns null.\n *\n * Otherwise, the argument is passed to the callback `f` and the\n * return value of `f` is returned.\n *\n * Curried variant of {@link map}. */\nexport function mapFn<T, U>(f: (element: T) => U): (nullable: T | undefined | null) => U | null {\n return nullable => map(nullable, f);\n}\n\n/** If the specified value is null or undefined, returns null.\n *\n * Otherwise, passes the specified value to the provided function and returns\n * the return value of that function.\n *\n * Alias for {@link map}. */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the exported declaration, the actual implementation is below.\nexport function mapNullable<T, U>(nullable: T | undefined | null, f: (element: T) => U): U | null;\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the implementation, the exported declaration is above.\nexport const mapNullable = map;\n\n/** Returns a function that takes a nullable value as its argument.\n *\n * If the function is called with null or undefined, it returns null.\n *\n * Otherwise, the argument is passed to the callback `f` and the\n * return value of `f` is returned.\n *\n * Alias for {@link mapFn}, which is a curried variant of {@link map}. */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the exported declaration, the actual implementation is below.\nexport function mapNullableFn<T, U>(\n f: (element: T) => U\n): (nullable: T | undefined | null) => U | null;\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the implementation, the exported declaration is above.\nexport const mapNullableFn = mapFn;\n\n/** Returns the specified value or, if the value is null or undefined, calls\n * the provided callback and returns the result of that function call.\n *\n * Useful as an alternative to {@link defaultValue} if the default value is\n * expensive to compute. */\nexport function mapNull<T, U = T>(nullable: T | undefined | null, f: () => U): T | U {\n return nullable == null ? f() : nullable;\n}\n\n/** Returns a function that returns the specified value or, if the value is\n * null or undefined, calls the provided callback and returns the result of\n * that function call.\n *\n * Useful as an alternative to {@link defaultValueFn} if the default value is\n * expensive to compute. */\nexport function mapNullFn<T, U = T>(f: () => U): (nullable: T | undefined | null) => T | U {\n return nullable => mapNull(nullable, f);\n}\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA;;8DAE8D;AAC9D,SAAgB,MAAM,CAAI,KAAc;IACpC,OAAO,KAAK,IAAI,IAAI,CAAC;AACzB,CAAC;AAFD,wBAEC;AAED;;8DAE8D;AAC9D,mEAAmE;AACnE,SAAgB,SAAS,CAAI,KAAkC;IAC3D,OAAO,KAAK,IAAI,IAAI,CAAC;AACzB,CAAC;AAFD,8BAEC;AAED;;;yDAGyD;AACzD,mEAAmE;AACnE,SAAgB,OAAO,CAAI,KAAkC;IACzD,IAAI,KAAK,IAAI,IAAI,EAAE;QACf,MAAM,IAAI,SAAS,CAAC,YAAY,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;KACpD;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAND,0BAMC;AAED;;;;8BAI8B;AAC9B,mEAAmE;AACnE,SAAgB,YAAY,CAAI,QAAqC,EAAE,YAAe;IAClF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.\n *\n * Useful as the predicate of filter functions and similar. */\nexport function isNull<T>(value: unknown): value is null | undefined {\n return value == null;\n}\n\n/** Tests if the specified value is null or undefined.\n *\n * Useful as the predicate of filter functions and similar. */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function isNotNull<T>(value: T | null | undefined | void): value is T {\n return value != null;\n}\n\n/** Asserts that the specified value is neither null nor undefined, and\n * returns it.\n *\n * @throws TypeError if the value is null or undefined */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function notNull<T>(value: T | null | undefined | void): T {\n if (value == null) {\n throw new TypeError(`value is ${String(value)}`);\n }\n\n return value;\n}\n\n/** Returns the specified value, or the default value if the specified value\n * is null or undefined.\n *\n * If the default value is expensive to compute, consider using\n * {@link mapNull} instead. */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function defaultValue<T>(nullable: T | undefined | null | void, defaultValue: T): T {\n return nullable ?? defaultValue;\n}\n\n/** Returns a function that returns the specified value, or the default value\n * if the specified value is null or undefined.\n *\n * If the default value is expensive to compute, consider using\n * {@link mapNullFn} instead. */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function defaultValueFn<T>(defaultValue: T): (nullable: T | undefined | null | void) => T {\n return nullable => nullable ?? defaultValue;\n}\n\n/** If the specified value is null or undefined, returns null.\n *\n * Otherwise, passes the specified value to the provided function and returns\n * the return value of that function. */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function map<T, U>(nullable: T | undefined | null | void, f: (element: T) => U): U | null {\n return nullable == null ? null : f(nullable) ?? null;\n}\n\n/** Returns a function that takes a nullable value as its argument.\n *\n * If the function is called with null or undefined, it returns null.\n *\n * Otherwise, the argument is passed to the callback `f` and the\n * return value of `f` is returned.\n *\n * Curried variant of {@link map}. */\nexport function mapFn<T, U>(\n f: (element: T) => U\n // eslint-disable-next-line @typescript-eslint/no-invalid-void-type\n): (nullable: T | undefined | null | void) => U | null {\n return nullable => map(nullable, f);\n}\n\n/** If the specified value is null or undefined, returns null.\n *\n * Otherwise, passes the specified value to the provided function and returns\n * the return value of that function.\n *\n * Alias for {@link map}. */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the exported declaration, the actual implementation is below.\nexport function mapNullable<T, U>(\n // eslint-disable-next-line @typescript-eslint/no-invalid-void-type\n nullable: T | undefined | null | void,\n f: (element: T) => U\n): U | null;\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the implementation, the exported declaration is above.\nexport const mapNullable = map;\n\n/** Returns a function that takes a nullable value as its argument.\n *\n * If the function is called with null or undefined, it returns null.\n *\n * Otherwise, the argument is passed to the callback `f` and the\n * return value of `f` is returned.\n *\n * Alias for {@link mapFn}, which is a curried variant of {@link map}. */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the exported declaration, the actual implementation is below.\nexport function mapNullableFn<T, U>(\n f: (element: T) => U\n // eslint-disable-next-line @typescript-eslint/no-invalid-void-type\n): (nullable: T | undefined | null | void) => U | null;\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore This is the implementation, the exported declaration is above.\nexport const mapNullableFn = mapFn;\n\n/** Returns the specified value or, if the value is null or undefined, calls\n * the provided callback and returns the result of that function call.\n *\n * Useful as an alternative to {@link defaultValue} if the default value is\n * expensive to compute. */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function mapNull<T, U = T>(nullable: T | undefined | null | void, f: () => U): T | U {\n return nullable == null ? f() : nullable;\n}\n\n/** Returns a function that returns the specified value or, if the value is\n * null or undefined, calls the provided callback and returns the result of\n * that function call.\n *\n * Useful as an alternative to {@link defaultValueFn} if the default value is\n * expensive to compute. */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport function mapNullFn<T, U = T>(f: () => U): (nullable: T | undefined | null | void) => T | U {\n return nullable => mapNull(nullable, f);\n}\n"]} |
+15
-14
| { | ||
| "name": "@softwareventures/nullable", | ||
| "version": "3.0.0", | ||
| "version": "3.1.0", | ||
| "description": "Pure functional utilities for nullable types", | ||
@@ -29,23 +29,24 @@ "keywords": [ | ||
| "dependencies": { | ||
| "tslib": "2.4.0" | ||
| "tslib": "2.4.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@softwareventures/eslint-config": "7.0.1", | ||
| "@softwareventures/prettier-config": "3.0.0", | ||
| "@softwareventures/semantic-release-config": "2.0.3", | ||
| "@softwareventures/tsconfig": "5.1.1", | ||
| "@typescript-eslint/eslint-plugin": "5.40.0", | ||
| "@typescript-eslint/parser": "5.40.0", | ||
| "ava": "4.3.3", | ||
| "@softwareventures/eslint-config": "7.1.0", | ||
| "@softwareventures/prettier-config": "4.0.0", | ||
| "@softwareventures/semantic-release-config": "3.1.0", | ||
| "@softwareventures/tsconfig": "7.0.0", | ||
| "@typescript-eslint/eslint-plugin": "5.44.0", | ||
| "@typescript-eslint/parser": "5.44.0", | ||
| "ava": "5.1.0", | ||
| "cz-conventional-changelog": "3.3.0", | ||
| "eslint": "8.25.0", | ||
| "eslint": "8.28.0", | ||
| "eslint-config-prettier": "8.5.0", | ||
| "eslint-plugin-import": "2.26.0", | ||
| "eslint-plugin-jsdoc": "39.3.6", | ||
| "eslint-plugin-jsdoc": "39.6.4", | ||
| "eslint-plugin-prefer-arrow": "1.2.3", | ||
| "eslint-plugin-sonarjs": "0.16.0", | ||
| "prettier": "2.7.1", | ||
| "semantic-release": "17.4.7", | ||
| "prettier": "2.8.0", | ||
| "semantic-release": "19.0.5", | ||
| "ts-expect": "1.3.0", | ||
| "ts-node": "10.9.1", | ||
| "typescript": "4.8.4" | ||
| "typescript": "4.9.3" | ||
| }, | ||
@@ -52,0 +53,0 @@ "eslintConfig": { |
17419
9.71%171
5.56%19
5.56%+ Added
- Removed
Updated