@ciwergrp/nuxid 1.0.2-release
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 +119 -0
- package/bin/kiban.mjs +41 -0
- package/console/request.mjs +337 -0
- package/dist/module.d.mts +188 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +439 -0
- package/dist/runtime/form.d.ts +21 -0
- package/dist/runtime/form.js +161 -0
- package/dist/runtime/helper/array/collapse.d.ts +1 -0
- package/dist/runtime/helper/array/collapse.js +9 -0
- package/dist/runtime/helper/array/crossJoin.d.ts +1 -0
- package/dist/runtime/helper/array/crossJoin.js +17 -0
- package/dist/runtime/helper/array/every.d.ts +1 -0
- package/dist/runtime/helper/array/every.js +3 -0
- package/dist/runtime/helper/array/first.d.ts +1 -0
- package/dist/runtime/helper/array/first.js +11 -0
- package/dist/runtime/helper/array/flatten.d.ts +1 -0
- package/dist/runtime/helper/array/flatten.js +14 -0
- package/dist/runtime/helper/array/index.d.ts +46 -0
- package/dist/runtime/helper/array/index.js +69 -0
- package/dist/runtime/helper/array/join.d.ts +1 -0
- package/dist/runtime/helper/array/join.js +11 -0
- package/dist/runtime/helper/array/last.d.ts +1 -0
- package/dist/runtime/helper/array/last.js +11 -0
- package/dist/runtime/helper/array/map.d.ts +1 -0
- package/dist/runtime/helper/array/map.js +3 -0
- package/dist/runtime/helper/array/mapSpread.d.ts +1 -0
- package/dist/runtime/helper/array/mapSpread.js +3 -0
- package/dist/runtime/helper/array/partition.d.ts +1 -0
- package/dist/runtime/helper/array/partition.js +12 -0
- package/dist/runtime/helper/array/random.d.ts +1 -0
- package/dist/runtime/helper/array/random.js +19 -0
- package/dist/runtime/helper/array/reject.d.ts +1 -0
- package/dist/runtime/helper/array/reject.js +3 -0
- package/dist/runtime/helper/array/shuffle.d.ts +1 -0
- package/dist/runtime/helper/array/shuffle.js +8 -0
- package/dist/runtime/helper/array/sole.d.ts +1 -0
- package/dist/runtime/helper/array/sole.js +7 -0
- package/dist/runtime/helper/array/some.d.ts +1 -0
- package/dist/runtime/helper/array/some.js +3 -0
- package/dist/runtime/helper/array/sort.d.ts +1 -0
- package/dist/runtime/helper/array/sort.js +4 -0
- package/dist/runtime/helper/array/sortDesc.d.ts +1 -0
- package/dist/runtime/helper/array/sortDesc.js +9 -0
- package/dist/runtime/helper/array/take.d.ts +1 -0
- package/dist/runtime/helper/array/take.js +9 -0
- package/dist/runtime/helper/array/where.d.ts +1 -0
- package/dist/runtime/helper/array/where.js +3 -0
- package/dist/runtime/helper/array/whereNotNull.d.ts +1 -0
- package/dist/runtime/helper/array/whereNotNull.js +3 -0
- package/dist/runtime/helper/array/wrap.d.ts +1 -0
- package/dist/runtime/helper/array/wrap.js +6 -0
- package/dist/runtime/helper/index.d.ts +4 -0
- package/dist/runtime/helper/index.js +4 -0
- package/dist/runtime/helper/number/clamp.d.ts +1 -0
- package/dist/runtime/helper/number/clamp.js +3 -0
- package/dist/runtime/helper/number/currency.d.ts +1 -0
- package/dist/runtime/helper/number/currency.js +14 -0
- package/dist/runtime/helper/number/fileSize.d.ts +1 -0
- package/dist/runtime/helper/number/fileSize.js +12 -0
- package/dist/runtime/helper/number/format.d.ts +1 -0
- package/dist/runtime/helper/number/format.js +12 -0
- package/dist/runtime/helper/number/humanize.d.ts +5 -0
- package/dist/runtime/helper/number/humanize.js +39 -0
- package/dist/runtime/helper/number/index.d.ts +37 -0
- package/dist/runtime/helper/number/index.js +60 -0
- package/dist/runtime/helper/number/intl.d.ts +5 -0
- package/dist/runtime/helper/number/intl.js +32 -0
- package/dist/runtime/helper/number/ordinal.d.ts +1 -0
- package/dist/runtime/helper/number/ordinal.js +26 -0
- package/dist/runtime/helper/number/pairs.d.ts +1 -0
- package/dist/runtime/helper/number/pairs.js +11 -0
- package/dist/runtime/helper/number/parse.d.ts +4 -0
- package/dist/runtime/helper/number/parse.js +19 -0
- package/dist/runtime/helper/number/percentage.d.ts +1 -0
- package/dist/runtime/helper/number/percentage.js +14 -0
- package/dist/runtime/helper/number/spell.d.ts +2 -0
- package/dist/runtime/helper/number/spell.js +145 -0
- package/dist/runtime/helper/number/state.d.ts +1 -0
- package/dist/runtime/helper/number/state.js +8 -0
- package/dist/runtime/helper/number/trim.d.ts +1 -0
- package/dist/runtime/helper/number/trim.js +3 -0
- package/dist/runtime/helper/object/add.d.ts +2 -0
- package/dist/runtime/helper/object/add.js +8 -0
- package/dist/runtime/helper/object/dot.d.ts +1 -0
- package/dist/runtime/helper/object/dot.js +19 -0
- package/dist/runtime/helper/object/except.d.ts +2 -0
- package/dist/runtime/helper/object/except.js +10 -0
- package/dist/runtime/helper/object/forget.d.ts +2 -0
- package/dist/runtime/helper/object/forget.js +24 -0
- package/dist/runtime/helper/object/get.d.ts +2 -0
- package/dist/runtime/helper/object/get.js +15 -0
- package/dist/runtime/helper/object/has.d.ts +2 -0
- package/dist/runtime/helper/object/has.js +5 -0
- package/dist/runtime/helper/object/index.d.ts +22 -0
- package/dist/runtime/helper/object/index.js +33 -0
- package/dist/runtime/helper/object/only.d.ts +2 -0
- package/dist/runtime/helper/object/only.js +12 -0
- package/dist/runtime/helper/object/set.d.ts +2 -0
- package/dist/runtime/helper/object/set.js +23 -0
- package/dist/runtime/helper/object/undot.d.ts +1 -0
- package/dist/runtime/helper/object/undot.js +8 -0
- package/dist/runtime/helper/object/utils.d.ts +3 -0
- package/dist/runtime/helper/object/utils.js +10 -0
- package/dist/runtime/helper/state.d.ts +6 -0
- package/dist/runtime/helper/state.js +50 -0
- package/dist/runtime/helper/string/basic.d.ts +7 -0
- package/dist/runtime/helper/string/basic.js +42 -0
- package/dist/runtime/helper/string/bounds.d.ts +6 -0
- package/dist/runtime/helper/string/bounds.js +42 -0
- package/dist/runtime/helper/string/case.d.ts +9 -0
- package/dist/runtime/helper/string/case.js +50 -0
- package/dist/runtime/helper/string/index.d.ts +57 -0
- package/dist/runtime/helper/string/index.js +100 -0
- package/dist/runtime/helper/string/locale.d.ts +1 -0
- package/dist/runtime/helper/string/locale.js +1 -0
- package/dist/runtime/helper/string/match.d.ts +4 -0
- package/dist/runtime/helper/string/match.js +15 -0
- package/dist/runtime/helper/string/pad.d.ts +3 -0
- package/dist/runtime/helper/string/pad.js +12 -0
- package/dist/runtime/helper/string/plural.d.ts +3 -0
- package/dist/runtime/helper/string/plural.js +16 -0
- package/dist/runtime/helper/string/replace.d.ts +4 -0
- package/dist/runtime/helper/string/replace.js +25 -0
- package/dist/runtime/helper/string/slug.d.ts +1 -0
- package/dist/runtime/helper/string/slug.js +8 -0
- package/dist/runtime/helper/string/transliterate.d.ts +2 -0
- package/dist/runtime/helper/string/transliterate.js +8 -0
- package/dist/runtime/helper/string/words.d.ts +2 -0
- package/dist/runtime/helper/string/words.js +13 -0
- package/dist/runtime/lodash.d.ts +1 -0
- package/dist/runtime/lodash.js +1 -0
- package/dist/runtime/pinia/composables.d.ts +2 -0
- package/dist/runtime/pinia/composables.js +3 -0
- package/dist/runtime/pinia/payload-plugin.d.ts +5 -0
- package/dist/runtime/pinia/payload-plugin.js +15 -0
- package/dist/runtime/pinia/plugin.d.ts +6 -0
- package/dist/runtime/pinia/plugin.js +22 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +4 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/validator.d.ts +13 -0
- package/dist/runtime/validator.js +445 -0
- package/dist/types.d.mts +11 -0
- package/package.json +90 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { collapse } from './collapse.js';
|
|
2
|
+
import { crossJoin } from './crossJoin.js';
|
|
3
|
+
import { every } from './every.js';
|
|
4
|
+
import { first } from './first.js';
|
|
5
|
+
import { flatten } from './flatten.js';
|
|
6
|
+
import { join } from './join.js';
|
|
7
|
+
import { last } from './last.js';
|
|
8
|
+
import { map } from './map.js';
|
|
9
|
+
import { mapSpread } from './mapSpread.js';
|
|
10
|
+
import { partition } from './partition.js';
|
|
11
|
+
import { random } from './random.js';
|
|
12
|
+
import { reject } from './reject.js';
|
|
13
|
+
import { shuffle } from './shuffle.js';
|
|
14
|
+
import { sole } from './sole.js';
|
|
15
|
+
import { some } from './some.js';
|
|
16
|
+
import { sort } from './sort.js';
|
|
17
|
+
import { sortDesc } from './sortDesc.js';
|
|
18
|
+
import { take } from './take.js';
|
|
19
|
+
import { where } from './where.js';
|
|
20
|
+
import { whereNotNull } from './whereNotNull.js';
|
|
21
|
+
import { wrap } from './wrap.js';
|
|
22
|
+
export interface ArrayHelper {
|
|
23
|
+
collapse: typeof collapse;
|
|
24
|
+
crossJoin: typeof crossJoin;
|
|
25
|
+
every: typeof every;
|
|
26
|
+
first: typeof first;
|
|
27
|
+
flatten: typeof flatten;
|
|
28
|
+
join: typeof join;
|
|
29
|
+
last: typeof last;
|
|
30
|
+
map: typeof map;
|
|
31
|
+
mapSpread: typeof mapSpread;
|
|
32
|
+
partition: typeof partition;
|
|
33
|
+
random: typeof random;
|
|
34
|
+
reject: typeof reject;
|
|
35
|
+
shuffle: typeof shuffle;
|
|
36
|
+
sole: typeof sole;
|
|
37
|
+
some: typeof some;
|
|
38
|
+
sort: typeof sort;
|
|
39
|
+
sortDesc: typeof sortDesc;
|
|
40
|
+
take: typeof take;
|
|
41
|
+
where: typeof where;
|
|
42
|
+
whereNotNull: typeof whereNotNull;
|
|
43
|
+
wrap: typeof wrap;
|
|
44
|
+
}
|
|
45
|
+
export declare function array(): ArrayHelper;
|
|
46
|
+
export { collapse, crossJoin, every, first, flatten, join, last, map, mapSpread, partition, random, reject, shuffle, sole, some, sort, sortDesc, take, where, whereNotNull, wrap, };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { collapse } from "./collapse.js";
|
|
2
|
+
import { crossJoin } from "./crossJoin.js";
|
|
3
|
+
import { every } from "./every.js";
|
|
4
|
+
import { first } from "./first.js";
|
|
5
|
+
import { flatten } from "./flatten.js";
|
|
6
|
+
import { join } from "./join.js";
|
|
7
|
+
import { last } from "./last.js";
|
|
8
|
+
import { map } from "./map.js";
|
|
9
|
+
import { mapSpread } from "./mapSpread.js";
|
|
10
|
+
import { partition } from "./partition.js";
|
|
11
|
+
import { random } from "./random.js";
|
|
12
|
+
import { reject } from "./reject.js";
|
|
13
|
+
import { shuffle } from "./shuffle.js";
|
|
14
|
+
import { sole } from "./sole.js";
|
|
15
|
+
import { some } from "./some.js";
|
|
16
|
+
import { sort } from "./sort.js";
|
|
17
|
+
import { sortDesc } from "./sortDesc.js";
|
|
18
|
+
import { take } from "./take.js";
|
|
19
|
+
import { where } from "./where.js";
|
|
20
|
+
import { whereNotNull } from "./whereNotNull.js";
|
|
21
|
+
import { wrap } from "./wrap.js";
|
|
22
|
+
export function array() {
|
|
23
|
+
return {
|
|
24
|
+
collapse,
|
|
25
|
+
crossJoin,
|
|
26
|
+
every,
|
|
27
|
+
first,
|
|
28
|
+
flatten,
|
|
29
|
+
join,
|
|
30
|
+
last,
|
|
31
|
+
map,
|
|
32
|
+
mapSpread,
|
|
33
|
+
partition,
|
|
34
|
+
random,
|
|
35
|
+
reject,
|
|
36
|
+
shuffle,
|
|
37
|
+
sole,
|
|
38
|
+
some,
|
|
39
|
+
sort,
|
|
40
|
+
sortDesc,
|
|
41
|
+
take,
|
|
42
|
+
where,
|
|
43
|
+
whereNotNull,
|
|
44
|
+
wrap
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
collapse,
|
|
49
|
+
crossJoin,
|
|
50
|
+
every,
|
|
51
|
+
first,
|
|
52
|
+
flatten,
|
|
53
|
+
join,
|
|
54
|
+
last,
|
|
55
|
+
map,
|
|
56
|
+
mapSpread,
|
|
57
|
+
partition,
|
|
58
|
+
random,
|
|
59
|
+
reject,
|
|
60
|
+
shuffle,
|
|
61
|
+
sole,
|
|
62
|
+
some,
|
|
63
|
+
sort,
|
|
64
|
+
sortDesc,
|
|
65
|
+
take,
|
|
66
|
+
where,
|
|
67
|
+
whereNotNull,
|
|
68
|
+
wrap
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function join(array: any[], glue: string, finalGlue?: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function join(array, glue, finalGlue = "") {
|
|
2
|
+
if (!array.length) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
if (!finalGlue || array.length < 2) {
|
|
6
|
+
return array.join(glue);
|
|
7
|
+
}
|
|
8
|
+
const head = array.slice(0, -1).join(glue);
|
|
9
|
+
const tail = array[array.length - 1];
|
|
10
|
+
return `${head}${finalGlue}${tail}`;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function last<T>(array: T[], callback?: (item: T, index: number) => boolean, defaultValue?: T | null): T | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function last(array, callback, defaultValue = null) {
|
|
2
|
+
if (!callback) {
|
|
3
|
+
return array.length ? array[array.length - 1] : defaultValue;
|
|
4
|
+
}
|
|
5
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
6
|
+
if (callback(array[i], i)) {
|
|
7
|
+
return array[i];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return defaultValue;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function map<T, U>(array: T[], callback: (item: T, index: number) => U): U[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mapSpread<T extends any[], U>(array: T[], callback: (...args: T) => U): U[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function partition<T>(array: T[], predicate: (item: T, index: number) => boolean): [T[], T[]];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function random<T>(array: T[], count?: number): T | T[] | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function random(array, count) {
|
|
2
|
+
if (array.length === 0) {
|
|
3
|
+
return count ? [] : void 0;
|
|
4
|
+
}
|
|
5
|
+
if (count === void 0) {
|
|
6
|
+
const index = Math.floor(Math.random() * array.length);
|
|
7
|
+
return array[index];
|
|
8
|
+
}
|
|
9
|
+
if (count < 0 || count > array.length) {
|
|
10
|
+
throw new Error("The number of items to pick must be between 0 and the array length.");
|
|
11
|
+
}
|
|
12
|
+
const copy = [...array];
|
|
13
|
+
const result = [];
|
|
14
|
+
for (let i = 0; i < count; i++) {
|
|
15
|
+
const index = Math.floor(Math.random() * copy.length);
|
|
16
|
+
result.push(copy.splice(index, 1)[0]);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function reject<T>(array: T[], predicate: (item: T, index: number) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shuffle<T>(array: T[]): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sole<T>(array: T[], predicate?: (item: T, index: number) => boolean): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function some<T>(array: T[], predicate: (item: T, index: number) => boolean): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sort<T>(array: T[], comparator?: (a: T, b: T) => number): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sortDesc<T>(array: T[], comparator?: (a: T, b: T) => number): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function take<T>(array: T[], limit: number): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function where<T>(array: T[], predicate: (item: T, index: number) => boolean): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function whereNotNull<T>(array: T[]): (T & {})[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wrap<T>(value: T | T[] | null | undefined): T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clamp(number: number, min: number, max: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function currency(number: number, inCurrency?: string, locale?: string | null, precision?: number | null): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defaultCurrency, defaultLocale } from "./state.js";
|
|
2
|
+
export function currency(number, inCurrency = "", locale, precision) {
|
|
3
|
+
const resolvedLocale = locale ?? defaultLocale();
|
|
4
|
+
const resolvedCurrency = inCurrency || defaultCurrency();
|
|
5
|
+
const options = {
|
|
6
|
+
style: "currency",
|
|
7
|
+
currency: resolvedCurrency
|
|
8
|
+
};
|
|
9
|
+
if (precision !== null && precision !== void 0) {
|
|
10
|
+
options.minimumFractionDigits = precision;
|
|
11
|
+
options.maximumFractionDigits = precision;
|
|
12
|
+
}
|
|
13
|
+
return new Intl.NumberFormat(resolvedLocale, options).format(number);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fileSize(bytes: number, precision?: number, maxPrecision?: number | null): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { format } from "./format.js";
|
|
2
|
+
export function fileSize(bytes, precision = 0, maxPrecision) {
|
|
3
|
+
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
4
|
+
const unitCount = units.length;
|
|
5
|
+
let size = bytes;
|
|
6
|
+
let unitIndex = 0;
|
|
7
|
+
while (size / 1024 > 0.9 && unitIndex < unitCount - 1) {
|
|
8
|
+
size /= 1024;
|
|
9
|
+
unitIndex++;
|
|
10
|
+
}
|
|
11
|
+
return `${format(size, precision, maxPrecision)} ${units[unitIndex]}`;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function format(number: number, precision?: number | null, maxPrecision?: number | null, locale?: string | null): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defaultLocale } from "./state.js";
|
|
2
|
+
export function format(number, precision, maxPrecision, locale) {
|
|
3
|
+
const resolvedLocale = locale ?? defaultLocale();
|
|
4
|
+
const options = {};
|
|
5
|
+
if (maxPrecision !== null && maxPrecision !== void 0) {
|
|
6
|
+
options.maximumFractionDigits = maxPrecision;
|
|
7
|
+
} else if (precision !== null && precision !== void 0) {
|
|
8
|
+
options.minimumFractionDigits = precision;
|
|
9
|
+
options.maximumFractionDigits = precision;
|
|
10
|
+
}
|
|
11
|
+
return new Intl.NumberFormat(resolvedLocale, options).format(number);
|
|
12
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type UnitMap = Record<number, string>;
|
|
2
|
+
export declare function abbreviate(number: number, precision?: number, maxPrecision?: number | null): any;
|
|
3
|
+
export declare function forHumans(number: number, precision?: number, maxPrecision?: number | null): any;
|
|
4
|
+
export declare function summarize(number: number, precision?: number, maxPrecision?: number | null, units?: UnitMap): any;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { format } from "./format.js";
|
|
2
|
+
const abbreviatedUnits = {
|
|
3
|
+
3: "K",
|
|
4
|
+
6: "M",
|
|
5
|
+
9: "B",
|
|
6
|
+
12: "T",
|
|
7
|
+
15: "Q"
|
|
8
|
+
};
|
|
9
|
+
const verboseUnits = {
|
|
10
|
+
3: " thousand",
|
|
11
|
+
6: " million",
|
|
12
|
+
9: " billion",
|
|
13
|
+
12: " trillion",
|
|
14
|
+
15: " quadrillion"
|
|
15
|
+
};
|
|
16
|
+
export function abbreviate(number, precision = 0, maxPrecision) {
|
|
17
|
+
return summarize(number, precision, maxPrecision, abbreviatedUnits);
|
|
18
|
+
}
|
|
19
|
+
export function forHumans(number, precision = 0, maxPrecision) {
|
|
20
|
+
return summarize(number, precision, maxPrecision, verboseUnits);
|
|
21
|
+
}
|
|
22
|
+
export function summarize(number, precision = 0, maxPrecision, units = abbreviatedUnits) {
|
|
23
|
+
if (number === 0) {
|
|
24
|
+
return precision > 0 ? format(0, precision, maxPrecision) : "0";
|
|
25
|
+
}
|
|
26
|
+
if (number < 0) {
|
|
27
|
+
return `-${summarize(Math.abs(number), precision, maxPrecision, units)}`;
|
|
28
|
+
}
|
|
29
|
+
if (number < 1) {
|
|
30
|
+
return format(number, precision, maxPrecision);
|
|
31
|
+
}
|
|
32
|
+
if (number >= 1e15) {
|
|
33
|
+
return `${summarize(number / 1e15, precision, maxPrecision, units)}${units[15] ?? ""}`;
|
|
34
|
+
}
|
|
35
|
+
const exponent = Math.floor(Math.log10(number));
|
|
36
|
+
const displayExponent = exponent - exponent % 3;
|
|
37
|
+
const scaledNumber = number / Math.pow(10, displayExponent);
|
|
38
|
+
return `${format(scaledNumber, precision, maxPrecision)}${units[displayExponent] ?? ""}`.trim();
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { abbreviate, forHumans } from './humanize.js';
|
|
2
|
+
import { clamp } from './clamp.js';
|
|
3
|
+
import { currency } from './currency.js';
|
|
4
|
+
import { defaultCurrency, defaultLocale, useCurrency, useLocale, withCurrency, withLocale } from './state.js';
|
|
5
|
+
import { fileSize } from './fileSize.js';
|
|
6
|
+
import { format } from './format.js';
|
|
7
|
+
import { ordinal } from './ordinal.js';
|
|
8
|
+
import { pairs } from './pairs.js';
|
|
9
|
+
import { parse, parseFloatNumber, parseIntNumber } from './parse.js';
|
|
10
|
+
import { percentage } from './percentage.js';
|
|
11
|
+
import { spell, spellOrdinal } from './spell.js';
|
|
12
|
+
import { trim } from './trim.js';
|
|
13
|
+
export interface NumberHelper {
|
|
14
|
+
abbreviate: typeof abbreviate;
|
|
15
|
+
forHumans: typeof forHumans;
|
|
16
|
+
clamp: typeof clamp;
|
|
17
|
+
currency: typeof currency;
|
|
18
|
+
defaultCurrency: typeof defaultCurrency;
|
|
19
|
+
defaultLocale: typeof defaultLocale;
|
|
20
|
+
fileSize: typeof fileSize;
|
|
21
|
+
format: typeof format;
|
|
22
|
+
ordinal: typeof ordinal;
|
|
23
|
+
pairs: typeof pairs;
|
|
24
|
+
parse: typeof parse;
|
|
25
|
+
parseFloatNumber: typeof parseFloatNumber;
|
|
26
|
+
parseIntNumber: typeof parseIntNumber;
|
|
27
|
+
percentage: typeof percentage;
|
|
28
|
+
spell: typeof spell;
|
|
29
|
+
spellOrdinal: typeof spellOrdinal;
|
|
30
|
+
trim: typeof trim;
|
|
31
|
+
useLocale: typeof useLocale;
|
|
32
|
+
withLocale: typeof withLocale;
|
|
33
|
+
useCurrency: typeof useCurrency;
|
|
34
|
+
withCurrency: typeof withCurrency;
|
|
35
|
+
}
|
|
36
|
+
export declare function number(): NumberHelper;
|
|
37
|
+
export { abbreviate, forHumans, clamp, currency, defaultCurrency, defaultLocale, fileSize, format, ordinal, pairs, parse, parseFloatNumber, parseIntNumber, percentage, spell, spellOrdinal, trim, useLocale, withLocale, useCurrency, withCurrency, };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { abbreviate, forHumans } from "./humanize.js";
|
|
2
|
+
import { clamp } from "./clamp.js";
|
|
3
|
+
import { currency } from "./currency.js";
|
|
4
|
+
import { defaultCurrency, defaultLocale, useCurrency, useLocale, withCurrency, withLocale } from "./state.js";
|
|
5
|
+
import { fileSize } from "./fileSize.js";
|
|
6
|
+
import { format } from "./format.js";
|
|
7
|
+
import { ordinal } from "./ordinal.js";
|
|
8
|
+
import { pairs } from "./pairs.js";
|
|
9
|
+
import { parse, parseFloatNumber, parseIntNumber } from "./parse.js";
|
|
10
|
+
import { percentage } from "./percentage.js";
|
|
11
|
+
import { spell, spellOrdinal } from "./spell.js";
|
|
12
|
+
import { trim } from "./trim.js";
|
|
13
|
+
export function number() {
|
|
14
|
+
return {
|
|
15
|
+
abbreviate,
|
|
16
|
+
forHumans,
|
|
17
|
+
clamp,
|
|
18
|
+
currency,
|
|
19
|
+
defaultCurrency,
|
|
20
|
+
defaultLocale,
|
|
21
|
+
fileSize,
|
|
22
|
+
format,
|
|
23
|
+
ordinal,
|
|
24
|
+
pairs,
|
|
25
|
+
parse,
|
|
26
|
+
parseFloatNumber,
|
|
27
|
+
parseIntNumber,
|
|
28
|
+
percentage,
|
|
29
|
+
spell,
|
|
30
|
+
spellOrdinal,
|
|
31
|
+
trim,
|
|
32
|
+
useLocale,
|
|
33
|
+
withLocale,
|
|
34
|
+
useCurrency,
|
|
35
|
+
withCurrency
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
abbreviate,
|
|
40
|
+
forHumans,
|
|
41
|
+
clamp,
|
|
42
|
+
currency,
|
|
43
|
+
defaultCurrency,
|
|
44
|
+
defaultLocale,
|
|
45
|
+
fileSize,
|
|
46
|
+
format,
|
|
47
|
+
ordinal,
|
|
48
|
+
pairs,
|
|
49
|
+
parse,
|
|
50
|
+
parseFloatNumber,
|
|
51
|
+
parseIntNumber,
|
|
52
|
+
percentage,
|
|
53
|
+
spell,
|
|
54
|
+
spellOrdinal,
|
|
55
|
+
trim,
|
|
56
|
+
useLocale,
|
|
57
|
+
withLocale,
|
|
58
|
+
useCurrency,
|
|
59
|
+
withCurrency
|
|
60
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defaultLocale } from "./state.js";
|
|
2
|
+
const numberSymbolsCache = /* @__PURE__ */ new Map();
|
|
3
|
+
function extractNumberSymbols(locale) {
|
|
4
|
+
const formatter = new Intl.NumberFormat(locale);
|
|
5
|
+
const parts = formatter.formatToParts(12345.6);
|
|
6
|
+
const group = parts.find((part) => part.type === "group")?.value ?? ",";
|
|
7
|
+
const decimal = parts.find((part) => part.type === "decimal")?.value ?? ".";
|
|
8
|
+
return { group, decimal };
|
|
9
|
+
}
|
|
10
|
+
export function getNumberSymbols(locale) {
|
|
11
|
+
const resolvedLocale = locale ?? defaultLocale();
|
|
12
|
+
if (!numberSymbolsCache.has(resolvedLocale)) {
|
|
13
|
+
numberSymbolsCache.set(resolvedLocale, extractNumberSymbols(resolvedLocale));
|
|
14
|
+
}
|
|
15
|
+
return numberSymbolsCache.get(resolvedLocale);
|
|
16
|
+
}
|
|
17
|
+
export function normalizeNumberString(value, locale) {
|
|
18
|
+
if (!value) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const { group, decimal } = getNumberSymbols(locale);
|
|
22
|
+
const escapedGroup = escapeRegExp(group);
|
|
23
|
+
const escapedDecimal = escapeRegExp(decimal);
|
|
24
|
+
const sanitized = value.replace(/\s+/g, "").replace(/\u00A0/g, "").replace(new RegExp(escapedGroup, "g"), "").replace(new RegExp(escapedDecimal, "g"), ".").replace(/[^0-9+.-]/g, "");
|
|
25
|
+
if (!sanitized || sanitized === "." || sanitized === "+" || sanitized === "-") {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return sanitized;
|
|
29
|
+
}
|
|
30
|
+
function escapeRegExp(value) {
|
|
31
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ordinal(number: number, locale?: string | null): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defaultLocale } from "./state.js";
|
|
2
|
+
const ordinalRulesCache = /* @__PURE__ */ new Map();
|
|
3
|
+
function getOrdinalRules(locale) {
|
|
4
|
+
if (!ordinalRulesCache.has(locale)) {
|
|
5
|
+
ordinalRulesCache.set(locale, new Intl.PluralRules(locale, { type: "ordinal" }));
|
|
6
|
+
}
|
|
7
|
+
return ordinalRulesCache.get(locale);
|
|
8
|
+
}
|
|
9
|
+
function ordinalSuffix(number, locale) {
|
|
10
|
+
const rule = getOrdinalRules(locale);
|
|
11
|
+
const category = rule.select(number);
|
|
12
|
+
switch (category) {
|
|
13
|
+
case "one":
|
|
14
|
+
return "st";
|
|
15
|
+
case "two":
|
|
16
|
+
return "nd";
|
|
17
|
+
case "few":
|
|
18
|
+
return "rd";
|
|
19
|
+
default:
|
|
20
|
+
return "th";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function ordinal(number, locale) {
|
|
24
|
+
const resolvedLocale = locale ?? defaultLocale();
|
|
25
|
+
return `${number}${ordinalSuffix(number, resolvedLocale)}`;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pairs(to: number, by: number, start?: number, offset?: number): [number, number][];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function pairs(to, by, start = 0, offset = 1) {
|
|
2
|
+
const output = [];
|
|
3
|
+
for (let lower = start; lower < to; lower += by) {
|
|
4
|
+
let upper = lower + by - offset;
|
|
5
|
+
if (upper > to) {
|
|
6
|
+
upper = to;
|
|
7
|
+
}
|
|
8
|
+
output.push([lower, upper]);
|
|
9
|
+
}
|
|
10
|
+
return output;
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type ParseType = 'float' | 'int';
|
|
2
|
+
export declare function parse(value: string, type?: ParseType, locale?: string): number | false;
|
|
3
|
+
export declare function parseIntNumber(value: string, locale?: string): number | false;
|
|
4
|
+
export declare function parseFloatNumber(value: string, locale?: string): number | false;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defaultLocale } from "./state.js";
|
|
2
|
+
import { normalizeNumberString } from "./intl.js";
|
|
3
|
+
export function parse(value, type = "float", locale) {
|
|
4
|
+
const normalized = normalizeNumberString(value, locale ?? defaultLocale());
|
|
5
|
+
if (normalized === null) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const result = type === "int" ? Number.parseInt(normalized, 10) : Number.parseFloat(normalized);
|
|
9
|
+
if (Number.isNaN(result)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
export function parseIntNumber(value, locale) {
|
|
15
|
+
return parse(value, "int", locale);
|
|
16
|
+
}
|
|
17
|
+
export function parseFloatNumber(value, locale) {
|
|
18
|
+
return parse(value, "float", locale);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function percentage(number: number, precision?: number, maxPrecision?: number | null, locale?: string | null): string;
|