@tolki/num 2.2.4 → 2.2.6
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 +17 -5
- package/dist/index.js +3 -28
- package/dist/num.d.ts +8 -0
- package/dist/num.d.ts.map +1 -1
- package/dist/num.js +233 -293
- package/dist/speller/index.d.ts.map +1 -1
- package/dist/speller/index.js +84 -93
- package/package.json +6 -4
- package/dist/en-US-Ct0OKCam.js +0 -431
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ pnpm add @tolki/num
|
|
|
28
28
|
|
|
29
29
|
### Importing the Package
|
|
30
30
|
|
|
31
|
-
You can import individual functions
|
|
31
|
+
You can import individual functions or the whole package as a namespace. Both tree-shake the same way:
|
|
32
32
|
|
|
33
33
|
Importing individual functions:
|
|
34
34
|
|
|
@@ -41,10 +41,10 @@ const formattedNumber = format(1234567.89); // '1,234,567.89'
|
|
|
41
41
|
const parsedNumber = parse("1,234,567.89"); // 1234567.89
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Importing the
|
|
44
|
+
Importing the package as a namespace:
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
|
-
// Import the
|
|
47
|
+
// Import the package as a namespace
|
|
48
48
|
import * as Num from "@tolki/num";
|
|
49
49
|
|
|
50
50
|
// Example usage
|
|
@@ -52,9 +52,21 @@ const formattedNumber = Num.format(1234567.89); // '1,234,567.89'
|
|
|
52
52
|
const parsedNumber = Num.parse("1,234,567.89"); // 1234567.89
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
A namespace import that reads its members by name, such as `Num.format(...)`, shakes exactly like named imports in Rollup, Rolldown (Vite 8), esbuild, webpack and Rspack: your bundle holds only the members you use. Passing the namespace object around, or reading a computed member such as `Num[name]`, keeps every function. See [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html#namespace-imports).
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
### Bundling
|
|
58
|
+
|
|
59
|
+
A helper call whose result nothing uses drops out of your bundle in Rollup, Rolldown (Vite 8), webpack and Rspack, because the helpers are marked as free of side effects. This holds for a call at the top level of a module too.
|
|
60
|
+
|
|
61
|
+
The exception is Rspack, where an unused top-level call to `spell` or `spellOrdinal` drops the call but keeps the loader code it needs for the dynamic `import()` of the `to-words` locale files. Writing `/* @__PURE__ */` before the call drops everything:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
export const words = /* @__PURE__ */ spell(5);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
esbuild doesn't follow the mark across files, so it needs the same comment on any helper call. [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html) covers every bundler.
|
|
68
|
+
|
|
69
|
+
`useLocale` and `useCurrency` set the defaults that every formatter reads, and `withLocale` and `withCurrency` run a callback around a temporary swap of them, so a call to any of the four is always kept.
|
|
58
70
|
|
|
59
71
|
## Tolki Number Utilities List
|
|
60
72
|
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import { abbreviate as
|
|
2
|
-
import { spell as
|
|
3
|
-
export {
|
|
4
|
-
a as abbreviate,
|
|
5
|
-
l as clamp,
|
|
6
|
-
o as currency,
|
|
7
|
-
n as defaultCurrency,
|
|
8
|
-
s as defaultLocale,
|
|
9
|
-
t as fileSize,
|
|
10
|
-
u as forHumans,
|
|
11
|
-
c as format,
|
|
12
|
-
i as minutesToHuman,
|
|
13
|
-
m as ordinal,
|
|
14
|
-
p as pairs,
|
|
15
|
-
f as parse,
|
|
16
|
-
d as parseFloat,
|
|
17
|
-
y as parseInt,
|
|
18
|
-
C as percentage,
|
|
19
|
-
H as secondsToHuman,
|
|
20
|
-
g as spell,
|
|
21
|
-
v as spellOrdinal,
|
|
22
|
-
L as summarize,
|
|
23
|
-
b as trim,
|
|
24
|
-
h as useCurrency,
|
|
25
|
-
w as useLocale,
|
|
26
|
-
x as withCurrency,
|
|
27
|
-
z as withLocale
|
|
28
|
-
};
|
|
1
|
+
import { abbreviate as e, clamp as t, currency as n, defaultCurrency as r, defaultLocale as i, fileSize as a, forHumans as o, format as s, minutesToHuman as c, ordinal as l, pairs as u, parse as d, parseFloat as f, parseInt as p, percentage as m, secondsToHuman as h, summarize as g, trim as _, useCurrency as v, useLocale as y, withCurrency as b, withLocale as x } from "./num.js";
|
|
2
|
+
import { spell as S, spellOrdinal as C } from "./speller/index.js";
|
|
3
|
+
export { e as abbreviate, t as clamp, n as currency, r as defaultCurrency, i as defaultLocale, a as fileSize, o as forHumans, s as format, c as minutesToHuman, l as ordinal, u as pairs, d as parse, f as parseFloat, p as parseInt, m as percentage, h as secondsToHuman, S as spell, C as spellOrdinal, g as summarize, _ as trim, v as useCurrency, y as useLocale, b as withCurrency, x as withLocale };
|
package/dist/num.d.ts
CHANGED
|
@@ -180,6 +180,8 @@ export declare function secondsToHuman(seconds: number | string, round?: boolean
|
|
|
180
180
|
/**
|
|
181
181
|
* Execute the given callback using the given locale.
|
|
182
182
|
*
|
|
183
|
+
* @sideEffects callback runs the caller callback around a temporary locale swap
|
|
184
|
+
*
|
|
183
185
|
* @param locale - The locale to use.
|
|
184
186
|
* @param callback - The callback to execute.
|
|
185
187
|
* @returns The result of the callback.
|
|
@@ -190,6 +192,8 @@ export declare function withLocale<TReturn>(locale: string, callback: () => TRet
|
|
|
190
192
|
/**
|
|
191
193
|
* Execute the given callback using the given currency.
|
|
192
194
|
*
|
|
195
|
+
* @sideEffects callback runs the caller callback around a temporary currency swap
|
|
196
|
+
*
|
|
193
197
|
* @param currency - The currency to use.
|
|
194
198
|
* @param callback - The callback to execute.
|
|
195
199
|
* @returns The result of the callback.
|
|
@@ -200,6 +204,8 @@ export declare function withCurrency<TReturn>(currency: string, callback: () =>
|
|
|
200
204
|
/**
|
|
201
205
|
* Set the default locale.
|
|
202
206
|
*
|
|
207
|
+
* @sideEffects state writes the module default locale
|
|
208
|
+
*
|
|
203
209
|
* @param locale - The locale to set.
|
|
204
210
|
* @returns void
|
|
205
211
|
*
|
|
@@ -209,6 +215,8 @@ export declare function useLocale(locale: string): void;
|
|
|
209
215
|
/**
|
|
210
216
|
* Set the default currency.
|
|
211
217
|
*
|
|
218
|
+
* @sideEffects state writes the module default currency
|
|
219
|
+
*
|
|
212
220
|
* @param currency - The currency to set.
|
|
213
221
|
* @returns void
|
|
214
222
|
*
|
package/dist/num.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;AAEH,wBAAgB,UAAU,CACtB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAU,EACrB,YAAY,GAAE,MAAM,GAAG,IAAW,GACnC,MAAM,GAAG,KAAK,CAEhB;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAqBhB;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CA2DzE;AAED;;;;;;;;GAQG;AAEH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAQhB;AAED;;;;;;;;GAQG;AAEH,wBAAgB,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,GAAG,KAAK,CAEhB;AAED;;;;;;;;GAQG;AAEH,wBAAgB,OAAO,CAAC,KAA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