Comparing version 1.6.5 to 1.6.6
@@ -985,3 +985,3 @@ 'use strict'; | ||
const replace = []; | ||
const slice = (v) => v.slice(flag.length); | ||
const refKey = (v) => v.slice(flag.length); | ||
const isRefStr = (v) => typeof v === 'string' && v.startsWith(flag); | ||
@@ -1007,7 +1007,7 @@ function _reviver(key, value) { | ||
isRef = true; | ||
let ref = slice(value); | ||
let ref = refKey(value); | ||
replace.unshift(() => { | ||
let refValue = refs[ref]; | ||
while (isRefStr(refValue)) { | ||
refValue = refs[slice(refValue)]; | ||
refValue = refs[refKey(refValue)]; | ||
} | ||
@@ -1684,22 +1684,23 @@ this[key] = refValue; | ||
}; | ||
// prettier-ignore | ||
function map(data, fn) { | ||
fn = fn || ((val) => val); | ||
if (isArray(data)) { | ||
return data.map((val, i) => fn(val, i)); | ||
} | ||
if (isSet(data)) { | ||
const cloned = new Set(); | ||
for (const val of data) { | ||
cloned.add(fn(val)); | ||
fn = fn || ((val) => val); | ||
if (isArray(data)) { | ||
return data.map((val, i) => fn(val, i)); | ||
} | ||
return cloned; | ||
} | ||
if (isPlainObject(data)) { | ||
const cloned = {}; | ||
for (const key in data) { | ||
cloned[key] = fn(data[key], key); | ||
if (isSet(data)) { | ||
const cloned = new Set(); | ||
for (const val of data) { | ||
cloned.add(fn(val)); | ||
} | ||
return cloned; | ||
} | ||
return cloned; | ||
} | ||
throw new Error(`Invalid type "${toRawType(data)}"`); | ||
if (isPlainObject(data)) { | ||
const cloned = {}; | ||
for (const key in data) { | ||
cloned[key] = fn(data[key], key); | ||
} | ||
return cloned; | ||
} | ||
throw new Error(`Invalid type "${toRawType(data)}"`); | ||
} | ||
@@ -1706,0 +1707,0 @@ const toCamelCase = (val, upper = false, reg = /[_-]/g) => { |
@@ -983,3 +983,3 @@ export { Queue } from 'small-queue'; | ||
const replace = []; | ||
const slice = (v) => v.slice(flag.length); | ||
const refKey = (v) => v.slice(flag.length); | ||
const isRefStr = (v) => typeof v === 'string' && v.startsWith(flag); | ||
@@ -1005,7 +1005,7 @@ function _reviver(key, value) { | ||
isRef = true; | ||
let ref = slice(value); | ||
let ref = refKey(value); | ||
replace.unshift(() => { | ||
let refValue = refs[ref]; | ||
while (isRefStr(refValue)) { | ||
refValue = refs[slice(refValue)]; | ||
refValue = refs[refKey(refValue)]; | ||
} | ||
@@ -1682,22 +1682,23 @@ this[key] = refValue; | ||
}; | ||
// prettier-ignore | ||
function map(data, fn) { | ||
fn = fn || ((val) => val); | ||
if (isArray(data)) { | ||
return data.map((val, i) => fn(val, i)); | ||
} | ||
if (isSet(data)) { | ||
const cloned = new Set(); | ||
for (const val of data) { | ||
cloned.add(fn(val)); | ||
fn = fn || ((val) => val); | ||
if (isArray(data)) { | ||
return data.map((val, i) => fn(val, i)); | ||
} | ||
return cloned; | ||
} | ||
if (isPlainObject(data)) { | ||
const cloned = {}; | ||
for (const key in data) { | ||
cloned[key] = fn(data[key], key); | ||
if (isSet(data)) { | ||
const cloned = new Set(); | ||
for (const val of data) { | ||
cloned.add(fn(val)); | ||
} | ||
return cloned; | ||
} | ||
return cloned; | ||
} | ||
throw new Error(`Invalid type "${toRawType(data)}"`); | ||
if (isPlainObject(data)) { | ||
const cloned = {}; | ||
for (const key in data) { | ||
cloned[key] = fn(data[key], key); | ||
} | ||
return cloned; | ||
} | ||
throw new Error(`Invalid type "${toRawType(data)}"`); | ||
} | ||
@@ -1704,0 +1705,0 @@ const toCamelCase = (val, upper = false, reg = /[_-]/g) => { |
@@ -1044,3 +1044,3 @@ (function (global, factory) { | ||
const replace = []; | ||
const slice = (v) => v.slice(flag.length); | ||
const refKey = (v) => v.slice(flag.length); | ||
const isRefStr = (v) => typeof v === 'string' && v.startsWith(flag); | ||
@@ -1066,7 +1066,7 @@ function _reviver(key, value) { | ||
isRef = true; | ||
let ref = slice(value); | ||
let ref = refKey(value); | ||
replace.unshift(() => { | ||
let refValue = refs[ref]; | ||
while (isRefStr(refValue)) { | ||
refValue = refs[slice(refValue)]; | ||
refValue = refs[refKey(refValue)]; | ||
} | ||
@@ -1747,22 +1747,23 @@ this[key] = refValue; | ||
}; | ||
// prettier-ignore | ||
function map(data, fn) { | ||
fn = fn || ((val) => val); | ||
if (isArray(data)) { | ||
return data.map((val, i) => fn(val, i)); | ||
} | ||
if (isSet(data)) { | ||
const cloned = new Set(); | ||
for (const val of data) { | ||
cloned.add(fn(val)); | ||
fn = fn || ((val) => val); | ||
if (isArray(data)) { | ||
return data.map((val, i) => fn(val, i)); | ||
} | ||
return cloned; | ||
} | ||
if (isPlainObject(data)) { | ||
const cloned = {}; | ||
for (const key in data) { | ||
cloned[key] = fn(data[key], key); | ||
if (isSet(data)) { | ||
const cloned = new Set(); | ||
for (const val of data) { | ||
cloned.add(fn(val)); | ||
} | ||
return cloned; | ||
} | ||
return cloned; | ||
} | ||
throw new Error(`Invalid type "${toRawType(data)}"`); | ||
if (isPlainObject(data)) { | ||
const cloned = {}; | ||
for (const key in data) { | ||
cloned[key] = fn(data[key], key); | ||
} | ||
return cloned; | ||
} | ||
throw new Error(`Invalid type "${toRawType(data)}"`); | ||
} | ||
@@ -1769,0 +1770,0 @@ const toCamelCase = (val, upper = false, reg = /[_-]/g) => { |
@@ -0,1 +1,2 @@ | ||
import type { Prettify } from './types'; | ||
export { Queue } from 'small-queue'; | ||
@@ -108,11 +109,11 @@ export { root } from './root'; | ||
export declare const remove: <T>(arr: T[] | Set<T>, el: T) => boolean; | ||
export declare function map<T>(data: Set<T>, fn?: (val: T) => T): Set<T>; | ||
export declare function map<T>( | ||
export declare function map<T, U>(data: Set<T>, fn?: (val: T) => U): Set<U>; | ||
export declare function map<T, U>( | ||
data: Array<T>, | ||
fn?: (val: T, i: number) => T, | ||
): Array<T>; | ||
export declare function map<T extends Record<PropertyKey, any>>( | ||
fn?: (val: T, i: number) => U, | ||
): Array<U>; | ||
export declare function map<T, U>( | ||
data: T, | ||
fn?: (val: T[keyof T], key: keyof T) => T[keyof T], | ||
): T; | ||
fn?: (val: T[keyof T], key: keyof T) => U, | ||
): Prettify<Record<keyof T, U>>; | ||
export declare const toCamelCase: ( | ||
@@ -119,0 +120,0 @@ val: string, |
{ | ||
"name": "aidly", | ||
"version": "1.6.5", | ||
"version": "1.6.6", | ||
"description": "Tool library.", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
259408
8307