@visactor/vutils 0.17.4 → 0.18.0-alpha.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/cjs/format/number/formatDecimal.d.ts +2 -0
- package/cjs/format/number/formatDecimal.js +18 -0
- package/cjs/format/number/formatDecimal.js.map +1 -0
- package/cjs/format/number/formatGroup.d.ts +1 -0
- package/cjs/format/number/formatGroup.js +17 -0
- package/cjs/format/number/formatGroup.js.map +1 -0
- package/cjs/format/number/formatPrefixAuto.d.ts +2 -0
- package/cjs/format/number/formatPrefixAuto.js +18 -0
- package/cjs/format/number/formatPrefixAuto.js.map +1 -0
- package/cjs/format/number/formatRounded.d.ts +1 -0
- package/cjs/format/number/formatRounded.js +17 -0
- package/cjs/format/number/formatRounded.js.map +1 -0
- package/cjs/format/number/formatTrim.d.ts +1 -0
- package/cjs/format/number/formatTrim.js +25 -0
- package/cjs/format/number/formatTrim.js.map +1 -0
- package/cjs/format/number/index.d.ts +2 -0
- package/cjs/format/number/index.js +21 -0
- package/cjs/format/number/index.js.map +1 -0
- package/cjs/format/number/number.d.ts +53 -0
- package/cjs/format/number/number.js +121 -0
- package/cjs/format/number/number.js.map +1 -0
- package/cjs/format/number/specifier.d.ts +28 -0
- package/cjs/format/number/specifier.js +41 -0
- package/cjs/format/number/specifier.js.map +1 -0
- package/cjs/format/time.d.ts +79 -0
- package/cjs/format/time.js +204 -0
- package/cjs/format/time.js.map +1 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.js +686 -0
- package/dist/index.min.js +1 -1
- package/es/format/number/formatDecimal.d.ts +2 -0
- package/es/format/number/formatDecimal.js +11 -0
- package/es/format/number/formatDecimal.js.map +1 -0
- package/es/format/number/formatGroup.d.ts +1 -0
- package/es/format/number/formatGroup.js +11 -0
- package/es/format/number/formatGroup.js.map +1 -0
- package/es/format/number/formatPrefixAuto.d.ts +2 -0
- package/es/format/number/formatPrefixAuto.js +11 -0
- package/es/format/number/formatPrefixAuto.js.map +1 -0
- package/es/format/number/formatRounded.d.ts +1 -0
- package/es/format/number/formatRounded.js +9 -0
- package/es/format/number/formatRounded.js.map +1 -0
- package/es/format/number/formatTrim.d.ts +1 -0
- package/es/format/number/formatTrim.js +19 -0
- package/es/format/number/formatTrim.js.map +1 -0
- package/es/format/number/index.d.ts +2 -0
- package/es/format/number/index.js +4 -0
- package/es/format/number/index.js.map +1 -0
- package/es/format/number/number.d.ts +53 -0
- package/es/format/number/number.js +125 -0
- package/es/format/number/number.js.map +1 -0
- package/es/format/number/specifier.d.ts +28 -0
- package/es/format/number/specifier.js +34 -0
- package/es/format/number/specifier.js.map +1 -0
- package/es/format/time.d.ts +79 -0
- package/es/format/time.js +196 -0
- package/es/format/time.js.map +1 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +4 -0
- package/es/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function formatDecimal(x) {
|
|
4
|
+
return Math.abs(x = Math.round(x)) >= 1e21 ? x.toLocaleString("en").replace(/,/g, "") : x.toString(10);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function formatDecimalParts(x, p) {
|
|
8
|
+
const _x = p ? x.toExponential(p - 1) : x.toExponential(), i = _x.indexOf("e");
|
|
9
|
+
if (i < 0) return null;
|
|
10
|
+
const coefficient = _x.slice(0, i);
|
|
11
|
+
return [ coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, +_x.slice(i + 1) ];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: !0
|
|
16
|
+
}), exports.formatDecimalParts = exports.formatDecimal = void 0, exports.formatDecimal = formatDecimal,
|
|
17
|
+
exports.formatDecimalParts = formatDecimalParts;
|
|
18
|
+
//# sourceMappingURL=formatDecimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/formatDecimal.ts"],"names":[],"mappings":";;;AAOA,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC3G,CAAC;AAFD,sCAEC;AAED,SAAgB,kBAAkB,CAAC,CAAS,EAAE,CAAU;IACtD,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IAC1D,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG,CAAC,EAAE;QACT,OAAO,IAAI,CAAC;KACb;IACD,MAAM,WAAW,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEnC,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC;AATD,gDASC","file":"formatDecimal.js","sourcesContent":["/* Adapted from d3-time-format by Mike Bostock\n * https://github.com/d3/d3-format\n * Licensed under the ISC\n\n * License: https://github.com/d3/d3-format/blob/main/LICENSE\n * @license\n */\nexport function formatDecimal(x: number) {\n return Math.abs((x = Math.round(x))) >= 1e21 ? x.toLocaleString('en').replace(/,/g, '') : x.toString(10);\n}\n\nexport function formatDecimalParts(x: number, p?: number): [string, number] | null {\n const _x = p ? x.toExponential(p - 1) : x.toExponential();\n const i = _x.indexOf('e');\n if (i < 0) {\n return null; // NaN, ±Infinity\n }\n const coefficient = _x.slice(0, i);\n\n return [coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, +_x.slice(i + 1)];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatGroup(grouping: number[], thousands: string): (value: string, width: number) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function formatGroup(grouping, thousands) {
|
|
4
|
+
return function(value, width) {
|
|
5
|
+
let i = value.length;
|
|
6
|
+
const t = [];
|
|
7
|
+
let j = 0, g = grouping[0], length = 0;
|
|
8
|
+
for (;i > 0 && g > 0 && (length + g + 1 > width && (g = Math.max(1, width - length)),
|
|
9
|
+
t.push(value.substring(i -= g, i + g)), !((length += g + 1) > width)); ) g = grouping[j = (j + 1) % grouping.length];
|
|
10
|
+
return t.reverse().join(thousands);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: !0
|
|
16
|
+
}), exports.formatGroup = void 0, exports.formatGroup = formatGroup;
|
|
17
|
+
//# sourceMappingURL=formatGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/formatGroup.ts"],"names":[],"mappings":";;;AAOA,SAAgB,WAAW,CAAC,QAAkB,EAAE,SAAiB;IAC/D,OAAO,UAAU,KAAa,EAAE,KAAa;QAC3C,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;QACrB,MAAM,CAAC,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,MAAM,GAAG,CAAC,CAAC;QAEf,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACrB,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE;gBAC1B,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;aACjC;YACD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACzC,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE;gBAC7B,MAAM;aACP;YACD,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;SAC/C;QAED,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC,CAAC;AACJ,CAAC;AArBD,kCAqBC","file":"formatGroup.js","sourcesContent":["/* Adapted from d3-time-format by Mike Bostock\n * https://github.com/d3/d3-format\n * Licensed under the ISC\n\n * License: https://github.com/d3/d3-format/blob/main/LICENSE\n * @license\n */\nexport function formatGroup(grouping: number[], thousands: string) {\n return function (value: string, width: number) {\n let i = value.length;\n const t = [];\n let j = 0;\n let g = grouping[0];\n let length = 0;\n\n while (i > 0 && g > 0) {\n if (length + g + 1 > width) {\n g = Math.max(1, width - length);\n }\n t.push(value.substring((i -= g), i + g));\n if ((length += g + 1) > width) {\n break;\n }\n g = grouping[(j = (j + 1) % grouping.length)];\n }\n\n return t.reverse().join(thousands);\n };\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.formatPrefixAuto = exports.prefixExponent = void 0;
|
|
6
|
+
|
|
7
|
+
const formatDecimal_1 = require("./formatDecimal");
|
|
8
|
+
|
|
9
|
+
function formatPrefixAuto(x, p) {
|
|
10
|
+
const d = (0, formatDecimal_1.formatDecimalParts)(x, p);
|
|
11
|
+
if (!d) return x + "";
|
|
12
|
+
const coefficient = d[0], exponent = d[1], i = exponent - (exports.prefixExponent = 3 * Math.max(-8, Math.min(8, Math.floor(exponent / 3)))) + 1, n = coefficient.length;
|
|
13
|
+
return i === n ? coefficient : i > n ? coefficient + new Array(i - n + 1).join("0") : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i) : "0." + new Array(1 - i).join("0") + (0,
|
|
14
|
+
formatDecimal_1.formatDecimalParts)(x, Math.max(0, p + i - 1))[0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.formatPrefixAuto = formatPrefixAuto;
|
|
18
|
+
//# sourceMappingURL=formatPrefixAuto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/formatPrefixAuto.ts"],"names":[],"mappings":";;;AAOA,mDAAqD;AAIrD,SAAgB,gBAAgB,CAAC,CAAS,EAAE,CAAS;IACnD,MAAM,CAAC,GAAG,IAAA,kCAAkB,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC,EAAE;QACN,OAAO,CAAC,GAAG,EAAE,CAAC;KACf;IACD,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,CAAC,GAAG,QAAQ,GAAG,CAAC,sBAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACpG,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC;IAC7B,OAAO,CAAC,KAAK,CAAC;QACZ,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,CAAC,WAAW,GAAG,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAC9C,CAAC,CAAC,CAAC,GAAG,CAAC;gBACP,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;gBACtD,CAAC,CAAC,IAAI,GAAG,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAA,kCAAkB,EAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3F,CAAC;AAhBD,4CAgBC","file":"formatPrefixAuto.js","sourcesContent":["/* Adapted from d3-time-format by Mike Bostock\n * https://github.com/d3/d3-format\n * Licensed under the ISC\n\n * License: https://github.com/d3/d3-format/blob/main/LICENSE\n * @license\n */\nimport { formatDecimalParts } from './formatDecimal';\n\nexport let prefixExponent: number;\n\nexport function formatPrefixAuto(x: number, p: number) {\n const d = formatDecimalParts(x, p);\n if (!d) {\n return x + '';\n }\n const coefficient = d[0];\n const exponent = d[1];\n const i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1;\n const n = coefficient.length;\n return i === n\n ? coefficient\n : i > n\n ? coefficient + new Array(i - n + 1).join('0')\n : i > 0\n ? coefficient.slice(0, i) + '.' + coefficient.slice(i)\n : '0.' + new Array(1 - i).join('0') + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatRounded(x: number, p: number): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.formatRounded = void 0;
|
|
6
|
+
|
|
7
|
+
const formatDecimal_1 = require("./formatDecimal");
|
|
8
|
+
|
|
9
|
+
function formatRounded(x, p) {
|
|
10
|
+
const d = (0, formatDecimal_1.formatDecimalParts)(x, p);
|
|
11
|
+
if (!d) return x + "";
|
|
12
|
+
const coefficient = d[0], exponent = d[1];
|
|
13
|
+
return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1) : coefficient + new Array(exponent - coefficient.length + 2).join("0");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.formatRounded = formatRounded;
|
|
17
|
+
//# sourceMappingURL=formatRounded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/formatRounded.ts"],"names":[],"mappings":";;;AAOA,mDAAqD;AAErD,SAAgB,aAAa,CAAC,CAAS,EAAE,CAAS;IAChD,MAAM,CAAC,GAAG,IAAA,kCAAkB,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC,EAAE;QACN,OAAO,CAAC,GAAG,EAAE,CAAC;KACf;IACD,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,QAAQ,GAAG,CAAC;QACjB,CAAC,CAAC,IAAI,GAAG,IAAI,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW;QACrD,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,QAAQ,GAAG,CAAC;YACnC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;YAC5E,CAAC,CAAC,WAAW,GAAG,IAAI,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3E,CAAC;AAZD,sCAYC","file":"formatRounded.js","sourcesContent":["/* Adapted from d3-time-format by Mike Bostock\n * https://github.com/d3/d3-format\n * Licensed under the ISC\n\n * License: https://github.com/d3/d3-format/blob/main/LICENSE\n * @license\n */\nimport { formatDecimalParts } from './formatDecimal';\n\nexport function formatRounded(x: number, p: number) {\n const d = formatDecimalParts(x, p);\n if (!d) {\n return x + '';\n }\n const coefficient = d[0];\n const exponent = d[1];\n return exponent < 0\n ? '0.' + new Array(-exponent).join('0') + coefficient\n : coefficient.length > exponent + 1\n ? coefficient.slice(0, exponent + 1) + '.' + coefficient.slice(exponent + 1)\n : coefficient + new Array(exponent - coefficient.length + 2).join('0');\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatTrim(s: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function formatTrim(s) {
|
|
4
|
+
const n = s.length;
|
|
5
|
+
let i1, i0 = -1;
|
|
6
|
+
out: for (let i = 1; i < n; ++i) switch (s[i]) {
|
|
7
|
+
case ".":
|
|
8
|
+
i0 = i1 = i;
|
|
9
|
+
break;
|
|
10
|
+
|
|
11
|
+
case "0":
|
|
12
|
+
0 === i0 && (i0 = i), i1 = i;
|
|
13
|
+
break;
|
|
14
|
+
|
|
15
|
+
default:
|
|
16
|
+
if (!+s[i]) break out;
|
|
17
|
+
i0 > 0 && (i0 = 0);
|
|
18
|
+
}
|
|
19
|
+
return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: !0
|
|
24
|
+
}), exports.formatTrim = void 0, exports.formatTrim = formatTrim;
|
|
25
|
+
//# sourceMappingURL=formatTrim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/formatTrim.ts"],"names":[],"mappings":";;;AAOA,SAAgB,UAAU,CAAC,CAAS;IAClC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACZ,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;QAC/B,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;YACZ,KAAK,GAAG;gBACN,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;gBACZ,MAAM;YACR,KAAK,GAAG;gBACN,IAAI,EAAE,KAAK,CAAC,EAAE;oBACZ,EAAE,GAAG,CAAC,CAAC;iBACR;gBACD,EAAE,GAAG,CAAC,CAAC;gBACP,MAAM;YACR;gBACE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;oBACV,MAAM,GAAG,CAAC;iBACX;gBACD,IAAI,EAAE,GAAG,CAAC,EAAE;oBACV,EAAE,GAAG,CAAC,CAAC;iBACR;gBACD,MAAM;SACT;KACF;IACD,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AA1BD,gCA0BC","file":"formatTrim.js","sourcesContent":["/* Adapted from d3-time-format by Mike Bostock\n * https://github.com/d3/d3-format\n * Licensed under the ISC\n\n * License: https://github.com/d3/d3-format/blob/main/LICENSE\n * @license\n */\nexport function formatTrim(s: string) {\n const n = s.length;\n let i0 = -1;\n let i1;\n out: for (let i = 1; i < n; ++i) {\n switch (s[i]) {\n case '.':\n i0 = i1 = i;\n break;\n case '0':\n if (i0 === 0) {\n i0 = i;\n }\n i1 = i;\n break;\n default:\n if (!+s[i]) {\n break out;\n }\n if (i0 > 0) {\n i0 = 0;\n }\n break;\n }\n }\n return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
void 0 === k2 && (k2 = k);
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
get: function() {
|
|
9
|
+
return m[k];
|
|
10
|
+
}
|
|
11
|
+
}), Object.defineProperty(o, k2, desc);
|
|
12
|
+
} : function(o, m, k, k2) {
|
|
13
|
+
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
+
}), __exportStar = this && this.__exportStar || function(m, exports) {
|
|
15
|
+
for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(exports, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), __exportStar(require("./number"), exports), __exportStar(require("./specifier"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B","file":"index.js","sourcesContent":["export * from './number';\nexport * from './specifier';\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { formatDecimal } from './formatDecimal';
|
|
2
|
+
import { formatPrefixAuto } from './formatPrefixAuto';
|
|
3
|
+
import { formatRounded } from './formatRounded';
|
|
4
|
+
export interface FormatLocale {
|
|
5
|
+
thousands: string;
|
|
6
|
+
grouping: number[];
|
|
7
|
+
currency: [string, string];
|
|
8
|
+
numerals?: string[] | undefined;
|
|
9
|
+
percent?: string | undefined;
|
|
10
|
+
minus?: string | undefined;
|
|
11
|
+
nan?: string | undefined;
|
|
12
|
+
decimal?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class NumberUtil {
|
|
15
|
+
private locale;
|
|
16
|
+
private group;
|
|
17
|
+
private currencyPrefix;
|
|
18
|
+
private currencySuffix;
|
|
19
|
+
private decimal;
|
|
20
|
+
private numerals;
|
|
21
|
+
private percent;
|
|
22
|
+
private minus;
|
|
23
|
+
private nan;
|
|
24
|
+
private static instance;
|
|
25
|
+
static getInstance(): NumberUtil;
|
|
26
|
+
private newFormat;
|
|
27
|
+
private _formatPrefix;
|
|
28
|
+
formatter: (specifier: string) => {
|
|
29
|
+
(value: number): string | string[];
|
|
30
|
+
toString(): string;
|
|
31
|
+
};
|
|
32
|
+
format: (specifier: string, value: number) => string | string[];
|
|
33
|
+
formatPrefix: (specifier: string, value: number) => (value: number) => string;
|
|
34
|
+
}
|
|
35
|
+
export declare const formatTypes: {
|
|
36
|
+
'%': (x: number, p: number) => string;
|
|
37
|
+
b: (x: number) => string;
|
|
38
|
+
c: (x: number) => string;
|
|
39
|
+
d: typeof formatDecimal;
|
|
40
|
+
f: (x: number, p: number) => string;
|
|
41
|
+
e: (x: number, p: number) => string;
|
|
42
|
+
g: (x: number, p: number) => string;
|
|
43
|
+
o: (x: number) => string;
|
|
44
|
+
p: (x: number, p: number) => string;
|
|
45
|
+
r: typeof formatRounded;
|
|
46
|
+
s: typeof formatPrefixAuto;
|
|
47
|
+
X: (x: number) => string;
|
|
48
|
+
x: (x: number) => string;
|
|
49
|
+
t: (x: number, p: number) => string;
|
|
50
|
+
z: (x: number, p: number) => string;
|
|
51
|
+
};
|
|
52
|
+
export declare function exponent(x: number): number;
|
|
53
|
+
export declare function formatNumerals(numerals: string[]): (value: string) => string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.formatNumerals = exports.exponent = exports.formatTypes = exports.NumberUtil = void 0;
|
|
6
|
+
|
|
7
|
+
const formatDecimal_1 = require("./formatDecimal"), formatGroup_1 = require("./formatGroup"), formatPrefixAuto_1 = require("./formatPrefixAuto"), formatRounded_1 = require("./formatRounded"), formatTrim_1 = require("./formatTrim"), specifier_1 = require("./specifier"), prefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ];
|
|
8
|
+
|
|
9
|
+
class NumberUtil {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.locale = {
|
|
12
|
+
thousands: ",",
|
|
13
|
+
grouping: [ 3 ],
|
|
14
|
+
currency: [ "$", "" ]
|
|
15
|
+
}, this.group = void 0 === this.locale.grouping || void 0 === this.locale.thousands ? group => group : (0,
|
|
16
|
+
formatGroup_1.formatGroup)([ ...this.locale.grouping ].map(Number), `${this.locale.thousands}`),
|
|
17
|
+
this.currencyPrefix = void 0 === this.locale.currency ? "" : this.locale.currency[0] + "",
|
|
18
|
+
this.currencySuffix = void 0 === this.locale.currency ? "" : this.locale.currency[1] + "",
|
|
19
|
+
this.decimal = void 0 === this.locale.decimal ? "." : this.locale.decimal + "",
|
|
20
|
+
this.numerals = void 0 === this.locale.numerals ? numerals => numerals : formatNumerals([ ...this.locale.numerals ].map(String)),
|
|
21
|
+
this.percent = void 0 === this.locale.percent ? "%" : this.locale.percent + "",
|
|
22
|
+
this.minus = void 0 === this.locale.minus ? "−" : this.locale.minus + "", this.nan = void 0 === this.locale.nan ? "NaN" : this.locale.nan + "",
|
|
23
|
+
this.formatter = specifier => this.newFormat(specifier), this.format = (specifier, value) => this.formatter(specifier)(value),
|
|
24
|
+
this.formatPrefix = (specifier, value) => this._formatPrefix(specifier, value);
|
|
25
|
+
}
|
|
26
|
+
static getInstance() {
|
|
27
|
+
return NumberUtil.instance || (NumberUtil.instance = new NumberUtil), NumberUtil.instance;
|
|
28
|
+
}
|
|
29
|
+
newFormat(specifier) {
|
|
30
|
+
const specifierIns = (0, specifier_1.formatSpecifier)(specifier);
|
|
31
|
+
let fill = specifierIns.fill, align = specifierIns.align;
|
|
32
|
+
const sign = specifierIns.sign, symbol = specifierIns.symbol;
|
|
33
|
+
let zero = specifierIns.zero;
|
|
34
|
+
const width = specifierIns.width;
|
|
35
|
+
let comma = specifierIns.comma, precision = specifierIns.precision, trim = specifierIns.trim, type = specifierIns.type;
|
|
36
|
+
"n" === type ? (comma = !0, type = "g") : exports.formatTypes[type] || (void 0 === precision && (precision = 12),
|
|
37
|
+
trim = !0, type = "g"), (zero || "0" === fill && "=" === align) && (zero = !0, fill = "0",
|
|
38
|
+
align = "=");
|
|
39
|
+
const prefix = "$" === symbol ? this.currencyPrefix : "#" === symbol && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "", suffix = "$" === symbol ? this.currencySuffix : /[%p]/.test(type) ? this.percent : "", formatType = exports.formatTypes[type], maybeSuffix = /[defgprstz%]/.test(type);
|
|
40
|
+
precision = void 0 === precision ? 6 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision)) : Math.max(0, Math.min(20, precision));
|
|
41
|
+
const {nan: nan, minus: minus, decimal: decimal, group: group, numerals: numerals} = this;
|
|
42
|
+
function format(value) {
|
|
43
|
+
let i, n, c, valuePrefix = prefix, valueSuffix = suffix, _value = value;
|
|
44
|
+
if ("c" === type) valueSuffix = formatType(_value) + valueSuffix, _value = ""; else {
|
|
45
|
+
_value = +_value;
|
|
46
|
+
let valueNegative = _value < 0 || 1 / _value < 0;
|
|
47
|
+
if (_value = isNaN(_value) ? nan : formatType(Math.abs(_value), precision), trim && (_value = (0,
|
|
48
|
+
formatTrim_1.formatTrim)(_value)), valueNegative && 0 == +_value && "+" !== sign && (valueNegative = !1),
|
|
49
|
+
valuePrefix = (valueNegative ? "(" === sign ? sign : minus : "-" === sign || "(" === sign ? "" : sign) + valuePrefix,
|
|
50
|
+
valueSuffix = ("s" === type ? prefixes[8 + formatPrefixAuto_1.prefixExponent / 3] : "") + valueSuffix + (valueNegative && "(" === sign ? ")" : ""),
|
|
51
|
+
maybeSuffix) for (i = -1, n = _value.length; ++i < n; ) if (c = _value.charCodeAt(i),
|
|
52
|
+
48 > c || c > 57) {
|
|
53
|
+
valueSuffix = (46 === c ? decimal + _value.slice(i + 1) : _value.slice(i)) + valueSuffix,
|
|
54
|
+
_value = _value.slice(0, i);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
comma && !zero && (_value = group(_value, 1 / 0));
|
|
59
|
+
let length = valuePrefix.length + _value.length + valueSuffix.length, padding = length < width ? new Array(width - length + 1).join(fill) : "";
|
|
60
|
+
switch (comma && zero && (_value = group(padding + _value, padding.length ? width - valueSuffix.length : 1 / 0),
|
|
61
|
+
padding = ""), align) {
|
|
62
|
+
case "<":
|
|
63
|
+
_value = valuePrefix + _value + valueSuffix + padding;
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case "=":
|
|
67
|
+
_value = valuePrefix + padding + _value + valueSuffix;
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case "^":
|
|
71
|
+
_value = padding.slice(0, length = padding.length >> 1) + valuePrefix + _value + valueSuffix + padding.slice(length);
|
|
72
|
+
break;
|
|
73
|
+
|
|
74
|
+
default:
|
|
75
|
+
_value = padding + valuePrefix + _value + valueSuffix;
|
|
76
|
+
}
|
|
77
|
+
return numerals(_value);
|
|
78
|
+
}
|
|
79
|
+
return format.toString = function() {
|
|
80
|
+
return specifier + "";
|
|
81
|
+
}, format;
|
|
82
|
+
}
|
|
83
|
+
_formatPrefix(specifier, value) {
|
|
84
|
+
const _specifier = (0, specifier_1.formatSpecifier)(specifier);
|
|
85
|
+
_specifier.type = "f";
|
|
86
|
+
const f = this.newFormat(_specifier.toString()), e = 3 * Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))), k = Math.pow(10, -e), prefix = prefixes[8 + e / 3];
|
|
87
|
+
return function(value) {
|
|
88
|
+
return f(k * value) + prefix;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function exponent(x) {
|
|
94
|
+
const _x = (0, formatDecimal_1.formatDecimalParts)(Math.abs(x));
|
|
95
|
+
return _x ? _x[1] : NaN;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function formatNumerals(numerals) {
|
|
99
|
+
return function(value) {
|
|
100
|
+
return value.replace(/[0-9]/g, (i => numerals[+i]));
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
exports.NumberUtil = NumberUtil, exports.formatTypes = {
|
|
105
|
+
"%": (x, p) => (100 * x).toFixed(p),
|
|
106
|
+
b: x => Math.round(x).toString(2),
|
|
107
|
+
c: x => x + "",
|
|
108
|
+
d: formatDecimal_1.formatDecimal,
|
|
109
|
+
f: (x, p) => x.toFixed(p),
|
|
110
|
+
e: (x, p) => x.toExponential(p),
|
|
111
|
+
g: (x, p) => x.toPrecision(p),
|
|
112
|
+
o: x => Math.round(x).toString(8),
|
|
113
|
+
p: (x, p) => (0, formatRounded_1.formatRounded)(100 * x, p),
|
|
114
|
+
r: formatRounded_1.formatRounded,
|
|
115
|
+
s: formatPrefixAuto_1.formatPrefixAuto,
|
|
116
|
+
X: x => Math.round(x).toString(16).toUpperCase(),
|
|
117
|
+
x: x => Math.round(x).toString(16),
|
|
118
|
+
t: (x, p) => Number.isInteger(x) ? x.toFixed(2) : Math.floor(x * Math.pow(10, p)) / Math.pow(10, p) + "",
|
|
119
|
+
z: (x, p) => x % 1 == 0 ? x + "" : x.toFixed(p)
|
|
120
|
+
}, exports.exponent = exponent, exports.formatNumerals = formatNumerals;
|
|
121
|
+
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/number.ts"],"names":[],"mappings":";;;AAQA,mDAAoE;AACpE,+CAA4C;AAC5C,yDAAsE;AACtE,mDAAgD;AAChD,6CAA0C;AAC1C,2CAA8C;AAa9C,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEtG,MAAa,UAAU;IAAvB;QACU,WAAM,GAAiB;YAC7B,SAAS,EAAE,GAAG;YACd,QAAQ,EAAE,CAAC,CAAC,CAAC;YACb,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;SACpB,CAAC;QAEM,UAAK,GACX,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS;YACvE,CAAC,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK;YACvB,CAAC,CAAC,IAAA,yBAAW,EAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7E,mBAAc,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,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AAC,QAAQ,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC;AAJD,wCAIC","file":"number.js","sourcesContent":["/* Adapted from d3-time-format by Mike Bostock\n * https://github.com/d3/d3-format\n * Licensed under the ISC\n\n * License: https://github.com/d3/d3-format/blob/main/LICENSE\n * @license\n */\n\nimport { formatDecimal, formatDecimalParts } from './formatDecimal';\nimport { formatGroup } from './formatGroup';\nimport { formatPrefixAuto, prefixExponent } from './formatPrefixAuto';\nimport { formatRounded } from './formatRounded';\nimport { formatTrim } from './formatTrim';\nimport { formatSpecifier } from './specifier';\n\nexport interface FormatLocale {\n thousands: string;\n grouping: number[];\n currency: [string, string];\n numerals?: string[] | undefined;\n percent?: string | undefined;\n minus?: string | undefined;\n nan?: string | undefined;\n decimal?: string;\n}\n\nconst prefixes = ['y', 'z', 'a', 'f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];\n\nexport class NumberUtil {\n private locale: FormatLocale = {\n thousands: ',',\n grouping: [3],\n currency: ['$', '']\n };\n\n private group =\n this.locale.grouping === undefined || this.locale.thousands === undefined\n ? (group: any) => group\n : formatGroup([...this.locale.grouping].map(Number), `${this.locale.thousands}`);\n private currencyPrefix = this.locale.currency === undefined ? '' : this.locale.currency[0] + '';\n private currencySuffix = this.locale.currency === undefined ? '' : this.locale.currency[1] + '';\n private decimal = this.locale.decimal === undefined ? '.' : this.locale.decimal + '';\n private numerals =\n this.locale.numerals === undefined\n ? (numerals: string[]) => numerals\n : formatNumerals([...this.locale.numerals].map(String));\n private percent = this.locale.percent === undefined ? '%' : this.locale.percent + '';\n private minus = this.locale.minus === undefined ? '−' : this.locale.minus + '';\n private nan = this.locale.nan === undefined ? 'NaN' : this.locale.nan + '';\n\n private static instance: NumberUtil;\n\n static getInstance(): NumberUtil {\n if (!NumberUtil.instance) {\n NumberUtil.instance = new NumberUtil();\n }\n return NumberUtil.instance;\n }\n\n private newFormat(specifier: string) {\n const specifierIns = formatSpecifier(specifier);\n\n let fill = specifierIns.fill;\n let align = specifierIns.align;\n const sign = specifierIns.sign;\n const symbol = specifierIns.symbol;\n let zero = specifierIns.zero;\n const width = specifierIns.width;\n let comma = specifierIns.comma;\n let precision = specifierIns.precision;\n let trim = specifierIns.trim;\n let type = specifierIns.type;\n\n // The \"n\" type is an alias for \",g\".\n if (type === 'n') {\n (comma = true), (type = 'g');\n }\n // The \"\" type, and any invalid type, is an alias for \".12~g\".\n // @ts-ignore\n else if (!formatTypes[type]) {\n precision === undefined && (precision = 12), (trim = true), (type = 'g');\n }\n\n // If zero fill is specified, padding goes after sign and before digits.\n // @ts-ignore\n if (zero || (fill === '0' && align === '=')) {\n (zero = true), (fill = '0'), (align = '=');\n }\n\n // Compute the prefix and suffix.\n // For SI-prefix, the suffix is lazily computed.\n const prefix =\n symbol === '$' ? this.currencyPrefix : symbol === '#' && /[boxX]/.test(type) ? '0' + type.toLowerCase() : '';\n const suffix = symbol === '$' ? this.currencySuffix : /[%p]/.test(type) ? this.percent : '';\n\n // What format function should we use?\n // Is this an integer type?\n // Can this type generate exponential notation?\n const formatType = formatTypes[type];\n const maybeSuffix = /[defgprstz%]/.test(type);\n\n // Set the default precision if not specified,\n // or clamp the specified precision to the supported range.\n // For significant precision, it must be in [1, 21].\n // For fixed precision, it must be in [0, 20].\n precision =\n precision === undefined\n ? 6\n : /[gprs]/.test(type)\n ? Math.max(1, Math.min(21, precision))\n : Math.max(0, Math.min(20, precision));\n\n const { nan, minus, decimal, group, numerals } = this;\n\n function format(value: number) {\n let valuePrefix = prefix;\n let valueSuffix = suffix;\n let i;\n let n;\n let c;\n let _value: any = value;\n\n if (type === 'c') {\n valueSuffix = formatType(_value) + valueSuffix;\n _value = '';\n } else {\n _value = +_value;\n\n // Determine the sign. -0 is not less than 0, but 1 / -0 is!\n let valueNegative = _value < 0 || 1 / _value < 0;\n\n // Perform the initial formatting.\n _value = isNaN(_value) ? nan : formatType(Math.abs(_value), precision);\n\n // Trim insignificant zeros.\n if (trim) {\n _value = formatTrim(_value);\n }\n\n // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.\n if (valueNegative && +_value === 0 && sign !== '+') {\n valueNegative = false;\n }\n\n // Compute the prefix and suffix.\n valuePrefix =\n (valueNegative ? (sign === '(' ? sign : minus) : sign === '-' || sign === '(' ? '' : sign) + valuePrefix;\n valueSuffix =\n (type === 's' ? prefixes[8 + prefixExponent / 3] : '') +\n valueSuffix +\n (valueNegative && sign === '(' ? ')' : '');\n\n // Break the formatted value into the integer “value” part that can be\n // grouped, and fractional or exponential “suffix” part that is not.\n if (maybeSuffix) {\n (i = -1), (n = _value.length);\n while (++i < n) {\n if (((c = _value.charCodeAt(i)), 48 > c || c > 57)) {\n valueSuffix = (c === 46 ? decimal + _value.slice(i + 1) : _value.slice(i)) + valueSuffix;\n _value = _value.slice(0, i);\n break;\n }\n }\n }\n }\n\n // If the fill character is not \"0\", grouping is applied before padding.\n if (comma && !zero) {\n _value = group(_value, Infinity);\n }\n\n // Compute the padding.\n let length = valuePrefix.length + _value.length + valueSuffix.length;\n let padding = length < width ? new Array(width - length + 1).join(fill) : '';\n\n // If the fill character is \"0\", grouping is applied after padding.\n if (comma && zero) {\n _value = group(padding + _value, padding.length ? width - valueSuffix.length : Infinity);\n padding = '';\n }\n\n // Reconstruct the final output based on the desired alignment.\n switch (align) {\n case '<':\n _value = valuePrefix + _value + valueSuffix + padding;\n break;\n case '=':\n _value = valuePrefix + padding + _value + valueSuffix;\n break;\n case '^':\n _value =\n padding.slice(0, (length = padding.length >> 1)) +\n valuePrefix +\n _value +\n valueSuffix +\n padding.slice(length);\n break;\n default:\n _value = padding + valuePrefix + _value + valueSuffix;\n break;\n }\n return numerals(_value);\n }\n\n format.toString = function () {\n return specifier + '';\n };\n\n return format;\n }\n\n private _formatPrefix(specifier: string, value: number) {\n const _specifier = formatSpecifier(specifier);\n _specifier.type = 'f';\n const f = this.newFormat(_specifier.toString());\n const e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3;\n const k = Math.pow(10, -e);\n const prefix = prefixes[8 + e / 3];\n return function (value: number) {\n return f(k * value) + prefix;\n };\n }\n\n formatter = (specifier: string) => {\n return this.newFormat(specifier);\n };\n\n format = (specifier: string, value: number) => {\n return this.formatter(specifier)(value);\n };\n\n formatPrefix = (specifier: string, value: number) => {\n return this._formatPrefix(specifier, value);\n };\n}\n\nexport const formatTypes = {\n '%': (x: number, p: number) => (x * 100).toFixed(p),\n b: (x: number) => Math.round(x).toString(2),\n c: (x: number) => x + '',\n d: formatDecimal,\n f: (x: number, p: number) => x.toFixed(p),\n e: (x: number, p: number) => x.toExponential(p),\n g: (x: number, p: number) => x.toPrecision(p),\n o: (x: number) => Math.round(x).toString(8),\n p: (x: number, p: number) => formatRounded(x * 100, p),\n r: formatRounded,\n s: formatPrefixAuto,\n X: (x: number) => Math.round(x).toString(16).toUpperCase(),\n x: (x: number) => Math.round(x).toString(16),\n t: (x: number, p: number) => {\n // 判断是否为整数\n if (Number.isInteger(x)) {\n return x.toFixed(2);\n }\n return Math.floor(x * Math.pow(10, p)) / Math.pow(10, p) + '';\n },\n z: (x: number, p: number) => (x % 1 === 0 ? x + '' : x.toFixed(p))\n};\n\nexport function exponent(x: number) {\n const _x = formatDecimalParts(Math.abs(x));\n return _x ? _x[1] : NaN;\n}\n\nexport function formatNumerals(numerals: string[]) {\n return function (value: string) {\n return value.replace(/[0-9]/g, (i: string) => numerals[+i]);\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface IFormatSpecifier {
|
|
2
|
+
fill?: string | undefined;
|
|
3
|
+
align?: string | undefined;
|
|
4
|
+
sign?: string | undefined;
|
|
5
|
+
symbol?: string | undefined;
|
|
6
|
+
zero?: string | undefined;
|
|
7
|
+
width?: string | undefined;
|
|
8
|
+
comma?: string | undefined;
|
|
9
|
+
precision?: string | undefined;
|
|
10
|
+
trim?: string | undefined;
|
|
11
|
+
type?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare class FormatSpecifier {
|
|
14
|
+
fill: string;
|
|
15
|
+
align: string;
|
|
16
|
+
sign: string;
|
|
17
|
+
symbol: string;
|
|
18
|
+
zero: boolean;
|
|
19
|
+
width: number;
|
|
20
|
+
comma: boolean;
|
|
21
|
+
precision: number;
|
|
22
|
+
trim: boolean;
|
|
23
|
+
type: string;
|
|
24
|
+
constructor(specifier?: IFormatSpecifier);
|
|
25
|
+
toString(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare const numberSpecifierReg: RegExp;
|
|
28
|
+
export declare function formatSpecifier(specifier: string): FormatSpecifier;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.formatSpecifier = exports.numberSpecifierReg = exports.FormatSpecifier = void 0;
|
|
6
|
+
|
|
7
|
+
const logger_1 = require("../../logger");
|
|
8
|
+
|
|
9
|
+
class FormatSpecifier {
|
|
10
|
+
constructor(specifier = {}) {
|
|
11
|
+
this.fill = void 0 === specifier.fill ? " " : specifier.fill + "", this.align = void 0 === specifier.align ? ">" : specifier.align + "",
|
|
12
|
+
this.sign = void 0 === specifier.sign ? "-" : specifier.sign + "", this.symbol = void 0 === specifier.symbol ? "" : specifier.symbol + "",
|
|
13
|
+
this.zero = !!specifier.zero, this.width = void 0 === specifier.width ? void 0 : +specifier.width,
|
|
14
|
+
this.comma = !!specifier.comma, this.precision = void 0 === specifier.precision ? void 0 : +specifier.precision,
|
|
15
|
+
this.trim = !!specifier.trim, this.type = void 0 === specifier.type ? "" : specifier.type + "";
|
|
16
|
+
}
|
|
17
|
+
toString() {
|
|
18
|
+
return this.fill + this.align + this.sign + this.symbol + (this.zero ? "0" : "") + (void 0 === this.width ? "" : Math.max(1, 0 | this.width)) + (this.comma ? "," : "") + (void 0 === this.precision ? "" : "." + Math.max(0, 0 | this.precision)) + (this.trim ? "~" : "") + this.type;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatSpecifier(specifier) {
|
|
23
|
+
let match;
|
|
24
|
+
if (match = exports.numberSpecifierReg.exec(specifier)) return new FormatSpecifier({
|
|
25
|
+
fill: match[1],
|
|
26
|
+
align: match[2],
|
|
27
|
+
sign: match[3],
|
|
28
|
+
symbol: match[4],
|
|
29
|
+
zero: match[5],
|
|
30
|
+
width: match[6],
|
|
31
|
+
comma: match[7],
|
|
32
|
+
precision: match[8] && match[8].slice(1),
|
|
33
|
+
trim: match[9],
|
|
34
|
+
type: match[10]
|
|
35
|
+
});
|
|
36
|
+
logger_1.Logger.getInstance().error("invalid format: " + specifier);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.FormatSpecifier = FormatSpecifier, exports.numberSpecifierReg = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i,
|
|
40
|
+
exports.formatSpecifier = formatSpecifier;
|
|
41
|
+
//# sourceMappingURL=specifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/number/specifier.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAetC,MAAa,eAAe;IAY1B,YAAY,YAA8B,EAAE;QAC1C,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,GAAG,EAAE,CAAC;QACrE,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,GAAG,EAAE,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,CA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ger';\n\nexport interface IFormatSpecifier {\n fill?: string | undefined;\n align?: string | undefined;\n sign?: string | undefined;\n symbol?: string | undefined;\n zero?: string | undefined;\n width?: string | undefined;\n comma?: string | undefined;\n precision?: string | undefined;\n trim?: string | undefined;\n type?: string | undefined;\n}\n\nexport class FormatSpecifier {\n fill;\n align;\n sign;\n symbol;\n zero;\n width;\n comma;\n precision;\n trim;\n type;\n\n constructor(specifier: IFormatSpecifier = {}) {\n this.fill = specifier.fill === undefined ? ' ' : specifier.fill + '';\n this.align = specifier.align === undefined ? '>' : specifier.align + '';\n this.sign = specifier.sign === undefined ? '-' : specifier.sign + '';\n this.symbol = specifier.symbol === undefined ? '' : specifier.symbol + '';\n this.zero = !!specifier.zero;\n this.width = specifier.width === undefined ? undefined : +specifier.width;\n this.comma = !!specifier.comma;\n this.precision = specifier.precision === undefined ? undefined : +specifier.precision;\n this.trim = !!specifier.trim;\n this.type = specifier.type === undefined ? '' : specifier.type + '';\n }\n\n toString() {\n return (\n this.fill +\n this.align +\n this.sign +\n this.symbol +\n (this.zero ? '0' : '') +\n (this.width === undefined ? '' : Math.max(1, this.width | 0)) +\n (this.comma ? ',' : '') +\n (this.precision === undefined ? '' : '.' + Math.max(0, this.precision | 0)) +\n (this.trim ? '~' : '') +\n this.type\n );\n }\n}\n\nexport const numberSpecifierReg = /^(?:(.)?([<>=^]))?([+\\-( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?(~)?([a-z%])?$/i;\n\nexport function formatSpecifier(specifier: string) {\n let match;\n if (!(match = numberSpecifierReg.exec(specifier))) {\n Logger.getInstance().error('invalid format: ' + specifier);\n return;\n }\n return new FormatSpecifier({\n fill: match[1],\n align: match[2],\n sign: match[3],\n symbol: match[4],\n zero: match[5],\n width: match[6],\n comma: match[7],\n precision: match[8] && match[8].slice(1),\n trim: match[9],\n type: match[10]\n });\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare class TimeUtil {
|
|
2
|
+
private locale_shortWeekdays;
|
|
3
|
+
private locale_periods;
|
|
4
|
+
private locale_weekdays;
|
|
5
|
+
private locale_shortMonths;
|
|
6
|
+
private numberRe;
|
|
7
|
+
private pads;
|
|
8
|
+
private requoteRe;
|
|
9
|
+
private periodRe;
|
|
10
|
+
private periodLookup;
|
|
11
|
+
private weekdayRe;
|
|
12
|
+
private weekdayLookup;
|
|
13
|
+
private shortWeekdayRe;
|
|
14
|
+
private shortWeekdayLookup;
|
|
15
|
+
private monthRe;
|
|
16
|
+
private monthLookup;
|
|
17
|
+
private shortMonthRe;
|
|
18
|
+
private shortMonthLookup;
|
|
19
|
+
private static instance;
|
|
20
|
+
static getInstance(): TimeUtil;
|
|
21
|
+
private requoteF;
|
|
22
|
+
private constructor();
|
|
23
|
+
private requote;
|
|
24
|
+
private localDate;
|
|
25
|
+
private utcDate;
|
|
26
|
+
private newDate;
|
|
27
|
+
private formatRe;
|
|
28
|
+
private formatLookup;
|
|
29
|
+
private locale_months;
|
|
30
|
+
private formatShortWeekday;
|
|
31
|
+
private formatWeekday;
|
|
32
|
+
private formatShortMonth;
|
|
33
|
+
private formatMonth;
|
|
34
|
+
private pad;
|
|
35
|
+
private formatDayOfMonth;
|
|
36
|
+
private formatHour24;
|
|
37
|
+
private formatHour12;
|
|
38
|
+
private formatMilliseconds;
|
|
39
|
+
private formatMonthNumber;
|
|
40
|
+
private formatMinutes;
|
|
41
|
+
private formatPeriod;
|
|
42
|
+
private formatSeconds;
|
|
43
|
+
private formatFullYear;
|
|
44
|
+
private formatUTCShortWeekday;
|
|
45
|
+
private formatUTCWeekday;
|
|
46
|
+
private formatUTCShortMonth;
|
|
47
|
+
private formatUTCMonth;
|
|
48
|
+
private formatUTCDayOfMonth;
|
|
49
|
+
private formatUTCHour24;
|
|
50
|
+
private formatUTCHour12;
|
|
51
|
+
private formatUTCMilliseconds;
|
|
52
|
+
private formatUTCMonthNumber;
|
|
53
|
+
private formatUTCMinutes;
|
|
54
|
+
private formatUTCPeriod;
|
|
55
|
+
private formatUTCSeconds;
|
|
56
|
+
private formatUTCFullYear;
|
|
57
|
+
private formats;
|
|
58
|
+
private utcFormats;
|
|
59
|
+
private parseShortWeekday;
|
|
60
|
+
private parseWeekday;
|
|
61
|
+
private parseShortMonth;
|
|
62
|
+
private parseMonth;
|
|
63
|
+
private parseDayOfMonth;
|
|
64
|
+
private parseHour24;
|
|
65
|
+
private parseMilliseconds;
|
|
66
|
+
private parseMonthNumber;
|
|
67
|
+
private parseMinutes;
|
|
68
|
+
private parsePeriod;
|
|
69
|
+
private parseSeconds;
|
|
70
|
+
private parseFullYear;
|
|
71
|
+
private parses;
|
|
72
|
+
private parseSpecifier;
|
|
73
|
+
private newParse;
|
|
74
|
+
private newFormat;
|
|
75
|
+
private getFullTimeStamp;
|
|
76
|
+
timeFormat: (specifier: string, timeText: string | number) => string;
|
|
77
|
+
timeUTCFormat: (specifier: string, timeText: string | number) => string;
|
|
78
|
+
timeParse: (specifier: string, timeText: string | number) => Date;
|
|
79
|
+
}
|