@thi.ng/strings 3.7.2 → 3.7.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/CHANGELOG.md +8 -1
- package/README.md +1 -1
- package/ansi.js +12 -37
- package/api.js +4 -5
- package/case.js +24 -56
- package/center.js +12 -32
- package/currency.js +16 -8
- package/cursor.js +16 -37
- package/entities.js +136 -149
- package/escape.js +39 -62
- package/float.js +26 -45
- package/format.js +19 -27
- package/groups.js +42 -53
- package/hollerith.js +4 -16
- package/initials.js +6 -27
- package/int.js +8 -2
- package/interpolate.js +9 -36
- package/join.js +6 -21
- package/package.json +11 -8
- package/pad-left.js +18 -25
- package/pad-right.js +12 -13
- package/parse.js +10 -6
- package/percent.js +4 -7
- package/radix.js +32 -54
- package/range.js +13 -18
- package/repeat.js +6 -5
- package/ruler.js +12 -63
- package/slugify.js +12 -48
- package/splice.js +15 -29
- package/split.d.ts +3 -0
- package/split.js +24 -28
- package/stringify.js +4 -12
- package/tabs.js +40 -81
- package/trim.js +7 -22
- package/truncate-left.js +6 -3
- package/truncate.js +8 -5
- package/units.js +77 -44
- package/utf8.js +72 -130
- package/uuid.js +4 -14
- package/vector.js +25 -28
- package/word-wrap.js +78 -141
- package/wrap.js +6 -5
package/escape.js
CHANGED
|
@@ -1,65 +1,42 @@
|
|
|
1
1
|
import { U16, U32 } from "./radix.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
const ESCAPES = {
|
|
3
|
+
0: "\0",
|
|
4
|
+
b: "\b",
|
|
5
|
+
t: " ",
|
|
6
|
+
r: "\r",
|
|
7
|
+
v: "\v",
|
|
8
|
+
f: "\f",
|
|
9
|
+
n: "\n",
|
|
10
|
+
"'": "'",
|
|
11
|
+
'"': '"',
|
|
12
|
+
"\\": "\\"
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
const ESCAPES_REV = {
|
|
15
|
+
0: "0",
|
|
16
|
+
8: "b",
|
|
17
|
+
9: "t",
|
|
18
|
+
10: "n",
|
|
19
|
+
11: "v",
|
|
20
|
+
12: "f",
|
|
21
|
+
13: "r",
|
|
22
|
+
33: "'",
|
|
23
|
+
34: '"',
|
|
24
|
+
92: "\\"
|
|
25
|
+
};
|
|
26
|
+
const escape = (src) => src.replace(
|
|
27
|
+
/[\0\b\t\n\v\f\r'"\\]/g,
|
|
28
|
+
(x) => `\\${ESCAPES_REV[x.charCodeAt(0)]}`
|
|
29
|
+
).replace(/[\ud800-\udfff]{2}/g, (x) => `\\U${U32(x.codePointAt(0))}`).replace(/[^\u0020-\u007e]/g, (x) => `\\u${U16(x.charCodeAt(0))}`);
|
|
30
|
+
const unescape = (src) => src.replace(
|
|
31
|
+
/\\u([0-9a-fA-F]{4})/g,
|
|
32
|
+
(_, id) => String.fromCharCode(parseInt(id, 16))
|
|
33
|
+
).replace(
|
|
34
|
+
/\\U([0-9a-fA-F]{8})/g,
|
|
35
|
+
(_, id) => String.fromCodePoint(parseInt(id, 16))
|
|
36
|
+
).replace(/\\([0btnvfr'"\\])/g, (_, id) => ESCAPES[id]);
|
|
37
|
+
export {
|
|
38
|
+
ESCAPES,
|
|
39
|
+
ESCAPES_REV,
|
|
40
|
+
escape,
|
|
41
|
+
unescape
|
|
25
42
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Escapes all non-ASCII characters (and well-known 0x0x control chars) using
|
|
28
|
-
* backslash escape sequences.
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* - Well-known low-ASCII control chars will be escaped using simple `\`, e.g.
|
|
32
|
-
* 0x0a => `\n`
|
|
33
|
-
* - Non-BMP chars will be escaped using `\Uxxxxxxxx`
|
|
34
|
-
* - Chars outside 0x20 - 0x7e range will be escaped using `\uxxxxx`
|
|
35
|
-
*
|
|
36
|
-
* @param src -
|
|
37
|
-
*/
|
|
38
|
-
export const escape = (src) => src
|
|
39
|
-
.replace(/[\0\b\t\n\v\f\r'"\\]/g, (x) => `\\${ESCAPES_REV[x.charCodeAt(0)]}`)
|
|
40
|
-
.replace(/[\ud800-\udfff]{2}/g, (x) => `\\U${U32(x.codePointAt(0))}`)
|
|
41
|
-
.replace(/[^\u0020-\u007e]/g, (x) => `\\u${U16(x.charCodeAt(0))}`);
|
|
42
|
-
/**
|
|
43
|
-
* Replaces `\uxxxx` UTF-16 escapes, full `\Uxxxxxxxx` UTF-32 codepoint escapes
|
|
44
|
-
* and other well-known backslash escape sequences (see {@link ESCAPES}) with
|
|
45
|
-
* the characters they represent.
|
|
46
|
-
*
|
|
47
|
-
* @remarks
|
|
48
|
-
* Any unknown named escape sequences (e.g. `\1`) will remain as is.
|
|
49
|
-
*
|
|
50
|
-
* - https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF
|
|
51
|
-
* - https://www.unicode.org/charts/
|
|
52
|
-
* - https://www.branah.com/unicode-converter
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* unescape("\\ud83d\\ude0e \\U0001f60e")
|
|
57
|
-
* // '😎'
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @param src -
|
|
61
|
-
*/
|
|
62
|
-
export const unescape = (src) => src
|
|
63
|
-
.replace(/\\u([0-9a-fA-F]{4})/g, (_, id) => String.fromCharCode(parseInt(id, 16)))
|
|
64
|
-
.replace(/\\U([0-9a-fA-F]{8})/g, (_, id) => String.fromCodePoint(parseInt(id, 16)))
|
|
65
|
-
.replace(/\\([0btnvfr'"\\])/g, (_, id) => ESCAPES[id]);
|
package/float.js
CHANGED
|
@@ -1,48 +1,29 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
2
|
import { padLeft } from "./pad-left.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* character width & precision. Uses scientific notation if needed.
|
|
19
|
-
*
|
|
20
|
-
* Default precision: 3 fractional digits
|
|
21
|
-
*/
|
|
22
|
-
export const floatFixedWidth = memoizeJ((width, prec = 3) => {
|
|
23
|
-
const l = width - prec - 1;
|
|
24
|
-
const pl = Math.pow(10, l);
|
|
25
|
-
const pln = -Math.pow(10, l - 1);
|
|
26
|
-
const pr = Math.pow(10, -(prec - 1));
|
|
27
|
-
const pad = padLeft(width);
|
|
28
|
-
return (x) => {
|
|
29
|
-
const ax = Math.abs(x);
|
|
30
|
-
return pad(nanOrInf(x) ||
|
|
31
|
-
(x === 0
|
|
32
|
-
? "0"
|
|
33
|
-
: ax < pr || ax >= pl
|
|
34
|
-
? exp(x, width)
|
|
35
|
-
: x.toFixed(prec - (x < pln ? 1 : 0))));
|
|
36
|
-
};
|
|
3
|
+
const float = memoizeJ(
|
|
4
|
+
(prec, special = false) => special ? (x) => nanOrInf(x) || x.toFixed(prec) : (x) => x.toFixed(prec)
|
|
5
|
+
);
|
|
6
|
+
const floatFixedWidth = memoizeJ((width, prec = 3) => {
|
|
7
|
+
const l = width - prec - 1;
|
|
8
|
+
const pl = Math.pow(10, l);
|
|
9
|
+
const pln = -Math.pow(10, l - 1);
|
|
10
|
+
const pr = Math.pow(10, -(prec - 1));
|
|
11
|
+
const pad = padLeft(width);
|
|
12
|
+
return (x) => {
|
|
13
|
+
const ax = Math.abs(x);
|
|
14
|
+
return pad(
|
|
15
|
+
nanOrInf(x) || (x === 0 ? "0" : ax < pr || ax >= pl ? exp(x, width) : x.toFixed(prec - (x < pln ? 1 : 0)))
|
|
16
|
+
);
|
|
17
|
+
};
|
|
37
18
|
});
|
|
38
|
-
const exp = (x, w) => x.toExponential(
|
|
39
|
-
|
|
40
|
-
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) -
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
const exp = (x, w) => x.toExponential(
|
|
20
|
+
Math.max(
|
|
21
|
+
w - 4 - (Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) - (x < 0 ? 1 : 0),
|
|
22
|
+
0
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
const nanOrInf = (x) => isNaN(x) ? "NaN" : x === Infinity ? "+\u221E" : x === -Infinity ? "-\u221E" : void 0;
|
|
26
|
+
export {
|
|
27
|
+
float,
|
|
28
|
+
floatFixedWidth
|
|
29
|
+
};
|
package/format.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const format = (fmt, ...args) => {
|
|
2
|
+
const acc = [];
|
|
3
|
+
for (let i = 0, j = 0, n = fmt.length; i < n; i++) {
|
|
4
|
+
const f = fmt[i];
|
|
5
|
+
const t = typeof f;
|
|
6
|
+
acc.push(
|
|
7
|
+
t === "function" ? f(args[j++]) : t === "object" ? f[args[j++]] : f
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return acc.join("");
|
|
11
|
+
};
|
|
12
|
+
const defFormat = (fmt) => (...args) => format(fmt, ...args);
|
|
13
|
+
const ignore = (_) => "";
|
|
14
|
+
const str = (x) => String(x);
|
|
15
|
+
export {
|
|
16
|
+
defFormat,
|
|
17
|
+
format,
|
|
18
|
+
ignore,
|
|
19
|
+
str
|
|
9
20
|
};
|
|
10
|
-
/**
|
|
11
|
-
* HOF version of {@link format}.
|
|
12
|
-
*
|
|
13
|
-
* @param fmt -
|
|
14
|
-
*/
|
|
15
|
-
export const defFormat = (fmt) => (...args) => format(fmt, ...args);
|
|
16
|
-
/**
|
|
17
|
-
* Helper for {@link format} which ignores argument and always returns
|
|
18
|
-
* an empty string.
|
|
19
|
-
*
|
|
20
|
-
* @param _ -
|
|
21
|
-
*/
|
|
22
|
-
export const ignore = (_) => "";
|
|
23
|
-
/**
|
|
24
|
-
* Helper for {@link format} which coerces `x` to a string.
|
|
25
|
-
*
|
|
26
|
-
* @param x -
|
|
27
|
-
*/
|
|
28
|
-
export const str = (x) => String(x);
|
package/groups.js
CHANGED
|
@@ -1,59 +1,48 @@
|
|
|
1
1
|
import { charRange } from "./range.js";
|
|
2
2
|
const defGroup = (...xs) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
3
|
+
const acc = {};
|
|
4
|
+
for (let range of xs) {
|
|
5
|
+
for (let c of range) {
|
|
6
|
+
acc[c] = true;
|
|
8
7
|
}
|
|
9
|
-
|
|
8
|
+
}
|
|
9
|
+
return Object.freeze(acc);
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"\v": true,
|
|
19
|
-
"\f": true,
|
|
20
|
-
"\r": true,
|
|
21
|
-
" ": true,
|
|
11
|
+
const WS = Object.freeze({
|
|
12
|
+
" ": true,
|
|
13
|
+
"\n": true,
|
|
14
|
+
"\v": true,
|
|
15
|
+
"\f": true,
|
|
16
|
+
"\r": true,
|
|
17
|
+
" ": true
|
|
22
18
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
export const LOWER = defGroup(charRange("a", "z"));
|
|
38
|
-
/**
|
|
39
|
-
* Object with ASCII uppercase characters as keys and their values set
|
|
40
|
-
* to true. All others undefined.
|
|
41
|
-
*/
|
|
42
|
-
export const UPPER = defGroup(charRange("A", "Z"));
|
|
43
|
-
/**
|
|
44
|
-
* Combination of {@link UPPER} and {@link LOWER}.
|
|
45
|
-
*/
|
|
46
|
-
export const ALPHA = Object.freeze({ ...UPPER, ...LOWER });
|
|
47
|
-
/**
|
|
48
|
-
* Combination of {@link ALPHA} and {@link DIGITS} and '_'.
|
|
49
|
-
*/
|
|
50
|
-
export const ALPHA_NUM = Object.freeze({
|
|
51
|
-
...ALPHA,
|
|
52
|
-
...DIGITS,
|
|
53
|
-
_: true,
|
|
19
|
+
const DIGITS = defGroup(charRange("0", "9"));
|
|
20
|
+
const HEX = defGroup(
|
|
21
|
+
charRange("0", "9"),
|
|
22
|
+
charRange("A", "F"),
|
|
23
|
+
charRange("a", "f")
|
|
24
|
+
);
|
|
25
|
+
const LOWER = defGroup(charRange("a", "z"));
|
|
26
|
+
const UPPER = defGroup(charRange("A", "Z"));
|
|
27
|
+
const ALPHA = Object.freeze({ ...UPPER, ...LOWER });
|
|
28
|
+
const ALPHA_NUM = Object.freeze({
|
|
29
|
+
...ALPHA,
|
|
30
|
+
...DIGITS,
|
|
31
|
+
_: true
|
|
54
32
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
33
|
+
const PUNCTUATION = defGroup(
|
|
34
|
+
charRange("!", "/"),
|
|
35
|
+
charRange(":", "@"),
|
|
36
|
+
charRange("[", "`"),
|
|
37
|
+
charRange("{", "~")
|
|
38
|
+
);
|
|
39
|
+
export {
|
|
40
|
+
ALPHA,
|
|
41
|
+
ALPHA_NUM,
|
|
42
|
+
DIGITS,
|
|
43
|
+
HEX,
|
|
44
|
+
LOWER,
|
|
45
|
+
PUNCTUATION,
|
|
46
|
+
UPPER,
|
|
47
|
+
WS
|
|
48
|
+
};
|
package/hollerith.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* ```ts
|
|
6
|
-
* hstr("abc") // "3Habc"
|
|
7
|
-
* hstr(123.45) // "6H123.45"
|
|
8
|
-
* hstr("") // "0H"
|
|
9
|
-
* hstr(null) // ""
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* https://en.wikipedia.org/wiki/Hollerith_constant
|
|
13
|
-
*
|
|
14
|
-
* @param x -
|
|
15
|
-
*/
|
|
16
|
-
export const hstr = (x) => x != null ? ((x = x.toString()), `${x.length}H${x}`) : "";
|
|
1
|
+
const hstr = (x) => x != null ? (x = x.toString(), `${x.length}H${x}`) : "";
|
|
2
|
+
export {
|
|
3
|
+
hstr
|
|
4
|
+
};
|
package/initials.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* ```ts
|
|
8
|
-
* initials(["alicia", "bella", "carerra"]);
|
|
9
|
-
* // "ABC"
|
|
10
|
-
*
|
|
11
|
-
* initials("shader-ast-GLSL".split("-"))
|
|
12
|
-
* // "SAG"
|
|
13
|
-
*
|
|
14
|
-
* initials("Ludwig van Beethoven".split(" "), null)
|
|
15
|
-
* // "LvB"
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param parts -
|
|
19
|
-
* @param mode -
|
|
20
|
-
*/
|
|
21
|
-
export const initials = (parts, mode = "u") => {
|
|
22
|
-
const res = parts.map((x) => x[0]).join("");
|
|
23
|
-
return mode === "u"
|
|
24
|
-
? res.toUpperCase()
|
|
25
|
-
: mode === "l"
|
|
26
|
-
? res.toLowerCase()
|
|
27
|
-
: res;
|
|
1
|
+
const initials = (parts, mode = "u") => {
|
|
2
|
+
const res = parts.map((x) => x[0]).join("");
|
|
3
|
+
return mode === "u" ? res.toUpperCase() : mode === "l" ? res.toLowerCase() : res;
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
initials
|
|
28
7
|
};
|
package/int.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const int = (x) => String(Math.trunc(x));
|
|
3
|
+
const intLocale = memoizeJ(
|
|
4
|
+
(locale) => (x) => Math.trunc(x).toLocaleString(locale)
|
|
5
|
+
);
|
|
6
|
+
export {
|
|
7
|
+
int,
|
|
8
|
+
intLocale
|
|
9
|
+
};
|
package/interpolate.js
CHANGED
|
@@ -1,39 +1,12 @@
|
|
|
1
1
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
2
2
|
const TPL = /\{(\d+)\}/g;
|
|
3
3
|
const TPL_K = /\{([a-z0-9_.-]+)\}/gi;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param src -
|
|
16
|
-
* @param args -
|
|
17
|
-
*/
|
|
18
|
-
export const interpolate = (src, ...args) => args.length > 0
|
|
19
|
-
? src.replace(TPL, (_, id) => String(args[parseInt(id, 10)]))
|
|
20
|
-
: src;
|
|
21
|
-
/**
|
|
22
|
-
* Similar to {@link interpolate}, but uses alphanumeric placeholders in the
|
|
23
|
-
* template string and an object of values for the stated keys.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* interpolateKeys(
|
|
28
|
-
* "let {id}: {type} = {val};",
|
|
29
|
-
* { id: "a", type: "number", val: 42 }
|
|
30
|
-
* )
|
|
31
|
-
* // "let a: number = 42;"
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @param src -
|
|
35
|
-
* @param keys -
|
|
36
|
-
*/
|
|
37
|
-
export const interpolateKeys = (src, keys) => src.replace(TPL_K, (_, id) => keys[id] != undefined
|
|
38
|
-
? String(keys[id])
|
|
39
|
-
: illegalArgs(`missing key: ${id}`));
|
|
4
|
+
const interpolate = (src, ...args) => args.length > 0 ? src.replace(TPL, (_, id) => String(args[parseInt(id, 10)])) : src;
|
|
5
|
+
const interpolateKeys = (src, keys) => src.replace(
|
|
6
|
+
TPL_K,
|
|
7
|
+
(_, id) => keys[id] != void 0 ? String(keys[id]) : illegalArgs(`missing key: ${id}`)
|
|
8
|
+
);
|
|
9
|
+
export {
|
|
10
|
+
interpolate,
|
|
11
|
+
interpolateKeys
|
|
12
|
+
};
|
package/join.js
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { memoize1 } from "@thi.ng/memoize/memoize1";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* ```ts
|
|
9
|
-
* const slashes = join("/");
|
|
10
|
-
*
|
|
11
|
-
* slashes([1, 2, 3]);
|
|
12
|
-
* // "1/2/3"
|
|
13
|
-
*
|
|
14
|
-
* const formatOBJFace = partial(
|
|
15
|
-
* format, ["f ", slashes, " ", slashes, " ", slashes]
|
|
16
|
-
* );
|
|
17
|
-
*
|
|
18
|
-
* formatOBJFace([1, 2], [3, 4], [5, 6]);
|
|
19
|
-
* // "f 1/2 3/4 5/6"
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export const join = memoize1((sep) => (x) => x.join(sep));
|
|
2
|
+
const join = memoize1(
|
|
3
|
+
(sep) => (x) => x.join(sep)
|
|
4
|
+
);
|
|
5
|
+
export {
|
|
6
|
+
join
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/strings",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.4",
|
|
4
4
|
"description": "Various string formatting & utility functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,13 +35,14 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/errors": "^2.4.
|
|
38
|
-
"@thi.ng/hex": "^2.3.
|
|
39
|
-
"@thi.ng/memoize": "^3.1.
|
|
38
|
+
"@thi.ng/api": "^8.9.13",
|
|
39
|
+
"@thi.ng/errors": "^2.4.7",
|
|
40
|
+
"@thi.ng/hex": "^2.3.25",
|
|
41
|
+
"@thi.ng/memoize": "^3.1.47"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
+
"esbuild": "^0.19.8",
|
|
43
46
|
"rimraf": "^5.0.5",
|
|
44
47
|
"tools": "^0.0.1",
|
|
45
48
|
"typedoc": "^0.25.4",
|
|
@@ -73,7 +76,7 @@
|
|
|
73
76
|
"access": "public"
|
|
74
77
|
},
|
|
75
78
|
"engines": {
|
|
76
|
-
"node": ">=
|
|
79
|
+
"node": ">=18"
|
|
77
80
|
},
|
|
78
81
|
"files": [
|
|
79
82
|
"./*.js",
|
|
@@ -201,5 +204,5 @@
|
|
|
201
204
|
"thi.ng": {
|
|
202
205
|
"year": 2015
|
|
203
206
|
},
|
|
204
|
-
"gitHead": "
|
|
207
|
+
"gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
|
|
205
208
|
}
|
package/pad-left.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
2
|
import { repeat } from "./repeat.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
x = x.toString();
|
|
13
|
-
len = len !== undefined ? len : x.length;
|
|
14
|
-
return len < n ? buf.substring(len) + x : x;
|
|
15
|
-
};
|
|
3
|
+
const padLeft = memoizeJ((n, ch = " ") => {
|
|
4
|
+
const buf = repeat(String(ch), n);
|
|
5
|
+
return (x, len) => {
|
|
6
|
+
if (x == null)
|
|
7
|
+
return buf;
|
|
8
|
+
x = x.toString();
|
|
9
|
+
len = len !== void 0 ? len : x.length;
|
|
10
|
+
return len < n ? buf.substring(len) + x : x;
|
|
11
|
+
};
|
|
16
12
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Zero-padded 4 digit formatter.
|
|
27
|
-
*/
|
|
28
|
-
export const Z4 = padLeft(4, "0");
|
|
13
|
+
const Z2 = padLeft(2, "0");
|
|
14
|
+
const Z3 = padLeft(3, "0");
|
|
15
|
+
const Z4 = padLeft(4, "0");
|
|
16
|
+
export {
|
|
17
|
+
Z2,
|
|
18
|
+
Z3,
|
|
19
|
+
Z4,
|
|
20
|
+
padLeft
|
|
21
|
+
};
|
package/pad-right.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
2
|
import { repeat } from "./repeat.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
x = x.toString();
|
|
13
|
-
len = len !== undefined ? len : x.length;
|
|
14
|
-
return len < n ? x + buf.substring(len) : x;
|
|
15
|
-
};
|
|
3
|
+
const padRight = memoizeJ((n, ch = " ") => {
|
|
4
|
+
const buf = repeat(String(ch), n);
|
|
5
|
+
return (x, len) => {
|
|
6
|
+
if (x == null)
|
|
7
|
+
return buf;
|
|
8
|
+
x = x.toString();
|
|
9
|
+
len = len !== void 0 ? len : x.length;
|
|
10
|
+
return len < n ? x + buf.substring(len) : x;
|
|
11
|
+
};
|
|
16
12
|
});
|
|
13
|
+
export {
|
|
14
|
+
padRight
|
|
15
|
+
};
|
package/parse.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const maybeParseInt = (x, defaultVal = 0, radix = 10) => {
|
|
2
|
+
const n = parseInt(x, radix);
|
|
3
|
+
return isNaN(n) ? defaultVal : n;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const maybeParseFloat = (x, defaultVal = 0) => {
|
|
6
|
+
const n = parseFloat(x);
|
|
7
|
+
return isNaN(n) ? defaultVal : n;
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
maybeParseFloat,
|
|
11
|
+
maybeParseInt
|
|
8
12
|
};
|
package/percent.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param prec - number of fractional digits (default: 0)
|
|
6
|
-
*/
|
|
7
|
-
export const percent = (prec = 0) => (x) => (x * 100).toFixed(prec) + "%";
|
|
1
|
+
const percent = (prec = 0) => (x) => (x * 100).toFixed(prec) + "%";
|
|
2
|
+
export {
|
|
3
|
+
percent
|
|
4
|
+
};
|