foreslash 0.3.4 → 0.3.6

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 CHANGED
@@ -1,6 +1,38 @@
1
1
  # Change Log
2
2
 
3
- ## Version 0.3.4 - 2025-11-
3
+ ## Version 0.3.6 - 2026-01-
4
+
5
+ Unstable version
6
+
7
+ Added some Base64 related methods
8
+
9
+ - Feat 🥥 Functions added: `encodeBase64` `decodeBase64` `blobToBase64` `base64ToBlob` `deprecate` and so forth
10
+ - Other fixes and improvements
11
+
12
+ 不稳定版本
13
+
14
+ 添加了一些 Base64 相关的方法
15
+
16
+ - 功能 🥥 添加函数: `encodeBase64` `decodeBase64` `blobToBase64` `base64ToBlob` `deprecate` 等
17
+ - 其他修复与优化
18
+
19
+ ## Version 0.3.5 - 2025-11-30
20
+
21
+ Unstable version
22
+
23
+ - Feat 🥥 Functions added: `uuidV7`
24
+ - Feat 🥥 Function change: `isOdd` and `isEven` now support BigInt
25
+ - Fix 🥕 Document: Added version tags to several methods
26
+ - Other fixes and improvements
27
+
28
+ 不稳定版本
29
+
30
+ - 功能 🥥 添加函数: `uuidV7`
31
+ - 功能 🥥 变更函数: `isOdd` 和 `isEven` 现在支持 BigInt
32
+ - 修复 🥕 文档: 补充部分方法的版本标签
33
+ - 其他修复与优化
34
+
35
+ ## Version 0.3.4 - 2025-11-17
4
36
 
5
37
  Unstable version
6
38
 
package/lib/index.cmn.cjs CHANGED
@@ -190,9 +190,9 @@ function isObject(value) {
190
190
  }
191
191
 
192
192
  const global$7 = getGlobalThis();
193
- const Blob = global$7.Blob;
193
+ const Blob$1 = global$7.Blob;
194
194
  function isBlob(value) {
195
- return !!Blob && isObject(value) && getTag(value) === 'Blob';
195
+ return !!Blob$1 && isObject(value) && getTag(value) === 'Blob';
196
196
  }
197
197
 
198
198
  function isBoolean(value) {
@@ -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) {
@@ -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]/);
@@ -1739,6 +1748,49 @@ function titleCase(str, options) {
1739
1748
  : ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
1740
1749
  }
1741
1750
 
