@fuman/utils
Advanced tools
+3
-0
@@ -54,4 +54,6 @@ "use strict"; | ||
| exports.assert = assert.assert; | ||
| exports.assertHasKey = assert.assertHasKey; | ||
| exports.assertMatches = assert.assertMatches; | ||
| exports.assertNonNull = assert.assertNonNull; | ||
| exports.unsafeCastType = assert.unsafeCastType; | ||
| exports.composeMiddlewares = composer.composeMiddlewares; | ||
@@ -85,1 +87,2 @@ exports.isBigInt = guards.isBigInt; | ||
| exports.unknownToError = error.unknownToError; | ||
| exports.unreachable = error.unreachable; |
+5
-2
@@ -19,3 +19,3 @@ import { noop } from "./misc/index.js"; | ||
| import * as bundle$1 from "./iter/bundle.js"; | ||
| import { asNonNull, assert, assertMatches, assertNonNull } from "./misc/assert.js"; | ||
| import { asNonNull, assert, assertHasKey, assertMatches, assertNonNull, unsafeCastType } from "./misc/assert.js"; | ||
| import { composeMiddlewares } from "./misc/composer.js"; | ||
@@ -30,3 +30,3 @@ import { isBigInt, isBoolean, isFalsy, isFunction, isNotNull, isNotUndefined, isNumber, isObject, isString, isSymbol, isTruthy } from "./misc/guards.js"; | ||
| import { LruSet } from "./structures/lru-set.js"; | ||
| import { NotImplementedError, notImplemented, notImplemented as notImplemented2, unknownToError } from "./types/error.js"; | ||
| import { NotImplementedError, notImplemented, notImplemented as notImplemented2, unknownToError, unreachable } from "./types/error.js"; | ||
| export { | ||
@@ -50,2 +50,3 @@ AggregateError, | ||
| assertEndsWith, | ||
| assertHasKey, | ||
| assertMatches, | ||
@@ -85,3 +86,5 @@ assertNonNull, | ||
| unknownToError, | ||
| unreachable, | ||
| unsafeCastType, | ||
| utf8 | ||
| }; |
+11
-0
@@ -10,2 +10,11 @@ "use strict"; | ||
| } | ||
| function assertHasKey(obj, key) { | ||
| if (!(key in obj)) { | ||
| throw new Error(`key ${JSON.stringify(key)} not found in object`, { | ||
| cause: { obj, key } | ||
| }); | ||
| } | ||
| } | ||
| function unsafeCastType(value) { | ||
| } | ||
| function assertNonNull(value) { | ||
@@ -31,3 +40,5 @@ if (value === null || value === void 0) { | ||
| exports.assert = assert; | ||
| exports.assertHasKey = assertHasKey; | ||
| exports.assertMatches = assertMatches; | ||
| exports.assertNonNull = assertNonNull; | ||
| exports.unsafeCastType = unsafeCastType; |
| import { Brand } from '../types/brand.js'; | ||
| export declare function assert(condition: boolean, message?: unknown): asserts condition; | ||
| export declare function assertHasKey<Obj extends object, Key extends string>(obj: Obj, key: Key): asserts obj is Obj & Record<Key, unknown>; | ||
| export declare function unsafeCastType<T>(value: unknown): asserts value is T; | ||
| export declare function assertNonNull<T>(value: T): asserts value is Exclude<T, null | undefined>; | ||
| export declare function asNonNull<T>(value: null extends T ? T : undefined extends T ? T : Brand<'type is not nullable', 'TypeError'>): Exclude<T, null | undefined>; | ||
| export declare function assertMatches(str: string, regex: RegExp): RegExpMatchArray; |
+2
-0
| import { Brand } from '../types/brand.js'; | ||
| export declare function assert(condition: boolean, message?: unknown): asserts condition; | ||
| export declare function assertHasKey<Obj extends object, Key extends string>(obj: Obj, key: Key): asserts obj is Obj & Record<Key, unknown>; | ||
| export declare function unsafeCastType<T>(value: unknown): asserts value is T; | ||
| export declare function assertNonNull<T>(value: T): asserts value is Exclude<T, null | undefined>; | ||
| export declare function asNonNull<T>(value: null extends T ? T : undefined extends T ? T : Brand<'type is not nullable', 'TypeError'>): Exclude<T, null | undefined>; | ||
| export declare function assertMatches(str: string, regex: RegExp): RegExpMatchArray; |
+12
-1
@@ -8,2 +8,11 @@ function assert(condition, message) { | ||
| } | ||
| function assertHasKey(obj, key) { | ||
| if (!(key in obj)) { | ||
| throw new Error(`key ${JSON.stringify(key)} not found in object`, { | ||
| cause: { obj, key } | ||
| }); | ||
| } | ||
| } | ||
| function unsafeCastType(value) { | ||
| } | ||
| function assertNonNull(value) { | ||
@@ -30,4 +39,6 @@ if (value === null || value === void 0) { | ||
| assert, | ||
| assertHasKey, | ||
| assertMatches, | ||
| assertNonNull | ||
| assertNonNull, | ||
| unsafeCastType | ||
| }; |
+1
-1
| { | ||
| "name": "@fuman/utils", | ||
| "type": "module", | ||
| "version": "0.0.11", | ||
| "version": "0.0.14", | ||
| "description": "various utils", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
+4
-0
@@ -16,2 +16,5 @@ "use strict"; | ||
| } | ||
| function unreachable() { | ||
| throw new Error("Unreachable"); | ||
| } | ||
| exports.NotImplementedError = NotImplementedError; | ||
@@ -21,1 +24,2 @@ exports.notImplemented = notImplemented; | ||
| exports.unknownToError = unknownToError; | ||
| exports.unreachable = unreachable; |
@@ -6,2 +6,3 @@ export declare function unknownToError(err: unknown): Error; | ||
| export declare function notImplemented(message?: string): never; | ||
| export declare function unreachable(): never; | ||
| export { notImplemented as todo }; |
+1
-0
@@ -6,2 +6,3 @@ export declare function unknownToError(err: unknown): Error; | ||
| export declare function notImplemented(message?: string): never; | ||
| export declare function unreachable(): never; | ||
| export { notImplemented as todo }; |
+5
-1
@@ -14,2 +14,5 @@ function unknownToError(err) { | ||
| } | ||
| function unreachable() { | ||
| throw new Error("Unreachable"); | ||
| } | ||
| export { | ||
@@ -19,3 +22,4 @@ NotImplementedError, | ||
| notImplemented as todo, | ||
| unknownToError | ||
| unknownToError, | ||
| unreachable | ||
| }; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
170409
0.86%4990
0.79%