@eternl/formats 0.1.0
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/README.md +132 -0
- package/dist/cjs/constants.js +21 -0
- package/dist/cjs/csv.js +83 -0
- package/dist/cjs/date.js +61 -0
- package/dist/cjs/display.js +213 -0
- package/dist/cjs/errors.js +48 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/internal/intl-cache.js +92 -0
- package/dist/cjs/internal/numeric.js +164 -0
- package/dist/cjs/types.js +16 -0
- package/dist/esm/constants.js +19 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/csv.js +77 -0
- package/dist/esm/csv.js.map +1 -0
- package/dist/esm/date.js +57 -0
- package/dist/esm/date.js.map +1 -0
- package/dist/esm/display.js +204 -0
- package/dist/esm/display.js.map +1 -0
- package/dist/esm/errors.js +42 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/intl-cache.js +87 -0
- package/dist/esm/internal/intl-cache.js.map +1 -0
- package/dist/esm/internal/numeric.js +154 -0
- package/dist/esm/internal/numeric.js.map +1 -0
- package/dist/esm/types.js +14 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/constants.d.ts +19 -0
- package/dist/types/csv.d.ts +5 -0
- package/dist/types/date.d.ts +2 -0
- package/dist/types/display.d.ts +9 -0
- package/dist/types/errors.d.ts +21 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/internal/intl-cache.d.ts +17 -0
- package/dist/types/internal/numeric.d.ts +19 -0
- package/dist/types/types.d.ts +50 -0
- package/package.json +54 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyGrouping = exports.bigToDecimalString = exports.computeNumericParts = exports.toFixedNoSci = exports.normalizeNumeric = void 0;
|
|
7
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const ROUNDING_MODE_MAP = {
|
|
11
|
+
roundDown: big_js_1.default.roundDown,
|
|
12
|
+
roundHalfUp: big_js_1.default.roundHalfUp,
|
|
13
|
+
roundHalfEven: big_js_1.default.roundHalfEven,
|
|
14
|
+
roundUp: big_js_1.default.roundUp
|
|
15
|
+
};
|
|
16
|
+
const assertNonNegativeInteger = (value, label) => {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
21
|
+
throw (0, errors_1.toRangeError)(errors_1.FormatError.NonNegativeIntegerRequired, { label });
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
const assertPositiveInteger = (value, label) => {
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
30
|
+
throw (0, errors_1.toRangeError)(errors_1.FormatError.PositiveIntegerRequired, { label });
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
const normalizeNumeric = (value) => {
|
|
35
|
+
if (value instanceof big_js_1.default) {
|
|
36
|
+
if (!value.c) {
|
|
37
|
+
return new big_js_1.default(constants_1.DECIMAL_ZERO);
|
|
38
|
+
}
|
|
39
|
+
return new big_js_1.default(value.toString());
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
if (!Number.isFinite(value)) {
|
|
43
|
+
throw (0, errors_1.toRangeError)(errors_1.FormatError.NumericValueNonFinite);
|
|
44
|
+
}
|
|
45
|
+
return new big_js_1.default(value);
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
const trimmed = value.trim();
|
|
49
|
+
if (!trimmed) {
|
|
50
|
+
throw (0, errors_1.toRangeError)(errors_1.FormatError.NumericStringEmpty);
|
|
51
|
+
}
|
|
52
|
+
return new big_js_1.default(trimmed);
|
|
53
|
+
}
|
|
54
|
+
throw (0, errors_1.toTypeError)(errors_1.FormatError.UnsupportedNumericInput);
|
|
55
|
+
};
|
|
56
|
+
exports.normalizeNumeric = normalizeNumeric;
|
|
57
|
+
const mapRoundingMode = (mode) => {
|
|
58
|
+
if (!mode) {
|
|
59
|
+
return big_js_1.default.roundHalfUp;
|
|
60
|
+
}
|
|
61
|
+
return ROUNDING_MODE_MAP[mode];
|
|
62
|
+
};
|
|
63
|
+
const toFixedNoSci = (value, fractionDigits, roundingMode) => {
|
|
64
|
+
const rm = mapRoundingMode(roundingMode);
|
|
65
|
+
let working = value;
|
|
66
|
+
if (fractionDigits !== undefined) {
|
|
67
|
+
working = working.round(fractionDigits, rm);
|
|
68
|
+
}
|
|
69
|
+
return (0, exports.bigToDecimalString)(working);
|
|
70
|
+
};
|
|
71
|
+
exports.toFixedNoSci = toFixedNoSci;
|
|
72
|
+
const computeNumericParts = (value, options = {}) => {
|
|
73
|
+
const minDecimals = assertNonNegativeInteger(options.minDecimals, 'minDecimals') ?? 0;
|
|
74
|
+
const maxDecimals = assertNonNegativeInteger(options.maxDecimals, 'maxDecimals');
|
|
75
|
+
const precision = assertPositiveInteger(options.precision, 'precision');
|
|
76
|
+
const roundingMode = mapRoundingMode(options.roundingMode);
|
|
77
|
+
if (maxDecimals !== undefined && maxDecimals < minDecimals) {
|
|
78
|
+
throw (0, errors_1.toRangeError)(errors_1.FormatError.MaxDecimalsLessThanMinimum);
|
|
79
|
+
}
|
|
80
|
+
let bigValue = (0, exports.normalizeNumeric)(value);
|
|
81
|
+
if (precision !== undefined) {
|
|
82
|
+
const precise = bigValue.toPrecision(precision, roundingMode);
|
|
83
|
+
bigValue = new big_js_1.default(precise);
|
|
84
|
+
}
|
|
85
|
+
if (maxDecimals !== undefined) {
|
|
86
|
+
bigValue = bigValue.round(maxDecimals, roundingMode);
|
|
87
|
+
}
|
|
88
|
+
const isZero = bigValue.eq(0);
|
|
89
|
+
const isNegative = !isZero && bigValue.s < 0;
|
|
90
|
+
const canonical = (0, exports.bigToDecimalString)(bigValue.abs());
|
|
91
|
+
let [integerPart, fractionPart = constants_1.DECIMAL_EMPTY] = canonical.split(constants_1.DECIMAL_DOT);
|
|
92
|
+
integerPart = integerPart.replace(/^(0+)(\d)/, '$2');
|
|
93
|
+
if (!integerPart) {
|
|
94
|
+
integerPart = constants_1.DECIMAL_ZERO;
|
|
95
|
+
}
|
|
96
|
+
if (fractionPart.length < minDecimals) {
|
|
97
|
+
fractionPart = fractionPart.padEnd(minDecimals, constants_1.DECIMAL_ZERO);
|
|
98
|
+
}
|
|
99
|
+
if (maxDecimals !== undefined && fractionPart.length > maxDecimals) {
|
|
100
|
+
fractionPart = fractionPart.slice(0, maxDecimals);
|
|
101
|
+
}
|
|
102
|
+
if (options.trimTrailingZeros) {
|
|
103
|
+
const minKeep = minDecimals;
|
|
104
|
+
while (fractionPart.length > minKeep && fractionPart.endsWith(constants_1.DECIMAL_ZERO)) {
|
|
105
|
+
fractionPart = fractionPart.slice(0, -1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
big: bigValue,
|
|
110
|
+
integer: integerPart,
|
|
111
|
+
fraction: fractionPart,
|
|
112
|
+
isNegative,
|
|
113
|
+
isZero
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
exports.computeNumericParts = computeNumericParts;
|
|
117
|
+
const bigToDecimalString = (value) => {
|
|
118
|
+
const coefficient = (value.c ?? [0]);
|
|
119
|
+
const exponent = value.e ?? 0;
|
|
120
|
+
const sign = value.s < 0 ? constants_1.DEFAULT_SIGN_MINUS : '';
|
|
121
|
+
if (coefficient.every((digit) => digit === 0)) {
|
|
122
|
+
return constants_1.DECIMAL_ZERO;
|
|
123
|
+
}
|
|
124
|
+
const digits = coefficient.join('');
|
|
125
|
+
const decimalIndex = exponent + 1;
|
|
126
|
+
if (decimalIndex <= 0) {
|
|
127
|
+
const zeros = constants_1.DECIMAL_ZERO.repeat(Math.abs(decimalIndex));
|
|
128
|
+
return `${sign}${constants_1.DECIMAL_ZERO}${constants_1.DECIMAL_DOT}${zeros}${digits}`.replace(/\.$/, '');
|
|
129
|
+
}
|
|
130
|
+
if (decimalIndex >= digits.length) {
|
|
131
|
+
const zeros = constants_1.DECIMAL_ZERO.repeat(decimalIndex - digits.length);
|
|
132
|
+
return `${sign}${digits}${zeros}`;
|
|
133
|
+
}
|
|
134
|
+
const integerPart = digits.slice(0, decimalIndex);
|
|
135
|
+
const fractionPart = digits.slice(decimalIndex);
|
|
136
|
+
return `${sign}${integerPart}${constants_1.DECIMAL_DOT}${fractionPart}`;
|
|
137
|
+
};
|
|
138
|
+
exports.bigToDecimalString = bigToDecimalString;
|
|
139
|
+
const applyGrouping = (integer, grouping, enableGrouping) => {
|
|
140
|
+
if (!enableGrouping || grouping.primary === 0 || integer.length <= grouping.primary) {
|
|
141
|
+
return integer;
|
|
142
|
+
}
|
|
143
|
+
const groups = [];
|
|
144
|
+
const primary = grouping.primary;
|
|
145
|
+
const secondary = grouping.secondary ?? primary;
|
|
146
|
+
let index = integer.length;
|
|
147
|
+
let usePrimary = true;
|
|
148
|
+
while (index > 0) {
|
|
149
|
+
const size = usePrimary ? primary : secondary;
|
|
150
|
+
if (size <= 0) {
|
|
151
|
+
groups.unshift(integer.slice(0, index));
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
const start = Math.max(index - size, 0);
|
|
155
|
+
groups.unshift(integer.slice(start, index));
|
|
156
|
+
index = start;
|
|
157
|
+
if (index <= 0) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
usePrimary = false;
|
|
161
|
+
}
|
|
162
|
+
return groups.join(grouping.separator);
|
|
163
|
+
};
|
|
164
|
+
exports.applyGrouping = applyGrouping;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPACT_UNITS = exports.SIGN_DISPLAYS = exports.NUMBER_STYLES = void 0;
|
|
4
|
+
exports.NUMBER_STYLES = {
|
|
5
|
+
decimal: 'decimal',
|
|
6
|
+
currency: 'currency',
|
|
7
|
+
percent: 'percent'
|
|
8
|
+
};
|
|
9
|
+
exports.SIGN_DISPLAYS = {
|
|
10
|
+
auto: 'auto',
|
|
11
|
+
always: 'always',
|
|
12
|
+
exceptZero: 'exceptZero',
|
|
13
|
+
never: 'never',
|
|
14
|
+
negative: 'negative'
|
|
15
|
+
};
|
|
16
|
+
exports.COMPACT_UNITS = ['K', 'M', 'B', 'T'];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { COMPACT_UNITS, NUMBER_STYLES } from './types';
|
|
2
|
+
export const STYLE_DECIMAL = NUMBER_STYLES.decimal;
|
|
3
|
+
export const STYLE_CURRENCY = NUMBER_STYLES.currency;
|
|
4
|
+
export const STYLE_PERCENT = NUMBER_STYLES.percent;
|
|
5
|
+
export const DISPLAY_SIGNS = {
|
|
6
|
+
minus: 'minus',
|
|
7
|
+
plus: 'plus',
|
|
8
|
+
none: 'none'
|
|
9
|
+
};
|
|
10
|
+
export const DISPLAY_SIGN_MINUS = DISPLAY_SIGNS.minus;
|
|
11
|
+
export const DISPLAY_SIGN_PLUS = DISPLAY_SIGNS.plus;
|
|
12
|
+
export const DISPLAY_SIGN_NONE = DISPLAY_SIGNS.none;
|
|
13
|
+
export const COMPACT_ORDER = [...COMPACT_UNITS].reverse();
|
|
14
|
+
export const DEFAULT_SIGN_MINUS = '-';
|
|
15
|
+
export const DEFAULT_SIGN_PLUS = '+';
|
|
16
|
+
export const DECIMAL_ZERO = '0';
|
|
17
|
+
export const DECIMAL_EMPTY = '';
|
|
18
|
+
export const DECIMAL_DOT = '.';
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,aAAa,EACb,aAAa,EACd,MAAkC,SAAS,CAAA;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAkB,aAAa,CAAC,OAAO,CAAA;AACjE,MAAM,CAAC,MAAM,cAAc,GAAiB,aAAa,CAAC,QAAQ,CAAA;AAClE,MAAM,CAAC,MAAM,aAAa,GAAkB,aAAa,CAAC,OAAO,CAAA;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAM;IAE9B,KAAK,EAAuB,OAAO;IACnC,IAAI,EAAwB,MAAM;IAClC,IAAI,EAAwB,MAAM;CAE1B,CAAA;AAIV,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC,KAAK,CAAA;AACrD,MAAM,CAAC,MAAM,iBAAiB,GAAI,aAAa,CAAC,IAAI,CAAA;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAI,aAAa,CAAC,IAAI,CAAA;AAEpD,MAAM,CAAC,MAAM,aAAa,GAAkB,CAAC,GAAG,aAAa,CAAC,CAAC,OAAO,EAAmB,CAAA;AAEzF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AACrC,MAAM,CAAC,MAAM,iBAAiB,GAAI,GAAG,CAAA;AAErC,MAAM,CAAC,MAAM,YAAY,GAAS,GAAG,CAAA;AACrC,MAAM,CAAC,MAAM,aAAa,GAAQ,EAAE,CAAA;AACpC,MAAM,CAAC,MAAM,WAAW,GAAU,GAAG,CAAA"}
|
package/dist/esm/csv.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DECIMAL_DOT, DECIMAL_EMPTY, DECIMAL_ZERO, DEFAULT_SIGN_MINUS } from './constants';
|
|
2
|
+
import { formatCsvDate } from './date';
|
|
3
|
+
import { computeNumericParts, normalizeNumeric } from './internal/numeric';
|
|
4
|
+
const stringifyNumericParts = (parts) => {
|
|
5
|
+
const fraction = parts.fraction.length > 0 ? `${DECIMAL_DOT}${parts.fraction}` : DECIMAL_EMPTY;
|
|
6
|
+
const integer = parts.integer || DECIMAL_ZERO;
|
|
7
|
+
const prefix = parts.isNegative ? DEFAULT_SIGN_MINUS : DECIMAL_EMPTY;
|
|
8
|
+
const value = `${prefix}${integer}${fraction}`;
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
export const formatCsvNumber = (value, options = {}) => {
|
|
12
|
+
const parts = computeNumericParts(value, options);
|
|
13
|
+
return stringifyNumericParts(parts);
|
|
14
|
+
};
|
|
15
|
+
export const formatCsvPercent = (value, options = {}) => {
|
|
16
|
+
const scaled = normalizeNumeric(value).times(100);
|
|
17
|
+
const parts = computeNumericParts(scaled, options);
|
|
18
|
+
return stringifyNumericParts(parts);
|
|
19
|
+
};
|
|
20
|
+
export const csvCurrencyCode = (code, customSymbols, useSymbol) => {
|
|
21
|
+
const trimmed = code.trim();
|
|
22
|
+
if (!trimmed) {
|
|
23
|
+
return DECIMAL_EMPTY;
|
|
24
|
+
}
|
|
25
|
+
const normalized = trimmed.toUpperCase();
|
|
26
|
+
if (useSymbol) {
|
|
27
|
+
const symbol = customSymbols?.[normalized];
|
|
28
|
+
if (symbol) {
|
|
29
|
+
return symbol;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return normalized;
|
|
33
|
+
};
|
|
34
|
+
const escapeCsvField = (value, delimiter) => {
|
|
35
|
+
const needsQuoting = value.includes(delimiter)
|
|
36
|
+
|| value.includes('\n')
|
|
37
|
+
|| value.includes('\r')
|
|
38
|
+
|| value.includes('"');
|
|
39
|
+
if (!needsQuoting) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
const escaped = value.replace(/"/g, '""');
|
|
43
|
+
return `"${escaped}"`;
|
|
44
|
+
};
|
|
45
|
+
const defaultFormatter = (value) => {
|
|
46
|
+
if (value === null || value === undefined) {
|
|
47
|
+
return DECIMAL_EMPTY;
|
|
48
|
+
}
|
|
49
|
+
if (value instanceof Date) {
|
|
50
|
+
return formatCsvDate(value);
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === 'number') {
|
|
53
|
+
return formatCsvNumber(value);
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === 'string') {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === 'boolean') {
|
|
59
|
+
return value ? 'true' : 'false';
|
|
60
|
+
}
|
|
61
|
+
return String(value);
|
|
62
|
+
};
|
|
63
|
+
export const buildCsv = (rows, columns, delimiter = ',', lineEnding = '\n') => {
|
|
64
|
+
const headerLine = columns.map((col) => escapeCsvField(col.header, delimiter)).join(delimiter);
|
|
65
|
+
const lines = [headerLine];
|
|
66
|
+
for (const row of rows) {
|
|
67
|
+
const fields = columns.map((col) => {
|
|
68
|
+
const raw = col.accessor(row);
|
|
69
|
+
const formatted = col.formatter ? col.formatter(raw) : defaultFormatter(raw);
|
|
70
|
+
const stringValue = formatted ?? DECIMAL_EMPTY;
|
|
71
|
+
return escapeCsvField(stringValue, delimiter);
|
|
72
|
+
});
|
|
73
|
+
lines.push(fields.join(delimiter));
|
|
74
|
+
}
|
|
75
|
+
return `${lines.join(lineEnding)}${lineEnding}`;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=csv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../../src/csv.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,kBAAkB,EACnB,MAAkC,aAAa,CAAA;AAChD,OAAO,EACL,aAAa,EACd,MAAkC,QAAQ,CAAA;AAC3C,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EACjB,MAAkC,oBAAoB,CAAA;AAEvD,MAAM,qBAAqB,GAAK,CAAC,KAA6C,EAAU,EAAE;IAExF,M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CAAA;IACjC,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAW,CAAI,IAAgB,EAChB,OAA+B,EAC/B,YAAsB,GAAG,EACzB,aAAsB,IAAI,EAAU,EAAE;IAExE,MAAM,UAAU,GAAc,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACzG,MAAM,KAAK,GAAmB,CAAC,UAAU,CAAC,CAAA;IAE1C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,MAAM,MAAM,GAAgB,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAE9C,MAAM,GAAG,GAAiB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YAC3C,MAAM,SAAS,GAAW,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;YACpF,MAAM,WAAW,GAAS,SAAS,IAAI,aAAa,CAAA;YAEpD,OAAO,cAAc,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,UAAU,EAAE,CAAA;AACjD,CAAC,CAAA"}
|
package/dist/esm/date.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FormatError, toError, toRangeError, toTypeError } from './errors';
|
|
2
|
+
import { getDateFormat } from './internal/intl-cache';
|
|
3
|
+
const toDate = (value) => {
|
|
4
|
+
if (value instanceof Date) {
|
|
5
|
+
const timestamp = value.getTime();
|
|
6
|
+
if (Number.isNaN(timestamp)) {
|
|
7
|
+
throw toRangeError(FormatError.DateValueInvalid);
|
|
8
|
+
}
|
|
9
|
+
return new Date(timestamp);
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'number') {
|
|
12
|
+
if (!Number.isFinite(value)) {
|
|
13
|
+
throw toRangeError(FormatError.DateNumberNonFinite);
|
|
14
|
+
}
|
|
15
|
+
const date = new Date(value);
|
|
16
|
+
if (Number.isNaN(date.getTime())) {
|
|
17
|
+
throw toRangeError(FormatError.DateValueInvalid);
|
|
18
|
+
}
|
|
19
|
+
return date;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
const trimmed = value.trim();
|
|
23
|
+
if (!trimmed) {
|
|
24
|
+
throw toRangeError(FormatError.DateStringEmpty);
|
|
25
|
+
}
|
|
26
|
+
const date = new Date(trimmed);
|
|
27
|
+
if (Number.isNaN(date.getTime())) {
|
|
28
|
+
throw toRangeError(FormatError.InvalidDateString);
|
|
29
|
+
}
|
|
30
|
+
return date;
|
|
31
|
+
}
|
|
32
|
+
throw toTypeError(FormatError.UnsupportedDateInput);
|
|
33
|
+
};
|
|
34
|
+
export const formatDisplayDate = (date, locale, options) => {
|
|
35
|
+
if (!locale) {
|
|
36
|
+
throw toError(FormatError.MissingLocale);
|
|
37
|
+
}
|
|
38
|
+
const parsed = toDate(date);
|
|
39
|
+
const formatter = getDateFormat(locale, options);
|
|
40
|
+
return formatter.format(parsed);
|
|
41
|
+
};
|
|
42
|
+
export const formatCsvDate = (date) => {
|
|
43
|
+
const parsed = toDate(date);
|
|
44
|
+
const iso = parsed.toISOString();
|
|
45
|
+
const datePart = iso.slice(0, 10);
|
|
46
|
+
const hasTime = parsed.getUTCHours() !== 0
|
|
47
|
+
|| parsed.getUTCMinutes() !== 0
|
|
48
|
+
|| parsed.getUTCSeconds() !== 0
|
|
49
|
+
|| parsed.getUTCMilliseconds() !== 0;
|
|
50
|
+
if (!hasTime) {
|
|
51
|
+
return datePart;
|
|
52
|
+
}
|
|
53
|
+
const timePart = iso.slice(11);
|
|
54
|
+
const withoutMillis = timePart.replace(/\.\d+Z$/, 'Z');
|
|
55
|
+
return `${datePart}T${withoutMillis}`;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,OAAO,EACP,YAAY,EACZ,WAAW,EACZ,MAAkC,UAAU,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAW,uBAAuB,CAAA;AAE1D,MAAM,MAAM,GAAoB,CAAC,KAA6B,EAAQ,EAAE;IAEtE,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAE1B,MAAM,SAAS,GAAa,KAAK,CAAC,OAAO,EAAE,CAAA;QAE3C,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YAE5B,MAAM,YAAY,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAA;QAClD,CAAC;QAED,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAA;IAC5B,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAE9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAE5B,MAAM,YAAY,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAA;QACrD,CAAC;QAED,MAAM,IAAI,GAAkB,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;QAE3C,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;YAEjC,MAAM,YAAY,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAA;QAClD,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC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nD,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC;WAC5B,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC;WAC5B,MAAM,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAA;IAEtC,IAAI,CAAC,OAAO,EAAgB,CAAC;QAAC,OAAO,QAAQ,CAAA;IAAC,CAAC;IAE/C,MAAM,QAAQ,GAAgB,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC3C,MAAM,aAAa,GAAW,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IAE9D,OAAO,GAAG,QAAQ,IAAI,aAAa,EAAE,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { applyGrouping, computeNumericParts, normalizeNumeric } from './internal/numeric';
|
|
3
|
+
import { getNumberFormatPattern } from './internal/intl-cache';
|
|
4
|
+
import { FormatError, toError } from './errors';
|
|
5
|
+
import { COMPACT_ORDER, DEFAULT_SIGN_MINUS, DEFAULT_SIGN_PLUS, DISPLAY_SIGN_MINUS, DISPLAY_SIGN_NONE, DISPLAY_SIGN_PLUS, STYLE_CURRENCY, STYLE_DECIMAL, STYLE_PERCENT } from './constants';
|
|
6
|
+
import { SIGN_DISPLAYS } from './types';
|
|
7
|
+
const DEFAULT_COMPACT_THRESHOLDS = {
|
|
8
|
+
K: new Big(1000),
|
|
9
|
+
M: new Big(1000000),
|
|
10
|
+
B: new Big(1000000000),
|
|
11
|
+
T: new Big(1000000000000)
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT_COMPACT_SUFFIXES = {
|
|
14
|
+
K: 'K',
|
|
15
|
+
M: 'M',
|
|
16
|
+
B: 'B',
|
|
17
|
+
T: 'T'
|
|
18
|
+
};
|
|
19
|
+
const resolveSignKind = (isNegative, isZero, signDisplay) => {
|
|
20
|
+
const mode = signDisplay ?? SIGN_DISPLAYS.auto;
|
|
21
|
+
switch (mode) {
|
|
22
|
+
case SIGN_DISPLAYS.always: return isNegative ? DISPLAY_SIGN_MINUS : DISPLAY_SIGN_PLUS;
|
|
23
|
+
case SIGN_DISPLAYS.exceptZero: return isNegative ? DISPLAY_SIGN_MINUS : (isZero ? DISPLAY_SIGN_NONE : DISPLAY_SIGN_PLUS);
|
|
24
|
+
case SIGN_DISPLAYS.never: return DISPLAY_SIGN_NONE;
|
|
25
|
+
case SIGN_DISPLAYS.negative: return isNegative ? DISPLAY_SIGN_MINUS : DISPLAY_SIGN_NONE;
|
|
26
|
+
case SIGN_DISPLAYS.auto:
|
|
27
|
+
default: return isNegative ? DISPLAY_SIGN_MINUS : DISPLAY_SIGN_NONE;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const resolveCurrencyToken = (template, options) => {
|
|
31
|
+
const code = options.currencyCode?.toUpperCase() ?? '';
|
|
32
|
+
if (options.useSymbol === false) {
|
|
33
|
+
return { value: code, fromCustom: false };
|
|
34
|
+
}
|
|
35
|
+
const custom = code ? options.customSymbols?.[code] : undefined;
|
|
36
|
+
if (custom) {
|
|
37
|
+
return { value: custom, fromCustom: true };
|
|
38
|
+
}
|
|
39
|
+
if (template && template !== code) {
|
|
40
|
+
return { value: template, fromCustom: false };
|
|
41
|
+
}
|
|
42
|
+
return { value: code, fromCustom: false };
|
|
43
|
+
};
|
|
44
|
+
const resolveCompact = (value, options) => {
|
|
45
|
+
if (!options.compact) {
|
|
46
|
+
return { value };
|
|
47
|
+
}
|
|
48
|
+
const abs = value.abs();
|
|
49
|
+
let chosen;
|
|
50
|
+
for (const unit of COMPACT_ORDER) {
|
|
51
|
+
const overrideThreshold = options.compactThresholds?.[unit];
|
|
52
|
+
const threshold = overrideThreshold !== undefined
|
|
53
|
+
? normalizeNumeric(overrideThreshold)
|
|
54
|
+
: DEFAULT_COMPACT_THRESHOLDS[unit];
|
|
55
|
+
if (abs.gte(threshold)) {
|
|
56
|
+
chosen = unit;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!chosen) {
|
|
61
|
+
return { value };
|
|
62
|
+
}
|
|
63
|
+
const threshold = options.compactThresholds?.[chosen]
|
|
64
|
+
? normalizeNumeric(options.compactThresholds[chosen])
|
|
65
|
+
: DEFAULT_COMPACT_THRESHOLDS[chosen];
|
|
66
|
+
const suffix = options.compactSuffixes?.[chosen] ?? DEFAULT_COMPACT_SUFFIXES[chosen];
|
|
67
|
+
const scaled = threshold.eq(0) ? value : value.div(threshold);
|
|
68
|
+
return { value: scaled, suffix };
|
|
69
|
+
};
|
|
70
|
+
const buildNumberFormatOptions = (options) => {
|
|
71
|
+
const nfOptions = {
|
|
72
|
+
style: options.style,
|
|
73
|
+
useGrouping: options.useGrouping !== false
|
|
74
|
+
};
|
|
75
|
+
if (options.signDisplay && options.signDisplay !== SIGN_DISPLAYS.negative) {
|
|
76
|
+
nfOptions.signDisplay = options.signDisplay;
|
|
77
|
+
}
|
|
78
|
+
if (options.minDecimals !== undefined) {
|
|
79
|
+
nfOptions.minimumFractionDigits = options.minDecimals;
|
|
80
|
+
}
|
|
81
|
+
if (options.maxDecimals !== undefined) {
|
|
82
|
+
nfOptions.maximumFractionDigits = options.maxDecimals;
|
|
83
|
+
}
|
|
84
|
+
if (options.style === STYLE_CURRENCY && options.currencyCode) {
|
|
85
|
+
nfOptions.currency = options.currencyCode;
|
|
86
|
+
nfOptions.currencyDisplay = options.useSymbol === false ? 'code' : 'symbol';
|
|
87
|
+
}
|
|
88
|
+
return nfOptions;
|
|
89
|
+
};
|
|
90
|
+
const formatFromPattern = (options, integerPart, fractionPart, sign, suffix) => {
|
|
91
|
+
const nfOptions = buildNumberFormatOptions(options);
|
|
92
|
+
const pattern = getNumberFormatPattern(options.locale, nfOptions);
|
|
93
|
+
const parts = sign === DISPLAY_SIGN_MINUS ? pattern.negative : pattern.positive;
|
|
94
|
+
const useGrouping = options.useGrouping !== false;
|
|
95
|
+
const groupedInteger = applyGrouping(integerPart, {
|
|
96
|
+
separator: pattern.groupSeparator,
|
|
97
|
+
primary: pattern.grouping.primary,
|
|
98
|
+
secondary: pattern.grouping.secondary
|
|
99
|
+
}, useGrouping);
|
|
100
|
+
const hasFraction = fractionPart.length > 0;
|
|
101
|
+
let result = '';
|
|
102
|
+
let integerInjected = false;
|
|
103
|
+
let currencyMeta;
|
|
104
|
+
let previousType;
|
|
105
|
+
for (const part of parts) {
|
|
106
|
+
switch (part.type) {
|
|
107
|
+
case 'integer': {
|
|
108
|
+
if (!integerInjected) {
|
|
109
|
+
result += groupedInteger;
|
|
110
|
+
integerInjected = true;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case 'group':
|
|
115
|
+
break;
|
|
116
|
+
case 'decimal': {
|
|
117
|
+
if (hasFraction) {
|
|
118
|
+
result += pattern.decimalSeparator;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'fraction': {
|
|
123
|
+
if (hasFraction) {
|
|
124
|
+
result += fractionPart;
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case 'minusSign': {
|
|
129
|
+
if (sign === DISPLAY_SIGN_MINUS) {
|
|
130
|
+
result += pattern.minusSign ?? part.value ?? DEFAULT_SIGN_MINUS;
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case 'plusSign': {
|
|
135
|
+
if (sign === DISPLAY_SIGN_PLUS) {
|
|
136
|
+
result += pattern.plusSign ?? part.value ?? DEFAULT_SIGN_PLUS;
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case 'currency': {
|
|
141
|
+
currencyMeta = currencyMeta ?? resolveCurrencyToken(part.value, options);
|
|
142
|
+
result += currencyMeta.value;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'percentSign': {
|
|
146
|
+
result += part.value;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case 'literal': {
|
|
150
|
+
if (previousType === 'currency' && currencyMeta?.fromCustom && /^\s+$/.test(part.value)) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
result += part.value;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default: {
|
|
157
|
+
result += part.value;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
previousType = part.type;
|
|
162
|
+
}
|
|
163
|
+
if (suffix) {
|
|
164
|
+
result += suffix;
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
};
|
|
168
|
+
const resolveDisplayOptions = (options, style) => {
|
|
169
|
+
if (!options.locale) {
|
|
170
|
+
throw toError(FormatError.MissingLocale);
|
|
171
|
+
}
|
|
172
|
+
if (style === STYLE_CURRENCY && !options.currencyCode) {
|
|
173
|
+
throw toError(FormatError.MissingCurrencyCode);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
...options,
|
|
177
|
+
style
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
const formatDisplayInternal = (value, options, style) => {
|
|
181
|
+
const resolved = resolveDisplayOptions(options, style);
|
|
182
|
+
const baseValue = style === STYLE_PERCENT
|
|
183
|
+
? normalizeNumeric(value).times(100)
|
|
184
|
+
: normalizeNumeric(value);
|
|
185
|
+
const { value: compactValue, suffix } = resolveCompact(baseValue, resolved);
|
|
186
|
+
const numericParts = computeNumericParts(compactValue, resolved);
|
|
187
|
+
const sign = resolveSignKind(numericParts.isNegative, numericParts.isZero, resolved.signDisplay);
|
|
188
|
+
return formatFromPattern(resolved, numericParts.integer, numericParts.fraction, sign, suffix);
|
|
189
|
+
};
|
|
190
|
+
export const formatDisplayNumber = (value, options) => {
|
|
191
|
+
const style = options.style ?? STYLE_DECIMAL;
|
|
192
|
+
return formatDisplayInternal(value, { ...options, style }, style);
|
|
193
|
+
};
|
|
194
|
+
export const formatDisplayCurrency = (value, options) => {
|
|
195
|
+
return formatDisplayInternal(value, { ...options, style: STYLE_CURRENCY }, STYLE_CURRENCY);
|
|
196
|
+
};
|
|
197
|
+
export const formatDisplayPercent = (value, options) => {
|
|
198
|
+
return formatDisplayInternal(value, { ...options, style: STYLE_PERCENT }, STYLE_PERCENT);
|
|
199
|
+
};
|
|
200
|
+
export const formatDisplayCompact = (value, options) => {
|
|
201
|
+
const style = options.style ?? STYLE_DECIMAL;
|
|
202
|
+
return formatDisplayInternal(value, { ...options, compact: true, style }, style);
|
|
203
|
+
};
|
|
204
|
+
//# sourceMappingURL=display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../src/display.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAyB,QAAQ,CAAA;AAO3C,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EACjB,MAAkC,oBAAoB,CAAA;AACvD,OAAO,EACL,sBAAsB,EACvB,MAAkC,uBAAuB,CAAA;AAC1D,OAAO,EACL,WAAW,EACX,OAAO,EACR,MAAkC,UAAU,CAAA;AAC7C,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAkC,aAAa,CAAA;AAChD,OAAO,EACL,aAAa,EACd,MAAkC,SAAS,CAAA;AAqB5C,MAAM,0BAA0B,GAAG;IAEjC,CAAC,EAA2B,IAAI,GAAG,CAAC,IAAK,CAAC;IAC1C,CAAC,EAA2B,IAAI,GAAG,CAAC,OAAS,CAAC;IAC9C,CAAC,EAA2B,IAAI,GAAG,CAAC,UAAa,CAAC;IAClD,CAAC,EAA2B,IAAI,GAAG,CAAC,aAAiB,CAAC;CAEpB,CAAA;AAEpC,MAAM,wBAAwB,GAAG;IAE/B,CAAC,EAA2B,GAAG;IAC/B,CAAC,EAA2B,GAAG;IAC/B,CAAC,EAA2B,GAAG;IAC/B,CAAC,E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equired"] = "positiveIntegerRequired";
|
|
5
|
+
FormatError["NumericValueNonFinite"] = "numericValueNonFinite";
|
|
6
|
+
FormatError["NumericStringEmpty"] = "numericStringEmpty";
|
|
7
|
+
FormatError["UnsupportedNumericInput"] = "unsupportedNumericInput";
|
|
8
|
+
FormatError["MaxDecimalsLessThanMinimum"] = "maxDecimalsLessThanMinimum";
|
|
9
|
+
FormatError["MissingLocale"] = "missingLocale";
|
|
10
|
+
FormatError["MissingCurrencyCode"] = "missingCurrencyCode";
|
|
11
|
+
FormatError["DateValueInvalid"] = "dateValueInvalid";
|
|
12
|
+
FormatError["DateStringEmpty"] = "dateStringEmpty";
|
|
13
|
+
FormatError["DateNumberNonFinite"] = "dateNumberNonFinite";
|
|
14
|
+
FormatError["InvalidDateString"] = "invalidDateString";
|
|
15
|
+
FormatError["UnsupportedDateInput"] = "unsupportedDateInput";
|
|
16
|
+
})(FormatError || (FormatError = {}));
|
|
17
|
+
const FORMAT_ERROR_MESSAGES = {
|
|
18
|
+
[FormatError.NonNegativeIntegerRequired]: '%label% must be a non-negative integer',
|
|
19
|
+
[FormatError.PositiveIntegerRequired]: '%label% must be a positive integer',
|
|
20
|
+
[FormatError.NumericValueNonFinite]: 'Numeric value must be a finite number',
|
|
21
|
+
[FormatError.NumericStringEmpty]: 'Numeric string cannot be empty',
|
|
22
|
+
[FormatError.UnsupportedNumericInput]: 'Unsupported numeric input type',
|
|
23
|
+
[FormatError.MaxDecimalsLessThanMinimum]: 'maxDecimals cannot be less than minDecimals',
|
|
24
|
+
[FormatError.MissingLocale]: 'Display formatting requires a locale',
|
|
25
|
+
[FormatError.MissingCurrencyCode]: 'Currency formatting requires a currencyCode',
|
|
26
|
+
[FormatError.DateValueInvalid]: 'Invalid date value',
|
|
27
|
+
[FormatError.DateStringEmpty]: 'Date string cannot be empty',
|
|
28
|
+
[FormatError.DateNumberNonFinite]: 'Date number must be finite',
|
|
29
|
+
[FormatError.InvalidDateString]: 'Invalid date string',
|
|
30
|
+
[FormatError.UnsupportedDateInput]: 'Unsupported date input type'
|
|
31
|
+
};
|
|
32
|
+
const applyDetails = (template, details) => {
|
|
33
|
+
if (!details) {
|
|
34
|
+
return template;
|
|
35
|
+
}
|
|
36
|
+
return Object.keys(details).reduce((message, key) => message.replace(new RegExp(`%${key}%`, 'g'), details[key]), template);
|
|
37
|
+
};
|
|
38
|
+
export const getFormatErrorMessage = (code, details) => applyDetails(FORMAT_ERROR_MESSAGES[code], details);
|
|
39
|
+
export const toRangeError = (code, details) => new RangeError(getFormatErrorMessage(code, details));
|
|
40
|
+
export const toTypeError = (code, details) => new TypeError(getFormatErrorMessage(code, details));
|
|
41
|
+
export const toError = (code, details) => new Error(getFormatErrorMessage(code, details));
|
|
42
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAeX;AAfD,WAAY,WAAW;IAErB,wEAA0D,CAAA;IAC1D,kEAAuD,CAAA;IACvD,8DAAqD,CAAA;IACrD,wDAAkD,CAAA;IAClD,kEAAuD,CAAA;IACvD,wEAA0D,CAAA;IAC1D,8CAA6C,CAAA;IAC7C,0DAAmD,CAAA;IACnD,oDAAgD,CAAA;IAChD,kDAA+C,CAAA;IAC/C,0DAAmD,CAAA;IACnD,sDAAiD,CAAA;IACjD,4DAAoD,CAAA;AACtD,CAAC,EAfW,WAAW,KAAX,WAAW,QAetB;AAMD,MAAM,qBAAqB,GAAK;IAE9B,CAAC,WAAW,CAAC,0BAA0B,CAAC,EAAQ,wCAAwC;IACxF,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAW,oCAAoC;IACpF,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAa,uCAAuC;IACvF,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAgB,gCAAgC;IAChF,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAW,gCAAgC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K,SAAS,CAAC,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;AAC/I,MAAM,CAAC,MAAM,OAAO,GAAY,CAAC,IAAiB,EAAE,OAAsB,EAAc,EAAE,CAAC,IAAS,KAAK,CAAC,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { formatDisplayNumber, formatDisplayCurrency, formatDisplayPercent, formatDisplayCompact } from './display';
|
|
2
|
+
export { formatCsvNumber, formatCsvPercent, csvCurrencyCode, buildCsv } from './csv';
|
|
3
|
+
export { formatDisplayDate, formatCsvDate } from './date';
|
|
4
|
+
export { FormatError, getFormatErrorMessage, toError, toRangeError, toTypeError } from './errors';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACrB,MAAkC,WAAW,CAAA;AAE9C,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACT,MAAkC,OAAO,CAAA;AAE1C,OAAO,EACL,iBAAiB,EACjB,aAAa,EACd,MAAkC,QAAQ,CAAA;AAE3C,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,OAAO,EACP,YAAY,EACZ,WAAW,EACZ,MAAkC,UAAU,CAAA"}
|