@gkucmierz/utils 1.28.8 → 1.29.1
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/main.mjs +10 -2
- package/package.json +1 -1
- package/src/format-big-number.mjs +49 -0
package/main.mjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
SetCnt
|
|
4
4
|
} from './src/SetCnt.mjs'
|
|
5
|
+
import {
|
|
6
|
+
Trie
|
|
7
|
+
} from './src/Trie.mjs'
|
|
5
8
|
import {
|
|
6
9
|
fromBase64, fromBase64Url, toBase64, toBase64Url
|
|
7
10
|
} from './src/base64.mjs'
|
|
@@ -9,7 +12,7 @@ import {
|
|
|
9
12
|
bijective2num, bijective2numBI, num2bijective, num2bijectiveBI
|
|
10
13
|
} from './src/bijective-numeration.mjs'
|
|
11
14
|
import {
|
|
12
|
-
binarySearchArr
|
|
15
|
+
binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl
|
|
13
16
|
} from './src/binary-search.mjs'
|
|
14
17
|
import {
|
|
15
18
|
copyCase
|
|
@@ -20,6 +23,9 @@ import {
|
|
|
20
23
|
import {
|
|
21
24
|
factors, factorsBI
|
|
22
25
|
} from './src/factors.mjs'
|
|
26
|
+
import {
|
|
27
|
+
formatBigNumber, formatBigNumberBI, wrapFn
|
|
28
|
+
} from './src/format-big-number.mjs'
|
|
23
29
|
import {
|
|
24
30
|
gcd, gcdBI
|
|
25
31
|
} from './src/gcd.mjs'
|
|
@@ -67,12 +73,14 @@ import {
|
|
|
67
73
|
} from './src/tonelli-shanks.mjs'
|
|
68
74
|
|
|
69
75
|
export * from './src/SetCnt.mjs';
|
|
76
|
+
export * from './src/Trie.mjs';
|
|
70
77
|
export * from './src/base64.mjs';
|
|
71
78
|
export * from './src/bijective-numeration.mjs';
|
|
72
79
|
export * from './src/binary-search.mjs';
|
|
73
80
|
export * from './src/copy-case.mjs';
|
|
74
81
|
export * from './src/egcd.mjs';
|
|
75
82
|
export * from './src/factors.mjs';
|
|
83
|
+
export * from './src/format-big-number.mjs';
|
|
76
84
|
export * from './src/gcd.mjs';
|
|
77
85
|
export * from './src/get-type.mjs';
|
|
78
86
|
export * from './src/gpn.mjs';
|
|
@@ -90,5 +98,5 @@ export * from './src/square-root.mjs';
|
|
|
90
98
|
export * from './src/tonelli-shanks.mjs';
|
|
91
99
|
|
|
92
100
|
export default [
|
|
93
|
-
SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, binarySearchArr, copyCase, egcd, factors, factorsBI, gcd, gcdBI, getType, gpn, gpnBI, Heap, heronsFormula, heronsFormulaBI, lcm, lcmBI, ListNode, matrixAsArray, memoize, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
|
|
101
|
+
SetCnt, Trie, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl, copyCase, egcd, factors, factorsBI, formatBigNumber, formatBigNumberBI, wrapFn, gcd, gcdBI, getType, gpn, gpnBI, Heap, heronsFormula, heronsFormulaBI, lcm, lcmBI, ListNode, matrixAsArray, memoize, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
|
|
94
102
|
];
|
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Formats a BigNumber, Number or string representation of a number
|
|
4
|
+
* by separating thousands with a provided separator.
|
|
5
|
+
*
|
|
6
|
+
* @param {number|string|bigint} num - The number to format.
|
|
7
|
+
* @param {string} [separator=''] - The string to use as a thousand separator.
|
|
8
|
+
* @param {function(string): string} [wrapFn=_=>_] - Optional function to wrap each part of the number.
|
|
9
|
+
* @returns {string} The formatted number.
|
|
10
|
+
*/
|
|
11
|
+
const formatBigNumberBoth = (num, separator = '', wrapFn = _ => _) => {
|
|
12
|
+
const str = String(num);
|
|
13
|
+
const rev = [...str].reverse().join('');
|
|
14
|
+
const match = rev.match(/(\d*\.\-?)|(\d{3}\-?)|(\d{1,3}\-?)|(\-)/g);
|
|
15
|
+
const revInside = (match && match.join('') === rev)
|
|
16
|
+
? match.map(part => [...part].reverse().join(''))
|
|
17
|
+
: [str];
|
|
18
|
+
const wrap = revInside.map(wrapFn);
|
|
19
|
+
return wrap.reverse().join(separator);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Formats a BigNumber, Number or string representation of a number
|
|
24
|
+
* by separating thousands with a provided separator.
|
|
25
|
+
* @param {number|string|bigint} num - The number to format.
|
|
26
|
+
* @param {string} [separator=''] - The string to use as a thousand separator.
|
|
27
|
+
* @param {function(string): string} [wrapFn=_=>_] - Optional function to wrap each part of the number.
|
|
28
|
+
* @returns {string} The formatted number.
|
|
29
|
+
*/
|
|
30
|
+
export const formatBigNumber = formatBigNumberBoth;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Formats a BigNumber, Number or string representation of a number
|
|
34
|
+
* by separating thousands with a provided separator. (Alias for BigInt logic)
|
|
35
|
+
* @param {number|string|bigint} num - The number to format.
|
|
36
|
+
* @param {string} [separator=''] - The string to use as a thousand separator.
|
|
37
|
+
* @param {function(string): string} [wrapFn=_=>_] - Optional function to wrap each part of the number.
|
|
38
|
+
* @returns {string} The formatted number.
|
|
39
|
+
*/
|
|
40
|
+
export const formatBigNumberBI = formatBigNumberBoth;
|
|
41
|
+
|
|
42
|
+
export const wrapFn = () => {
|
|
43
|
+
let even = true;
|
|
44
|
+
return part => {
|
|
45
|
+
const cls = even ? 'even' : 'odd';
|
|
46
|
+
even = !even;
|
|
47
|
+
return `<span class="${cls}">${part}</span>`;
|
|
48
|
+
};
|
|
49
|
+
};
|