@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/escape.js CHANGED
@@ -1,65 +1,42 @@
1
1
  import { U16, U32 } from "./radix.js";
2
- export const ESCAPES = {
3
- 0: "\0",
4
- b: "\b",
5
- t: "\t",
6
- r: "\r",
7
- v: "\v",
8
- f: "\f",
9
- n: "\n",
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
- export 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: "\\",
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
- * Returns {@link Stringer} which formats numbers to given precision. If
5
- * `special` is true, then exceptional handling for:
6
- *
7
- * - NaN => "NaN"
8
- * - Infinity => "+/-∞"
9
- *
10
- * @param len - number of fractional digits
11
- * @param special - true, if special handling for NaN/Infinity values
12
- */
13
- export const float = memoizeJ((prec, special = false) => special
14
- ? (x) => nanOrInf(x) || x.toFixed(prec)
15
- : (x) => x.toFixed(prec));
16
- /**
17
- * Similar to `float`, returns {@link Stringer} which formats numbers to given
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(Math.max(w -
39
- 4 -
40
- (Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) -
41
- (x < 0 ? 1 : 0), 0));
42
- const nanOrInf = (x) => isNaN(x)
43
- ? "NaN"
44
- : x === Infinity
45
- ? "+∞"
46
- : x === -Infinity
47
- ? "-∞"
48
- : undefined;
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
- export 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(t === "function" ? f(args[j++]) : t === "object" ? f[args[j++]] : f);
7
- }
8
- return acc.join("");
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
- const acc = {};
4
- for (let range of xs) {
5
- for (let c of range) {
6
- acc[c] = true;
7
- }
3
+ const acc = {};
4
+ for (let range of xs) {
5
+ for (let c of range) {
6
+ acc[c] = true;
8
7
  }
9
- return Object.freeze(acc);
8
+ }
9
+ return Object.freeze(acc);
10
10
  };
11
- /**
12
- * Object with whitespace characters as keys and their values set to
13
- * true. All others undefined.
14
- */
15
- export const WS = Object.freeze({
16
- "\t": true,
17
- "\n": true,
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
- * Object with 0-9 characters as keys and their values set to true. All
25
- * others undefined.
26
- */
27
- export const DIGITS = defGroup(charRange("0", "9"));
28
- /**
29
- * Object with hex digit characters (upper & lower case versions) as
30
- * keys and their values set to true. All others undefined.
31
- */
32
- export const HEX = defGroup(charRange("0", "9"), charRange("A", "F"), charRange("a", "f"));
33
- /**
34
- * Object with ASCII lowercase characters as keys and their values set
35
- * to true. All others undefined.
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
- * Object with ASCII punctuation characters as keys and their values set
57
- * to true. All others undefined.
58
- */
59
- export const PUNCTUATION = defGroup(charRange("!", "/"), charRange(":", "@"), charRange("[", "`"), charRange("{", "~"));
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
- * Formats given value `x` as Fortran style Hollerith string.
3
- *
4
- * @example
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
- * Takes an array of string parts and returns a new string of each part's
3
- * initial character. The `mode` arg can be used to customize result casing
4
- * (default: uppercase). If `mode` is null, the original casing will be kept.
5
- *
6
- * @example
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
- export const int = (x) => String(Math.trunc(x));
3
- export const intLocale = memoizeJ((locale) => (x) => Math.trunc(x).toLocaleString(locale));
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
- * Takes a string template with embedded `{number}` style terms and any
6
- * number of args. Replaces numbered terms with their respective args
7
- * given.
8
- *
9
- * @example
10
- * ```ts
11
- * interpolate("let {0}: {2} = {1};", "a", 42, "number")
12
- * // "let a: number = 42;"
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
- * Higher-order version of `Array.join()`. Takes separator string `sep`
4
- * and returns function which accepts an array and joins all elements w/
5
- * separator into a result string.
6
- *
7
- * @example
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.2",
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 clean && tsc --declaration",
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.11",
37
- "@thi.ng/errors": "^2.4.5",
38
- "@thi.ng/hex": "^2.3.23",
39
- "@thi.ng/memoize": "^3.1.45"
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": ">=12.7"
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": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
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
- * @param n - target length
5
- * @param ch - pad character(s)
6
- */
7
- export const padLeft = memoizeJ((n, ch = " ") => {
8
- const buf = repeat(String(ch), n);
9
- return (x, len) => {
10
- if (x == null)
11
- return buf;
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
- * Zero-padded 2 digit formatter.
19
- */
20
- export const Z2 = padLeft(2, "0");
21
- /**
22
- * Zero-padded 3 digit formatter.
23
- */
24
- export const Z3 = padLeft(3, "0");
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
- * @param n - target length
5
- * @param ch - pad character(s)
6
- */
7
- export const padRight = memoizeJ((n, ch = " ") => {
8
- const buf = repeat(String(ch), n);
9
- return (x, len) => {
10
- if (x == null)
11
- return buf;
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
- export const maybeParseInt = (x, defaultVal = 0, radix = 10) => {
2
- const n = parseInt(x, radix);
3
- return isNaN(n) ? defaultVal : n;
1
+ const maybeParseInt = (x, defaultVal = 0, radix = 10) => {
2
+ const n = parseInt(x, radix);
3
+ return isNaN(n) ? defaultVal : n;
4
4
  };
5
- export const maybeParseFloat = (x, defaultVal = 0) => {
6
- const n = parseFloat(x);
7
- return isNaN(n) ? defaultVal : n;
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
- * Returns {@link Stringer} which formats given fractions as percentage (e.g.
3
- * `0.1234 => 12.34%`).
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
+ };