@jiakun-zhao/utils 1.3.3 → 1.3.4

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/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from '@antfu/utils';
2
- export { default as naturalCompare } from 'natural-compare';
3
2
 
4
3
  declare const isArray: (arg: any) => arg is any[];
5
4
  declare function singleOrNull<T>(arr: T[]): T | null;
@@ -7,40 +6,14 @@ declare function createArray<T = number>(length: number, mapFn?: (index: number)
7
6
 
8
7
  declare function cleanText(str: string, searchValue: RegExp | string): string;
9
8
 
9
+ declare const naturalCompare: {
10
+ (a: string, b: string): -1 | 0 | 1;
11
+ (a: number, b: number): -1 | 0 | 1;
12
+ };
10
13
  declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
11
14
  declare function from<T>(value: T): {
12
- to: <R>(fn: (value: T) => R) => {
13
- to: <R_1>(fn: (value: R) => R_1) => {
14
- to: <R_2>(fn: (value: R_1) => R_2) => {
15
- to: <R_3>(fn: (value: R_2) => R_3) => {
16
- to: <R_4>(fn: (value: R_3) => R_4) => {
17
- to: <R_5>(fn: (value: R_4) => R_5) => {
18
- to: <R_6>(fn: (value: R_5) => R_6) => {
19
- to: <R_7>(fn: (value: R_6) => R_7) => {
20
- to: <R_8>(fn: (value: R_7) => R_8) => {
21
- to: <R_9>(fn: (value: R_8) => R_9) => {
22
- to: <R_10>(fn: (value: R_9) => R_10) => /*elided*/ any;
23
- get: () => R_9;
24
- };
25
- get: () => R_8;
26
- };
27
- get: () => R_7;
28
- };
29
- get: () => R_6;
30
- };
31
- get: () => R_5;
32
- };
33
- get: () => R_4;
34
- };
35
- get: () => R_3;
36
- };
37
- get: () => R_2;
38
- };
39
- get: () => R_1;
40
- };
41
- get: () => R;
42
- };
43
15
  get: () => T;
16
+ to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
44
17
  };
45
18
 
46
- export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
19
+ export { cleanText, createArray, from, getValueOrUndefined, isArray, naturalCompare, singleOrNull };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from '@antfu/utils';
2
- export { default as naturalCompare } from 'natural-compare';
3
2
 
4
3
  declare const isArray: (arg: any) => arg is any[];
5
4
  declare function singleOrNull<T>(arr: T[]): T | null;
@@ -7,40 +6,14 @@ declare function createArray<T = number>(length: number, mapFn?: (index: number)
7
6
 
8
7
  declare function cleanText(str: string, searchValue: RegExp | string): string;
9
8
 
9
+ declare const naturalCompare: {
10
+ (a: string, b: string): -1 | 0 | 1;
11
+ (a: number, b: number): -1 | 0 | 1;
12
+ };
10
13
  declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
11
14
  declare function from<T>(value: T): {
12
- to: <R>(fn: (value: T) => R) => {
13
- to: <R_1>(fn: (value: R) => R_1) => {
14
- to: <R_2>(fn: (value: R_1) => R_2) => {
15
- to: <R_3>(fn: (value: R_2) => R_3) => {
16
- to: <R_4>(fn: (value: R_3) => R_4) => {
17
- to: <R_5>(fn: (value: R_4) => R_5) => {
18
- to: <R_6>(fn: (value: R_5) => R_6) => {
19
- to: <R_7>(fn: (value: R_6) => R_7) => {
20
- to: <R_8>(fn: (value: R_7) => R_8) => {
21
- to: <R_9>(fn: (value: R_8) => R_9) => {
22
- to: <R_10>(fn: (value: R_9) => R_10) => /*elided*/ any;
23
- get: () => R_9;
24
- };
25
- get: () => R_8;
26
- };
27
- get: () => R_7;
28
- };
29
- get: () => R_6;
30
- };
31
- get: () => R_5;
32
- };
33
- get: () => R_4;
34
- };
35
- get: () => R_3;
36
- };
37
- get: () => R_2;
38
- };
39
- get: () => R_1;
40
- };
41
- get: () => R;
42
- };
43
15
  get: () => T;
16
+ to: <R>(fn: (value: T) => R) => ReturnType<typeof from<R>>;
44
17
  };
45
18
 
46
- export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
19
+ export { cleanText, createArray, from, getValueOrUndefined, isArray, naturalCompare, singleOrNull };
package/dist/index.mjs CHANGED
@@ -1,5 +1,75 @@
1
1
  export * from '@antfu/utils';
2
- export { default as naturalCompare } from 'natural-compare';
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ var naturalCompare$1 = {exports: {}};
8
+
9
+ var hasRequiredNaturalCompare;
10
+
11
+ function requireNaturalCompare () {
12
+ if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
13
+ hasRequiredNaturalCompare = 1;
14
+ /*
15
+ * @version 1.4.0
16
+ * @date 2015-10-26
17
+ * @stability 3 - Stable
18
+ * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
19
+ * @license MIT License
20
+ */
21
+
22
+
23
+ var naturalCompare = function(a, b) {
24
+ var i, codeA
25
+ , codeB = 1
26
+ , posA = 0
27
+ , posB = 0
28
+ , alphabet = String.alphabet;
29
+
30
+ function getCode(str, pos, code) {
31
+ if (code) {
32
+ for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
33
+ return +str.slice(pos - 1, i)
34
+ }
35
+ code = alphabet && alphabet.indexOf(str.charAt(pos));
36
+ return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
37
+ : code < 46 ? 65 // -
38
+ : code < 48 ? code - 1
39
+ : code < 58 ? code + 18 // 0-9
40
+ : code < 65 ? code - 11
41
+ : code < 91 ? code + 11 // A-Z
42
+ : code < 97 ? code - 37
43
+ : code < 123 ? code + 5 // a-z
44
+ : code - 63
45
+ }
46
+
47
+
48
+ if ((a+="") != (b+="")) for (;codeB;) {
49
+ codeA = getCode(a, posA++);
50
+ codeB = getCode(b, posB++);
51
+
52
+ if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
53
+ codeA = getCode(a, posA, posA);
54
+ codeB = getCode(b, posB, posA = i);
55
+ posB = i;
56
+ }
57
+
58
+ if (codeA != codeB) return (codeA < codeB) ? -1 : 1
59
+ }
60
+ return 0
61
+ };
62
+
63
+ try {
64
+ naturalCompare$1.exports = naturalCompare;
65
+ } catch (e) {
66
+ String.naturalCompare = naturalCompare;
67
+ }
68
+ return naturalCompare$1.exports;
69
+ }
70
+
71
+ var naturalCompareExports = requireNaturalCompare();
72
+ const naturalCompareFn = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
3
73
 
4
74
  const isArray = Array.isArray;
5
75
  function singleOrNull(arr) {
@@ -13,14 +83,15 @@ function cleanText(str, searchValue) {
13
83
  return str.replace(searchValue, "");
14
84
  }
15
85
 
86
+ const naturalCompare = naturalCompareFn;
16
87
  function getValueOrUndefined(condition, value) {
17
88
  return condition ? value : void 0;
18
89
  }
19
90
  function from(value) {
20
91
  return {
21
- to: (fn) => from(fn(value)),
22
- get: () => value
92
+ get: () => value,
93
+ to: (fn) => from(fn(value))
23
94
  };
24
95
  }
25
96
 
26
- export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };
97
+ export { cleanText, createArray, from, getValueOrUndefined, isArray, naturalCompare, singleOrNull };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jiakun-zhao/utils",
3
3
  "type": "module",
4
- "version": "1.3.3",
4
+ "version": "1.3.4",
5
5
  "description": "Utils.",
6
6
  "author": "Jiakun Zhao <hi@zhaojiakun.com>",
7
7
  "license": "MIT",
@@ -16,19 +16,17 @@
16
16
  "exports": {
17
17
  ".": {
18
18
  "import": "./dist/index.mjs",
19
- "require": "./dist/index.cjs",
20
19
  "types": "./dist/index.d.ts"
21
20
  }
22
21
  },
23
- "main": "./dist/index.cjs",
22
+ "main": "./dist/index.mjs",
24
23
  "module": "./dist/index.mjs",
25
24
  "types": "./dist/index.d.ts",
26
25
  "files": [
27
26
  "dist"
28
27
  ],
29
28
  "dependencies": {
30
- "@antfu/utils": "^9.2.0",
31
- "natural-compare": "^1.4.0"
29
+ "@antfu/utils": "^9.2.0"
32
30
  },
33
31
  "devDependencies": {
34
32
  "@jiakun-zhao/eslint-config": "^4.1.8",
@@ -36,6 +34,7 @@
36
34
  "@types/node": "^24.0.3",
37
35
  "bumpp": "^10.2.0",
38
36
  "eslint": "^9.29.0",
37
+ "natural-compare": "^1.4.0",
39
38
  "typescript": "^5.8.3",
40
39
  "unbuild": "^3.5.0",
41
40
  "vitest": "^3.2.4"
package/dist/index.cjs DELETED
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- const utils = require('@antfu/utils');
4
- const naturalCompare = require('natural-compare');
5
-
6
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
7
-
8
- const naturalCompare__default = /*#__PURE__*/_interopDefaultCompat(naturalCompare);
9
-
10
- const isArray = Array.isArray;
11
- function singleOrNull(arr) {
12
- return arr.length === 1 ? arr[0] : null;
13
- }
14
- function createArray(length, mapFn) {
15
- return Array.from({ length }, (_, index) => mapFn?.(index) ?? index);
16
- }
17
-
18
- function cleanText(str, searchValue) {
19
- return str.replace(searchValue, "");
20
- }
21
-
22
- function getValueOrUndefined(condition, value) {
23
- return condition ? value : void 0;
24
- }
25
- function from(value) {
26
- return {
27
- to: (fn) => from(fn(value)),
28
- get: () => value
29
- };
30
- }
31
-
32
- exports.naturalCompare = naturalCompare__default;
33
- exports.cleanText = cleanText;
34
- exports.createArray = createArray;
35
- exports.from = from;
36
- exports.getValueOrUndefined = getValueOrUndefined;
37
- exports.isArray = isArray;
38
- exports.singleOrNull = singleOrNull;
39
- Object.prototype.hasOwnProperty.call(utils, '__proto__') &&
40
- !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
41
- Object.defineProperty(exports, '__proto__', {
42
- enumerable: true,
43
- value: utils['__proto__']
44
- });
45
-
46
- Object.keys(utils).forEach(function (k) {
47
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
48
- });
package/dist/index.d.cts DELETED
@@ -1,46 +0,0 @@
1
- export * from '@antfu/utils';
2
- export { default as naturalCompare } from 'natural-compare';
3
-
4
- declare const isArray: (arg: any) => arg is any[];
5
- declare function singleOrNull<T>(arr: T[]): T | null;
6
- declare function createArray<T = number>(length: number, mapFn?: (index: number) => T): T[];
7
-
8
- declare function cleanText(str: string, searchValue: RegExp | string): string;
9
-
10
- declare function getValueOrUndefined<T>(condition: any, value: T): T | undefined;
11
- declare function from<T>(value: T): {
12
- to: <R>(fn: (value: T) => R) => {
13
- to: <R_1>(fn: (value: R) => R_1) => {
14
- to: <R_2>(fn: (value: R_1) => R_2) => {
15
- to: <R_3>(fn: (value: R_2) => R_3) => {
16
- to: <R_4>(fn: (value: R_3) => R_4) => {
17
- to: <R_5>(fn: (value: R_4) => R_5) => {
18
- to: <R_6>(fn: (value: R_5) => R_6) => {
19
- to: <R_7>(fn: (value: R_6) => R_7) => {
20
- to: <R_8>(fn: (value: R_7) => R_8) => {
21
- to: <R_9>(fn: (value: R_8) => R_9) => {
22
- to: <R_10>(fn: (value: R_9) => R_10) => /*elided*/ any;
23
- get: () => R_9;
24
- };
25
- get: () => R_8;
26
- };
27
- get: () => R_7;
28
- };
29
- get: () => R_6;
30
- };
31
- get: () => R_5;
32
- };
33
- get: () => R_4;
34
- };
35
- get: () => R_3;
36
- };
37
- get: () => R_2;
38
- };
39
- get: () => R_1;
40
- };
41
- get: () => R;
42
- };
43
- get: () => T;
44
- };
45
-
46
- export { cleanText, createArray, from, getValueOrUndefined, isArray, singleOrNull };