1751
+ function encodeBase64(str) {
1752
+ const utf8Bytes = new TextEncoder().encode(str);
1753
+ let binary = '';
1754
+ utf8Bytes.forEach((byte) => {
1755
+ binary += String.fromCharCode(byte);
1756
+ });
1757
+ return btoa(binary);
1758
+ }
1759
+ function decodeBase64(base64Str) {
1760
+ const binary = atob(base64Str);
1761
+ const bytes = new Uint8Array(binary.length);
1762
+ for (let i = 0; i < binary.length; i++) {
1763
+ bytes[i] = binary.charCodeAt(i);
1764
+ }
1765
+ return new TextDecoder().decode(bytes);
1766
+ }
1767
+ function blobToBase64(blob) {
1768
+ return new Promise((resolve, reject) => {
1769
+ const reader = new FileReader();
1770
+ reader.onloadend = () => {
1771
+ const dataUrl = reader.result;
1772
+ const base64 = dataUrl.split(',')[1];
1773
+ resolve(base64);
1774
+ };
1775
+ reader.onerror = reject;
1776
+ reader.readAsDataURL(blob);
1777
+ });
1778
+ }
1779
+ function base64ToBlob(base64Str, mimeType = 'text/plain') {
1780
+ const byteCharacters = atob(base64Str);
1781
+ const byteArray = new Uint8Array(byteCharacters.length);
1782
+ for (let i = 0; i < byteCharacters.length; i++) {
1783
+ byteArray[i] = byteCharacters.charCodeAt(i);
1784
+ }
1785
+ return new Blob([byteArray], { type: mimeType });
1786
+ }
1787
+ function dataUrlToBlob(dataUrl) {
1788
+ const [header, base64Str] = dataUrl.split(',');
1789
+ const mimeMatch = header.match(/data:([^;]*)(?:;charset:.*?)?(?:;base64)?/);
1790
+ const mimeType = mimeMatch ? mimeMatch[1] || 'text/plain' : 'text/plain';
1791
+ return base64ToBlob(base64Str, mimeType);
1792
+ }
1793
+
1742
1794
  function capitalize(str) {
1743
1795
  if (!str)
1744
1796
  return str;
@@ -2367,6 +2419,21 @@ function deepMerge(target, source, option) {
2367
2419
  return res;
2368
2420
  }
2369
2421
 
2422
+ function deprecate(fn, msg, code) {
2423
+ let isWarned = false;
2424
+ return function deprecateFn(...args) {
2425
+ const res = fn.apply(this, args);
2426
+ if (!isWarned) {
2427
+ if (code)
2428
+ console.warn(`[${code}]`, msg);
2429
+ else
2430
+ console.warn(msg);
2431
+ isWarned = true;
2432
+ }
2433
+ return res;
2434
+ };
2435
+ }
2436
+
2370
2437
  function _fastClone(obj, map) {
2371
2438
  if (map.has(obj))
2372
2439
  return map.get(obj);
@@ -2574,6 +2641,8 @@ exports.$$Empty = $$Empty;
2574
2641
  exports._ = _;
2575
2642
  exports.acceptableFileName = acceptableFileName;
2576
2643
  exports.acceptableFileType = acceptableFileType;
2644
+ exports.base64ToBlob = base64ToBlob;
2645
+ exports.blobToBase64 = blobToBase64;
2577
2646
  exports.camelCase = camelCase;
2578
2647
  exports.capitalize = capitalize;
2579
2648
  exports.cartesianProduct = cartesianProduct;
@@ -2587,12 +2656,16 @@ exports.chunk = chunk;
2587
2656
  exports.clamp = clamp;
2588
2657
  exports.compose = compose;
2589
2658
  exports.curry = _curryMore;
2659
+ exports.dataUrlToBlob = dataUrlToBlob;
2590
2660
  exports.debounce = debounce;
2591
2661
  exports.decimalNotation = decimalNotation;
2662
+ exports.decodeBase64 = decodeBase64;
2592
2663
  exports.dedent = dedent;
2593
2664
  exports.deepClone = deepClone;
2594
2665
  exports.deepMerge = deepMerge;
2595
2666
  exports.defer = defer;
2667
+ exports.deprecate = deprecate;
2668
+ exports.encodeBase64 = encodeBase64;
2596
2669
  exports.fastClone = fastClone;
2597
2670
  exports.format = format;
2598
2671
  exports.getAcceptableExtByMIME = getAcceptableExtByMIME;
@@ -2694,4 +2767,5 @@ exports.ulid = ulid;
2694
2767
  exports.uncapitalize = uncapitalize;
2695
2768
  exports.uuidNil = uuidNil;
2696
2769
  exports.uuidV4 = uuidV4;
2770
+ exports.uuidV7 = uuidV7;
2697
2771
  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
  * 用线性插值法求取一个中间值
@@ -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 [见标准第 4.1.7 节](https://www.ietf.org/rfc/rfc4122.txt) */
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.ietf.org/rfc/rfc4122.txt) 字符串(小写)
1484
- * @returns 一个标准的 UUID V4 字符串
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
  * 将输入的字符串处理成小驼峰格式
@@ -1599,6 +1612,77 @@ declare function titleCase(str: string, options?: {
1599
1612
  keepNumber?: boolean;
1600
1613
  }): string;
1601
1614
 
1615
+ /**
1616
+ * 将一个字符串转换为 Base64 编码的字符串, 支持中文等
1617
+ * - 内部使用到了 `btoa` 方法, 可能会有报错
1618
+ * - 如果想在 Internet Explorer 上使用, 请 polyFill `TextEncoder` 对象
1619
+ * @param str 需要转换的字符串
1620
+ * @returns 输入字符串转换为 Base64 编码后的字符串
1621
+ * @example
1622
+ * ```js
1623
+ * encodeBase64('abc123') // YWJjMTIz
1624
+ * encodeBase64('文字') // 5paH5a2X
1625
+ * ```
1626
+ * @version 0.3.6
1627
+ */
1628
+ declare function encodeBase64(str: string): string;
1629
+ /**
1630
+ * 将一个 Base64 编码的字符串转换为普通字符串, 支持中文等
1631
+ * - 内部使用到了 `atob` 方法, 可能会有报错
1632
+ * - 如果想在 Internet Explorer 上使用, 请 polyFill `TextDecoder` 对象
1633
+ * @param base64Str 需要转换的 Base64 编码字符串
1634
+ * @returns 输入 Base64 编码字符串转换后的普通字符串
1635
+ * @example
1636
+ * ```js
1637
+ * decodeBase64('YWJjMTIz') // abc123
1638
+ * decodeBase64('5paH5a2X') // 文字
1639
+ * ```
1640
+ * @version 0.3.6
1641
+ */
1642
+ declare function decodeBase64(base64Str: string): string;
1643
+ /**
1644
+ * 将 Blob 对象转换为 Base64 编码的字符串
1645
+ * - 如果想在 Internet Explorer 9 及更早的 IE 上使用, 请 polyFill `FileReader` 对象
1646
+ * @param blob 需要转换的 Blob 对象
1647
+ * @returns 输入 Blob 对象转换为 Base64 编码后的字符串
1648
+ * @example
1649
+ * ```js
1650
+ * const blob = new Blob(['Hello, world!'], { type: 'text/plain' })
1651
+ * blobToBase64(blob).then(base64 => {
1652
+ * console.log(base64) // SGVsbG8sIHdvcmxkIQ==
1653
+ * })
1654
+ * ```
1655
+ * @version 0.3.6
1656
+ */
1657
+ declare function blobToBase64(blob: Blob): Promise<string>;
1658
+ /**
1659
+ * 将 Base64 编码的字符串转换为 Blob 对象
1660
+ * @param base64Str 需要转换的 Base64 编码字符串
1661
+ * @param mimeType 转换后 Blob 对象的 MIME 类型, 默认为 'text/plain'
1662
+ * @returns 输入 Base64 编码字符串转换后的 Blob 对象
1663
+ * @example
1664
+ * ```js
1665
+ * const base64 = 'SGVsbG8sIHdvcmxkIQ=='
1666
+ * const blob = base64ToBlob(base64, 'text/plain')
1667
+ * console.log(blob) // Blob { size: 13, type: "text/plain" }
1668
+ * ```
1669
+ * @version 0.3.6
1670
+ */
1671
+ declare function base64ToBlob(base64Str: string, mimeType?: string): Blob;
1672
+ /**
1673
+ * 将 Data URL 转换为 Blob 对象
1674
+ * @param dataUrl 需要转换的 Data URL 字符串
1675
+ * @returns 输入 Data URL 转换后的 Blob 对象
1676
+ * @example
1677
+ * ```js
1678
+ * const dataUrl = 'data:text/plain;base64,SGVsbG8sIHdvcmxkIQ=='
1679
+ * const blob = dataUrlToBlob(dataUrl)
1680
+ * console.log(blob) // Blob { size: 13, type: "text/plain" }
1681
+ * ```
1682
+ * @version 0.3.6
1683
+ */
1684
+ declare function dataUrlToBlob(dataUrl: string): Blob;
1685
+
1602
1686
  /**
1603
1687
  * 将字符串的首字母大写
1604
1688
  * @param str 字符串
@@ -2152,6 +2236,32 @@ type MergeOption = {
2152
2236
  */
2153
2237
  declare function deepMerge<Target, Source, Result = Target & Source>(target: Target, source: Source, option?: MergeOption): Result;
2154
2238
 
2239
+ /**
2240
+ * 将一个函数标记为已废弃(不推荐使用), 类似 NodeJS 的 `utils.deprecate`
2241
+ * @param fn 需要标记为已废弃的函数
2242
+ * @param msg 调用函数时, 在控制台发出的警报信息
2243
+ * @param code 选填, 废弃编码
2244
+ * @returns 一个与传入的函数输入输出一致的新函数, 区别是第一次调用时会在控制台触发一次警告
2245
+ * @example
2246
+ * ```js
2247
+ * const fn = () => {
2248
+ * console.log('test')
2249
+ * return 123
2250
+ * }
2251
+ * const deprecateFn = deprecate(fn, 'Do not use this!', 'Foreslash')
2252
+ * const res = deprecateFn() // res 值为 123
2253
+ * deprecateFn()
2254
+ * deprecateFn()
2255
+ * // console:
2256
+ * // test
2257
+ * // [Foreslash] Do not use this!
2258
+ * // test
2259
+ * // test
2260
+ * ```
2261
+ * @version 0.3.6
2262
+ */
2263
+ declare function deprecate<Fn extends Function>(fn: Fn, msg: string, code?: string): Fn;
2264
+
2155
2265
  /**
2156
2266
  * 快速深拷贝
2157
2267
  * - 功能较为齐全, 相对 `deepClone` 而言运行更快
@@ -2459,5 +2569,5 @@ declare function throttle<T extends any[]>(fn: (...args: T) => any, delay: numbe
2459
2569
  reset: () => void;
2460
2570
  };
2461
2571
 
2462
- 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, withResolvers };
2572
+ export { $$Empty, _, acceptableFileName, acceptableFileType, base64ToBlob, blobToBase64, camelCase, capitalize, cartesianProduct, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, castArray, chunk, clamp, compose, _curryMore as curry, dataUrlToBlob, debounce, decimalNotation, decodeBase64, dedent, deepClone, deepMerge, defer, deprecate, encodeBase64, 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 };
2463
2573
  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
@@ -188,9 +188,9 @@ function isObject(value) {
188
188
  }
189
189
 
190
190
  const global$7 = getGlobalThis();
191
- const Blob = global$7.Blob;
191
+ const Blob$1 = global$7.Blob;
192
192
  function isBlob(value) {
193
- return !!Blob && isObject(value) && getTag(value) === 'Blob';
193
+ return !!Blob$1 && isObject(value) && getTag(value) === 'Blob';
194
194
  }
195
195
 
196
196
  function isBoolean(value) {
@@ -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) {
@@ -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]/);
@@ -1737,6 +1746,49 @@ function titleCase(str, options) {
1737
1746
  : ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
1738
1747
  }
1739
1748
 
1749
+ function encodeBase64(str) {
1750
+ const utf8Bytes = new TextEncoder().encode(str);
1751
+ let binary = '';
1752
+ utf8Bytes.forEach((byte) => {
1753
+ binary += String.fromCharCode(byte);
1754
+ });
1755
+ return btoa(binary);
1756
+ }
1757
+ function decodeBase64(base64Str) {
1758
+ const binary = atob(base64Str);
1759
+ const bytes = new Uint8Array(binary.length);
1760
+ for (let i = 0; i < binary.length; i++) {
1761
+ bytes[i] = binary.charCodeAt(i);
1762
+ }
1763
+ return new TextDecoder().decode(bytes);
1764
+ }
1765
+ function blobToBase64(blob) {
1766
+ return new Promise((resolve, reject) => {
1767
+ const reader = new FileReader();
1768
+ reader.onloadend = () => {
1769
+ const dataUrl = reader.result;
1770
+ const base64 = dataUrl.split(',')[1];
1771
+ resolve(base64);
1772
+ };
1773
+ reader.onerror = reject;
1774
+ reader.readAsDataURL(blob);
1775
+ });
1776
+ }
1777
+ function base64ToBlob(base64Str, mimeType = 'text/plain') {
1778
+ const byteCharacters = atob(base64Str);
1779
+ const byteArray = new Uint8Array(byteCharacters.length);
1780
+ for (let i = 0; i < byteCharacters.length; i++) {
1781
+ byteArray[i] = byteCharacters.charCodeAt(i);
1782
+ }
1783
+ return new Blob([byteArray], { type: mimeType });
1784
+ }
1785
+ function dataUrlToBlob(dataUrl) {
1786
+ const [header, base64Str] = dataUrl.split(',');
1787
+ const mimeMatch = header.match(/data:([^;]*)(?:;charset:.*?)?(?:;base64)?/);
1788
+ const mimeType = mimeMatch ? mimeMatch[1] || 'text/plain' : 'text/plain';
1789
+ return base64ToBlob(base64Str, mimeType);
1790
+ }
1791
+
1740
1792
  function capitalize(str) {
1741
1793
  if (!str)
1742
1794
  return str;
@@ -2365,6 +2417,21 @@ function deepMerge(target, source, option) {
2365
2417
  return res;
2366
2418
  }
2367
2419
 
2420
+ function deprecate(fn, msg, code) {
2421
+ let isWarned = false;
2422
+ return function deprecateFn(...args) {
2423
+ const res = fn.apply(this, args);
2424
+ if (!isWarned) {
2425
+ if (code)
2426
+ console.warn(`[${code}]`, msg);
2427
+ else
2428
+ console.warn(msg);
2429
+ isWarned = true;
2430
+ }
2431
+ return res;
2432
+ };
2433
+ }
2434
+
2368
2435
  function _fastClone(obj, map) {
2369
2436
  if (map.has(obj))
2370
2437
  return map.get(obj);
@@ -2568,4 +2635,4 @@ function throttle(fn, delay, options) {
2568
2635
  return _throttle(fn, delay, Object.assign({ trailing: false, leading: true }, options));
2569
2636
  }
2570
2637
 
2571
- 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, withResolvers };
2638
+ export { $$Empty, _, acceptableFileName, acceptableFileType, base64ToBlob, blobToBase64, camelCase, capitalize, cartesianProduct, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, castArray, chunk, clamp, compose, _curryMore as curry, dataUrlToBlob, debounce, decimalNotation, decodeBase64, dedent, deepClone, deepMerge, defer, deprecate, encodeBase64, 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
@@ -194,9 +194,9 @@ See the Mulan PSL v2 for more details.
194
194
  }
195
195
 
196
196
  const global$7 = getGlobalThis();
197
- const Blob = global$7.Blob;
197
+ const Blob$1 = global$7.Blob;
198
198
  function isBlob(value) {
199
- return !!Blob && isObject(value) && getTag(value) === 'Blob';
199
+ return !!Blob$1 && isObject(value) && getTag(value) === 'Blob';
200
200
  }
201
201
 
202
202
  function isBoolean(value) {
@@ -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) {
@@ -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]/);
@@ -1743,6 +1752,49 @@ See the Mulan PSL v2 for more details.
1743
1752
  : ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
1744
1753
  }
1745
1754
 
1755
+ function encodeBase64(str) {
1756
+ const utf8Bytes = new TextEncoder().encode(str);
1757
+ let binary = '';
1758
+ utf8Bytes.forEach((byte) => {
1759
+ binary += String.fromCharCode(byte);
1760
+ });
1761
+ return btoa(binary);
1762
+ }
1763
+ function decodeBase64(base64Str) {
1764
+ const binary = atob(base64Str);
1765
+ const bytes = new Uint8Array(binary.length);
1766
+ for (let i = 0; i < binary.length; i++) {
1767
+ bytes[i] = binary.charCodeAt(i);
1768
+ }
1769
+ return new TextDecoder().decode(bytes);
1770
+ }
1771
+ function blobToBase64(blob) {
1772
+ return new Promise((resolve, reject) => {
1773
+ const reader = new FileReader();
1774
+ reader.onloadend = () => {
1775
+ const dataUrl = reader.result;
1776
+ const base64 = dataUrl.split(',')[1];
1777
+ resolve(base64);
1778
+ };
1779
+ reader.onerror = reject;
1780
+ reader.readAsDataURL(blob);
1781
+ });
1782
+ }
1783
+ function base64ToBlob(base64Str, mimeType = 'text/plain') {
1784
+ const byteCharacters = atob(base64Str);
1785
+ const byteArray = new Uint8Array(byteCharacters.length);
1786
+ for (let i = 0; i < byteCharacters.length; i++) {
1787
+ byteArray[i] = byteCharacters.charCodeAt(i);
1788
+ }
1789
+ return new Blob([byteArray], { type: mimeType });
1790
+ }
1791
+ function dataUrlToBlob(dataUrl) {
1792
+ const [header, base64Str] = dataUrl.split(',');
1793
+ const mimeMatch = header.match(/data:([^;]*)(?:;charset:.*?)?(?:;base64)?/);
1794
+ const mimeType = mimeMatch ? mimeMatch[1] || 'text/plain' : 'text/plain';
1795
+ return base64ToBlob(base64Str, mimeType);
1796
+ }
1797
+
1746
1798
  function capitalize(str) {
1747
1799
  if (!str)
1748
1800
  return str;
@@ -2371,6 +2423,21 @@ See the Mulan PSL v2 for more details.
2371
2423
  return res;
2372
2424
  }
2373
2425
 
2426
+ function deprecate(fn, msg, code) {
2427
+ let isWarned = false;
2428
+ return function deprecateFn(...args) {
2429
+ const res = fn.apply(this, args);
2430
+ if (!isWarned) {
2431
+ if (code)
2432
+ console.warn(`[${code}]`, msg);
2433
+ else
2434
+ console.warn(msg);
2435
+ isWarned = true;
2436
+ }
2437
+ return res;
2438
+ };
2439
+ }
2440
+
2374
2441
  function _fastClone(obj, map) {
2375
2442
  if (map.has(obj))
2376
2443
  return map.get(obj);
@@ -2578,6 +2645,8 @@ See the Mulan PSL v2 for more details.
2578
2645
  exports._ = _;
2579
2646
  exports.acceptableFileName = acceptableFileName;
2580
2647
  exports.acceptableFileType = acceptableFileType;
2648
+ exports.base64ToBlob = base64ToBlob;
2649
+ exports.blobToBase64 = blobToBase64;
2581
2650
  exports.camelCase = camelCase;
2582
2651
  exports.capitalize = capitalize;
2583
2652
  exports.cartesianProduct = cartesianProduct;
@@ -2591,12 +2660,16 @@ See the Mulan PSL v2 for more details.
2591
2660
  exports.clamp = clamp;
2592
2661
  exports.compose = compose;
2593
2662
  exports.curry = _curryMore;
2663
+ exports.dataUrlToBlob = dataUrlToBlob;
2594
2664
  exports.debounce = debounce;
2595
2665
  exports.decimalNotation = decimalNotation;
2666
+ exports.decodeBase64 = decodeBase64;
2596
2667
  exports.dedent = dedent;
2597
2668
  exports.deepClone = deepClone;
2598
2669
  exports.deepMerge = deepMerge;
2599
2670
  exports.defer = defer;
2671
+ exports.deprecate = deprecate;
2672
+ exports.encodeBase64 = encodeBase64;
2600
2673
  exports.fastClone = fastClone;
2601
2674
  exports.format = format;
2602
2675
  exports.getAcceptableExtByMIME = getAcceptableExtByMIME;
@@ -2698,6 +2771,7 @@ See the Mulan PSL v2 for more details.
2698
2771
  exports.uncapitalize = uncapitalize;
2699
2772
  exports.uuidNil = uuidNil;
2700
2773
  exports.uuidV4 = uuidV4;
2774
+ exports.uuidV7 = uuidV7;
2701
2775
  exports.withResolvers = withResolvers;
2702
2776
 
2703
2777
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreslash",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Foreslash is a Javascript utilities lib which contains plenty of practical functions.",
5
5
  "author": "moushu",
6
6
  "license": "Mulan PSL v2",
@@ -36,6 +36,7 @@
36
36
  "dev": "rollup -c -w",
37
37
  "build": "rollup -c",
38
38
  "test": "tsd --files /test/**/*.test-d.ts && jest --coverage",
39
+ "test:slow": "tsd --files /test/**/*.test-d.ts && jest --coverage --runInBand",
39
40
  "prepublishOnly": "jest --coverage && npm run build",
40
41
  "docs:dev": "rollup -c && vitepress dev docs",
41
42
  "docs:build": "rollup -c && vitepress build docs",