@saulx/utils
Advanced tools
Comparing version 3.2.2 to 3.3.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encodeBase64 = exports.decodeBase64 = void 0; | ||
const b64ToUint6 = (nChr) => { | ||
@@ -29,3 +30,3 @@ return nChr > 64 && nChr < 91 | ||
}; | ||
exports.decodeBase64 = (base64String, nBlocksSize) => { | ||
const decodeBase64 = (base64String, nBlocksSize) => { | ||
// Only necessary if the base64 includes whitespace such as line breaks | ||
@@ -57,3 +58,4 @@ const sB64Enc = base64String.replace(/[^A-Za-z0-9+/]/g, ''); | ||
}; | ||
exports.encodeBase64 = (utf8Array) => { | ||
exports.decodeBase64 = decodeBase64; | ||
const encodeBase64 = (utf8Array) => { | ||
let nMod3 = 2; | ||
@@ -78,2 +80,3 @@ let sB64Enc = ''; | ||
}; | ||
exports.encodeBase64 = encodeBase64; | ||
//# sourceMappingURL=base64.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deepMerge = exports.deepMergeArrays = void 0; | ||
const merge = (target, source) => { | ||
@@ -4,0 +5,0 @@ if (source.constructor === Array) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createDecode = (isLong, longest, encodeChars = ['$'], reverseCharMap) => { | ||
exports.createDecode = void 0; | ||
const createDecode = (isLong, longest, encodeChars = ['$'], reverseCharMap) => { | ||
if (encodeChars.length > 1 && isLong) { | ||
@@ -81,2 +82,3 @@ // only isLong for now... | ||
}; | ||
exports.createDecode = createDecode; | ||
//# sourceMappingURL=decode.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createEncode = void 0; | ||
const cycleChars = (encodeChars, encodeCharIndex) => { | ||
@@ -9,3 +10,3 @@ if (encodeCharIndex % 2) { | ||
}; | ||
exports.createEncode = (charLen, charMap, encodeChars) => { | ||
const createEncode = (charLen, charMap, encodeChars) => { | ||
if (encodeChars.length > 1 && charLen === 1) { | ||
@@ -106,2 +107,3 @@ const encodeCharsLen = encodeChars.length; | ||
}; | ||
exports.createEncode = createEncode; | ||
//# sourceMappingURL=encode.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createEncoder = void 0; | ||
const decode_1 = require("./decode"); | ||
const encode_1 = require("./encode"); | ||
const padding_1 = require("../padding"); | ||
exports.createEncoder = (chars, encodeChars = ['$']) => { | ||
const createEncoder = (chars, encodeChars = ['$']) => { | ||
let charLen = 1; | ||
@@ -37,3 +38,3 @@ const isLong = chars.length > 36; | ||
if (key.length < longest) { | ||
const nKey = padding_1.padLeft(key, longest, '0'); | ||
const nKey = (0, padding_1.padLeft)(key, longest, '0'); | ||
const c = reverseCharMap[key]; | ||
@@ -54,6 +55,7 @@ if (encodeChars.length > 1) { | ||
reverseCharMap, | ||
encode: encode_1.createEncode(charLen, charMap, encodeChars), | ||
decode: decode_1.createDecode(isLong, longest, encodeChars, reverseCharMap), | ||
encode: (0, encode_1.createEncode)(charLen, charMap, encodeChars), | ||
decode: (0, decode_1.createDecode)(isLong, longest, encodeChars, reverseCharMap), | ||
}; | ||
}; | ||
exports.createEncoder = createEncoder; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type OperandTypes = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' | 'null'; | ||
export type OperandTypes = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' | 'null'; | ||
export declare const getType: (item: any) => OperandTypes; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getType = (item) => { | ||
exports.getType = void 0; | ||
const getType = (item) => { | ||
return item === null ? 'null' : Array.isArray(item) ? 'array' : typeof item; | ||
}; | ||
exports.getType = getType; | ||
//# sourceMappingURL=getType.js.map |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
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 __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -9,2 +20,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomString = exports.retry = exports.toEnvVar = exports.deepEqual = exports.wait = exports.isObject = exports.readStream = exports.queued = exports.deepCopy = void 0; | ||
const deepCopy_1 = __importDefault(require("./deepCopy")); | ||
@@ -28,10 +40,10 @@ exports.deepCopy = deepCopy_1.default; | ||
exports.randomString = randomString_1.default; | ||
__export(require("./padding")); | ||
__export(require("./encoder")); | ||
__export(require("./deepMerge")); | ||
__export(require("./walker")); | ||
__export(require("./getType")); | ||
__export(require("./query")); | ||
__export(require("./base64")); | ||
__export(require("./utf8")); | ||
__exportStar(require("./padding"), exports); | ||
__exportStar(require("./encoder"), exports); | ||
__exportStar(require("./deepMerge"), exports); | ||
__exportStar(require("./walker"), exports); | ||
__exportStar(require("./getType"), exports); | ||
__exportStar(require("./query"), exports); | ||
__exportStar(require("./base64"), exports); | ||
__exportStar(require("./utf8"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.padLeft = (str, len, char) => { | ||
exports.padRight = exports.padLeft = void 0; | ||
const padLeft = (str, len, char) => { | ||
const l = str.length; | ||
@@ -10,3 +11,4 @@ for (let i = 0; i < len - l; i++) { | ||
}; | ||
exports.padRight = (str, len, char) => { | ||
exports.padLeft = padLeft; | ||
const padRight = (str, len, char) => { | ||
const l = str.length; | ||
@@ -18,2 +20,3 @@ for (let i = 0; i < len - l; i++) { | ||
}; | ||
exports.padRight = padRight; | ||
//# sourceMappingURL=padding.js.map |
@@ -1,3 +0,3 @@ | ||
declare type QueryValue = string | number | boolean; | ||
declare type QueryParams = { | ||
type QueryValue = string | number | boolean; | ||
type QueryParams = { | ||
[key: string]: QueryValue | QueryValue[] | { | ||
@@ -7,6 +7,6 @@ [key: string]: any; | ||
}; | ||
export declare const parseQuery: (query: string) => void | QueryParams; | ||
export declare const serializeQuery: (q: string | number | boolean | QueryValue[] | { | ||
export declare const parseQuery: (query: string) => QueryParams | void; | ||
export declare const serializeQuery: (q: QueryValue | QueryValue[] | { | ||
[key: string]: any; | ||
}, deep?: boolean) => string; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeQuery = exports.parseQuery = void 0; | ||
const parseQueryValue = (q) => { | ||
@@ -25,3 +26,3 @@ if (q.includes(',')) { | ||
}; | ||
exports.parseQuery = (query) => { | ||
const parseQuery = (query) => { | ||
if (query) { | ||
@@ -101,2 +102,3 @@ try { | ||
}; | ||
exports.parseQuery = parseQuery; | ||
const topLevelObject = (q) => { | ||
@@ -110,3 +112,3 @@ const args = []; | ||
else { | ||
args.push(`${key}=${exports.serializeQuery(value, true)}`); | ||
args.push(`${key}=${(0, exports.serializeQuery)(value, true)}`); | ||
} | ||
@@ -116,3 +118,3 @@ } | ||
}; | ||
exports.serializeQuery = (q, deep = false) => { | ||
const serializeQuery = (q, deep = false) => { | ||
if (typeof q === 'string') { | ||
@@ -139,3 +141,3 @@ return q; | ||
} | ||
return exports.serializeQuery(v, true); | ||
return (0, exports.serializeQuery)(v, true); | ||
}) | ||
@@ -152,2 +154,3 @@ .join(','); | ||
}; | ||
exports.serializeQuery = serializeQuery; | ||
//# sourceMappingURL=query.js.map |
@@ -0,4 +1,10 @@ | ||
type Retry = { | ||
max?: number; | ||
minTime?: number; | ||
maxTime?: number; | ||
}; | ||
declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a?: A, b?: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
concurrency?: number; | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a?: A, b?: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -8,2 +14,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b?: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b?: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -13,2 +20,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -18,2 +26,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d?: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -23,2 +32,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e?: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -28,2 +38,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f?: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -33,2 +44,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g?: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -38,2 +50,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h?: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h?: H, i?: I, j?: J) => Promise<K>; | ||
@@ -43,2 +56,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i?: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i?: I, j?: J) => Promise<K>; | ||
@@ -48,2 +62,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j?: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j?: J) => Promise<K>; | ||
@@ -53,2 +68,3 @@ declare function queued<K>(promiseFn: () => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): () => Promise<K>; | ||
@@ -58,2 +74,3 @@ declare function queued<A, K>(promiseFn: (a: A) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A) => Promise<K>; | ||
@@ -63,2 +80,3 @@ declare function queued<A, B, K>(promiseFn: (a: A, b: B) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B) => Promise<K>; | ||
@@ -68,2 +86,3 @@ declare function queued<A, B, C, K>(promiseFn: (a: A, b: B, c: C) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C) => Promise<K>; | ||
@@ -73,2 +92,3 @@ declare function queued<A, B, C, D, K>(promiseFn: (a: A, b: B, c: C, d: D) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D) => Promise<K>; | ||
@@ -78,2 +98,3 @@ declare function queued<A, B, C, D, E, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E) => Promise<K>; | ||
@@ -83,2 +104,3 @@ declare function queued<A, B, C, D, E, F, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F) => Promise<K>; | ||
@@ -88,2 +110,3 @@ declare function queued<A, B, C, D, E, F, G, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G) => Promise<K>; | ||
@@ -93,2 +116,3 @@ declare function queued<A, B, C, D, E, F, G, H, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) => Promise<K>; | ||
@@ -98,2 +122,3 @@ declare function queued<A, B, C, D, E, F, G, H, I, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I) => Promise<K>; | ||
@@ -103,3 +128,4 @@ declare function queued<A, B, C, D, E, F, G, H, I, J, K>(promiseFn: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J) => Promise<K>, opts?: { | ||
dedup?: (...args: any[]) => number | string; | ||
retry?: Retry; | ||
}): (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J) => Promise<K>; | ||
export default queued; |
@@ -8,2 +8,23 @@ "use strict"; | ||
const is_plain_obj_1 = __importDefault(require("is-plain-obj")); | ||
function retryPromiseFn(fn, retry) { | ||
let retries = 0; | ||
const retryIt = async (...args) => { | ||
try { | ||
// @ts-ignore | ||
return await fn(...args); | ||
} | ||
catch (err) { | ||
retries++; | ||
if (!retry.max || retries < retry.max) { | ||
setTimeout(() => { | ||
retryIt(...args); | ||
}, Math.min(retries * (retry.minTime ?? 1e3), retry.maxTime ?? Infinity)); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
}; | ||
return retryIt; | ||
} | ||
const defaultDedup = (...args) => { | ||
@@ -15,10 +36,10 @@ let x = ''; | ||
if (Array.isArray(arg)) { | ||
x += hash_1.hashObjectIgnoreKeyOrder(arg); | ||
x += (0, hash_1.hashObjectIgnoreKeyOrder)(arg); | ||
} | ||
else if (is_plain_obj_1.default(arg)) { | ||
x += hash_1.hashObjectIgnoreKeyOrder(arg); | ||
else if ((0, is_plain_obj_1.default)(arg)) { | ||
x += (0, hash_1.hashObjectIgnoreKeyOrder)(arg); | ||
} | ||
} | ||
else { | ||
x += hash_1.hash(arg); | ||
x += (0, hash_1.hash)(arg); | ||
} | ||
@@ -34,2 +55,5 @@ } | ||
function queued(promiseFn, opts = {}) { | ||
if (opts.retry) { | ||
promiseFn = retryPromiseFn(promiseFn, opts.retry); | ||
} | ||
// default options | ||
@@ -52,3 +76,2 @@ if (!opts.dedup) { | ||
keysInProgress.add(key); | ||
// console.log('EXEC', 'conc', keysInProgress.size, key, l.args) | ||
promiseFn(...l.args) | ||
@@ -55,0 +78,0 @@ .then((v) => { |
@@ -10,7 +10,6 @@ "use strict"; | ||
function randomString(length, opts) { | ||
var _a, _b, _c, _d; | ||
const noSpecials = ((_a = opts) === null || _a === void 0 ? void 0 : _a.noSpecials) || false; | ||
const noLowerCase = ((_b = opts) === null || _b === void 0 ? void 0 : _b.noLowerCase) || false; | ||
const noUpperCase = ((_c = opts) === null || _c === void 0 ? void 0 : _c.noUpperCase) || false; | ||
const noNumbers = ((_d = opts) === null || _d === void 0 ? void 0 : _d.noNumbers) || false; | ||
const noSpecials = opts?.noSpecials || false; | ||
const noLowerCase = opts?.noLowerCase || false; | ||
const noUpperCase = opts?.noUpperCase || false; | ||
const noNumbers = opts?.noNumbers || false; | ||
const upperCaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
@@ -17,0 +16,0 @@ const lowerCaseChars = 'abcdefghijklmnopqrstuvwxyz'; |
"use strict"; | ||
// Faster in some browsers e.g. chrome then native textEncoder (dont use in nodejs!) | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uft8ToString = (aBytes) => { | ||
exports.stringToUtf8 = exports.uft8ToString = void 0; | ||
const uft8ToString = (aBytes) => { | ||
let sView = ''; | ||
@@ -42,3 +43,4 @@ let nPart; | ||
}; | ||
exports.stringToUtf8 = (str) => { | ||
exports.uft8ToString = uft8ToString; | ||
const stringToUtf8 = (str) => { | ||
let nChr; | ||
@@ -111,2 +113,3 @@ const nStrLen = str.length; | ||
}; | ||
exports.stringToUtf8 = stringToUtf8; | ||
//# sourceMappingURL=utf8.js.map |
import { OperandTypes } from './'; | ||
declare type RecurseFn<L> = (item: L) => Promise<boolean>; | ||
export declare type WalkerListFn<L> = (target: any, previousPath?: string) => Promise<L[]>; | ||
declare type ItemMatchFn<L> = (item: L) => Promise<boolean>; | ||
declare type ListItem = { | ||
type RecurseFn<L> = (item: L) => Promise<boolean>; | ||
export type WalkerListFn<L> = (target: any, previousPath?: string) => Promise<L[]>; | ||
type ItemMatchFn<L> = (item: L) => Promise<boolean>; | ||
type ListItem = { | ||
name: string; | ||
@@ -11,4 +11,4 @@ ref: any; | ||
}; | ||
export declare type WalkerTargetValidationFn = (target: any) => Promise<boolean>; | ||
declare type ItemFn = (item: any, info: { | ||
export type WalkerTargetValidationFn = (target: any) => Promise<boolean>; | ||
type ItemFn = (item: any, info: { | ||
name: string; | ||
@@ -18,3 +18,3 @@ path: string; | ||
}) => Promise<void>; | ||
export declare type Walk<L = ListItem, F = ItemFn> = (target: any, itemFn: F, options?: { | ||
export type Walk<L = ListItem, F = ItemFn> = (target: any, itemFn: F, options?: { | ||
listFn?: WalkerListFn<L>; | ||
@@ -21,0 +21,0 @@ itemMatchFn?: ItemMatchFn<L>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.walk = void 0; | ||
const _1 = require("./"); | ||
const defaultItemMatchFn = async (item) => _1.getType(item.ref) !== 'object'; | ||
const defaultItemMatchFn = async (item) => (0, _1.getType)(item.ref) !== 'object'; | ||
const defaultListFn = async (target, previousPath) => { | ||
@@ -10,14 +11,20 @@ return Object.keys(target).map((key) => ({ | ||
path: [previousPath, key].filter(Boolean).join('/'), | ||
type: _1.getType(target[key]), | ||
type: (0, _1.getType)(target[key]), | ||
})); | ||
}; | ||
const defaultRecurseFn = async (item) => _1.getType(item.ref) === 'object'; | ||
const defaultTargetValidationFn = async (target) => _1.getType(target) === 'object'; | ||
exports.walk = async (target, itemFn, options) => { | ||
options = Object.assign({ listFn: defaultListFn, itemMatchFn: defaultItemMatchFn, recurseFn: defaultRecurseFn, targetValidationFn: defaultTargetValidationFn }, options); | ||
if (_1.getType(options.targetValidationFn) === 'function' && | ||
const defaultRecurseFn = async (item) => (0, _1.getType)(item.ref) === 'object'; | ||
const defaultTargetValidationFn = async (target) => (0, _1.getType)(target) === 'object'; | ||
const walk = async (target, itemFn, options) => { | ||
options = { | ||
listFn: defaultListFn, | ||
itemMatchFn: defaultItemMatchFn, | ||
recurseFn: defaultRecurseFn, | ||
targetValidationFn: defaultTargetValidationFn, | ||
...options, | ||
}; | ||
if ((0, _1.getType)(options.targetValidationFn) === 'function' && | ||
!(await options.targetValidationFn(target))) | ||
return; | ||
['listFn', 'itemMatchFn', 'recurseFn'].forEach((fn) => { | ||
if (_1.getType(options[fn]) !== 'function') | ||
if ((0, _1.getType)(options[fn]) !== 'function') | ||
throw new Error(fn + ' should be a function'); | ||
@@ -32,6 +39,10 @@ }); | ||
if (await options.recurseFn(item)) { | ||
await exports.walk(item.ref, itemFn, Object.assign(Object.assign({}, options), { previousPath: item.path })); | ||
await (0, exports.walk)(item.ref, itemFn, { | ||
...options, | ||
previousPath: item.path, | ||
}); | ||
} | ||
})); | ||
}; | ||
exports.walk = walk; | ||
//# sourceMappingURL=walker.js.map |
{ | ||
"name": "@saulx/utils", | ||
"main": "./dist/index.js", | ||
"version": "3.2.2", | ||
"version": "3.3.0", | ||
"scripts": { | ||
@@ -52,4 +52,4 @@ "build": "tsc", | ||
"ts-node": "8.5.4", | ||
"typescript": "3.7.3" | ||
"typescript": "^4.9.5" | ||
} | ||
} |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95287
65
1432