foreslash 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/lib/index.cmn.cjs +61 -3
- package/lib/index.d.ts +71 -7
- package/lib/index.mjs +59 -4
- package/lib/index.umd.js +61 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## Version 0.3.5 - 2025-11-30
|
|
4
|
+
|
|
5
|
+
Unstable version
|
|
6
|
+
|
|
7
|
+
- Feat 🥥 Functions added: `uuidV7`
|
|
8
|
+
- Feat 🥥 Function change: `isOdd` and `isEven` now support BigInt
|
|
9
|
+
- Fix 🥕 Document: Added version tags to several methods
|
|
10
|
+
- Other fixes and improvements
|
|
11
|
+
|
|
12
|
+
不稳定版本
|
|
13
|
+
|
|
14
|
+
- 功能 🥥 添加函数: `uuidV7`
|
|
15
|
+
- 功能 🥥 变更函数: `isOdd` 和 `isEven` 现在支持 BigInt
|
|
16
|
+
- 修复 🥕 文档: 补充部分方法的版本标签
|
|
17
|
+
- 其他修复与优化
|
|
18
|
+
|
|
19
|
+
## Version 0.3.4 - 2025-11-17
|
|
20
|
+
|
|
21
|
+
Unstable version
|
|
22
|
+
|
|
23
|
+
- Feat 🥥 Functions added: `omit` `pick`
|
|
24
|
+
- Other fixes and improvements
|
|
25
|
+
|
|
26
|
+
不稳定版本
|
|
27
|
+
|
|
28
|
+
- 功能 🥥 添加函数: `omit` `pick`
|
|
29
|
+
- 其他修复与优化
|
|
30
|
+
|
|
3
31
|
## Version 0.3.3 - 2025-11-05
|
|
4
32
|
|
|
5
33
|
Unstable version
|
package/lib/index.cmn.cjs
CHANGED
|
@@ -468,10 +468,10 @@ function decimalNotation(num) {
|
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
function isOdd(num) {
|
|
471
|
-
return !!(num & 1);
|
|
471
|
+
return !!(typeof num === 'bigint' ? num & BigInt(1) : num & 1);
|
|
472
472
|
}
|
|
473
473
|
function isEven(num) {
|
|
474
|
-
return !(num & 1);
|
|
474
|
+
return !(typeof num === 'bigint' ? num & BigInt(1) : num & 1);
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
function round(num, precision, type) {
|
|
@@ -749,7 +749,7 @@ function scientificNotation(num, options) {
|
|
|
749
749
|
return str;
|
|
750
750
|
const type = (options || {}).type || 'unicode';
|
|
751
751
|
const _precision = (options || {}).precision;
|
|
752
|
-
const precision = isNumber(_precision) ? clamp(_precision
|
|
752
|
+
const precision = isNumber(_precision) ? clamp(_precision, 0, Infinity) : null;
|
|
753
753
|
const round = (options || {}).round || 'round';
|
|
754
754
|
let [integer, fractional] = str.split('.');
|
|
755
755
|
let sign = '';
|
|
@@ -1607,6 +1607,15 @@ function uuidV4() {
|
|
|
1607
1607
|
return (`${r.slice(0, 8)}-${r.slice(8, 12)}-4${r.slice(12, 15)}-` +
|
|
1608
1608
|
`${'89ab'[Math.floor(Math.random() * 4)]}${r.slice(15, 18)}-${r.slice(18)}`);
|
|
1609
1609
|
}
|
|
1610
|
+
function uuidV7() {
|
|
1611
|
+
const r = randomHexString(18);
|
|
1612
|
+
let t = Date.now().toString(16);
|
|
1613
|
+
if (t.length < 12)
|
|
1614
|
+
t = '0'.repeat(12 - t.length) + t;
|
|
1615
|
+
t = t.slice(t.length - 12, t.length);
|
|
1616
|
+
return (`${t.slice(0, 8)}-${t.slice(8, 12)}-7${r.slice(0, 3)}-` +
|
|
1617
|
+
`${'89ab'[Math.floor(Math.random() * 4)]}${r.slice(3, 6)}-${r.slice(6)}`);
|
|
1618
|
+
}
|
|
1610
1619
|
|
|
1611
1620
|
const getDefaultVarCase = () => ({ code: '', upperCase: false, number: false });
|
|
1612
1621
|
const isUpperCase = RegExp.prototype.test.bind(/[A-Z]/);
|
|
@@ -2489,6 +2498,27 @@ function not(value) {
|
|
|
2489
2498
|
return !Boolean(value);
|
|
2490
2499
|
}
|
|
2491
2500
|
|
|
2501
|
+
function omit(obj, keys) {
|
|
2502
|
+
const res = (Object.getPrototypeOf(obj) ? {} : Object.create(null));
|
|
2503
|
+
const ownKeys = Reflect.ownKeys(obj);
|
|
2504
|
+
if (isFunction(keys)) {
|
|
2505
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2506
|
+
const key = ownKeys[i];
|
|
2507
|
+
if (!keys(obj[key], key, obj))
|
|
2508
|
+
res[key] = obj[key];
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
else {
|
|
2512
|
+
const keysSet = new Set((isArray(keys) ? keys : [keys]).map((k) => (isNumber(k) ? String(k) : k)));
|
|
2513
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2514
|
+
const key = ownKeys[i];
|
|
2515
|
+
if (!keysSet.has(key))
|
|
2516
|
+
res[key] = obj[key];
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
return res;
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2492
2522
|
function pass(value) {
|
|
2493
2523
|
return value;
|
|
2494
2524
|
}
|
|
@@ -2499,6 +2529,31 @@ function passWith(fn) {
|
|
|
2499
2529
|
});
|
|
2500
2530
|
}
|
|
2501
2531
|
|
|
2532
|
+
function pick(obj, keys) {
|
|
2533
|
+
const res = (Object.getPrototypeOf(obj) ? {} : Object.create(null));
|
|
2534
|
+
const ownKeys = Reflect.ownKeys(obj);
|
|
2535
|
+
if (isFunction(keys)) {
|
|
2536
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2537
|
+
const key = ownKeys[i];
|
|
2538
|
+
if (keys(obj[key], key, obj))
|
|
2539
|
+
res[key] = obj[key];
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
else if (isArray(keys)) {
|
|
2543
|
+
const keysSet = new Set(ownKeys);
|
|
2544
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2545
|
+
const key = keys[i];
|
|
2546
|
+
if (keysSet.has(isNumber(key) ? String(key) : key))
|
|
2547
|
+
res[key] = obj[key];
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
else if (isString(keys) || isNumber(keys) || isSymbol(keys)) {
|
|
2551
|
+
if (ownKeys.includes(isNumber(keys) ? String(keys) : keys))
|
|
2552
|
+
res[keys] = obj[keys];
|
|
2553
|
+
}
|
|
2554
|
+
return res;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2502
2557
|
function pipe(...pipeFunc) {
|
|
2503
2558
|
if (pipeFunc.length === 0) {
|
|
2504
2559
|
throw new Error('Invalid pipeFunc parameter: pipeFunc is empty');
|
|
@@ -2613,10 +2668,12 @@ exports.lerp = lerp;
|
|
|
2613
2668
|
exports.memo = memo;
|
|
2614
2669
|
exports.noop = noop;
|
|
2615
2670
|
exports.not = not;
|
|
2671
|
+
exports.omit = omit;
|
|
2616
2672
|
exports.parallel = parallel;
|
|
2617
2673
|
exports.pascalCase = pascalCase;
|
|
2618
2674
|
exports.pass = pass;
|
|
2619
2675
|
exports.passWith = passWith;
|
|
2676
|
+
exports.pick = pick;
|
|
2620
2677
|
exports.pipe = pipe;
|
|
2621
2678
|
exports.randomBase32String = randomBase32String;
|
|
2622
2679
|
exports.randomChoice = randomChoice;
|
|
@@ -2646,4 +2703,5 @@ exports.ulid = ulid;
|
|
|
2646
2703
|
exports.uncapitalize = uncapitalize;
|
|
2647
2704
|
exports.uuidNil = uuidNil;
|
|
2648
2705
|
exports.uuidV4 = uuidV4;
|
|
2706
|
+
exports.uuidV7 = uuidV7;
|
|
2649
2707
|
exports.withResolvers = withResolvers;
|
package/lib/index.d.ts
CHANGED
|
@@ -1031,14 +1031,14 @@ declare function format(num: number | string, options?: {
|
|
|
1031
1031
|
* @returns 如果是奇数则返回 true 否则返回 false
|
|
1032
1032
|
* @version 0.3.2
|
|
1033
1033
|
*/
|
|
1034
|
-
declare function isOdd(num: number): boolean;
|
|
1034
|
+
declare function isOdd(num: number | bigint): boolean;
|
|
1035
1035
|
/**
|
|
1036
1036
|
* 检查一个数字是否为偶数
|
|
1037
1037
|
* @param num 需要检查的数字
|
|
1038
1038
|
* @returns 如果是偶数则返回 true 否则返回 false
|
|
1039
1039
|
* @version 0.3.2
|
|
1040
1040
|
*/
|
|
1041
|
-
declare function isEven(num: number): boolean;
|
|
1041
|
+
declare function isEven(num: number | bigint): boolean;
|
|
1042
1042
|
|
|
1043
1043
|
/**
|
|
1044
1044
|
* 用线性插值法求取一个中间值
|
|
@@ -1095,7 +1095,7 @@ declare function lerp(val1: number[][], val2: number[][], t: number): number[][]
|
|
|
1095
1095
|
* - `'unicode'` 使用 Unicode 表示 `'I̅V̅XC'`
|
|
1096
1096
|
* - `'js'` 适合用于 JavaScript 代码字符串 `'I\\u0305V\\u0305XC'`
|
|
1097
1097
|
* - `'html'` 适合用于 HTML 展示的字符串 `'I̅V̅XC'`
|
|
1098
|
-
* - `'json'` 一个 JSON 字符串, 具体数值是下标^1000 `["XC", "IV"]`
|
|
1098
|
+
* - `'json'` 一个 JSON 字符串, 具体数值是下标^1000 `'["XC", "IV"]'`
|
|
1099
1099
|
*
|
|
1100
1100
|
* `thousand` 千分位类型, 默认为 `normal`
|
|
1101
1101
|
* - `'normal'` 习惯用法, 超过 3999 的部分才使用上划线区分
|
|
@@ -1456,6 +1456,7 @@ declare function randomBase32String(length: number, isCrockford?: boolean): stri
|
|
|
1456
1456
|
* shuffle('abcdefg') // ['d', 'e', 'a', 'c', 'g', 'f', 'b']
|
|
1457
1457
|
* shuffle([1, 2, 3, 4, 5, 6, 7, 8]) // [3, 2, 6, 5, 8, 1, 7, 4]
|
|
1458
1458
|
* ```
|
|
1459
|
+
* @version 0.1.1
|
|
1459
1460
|
*/
|
|
1460
1461
|
declare function shuffle<T>(arr: ArrayLike<T> | Iterable<T>): Array<T>;
|
|
1461
1462
|
|
|
@@ -1474,20 +1475,32 @@ declare function shuffle<T>(arr: ArrayLike<T> | Iterable<T>): Array<T>;
|
|
|
1474
1475
|
* ulid(true, 0) // 0000000000D64N3ZR75CXM1J83 同一时间戳单调递增
|
|
1475
1476
|
* ulid(false, 0) // 0000000000Z3VJ5THVXV4ZE6CO 取消单调性
|
|
1476
1477
|
* ```
|
|
1478
|
+
* @version 0.1.2
|
|
1477
1479
|
*/
|
|
1478
1480
|
declare function ulid(monotonic?: boolean, time?: number): string;
|
|
1479
1481
|
|
|
1480
|
-
/** 空 UUID [见标准第
|
|
1482
|
+
/** 空 UUID [见标准第 5.9 节](https://www.rfc-editor.org/rfc/rfc9562.html#name-nil-uuid) */
|
|
1481
1483
|
declare const uuidNil = "00000000-0000-0000-0000-000000000000";
|
|
1482
1484
|
/**
|
|
1483
|
-
* 生成 [UUID V4](https://www.
|
|
1484
|
-
* @returns
|
|
1485
|
+
* 生成 [UUID V4](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-4) 字符串(小写)
|
|
1486
|
+
* @returns 一个 RFC 9562 标准的 UUID V4 字符串
|
|
1485
1487
|
* @example
|
|
1486
1488
|
* ```js
|
|
1487
1489
|
* uuidV4() // "ea64fb4f-a0a2-4193-8374-d291a522d8b3"
|
|
1488
1490
|
* ```
|
|
1491
|
+
* @version 0.1.2
|
|
1489
1492
|
*/
|
|
1490
1493
|
declare function uuidV4(): string;
|
|
1494
|
+
/**
|
|
1495
|
+
* 生成 [UUID V7](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-7) 字符串(小写)
|
|
1496
|
+
* @returns 一个 RFC 9562 标准的 UUID V7 字符串
|
|
1497
|
+
* @example
|
|
1498
|
+
* ```js
|
|
1499
|
+
* uuidV7() // "019aba02-45ad-703c-a17e-05f8d7ebe357"
|
|
1500
|
+
* ```
|
|
1501
|
+
* @version 0.3.4
|
|
1502
|
+
*/
|
|
1503
|
+
declare function uuidV7(): string;
|
|
1491
1504
|
|
|
1492
1505
|
/**
|
|
1493
1506
|
* 将输入的字符串处理成小驼峰格式
|
|
@@ -2245,6 +2258,34 @@ declare const noop: (...args: any[]) => void;
|
|
|
2245
2258
|
*/
|
|
2246
2259
|
declare function not(value: unknown): boolean;
|
|
2247
2260
|
|
|
2261
|
+
type KeyOf<T extends object> = object extends T ? keyof any : keyof T;
|
|
2262
|
+
type ValueOf<T extends object> = object extends T ? unknown : T[keyof T];
|
|
2263
|
+
type PickPredicate<T extends object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => any;
|
|
2264
|
+
type OmitPredicate<T extends object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => any;
|
|
2265
|
+
|
|
2266
|
+
/**
|
|
2267
|
+
* 给定一个对象和对象中键的列表, 返回一个**排除**给定键的新对象(是传入对象的浅拷贝)\
|
|
2268
|
+
* 如果你希望深拷贝一个对象, 请使用 `deepClone` 或 `fastClone`
|
|
2269
|
+
* @param obj 需要处理的对象
|
|
2270
|
+
* @param keys 需要**排除**的键, 可以是一个数组、字符串或谓词函数
|
|
2271
|
+
* @returns 传入对象的浅拷贝, 与传入对象不同的是新对象**排除了**指定的键
|
|
2272
|
+
* @example
|
|
2273
|
+
* ```ts
|
|
2274
|
+
* omit({ a: 1, b: 2, c: '' }, ['a', 'c']) // { b: 2 }
|
|
2275
|
+
* omit({ a: 1, b: 2, c: '' }, 'b') // { a: 1, c: '' }
|
|
2276
|
+
* // 谓词函数
|
|
2277
|
+
* omit({ a: 1, b: 2, c: '' }, (value, key) => value === 2 || key === 'c') // { a: 1 }
|
|
2278
|
+
* // 需要注意的是传入谓词函数时可能会有类型不匹配的问题
|
|
2279
|
+
* // Typescript 无法得知最终过滤的结果, 而是认为过滤结果与原类型一致
|
|
2280
|
+
* const obj = omit({ a: 1, b: 2 }, (value, key) => value === 2) // { a: 1 }
|
|
2281
|
+
* type typeofObj = typeof obj // { a: number; b: number } <- Typescript 没有推导出正确结果
|
|
2282
|
+
* ```
|
|
2283
|
+
* @version 0.3.4
|
|
2284
|
+
*/
|
|
2285
|
+
declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
2286
|
+
declare function omit<T extends object, K extends keyof T>(obj: T, keys: OmitPredicate<T>): T;
|
|
2287
|
+
declare function omit<T extends object, K extends keyof T>(obj: T, key: K): Omit<T, K>;
|
|
2288
|
+
|
|
2248
2289
|
/**
|
|
2249
2290
|
* 不做任何操作,返回第一个参数,一般用于函数式编程
|
|
2250
2291
|
* @param value 任意值
|
|
@@ -2273,6 +2314,29 @@ declare function pass(): undefined;
|
|
|
2273
2314
|
*/
|
|
2274
2315
|
declare function passWith<T>(fn: (arg: T) => any): typeof pass;
|
|
2275
2316
|
|
|
2317
|
+
/**
|
|
2318
|
+
* 给定一个对象和对象中键的列表, 返回一个**只包含**给定键的新对象(是传入对象的浅拷贝)\
|
|
2319
|
+
* 如果你希望深拷贝一个对象, 请使用 `deepClone` 或 `fastClone`
|
|
2320
|
+
* @param obj 需要处理的对象
|
|
2321
|
+
* @param keys 需要**取出**的键, 可以是一个数组、字符串或谓词函数
|
|
2322
|
+
* @returns 传入对象的浅拷贝, 与传入对象不同的是新对象仅包含指定的键
|
|
2323
|
+
* @example
|
|
2324
|
+
* ```ts
|
|
2325
|
+
* pick({ a: 1, b: 2, c: '' }, ['a', 'c']) // { a: 1, c: '' }
|
|
2326
|
+
* pick({ a: 1, b: 2, c: '' }, 'b') // { b: 2 }
|
|
2327
|
+
* // 谓词函数
|
|
2328
|
+
* pick({ a: 1, b: 2, c: '' }, (value, key) => value === 2 || key === 'c') // { b: 2, c: '' }
|
|
2329
|
+
* // 需要注意的是传入谓词函数时可能会有类型不匹配的问题
|
|
2330
|
+
* // Typescript 无法得知最终过滤的结果, 而是认为过滤结果与原类型一致
|
|
2331
|
+
* const obj = pick({ a: 1, b: 2 }, (value, key) => value === 2) // { b: 2 }
|
|
2332
|
+
* type typeofObj = typeof obj // { a: number; b: number } <- Typescript 没有推导出正确结果
|
|
2333
|
+
* ```
|
|
2334
|
+
* @version 0.3.4
|
|
2335
|
+
*/
|
|
2336
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
2337
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: PickPredicate<T>): T;
|
|
2338
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, key: K): Pick<T, K>;
|
|
2339
|
+
|
|
2276
2340
|
// pipe
|
|
2277
2341
|
type PipeFuncList1<PipeArgs extends any[], PipeResult> = [(...args: PipeArgs) => PipeResult]
|
|
2278
2342
|
type PipeFuncList2<PipeArgs extends any[], PipeResult, Mid1 = any> = [
|
|
@@ -2408,5 +2472,5 @@ declare function throttle<T extends any[]>(fn: (...args: T) => any, delay: numbe
|
|
|
2408
2472
|
reset: () => void;
|
|
2409
2473
|
};
|
|
2410
2474
|
|
|
2411
|
-
export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, cartesianProduct, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, castArray, chunk, clamp, compose, _curryMore as curry, debounce, decimalNotation, dedent, deepClone, deepMerge, defer, fastClone, format, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getInitP, getTag, indent, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isEven, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isOdd, isPlaceholder, isPlainObject, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, lerp, memo, noop, not, parallel, pascalCase, pass, passWith, pipe, randomBase32String, randomChoice, randomDistribution, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, romanNumerals, round, roundBank, roundBase, roundCeil, roundFloor, scientificNotation, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, withResolvers };
|
|
2475
|
+
export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, cartesianProduct, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, castArray, chunk, clamp, compose, _curryMore as curry, debounce, decimalNotation, dedent, deepClone, deepMerge, defer, fastClone, format, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getInitP, getTag, indent, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isEven, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isOdd, isPlaceholder, isPlainObject, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, lerp, memo, noop, not, omit, parallel, pascalCase, pass, passWith, pick, pipe, randomBase32String, randomChoice, randomDistribution, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, romanNumerals, round, roundBank, roundBase, roundCeil, roundFloor, scientificNotation, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, uuidV7, withResolvers };
|
|
2412
2476
|
export type { BaseMargeType, CastArray, Chunked, CloneOptions, CustomCloner, IsNegative, IsPositive, IsZero, MergeOption, MergeStrategy, MergeStrategyFunction, MergeType, MergeTypeStrategy, Not, RangeOptions, SourceMergeType, Stringify, TargetMergeType, TypedArray };
|
package/lib/index.mjs
CHANGED
|
@@ -466,10 +466,10 @@ function decimalNotation(num) {
|
|
|
466
466
|
}
|
|
467
467
|
|
|
468
468
|
function isOdd(num) {
|
|
469
|
-
return !!(num & 1);
|
|
469
|
+
return !!(typeof num === 'bigint' ? num & BigInt(1) : num & 1);
|
|
470
470
|
}
|
|
471
471
|
function isEven(num) {
|
|
472
|
-
return !(num & 1);
|
|
472
|
+
return !(typeof num === 'bigint' ? num & BigInt(1) : num & 1);
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
function round(num, precision, type) {
|
|
@@ -747,7 +747,7 @@ function scientificNotation(num, options) {
|
|
|
747
747
|
return str;
|
|
748
748
|
const type = (options || {}).type || 'unicode';
|
|
749
749
|
const _precision = (options || {}).precision;
|
|
750
|
-
const precision = isNumber(_precision) ? clamp(_precision
|
|
750
|
+
const precision = isNumber(_precision) ? clamp(_precision, 0, Infinity) : null;
|
|
751
751
|
const round = (options || {}).round || 'round';
|
|
752
752
|
let [integer, fractional] = str.split('.');
|
|
753
753
|
let sign = '';
|
|
@@ -1605,6 +1605,15 @@ function uuidV4() {
|
|
|
1605
1605
|
return (`${r.slice(0, 8)}-${r.slice(8, 12)}-4${r.slice(12, 15)}-` +
|
|
1606
1606
|
`${'89ab'[Math.floor(Math.random() * 4)]}${r.slice(15, 18)}-${r.slice(18)}`);
|
|
1607
1607
|
}
|
|
1608
|
+
function uuidV7() {
|
|
1609
|
+
const r = randomHexString(18);
|
|
1610
|
+
let t = Date.now().toString(16);
|
|
1611
|
+
if (t.length < 12)
|
|
1612
|
+
t = '0'.repeat(12 - t.length) + t;
|
|
1613
|
+
t = t.slice(t.length - 12, t.length);
|
|
1614
|
+
return (`${t.slice(0, 8)}-${t.slice(8, 12)}-7${r.slice(0, 3)}-` +
|
|
1615
|
+
`${'89ab'[Math.floor(Math.random() * 4)]}${r.slice(3, 6)}-${r.slice(6)}`);
|
|
1616
|
+
}
|
|
1608
1617
|
|
|
1609
1618
|
const getDefaultVarCase = () => ({ code: '', upperCase: false, number: false });
|
|
1610
1619
|
const isUpperCase = RegExp.prototype.test.bind(/[A-Z]/);
|
|
@@ -2487,6 +2496,27 @@ function not(value) {
|
|
|
2487
2496
|
return !Boolean(value);
|
|
2488
2497
|
}
|
|
2489
2498
|
|
|
2499
|
+
function omit(obj, keys) {
|
|
2500
|
+
const res = (Object.getPrototypeOf(obj) ? {} : Object.create(null));
|
|
2501
|
+
const ownKeys = Reflect.ownKeys(obj);
|
|
2502
|
+
if (isFunction(keys)) {
|
|
2503
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2504
|
+
const key = ownKeys[i];
|
|
2505
|
+
if (!keys(obj[key], key, obj))
|
|
2506
|
+
res[key] = obj[key];
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
else {
|
|
2510
|
+
const keysSet = new Set((isArray(keys) ? keys : [keys]).map((k) => (isNumber(k) ? String(k) : k)));
|
|
2511
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2512
|
+
const key = ownKeys[i];
|
|
2513
|
+
if (!keysSet.has(key))
|
|
2514
|
+
res[key] = obj[key];
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
return res;
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2490
2520
|
function pass(value) {
|
|
2491
2521
|
return value;
|
|
2492
2522
|
}
|
|
@@ -2497,6 +2527,31 @@ function passWith(fn) {
|
|
|
2497
2527
|
});
|
|
2498
2528
|
}
|
|
2499
2529
|
|
|
2530
|
+
function pick(obj, keys) {
|
|
2531
|
+
const res = (Object.getPrototypeOf(obj) ? {} : Object.create(null));
|
|
2532
|
+
const ownKeys = Reflect.ownKeys(obj);
|
|
2533
|
+
if (isFunction(keys)) {
|
|
2534
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2535
|
+
const key = ownKeys[i];
|
|
2536
|
+
if (keys(obj[key], key, obj))
|
|
2537
|
+
res[key] = obj[key];
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
else if (isArray(keys)) {
|
|
2541
|
+
const keysSet = new Set(ownKeys);
|
|
2542
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2543
|
+
const key = keys[i];
|
|
2544
|
+
if (keysSet.has(isNumber(key) ? String(key) : key))
|
|
2545
|
+
res[key] = obj[key];
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
else if (isString(keys) || isNumber(keys) || isSymbol(keys)) {
|
|
2549
|
+
if (ownKeys.includes(isNumber(keys) ? String(keys) : keys))
|
|
2550
|
+
res[keys] = obj[keys];
|
|
2551
|
+
}
|
|
2552
|
+
return res;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2500
2555
|
function pipe(...pipeFunc) {
|
|
2501
2556
|
if (pipeFunc.length === 0) {
|
|
2502
2557
|
throw new Error('Invalid pipeFunc parameter: pipeFunc is empty');
|
|
@@ -2522,4 +2577,4 @@ function throttle(fn, delay, options) {
|
|
|
2522
2577
|
return _throttle(fn, delay, Object.assign({ trailing: false, leading: true }, options));
|
|
2523
2578
|
}
|
|
2524
2579
|
|
|
2525
|
-
export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, cartesianProduct, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, castArray, chunk, clamp, compose, _curryMore as curry, debounce, decimalNotation, dedent, deepClone, deepMerge, defer, fastClone, format, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getInitP, getTag, indent, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isEven, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isOdd, isPlaceholder, isPlainObject, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, lerp, memo, noop, not, parallel, pascalCase, pass, passWith, pipe, randomBase32String, randomChoice, randomDistribution, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, romanNumerals, round, roundBank, roundBase, roundCeil, roundFloor, scientificNotation, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, withResolvers };
|
|
2580
|
+
export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, cartesianProduct, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, castArray, chunk, clamp, compose, _curryMore as curry, debounce, decimalNotation, dedent, deepClone, deepMerge, defer, fastClone, format, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getInitP, getTag, indent, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isEven, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isOdd, isPlaceholder, isPlainObject, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, lerp, memo, noop, not, omit, parallel, pascalCase, pass, passWith, pick, pipe, randomBase32String, randomChoice, randomDistribution, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, romanNumerals, round, roundBank, roundBase, roundCeil, roundFloor, scientificNotation, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, uuidV7, withResolvers };
|
package/lib/index.umd.js
CHANGED
|
@@ -472,10 +472,10 @@ See the Mulan PSL v2 for more details.
|
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
function isOdd(num) {
|
|
475
|
-
return !!(num & 1);
|
|
475
|
+
return !!(typeof num === 'bigint' ? num & BigInt(1) : num & 1);
|
|
476
476
|
}
|
|
477
477
|
function isEven(num) {
|
|
478
|
-
return !(num & 1);
|
|
478
|
+
return !(typeof num === 'bigint' ? num & BigInt(1) : num & 1);
|
|
479
479
|
}
|
|
480
480
|
|
|
481
481
|
function round(num, precision, type) {
|
|
@@ -753,7 +753,7 @@ See the Mulan PSL v2 for more details.
|
|
|
753
753
|
return str;
|
|
754
754
|
const type = (options || {}).type || 'unicode';
|
|
755
755
|
const _precision = (options || {}).precision;
|
|
756
|
-
const precision = isNumber(_precision) ? clamp(_precision
|
|
756
|
+
const precision = isNumber(_precision) ? clamp(_precision, 0, Infinity) : null;
|
|
757
757
|
const round = (options || {}).round || 'round';
|
|
758
758
|
let [integer, fractional] = str.split('.');
|
|
759
759
|
let sign = '';
|
|
@@ -1611,6 +1611,15 @@ See the Mulan PSL v2 for more details.
|
|
|
1611
1611
|
return (`${r.slice(0, 8)}-${r.slice(8, 12)}-4${r.slice(12, 15)}-` +
|
|
1612
1612
|
`${'89ab'[Math.floor(Math.random() * 4)]}${r.slice(15, 18)}-${r.slice(18)}`);
|
|
1613
1613
|
}
|
|
1614
|
+
function uuidV7() {
|
|
1615
|
+
const r = randomHexString(18);
|
|
1616
|
+
let t = Date.now().toString(16);
|
|
1617
|
+
if (t.length < 12)
|
|
1618
|
+
t = '0'.repeat(12 - t.length) + t;
|
|
1619
|
+
t = t.slice(t.length - 12, t.length);
|
|
1620
|
+
return (`${t.slice(0, 8)}-${t.slice(8, 12)}-7${r.slice(0, 3)}-` +
|
|
1621
|
+
`${'89ab'[Math.floor(Math.random() * 4)]}${r.slice(3, 6)}-${r.slice(6)}`);
|
|
1622
|
+
}
|
|
1614
1623
|
|
|
1615
1624
|
const getDefaultVarCase = () => ({ code: '', upperCase: false, number: false });
|
|
1616
1625
|
const isUpperCase = RegExp.prototype.test.bind(/[A-Z]/);
|
|
@@ -2493,6 +2502,27 @@ See the Mulan PSL v2 for more details.
|
|
|
2493
2502
|
return !Boolean(value);
|
|
2494
2503
|
}
|
|
2495
2504
|
|
|
2505
|
+
function omit(obj, keys) {
|
|
2506
|
+
const res = (Object.getPrototypeOf(obj) ? {} : Object.create(null));
|
|
2507
|
+
const ownKeys = Reflect.ownKeys(obj);
|
|
2508
|
+
if (isFunction(keys)) {
|
|
2509
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2510
|
+
const key = ownKeys[i];
|
|
2511
|
+
if (!keys(obj[key], key, obj))
|
|
2512
|
+
res[key] = obj[key];
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
else {
|
|
2516
|
+
const keysSet = new Set((isArray(keys) ? keys : [keys]).map((k) => (isNumber(k) ? String(k) : k)));
|
|
2517
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2518
|
+
const key = ownKeys[i];
|
|
2519
|
+
if (!keysSet.has(key))
|
|
2520
|
+
res[key] = obj[key];
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
return res;
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2496
2526
|
function pass(value) {
|
|
2497
2527
|
return value;
|
|
2498
2528
|
}
|
|
@@ -2503,6 +2533,31 @@ See the Mulan PSL v2 for more details.
|
|
|
2503
2533
|
});
|
|
2504
2534
|
}
|
|
2505
2535
|
|
|
2536
|
+
function pick(obj, keys) {
|
|
2537
|
+
const res = (Object.getPrototypeOf(obj) ? {} : Object.create(null));
|
|
2538
|
+
const ownKeys = Reflect.ownKeys(obj);
|
|
2539
|
+
if (isFunction(keys)) {
|
|
2540
|
+
for (let i = 0; i < ownKeys.length; i++) {
|
|
2541
|
+
const key = ownKeys[i];
|
|
2542
|
+
if (keys(obj[key], key, obj))
|
|
2543
|
+
res[key] = obj[key];
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
else if (isArray(keys)) {
|
|
2547
|
+
const keysSet = new Set(ownKeys);
|
|
2548
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2549
|
+
const key = keys[i];
|
|
2550
|
+
if (keysSet.has(isNumber(key) ? String(key) : key))
|
|
2551
|
+
res[key] = obj[key];
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
else if (isString(keys) || isNumber(keys) || isSymbol(keys)) {
|
|
2555
|
+
if (ownKeys.includes(isNumber(keys) ? String(keys) : keys))
|
|
2556
|
+
res[keys] = obj[keys];
|
|
2557
|
+
}
|
|
2558
|
+
return res;
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2506
2561
|
function pipe(...pipeFunc) {
|
|
2507
2562
|
if (pipeFunc.length === 0) {
|
|
2508
2563
|
throw new Error('Invalid pipeFunc parameter: pipeFunc is empty');
|
|
@@ -2617,10 +2672,12 @@ See the Mulan PSL v2 for more details.
|
|
|
2617
2672
|
exports.memo = memo;
|
|
2618
2673
|
exports.noop = noop;
|
|
2619
2674
|
exports.not = not;
|
|
2675
|
+
exports.omit = omit;
|
|
2620
2676
|
exports.parallel = parallel;
|
|
2621
2677
|
exports.pascalCase = pascalCase;
|
|
2622
2678
|
exports.pass = pass;
|
|
2623
2679
|
exports.passWith = passWith;
|
|
2680
|
+
exports.pick = pick;
|
|
2624
2681
|
exports.pipe = pipe;
|
|
2625
2682
|
exports.randomBase32String = randomBase32String;
|
|
2626
2683
|
exports.randomChoice = randomChoice;
|
|
@@ -2650,6 +2707,7 @@ See the Mulan PSL v2 for more details.
|
|
|
2650
2707
|
exports.uncapitalize = uncapitalize;
|
|
2651
2708
|
exports.uuidNil = uuidNil;
|
|
2652
2709
|
exports.uuidV4 = uuidV4;
|
|
2710
|
+
exports.uuidV7 = uuidV7;
|
|
2653
2711
|
exports.withResolvers = withResolvers;
|
|
2654
2712
|
|
|
2655
2713
|
}));
|