@vope/utils 1.4.17 → 1.4.19
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/cjs/index.js +68 -7
- package/lib/index.js +2 -0
- package/lib/memory/basic.js +18 -0
- package/lib/memory/simple.js +13 -5
- package/lib/parse/num.js +35 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/memory/basic.d.ts +12 -0
- package/types/memory/simple.d.ts +8 -0
- package/types/parse/num.d.ts +8 -0
package/cjs/index.js
CHANGED
|
@@ -49,6 +49,7 @@ __export(src_exports, {
|
|
|
49
49
|
joinPaths: () => joinPaths,
|
|
50
50
|
loadImage: () => loadImage,
|
|
51
51
|
once: () => once,
|
|
52
|
+
parseNum: () => parseNum,
|
|
52
53
|
rotateAngle: () => rotateAngle,
|
|
53
54
|
rotateRad: () => rotateRad,
|
|
54
55
|
wait: () => wait
|
|
@@ -358,6 +359,24 @@ var MemoryBasic = class {
|
|
|
358
359
|
}
|
|
359
360
|
return this;
|
|
360
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* some(按入栈顺序)
|
|
364
|
+
*/
|
|
365
|
+
some(callback) {
|
|
366
|
+
return this.list.some(callback);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* map(按入栈顺序)
|
|
370
|
+
*/
|
|
371
|
+
map(callback) {
|
|
372
|
+
return this.list.map(callback);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* reduce(按入栈顺序)
|
|
376
|
+
*/
|
|
377
|
+
reduce(callback, initialValue) {
|
|
378
|
+
return this.list.reduce(callback, initialValue);
|
|
379
|
+
}
|
|
361
380
|
/**
|
|
362
381
|
* 检测存储是否包含某种类型
|
|
363
382
|
*/
|
|
@@ -525,15 +544,23 @@ var MemorySimple = class {
|
|
|
525
544
|
this.#memory.forEach(callback);
|
|
526
545
|
return this;
|
|
527
546
|
}
|
|
547
|
+
/**
|
|
548
|
+
* some(按入栈顺序)
|
|
549
|
+
*/
|
|
550
|
+
some(callback) {
|
|
551
|
+
return this.#memory.some(callback);
|
|
552
|
+
}
|
|
528
553
|
/**
|
|
529
554
|
* map(按入栈顺序)
|
|
530
555
|
*/
|
|
531
556
|
map(callback) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
557
|
+
return this.#memory.map(callback);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* reduce(按入栈顺序)
|
|
561
|
+
*/
|
|
562
|
+
reduce(callback, initialValue) {
|
|
563
|
+
return this.#memory.reduce(callback, initialValue);
|
|
537
564
|
}
|
|
538
565
|
/**
|
|
539
566
|
* 获取指定类型存储数据
|
|
@@ -570,6 +597,40 @@ var once = (func, thisArg) => {
|
|
|
570
597
|
return (...list) => inited ? local : (inited = true, local = func.apply(thisArg, list));
|
|
571
598
|
};
|
|
572
599
|
|
|
600
|
+
// src/parse/num.ts
|
|
601
|
+
var import_lodash_es3 = require("lodash-es");
|
|
602
|
+
var pow = Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
|
603
|
+
var re_num = /^([-+]?)0*(\d+)(?:(n)|(?:\.(\d+))?(?:[Ee]([-+]?)(\d+))?)$/;
|
|
604
|
+
var parseNum = (num) => {
|
|
605
|
+
if ((0, import_lodash_es3.isNumber)(num) || typeof num === "bigint")
|
|
606
|
+
return num;
|
|
607
|
+
const match = num.match(re_num);
|
|
608
|
+
if (!match)
|
|
609
|
+
return Number.NaN;
|
|
610
|
+
const [, valueSymbol, integer, bigint, decimal, powSymbol, powValue] = match;
|
|
611
|
+
if (bigint === "n")
|
|
612
|
+
return BigInt(valueSymbol + integer);
|
|
613
|
+
const powSize = integer.length - 1 + (powValue ? powSymbol === "-" ? -powValue : +powValue : 0);
|
|
614
|
+
if (powSize < pow || powSize === pow && +integer.slice(0, -1) < Number.MAX_SAFE_INTEGER / 10)
|
|
615
|
+
return +num;
|
|
616
|
+
try {
|
|
617
|
+
const bigValue = BigInt(integer.slice(0, powSize + 1).padEnd(powSize + 1, "0"));
|
|
618
|
+
let smallValue;
|
|
619
|
+
if (decimal && powValue && powSymbol !== "-") {
|
|
620
|
+
const powNum = +powValue;
|
|
621
|
+
const effectDecimal = decimal.slice(0, Math.min(pow, powNum));
|
|
622
|
+
const tinyValue = decimal.length > pow && powNum > pow ? BigInt(+decimal.slice(pow, powNum)) * BigInt(10 ** Math.max(powNum - decimal.length, 0)) : BigInt(0);
|
|
623
|
+
smallValue = BigInt(effectDecimal) * BigInt(10 ** (powNum - effectDecimal.length)) + tinyValue;
|
|
624
|
+
} else {
|
|
625
|
+
smallValue = BigInt(0);
|
|
626
|
+
}
|
|
627
|
+
const value = bigValue + smallValue;
|
|
628
|
+
return valueSymbol === "-" ? value * BigInt(-1) : value;
|
|
629
|
+
} catch {
|
|
630
|
+
return Number.NaN;
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
573
634
|
// src/rotate/rad.ts
|
|
574
635
|
var rotateRad = (from, rad, visit = [0, 0]) => {
|
|
575
636
|
const x = from[0] - visit[0];
|
|
@@ -584,7 +645,7 @@ var rotateRad = (from, rad, visit = [0, 0]) => {
|
|
|
584
645
|
var rotateAngle = (from, angle, visit) => rotateRad(from, angle / 180 * Math.PI, visit);
|
|
585
646
|
|
|
586
647
|
// src/style/css.ts
|
|
587
|
-
var
|
|
648
|
+
var import_lodash_es4 = require("lodash-es");
|
|
588
649
|
var hump = /[A-Z]/g;
|
|
589
650
|
var css = (...args) => {
|
|
590
651
|
const list = [];
|
|
@@ -592,7 +653,7 @@ var css = (...args) => {
|
|
|
592
653
|
const data = args[i];
|
|
593
654
|
if (!data)
|
|
594
655
|
continue;
|
|
595
|
-
if ((0,
|
|
656
|
+
if ((0, import_lodash_es4.isString)(data)) {
|
|
596
657
|
list.push(data);
|
|
597
658
|
} else if (Array.isArray(data)) {
|
|
598
659
|
const result = css(...data);
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { MemoryList } from "./memory/list";
|
|
|
18
18
|
import { MemoryPower } from "./memory/power";
|
|
19
19
|
import { MemorySimple } from "./memory/simple";
|
|
20
20
|
import { once } from "./once";
|
|
21
|
+
import { parseNum } from "./parse/num";
|
|
21
22
|
import { deconPowersSum } from "./power/decon";
|
|
22
23
|
import { rotateAngle } from "./rotate/angle";
|
|
23
24
|
import { rotateRad } from "./rotate/rad";
|
|
@@ -58,6 +59,7 @@ export {
|
|
|
58
59
|
joinPaths,
|
|
59
60
|
loadImage,
|
|
60
61
|
once,
|
|
62
|
+
parseNum,
|
|
61
63
|
rotateAngle,
|
|
62
64
|
rotateRad,
|
|
63
65
|
wait
|
package/lib/memory/basic.js
CHANGED
|
@@ -52,6 +52,24 @@ class MemoryBasic {
|
|
|
52
52
|
}
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* some(按入栈顺序)
|
|
57
|
+
*/
|
|
58
|
+
some(callback) {
|
|
59
|
+
return this.list.some(callback);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* map(按入栈顺序)
|
|
63
|
+
*/
|
|
64
|
+
map(callback) {
|
|
65
|
+
return this.list.map(callback);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* reduce(按入栈顺序)
|
|
69
|
+
*/
|
|
70
|
+
reduce(callback, initialValue) {
|
|
71
|
+
return this.list.reduce(callback, initialValue);
|
|
72
|
+
}
|
|
55
73
|
/**
|
|
56
74
|
* 检测存储是否包含某种类型
|
|
57
75
|
*/
|
package/lib/memory/simple.js
CHANGED
|
@@ -39,15 +39,23 @@ class MemorySimple {
|
|
|
39
39
|
this.#memory.forEach(callback);
|
|
40
40
|
return this;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* some(按入栈顺序)
|
|
44
|
+
*/
|
|
45
|
+
some(callback) {
|
|
46
|
+
return this.#memory.some(callback);
|
|
47
|
+
}
|
|
42
48
|
/**
|
|
43
49
|
* map(按入栈顺序)
|
|
44
50
|
*/
|
|
45
51
|
map(callback) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
return this.#memory.map(callback);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* reduce(按入栈顺序)
|
|
56
|
+
*/
|
|
57
|
+
reduce(callback, initialValue) {
|
|
58
|
+
return this.#memory.reduce(callback, initialValue);
|
|
51
59
|
}
|
|
52
60
|
/**
|
|
53
61
|
* 获取指定类型存储数据
|
package/lib/parse/num.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isNumber } from "lodash-es";
|
|
2
|
+
const pow = Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
|
3
|
+
const re_num = /^([-+]?)0*(\d+)(?:(n)|(?:\.(\d+))?(?:[Ee]([-+]?)(\d+))?)$/;
|
|
4
|
+
const parseNum = (num) => {
|
|
5
|
+
if (isNumber(num) || typeof num === "bigint")
|
|
6
|
+
return num;
|
|
7
|
+
const match = num.match(re_num);
|
|
8
|
+
if (!match)
|
|
9
|
+
return Number.NaN;
|
|
10
|
+
const [, valueSymbol, integer, bigint, decimal, powSymbol, powValue] = match;
|
|
11
|
+
if (bigint === "n")
|
|
12
|
+
return BigInt(valueSymbol + integer);
|
|
13
|
+
const powSize = integer.length - 1 + (powValue ? powSymbol === "-" ? -powValue : +powValue : 0);
|
|
14
|
+
if (powSize < pow || powSize === pow && +integer.slice(0, -1) < Number.MAX_SAFE_INTEGER / 10)
|
|
15
|
+
return +num;
|
|
16
|
+
try {
|
|
17
|
+
const bigValue = BigInt(integer.slice(0, powSize + 1).padEnd(powSize + 1, "0"));
|
|
18
|
+
let smallValue;
|
|
19
|
+
if (decimal && powValue && powSymbol !== "-") {
|
|
20
|
+
const powNum = +powValue;
|
|
21
|
+
const effectDecimal = decimal.slice(0, Math.min(pow, powNum));
|
|
22
|
+
const tinyValue = decimal.length > pow && powNum > pow ? BigInt(+decimal.slice(pow, powNum)) * BigInt(10 ** Math.max(powNum - decimal.length, 0)) : BigInt(0);
|
|
23
|
+
smallValue = BigInt(effectDecimal) * BigInt(10 ** (powNum - effectDecimal.length)) + tinyValue;
|
|
24
|
+
} else {
|
|
25
|
+
smallValue = BigInt(0);
|
|
26
|
+
}
|
|
27
|
+
const value = bigValue + smallValue;
|
|
28
|
+
return valueSymbol === "-" ? value * BigInt(-1) : value;
|
|
29
|
+
} catch {
|
|
30
|
+
return Number.NaN;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
parseNum
|
|
35
|
+
};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { MemoryList } from './memory/list';
|
|
|
18
18
|
export { MemoryPower } from './memory/power';
|
|
19
19
|
export { MemorySimple } from './memory/simple';
|
|
20
20
|
export { once } from './once';
|
|
21
|
+
export { parseNum } from './parse/num';
|
|
21
22
|
export { deconPowersSum } from './power/decon';
|
|
22
23
|
export { rotateAngle } from './rotate/angle';
|
|
23
24
|
export { rotateRad } from './rotate/rad';
|
package/types/memory/basic.d.ts
CHANGED
|
@@ -39,6 +39,18 @@ export declare class MemoryBasic<T, Reactor, Type extends Memory.Type> {
|
|
|
39
39
|
* 遍历所有存储类型
|
|
40
40
|
*/
|
|
41
41
|
forType(callback: (data: T[], type: Type) => void): this;
|
|
42
|
+
/**
|
|
43
|
+
* some(按入栈顺序)
|
|
44
|
+
*/
|
|
45
|
+
some(callback: (data: T, index: number) => boolean): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* map(按入栈顺序)
|
|
48
|
+
*/
|
|
49
|
+
map<V>(callback: (data: T, index: number) => V): V[];
|
|
50
|
+
/**
|
|
51
|
+
* reduce(按入栈顺序)
|
|
52
|
+
*/
|
|
53
|
+
reduce<V>(callback: (previousValue: V, currentValue: T, currentIndex: number) => V, initialValue: V): V;
|
|
42
54
|
/**
|
|
43
55
|
* 检测存储是否包含某种类型
|
|
44
56
|
*/
|
package/types/memory/simple.d.ts
CHANGED
|
@@ -23,10 +23,18 @@ export declare class MemorySimple<T, Type extends Memory.Type> implements Basic<
|
|
|
23
23
|
* 遍历所有存储数据(按入栈顺序)
|
|
24
24
|
*/
|
|
25
25
|
forEach(callback: (data: T, index: number) => void): this;
|
|
26
|
+
/**
|
|
27
|
+
* some(按入栈顺序)
|
|
28
|
+
*/
|
|
29
|
+
some(callback: (data: T, index: number) => boolean): boolean;
|
|
26
30
|
/**
|
|
27
31
|
* map(按入栈顺序)
|
|
28
32
|
*/
|
|
29
33
|
map<V>(callback: (data: T, index: number) => V): V[];
|
|
34
|
+
/**
|
|
35
|
+
* reduce(按入栈顺序)
|
|
36
|
+
*/
|
|
37
|
+
reduce<V>(callback: (previousValue: V, currentValue: T, currentIndex: number) => V, initialValue: V): V;
|
|
30
38
|
/**
|
|
31
39
|
* 获取指定类型存储数据
|
|
32
40
|
*/
|