@bscotch/utility
Advanced tools
Comparing version 6.6.0 to 6.7.0
import type { ArrayWrapped, Defined, EmptyArray, NotFalsey, NotNullish } from '../types/utility.js'; | ||
import { Narrow } from '../types/utility/narrow.js'; | ||
import type { Narrow } from '../types/utility/narrow.js'; | ||
export declare function literal<T>(v: Narrow<T>): T; | ||
@@ -4,0 +4,0 @@ export declare function filterTruthy<T>(array: T[]): NotFalsey<T>[]; |
@@ -1,2 +0,2 @@ | ||
import { ok } from 'assert'; | ||
import { assert } from './types.js'; | ||
export * from './jsonPointer.types.js'; | ||
@@ -33,4 +33,4 @@ class Pointable { | ||
const path = ensureParsedJsonPointer(_path); | ||
ok(path.length > 0, `Path must be non-empty, otherwise the value cannot be mutated.`); | ||
ok(object, `Can only set values when there is at least a root object/array.`); | ||
assert(path.length > 0, `Path must be non-empty, otherwise the value cannot be mutated.`); | ||
assert(object, `Can only set values when there is at least a root object/array.`); | ||
let [key] = path; | ||
@@ -40,7 +40,7 @@ const [, nextKey, ...rest] = path; | ||
if (Array.isArray(object)) { | ||
ok(typeof key === 'number' || key === '-', `Array keys must be numbers or '-'`); | ||
assert(typeof key === 'number' || key === '-', `Array keys must be numbers or '-'`); | ||
key = key === '-' ? object.length : key; | ||
} | ||
else { | ||
ok(typeof object === 'object', `Pointer came across non-object/array value of type ${typeof object} at key ${key}`); | ||
assert(typeof object === 'object', `Pointer came across non-object/array value of type ${typeof object} at key ${key}`); | ||
key = String(key); | ||
@@ -59,6 +59,6 @@ } | ||
if (key in object) { | ||
ok(object[key] === undefined || typeof object[key] === 'object', `The value at key ${key} is not an object or array, and therefore cannot be indexed with key ${nextKey}`); | ||
assert(object[key] === undefined || typeof object[key] === 'object', `The value at key ${key} is not an object or array, and therefore cannot be indexed with key ${nextKey}`); | ||
} | ||
if (!(key in object) || object[key] === undefined) { | ||
ok(options?.createMissing, `Upstream key ${key} does not exist.`); | ||
assert(options?.createMissing, `Upstream key ${key} does not exist.`); | ||
object[key] = typeof nextKey === 'number' ? [] : {}; | ||
@@ -76,8 +76,8 @@ } | ||
export function ensureParsedJsonPointer(pointer) { | ||
ok(typeof pointer === 'string' || Array.isArray(pointer), 'pointer must be a string or array'); | ||
ok(typeof pointer !== 'string' || pointer === '' || pointer.startsWith('/'), 'pointer must start with "/" or be an empty string'); | ||
assert(typeof pointer === 'string' || Array.isArray(pointer), 'pointer must be a string or array'); | ||
assert(typeof pointer !== 'string' || pointer === '' || pointer.startsWith('/'), 'pointer must start with "/" or be an empty string'); | ||
pointer = typeof pointer === 'string' ? pointer.split('/').slice(1) : pointer; | ||
return pointer.map((_part) => { | ||
const part = typeof _part === 'string' && _part.match(/^\d+$/) ? Number(_part) : _part; | ||
ok(['string', 'number'].includes(typeof part), `pointer must be an array of strings and numbers: ${_part} is of type ${typeof _part}`); | ||
assert(['string', 'number'].includes(typeof part), `pointer must be an array of strings and numbers: ${_part} is of type ${typeof _part}`); | ||
return part; | ||
@@ -101,3 +101,3 @@ }); | ||
const path = ensureParsedJsonPointer(_path); | ||
ok(path.length, `Cannot delete the root of an object`); | ||
assert(path.length, `Cannot delete the root of an object`); | ||
const [key, ...rest] = path; | ||
@@ -114,3 +114,3 @@ // the `in` operator works for fields as strings and numbers, | ||
} | ||
ok(typeof +key === 'number' && !isNaN(+key), `Expected ${key} to be a number`); | ||
assert(typeof +key === 'number' && !isNaN(+key), `Expected ${key} to be a number`); | ||
object.splice(+key, 1); | ||
@@ -117,0 +117,0 @@ } |
import type { Decorator } from './decorator.js'; | ||
export { MemoizedClass } from './memoize.lib.js'; | ||
export type { MemoizedClass } from './memoize.lib.js'; | ||
/** | ||
@@ -4,0 +4,0 @@ * A simple decorator for adding caching to a class method |
import { createDecorator } from './decorator.js'; | ||
import { clearMemoized, memoizedValue } from './memoize.lib.js'; | ||
import { clearMemoized, memoizedValue, } from './memoize.lib.js'; | ||
/** | ||
@@ -4,0 +4,0 @@ * A simple decorator for adding caching to a class method |
import type { Merge } from 'type-fest'; | ||
import { Inverted, Primitive } from '../index.js'; | ||
import { PlainObject } from '../types/utility/primitives.js'; | ||
import type { Inverted } from '../types/utility.js'; | ||
import type { PlainObject, Primitive } from '../types/utility/primitives.js'; | ||
export type KeySortRef<T> = T extends Primitive ? unknown : T extends Array<infer U> ? Array<KeySortRef<U>> : T extends PlainObject<T> ? { | ||
@@ -5,0 +5,0 @@ [K in keyof T]?: unknown; |
@@ -1,2 +0,2 @@ | ||
import { arrayIsDuplicates } from '../index.js'; | ||
import { arrayIsDuplicates } from './array.js'; | ||
import { assert } from './types.js'; | ||
@@ -3,0 +3,0 @@ export function sortKeysByReference(data, reference) { |
/// <reference types="node" /> | ||
import { ArrayOrSingleton, RegExpExecArrayWithIndices } from '../index.js'; | ||
import type { ArrayOrSingleton, RegExpExecArrayWithIndices } from '../types/utility.js'; | ||
export declare function sortStringsByLength(strings: string[]): string[]; | ||
@@ -4,0 +4,0 @@ export declare function getShortestString(strings: string[]): string; |
{ | ||
"name": "@bscotch/utility", | ||
"version": "6.6.0", | ||
"version": "6.7.0", | ||
"description": "Bscotch Utilities: Methods for common Node.js needs.", | ||
@@ -22,2 +22,6 @@ "keywords": [ | ||
}, | ||
"./browser": { | ||
"types": "./dist/browser.d.ts", | ||
"import": "./dist/browser.js" | ||
}, | ||
"./decorator": { | ||
@@ -24,0 +28,0 @@ "types": "./dist/lib/decorator.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
249299
138
3583