@sproutsocial/seeds-react-numeral 1.0.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/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +12 -0
- package/dist/esm/index.js +154 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +192 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +13 -0
- package/package.json +46 -0
- package/src/Numeral.stories.tsx +169 -0
- package/src/Numeral.tsx +208 -0
- package/src/NumeralTypes.ts +27 -0
- package/src/__tests__/Numeral.typetest.tsx +32 -0
- package/src/__tests__/features/A11y.test.tsx +11 -0
- package/src/__tests__/features/abbreviate.test.ts +215 -0
- package/src/__tests__/features/currency.test.ts +122 -0
- package/src/__tests__/features/defaults.test.ts +231 -0
- package/src/__tests__/features/invalid.test.ts +47 -0
- package/src/__tests__/features/locale.test.ts +417 -0
- package/src/__tests__/features/precision.test.ts +452 -0
- package/src/__tests__/features/testNumeral.tsx +82 -0
- package/src/__tests__/features/zero.test.ts +51 -0
- package/src/constants.ts +16 -0
- package/src/index.ts +6 -0
- package/src/styled.d.ts +7 -0
- package/src/styles.ts +12 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +12 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import testNumeral from "./testNumeral";
|
|
2
|
+
|
|
3
|
+
describe("When using a locale...", () => {
|
|
4
|
+
describe("... it should use the proper punctuation and spacing", () => {
|
|
5
|
+
// positive values
|
|
6
|
+
testNumeral(
|
|
7
|
+
1,
|
|
8
|
+
{
|
|
9
|
+
locale: "de-DE",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
text: "1",
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
testNumeral(
|
|
16
|
+
12,
|
|
17
|
+
{
|
|
18
|
+
locale: "de-DE",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
text: "12",
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
testNumeral(
|
|
25
|
+
123.678,
|
|
26
|
+
{
|
|
27
|
+
locale: "en-US",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
text: "123.68",
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
testNumeral(
|
|
34
|
+
123.678,
|
|
35
|
+
{
|
|
36
|
+
locale: "fr-FR",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
text: "123,68",
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
testNumeral(
|
|
43
|
+
123.678,
|
|
44
|
+
{
|
|
45
|
+
locale: "de-DE",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
text: "123,68",
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
testNumeral(
|
|
52
|
+
123.678,
|
|
53
|
+
{
|
|
54
|
+
locale: "es-ES",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
text: "123,68",
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
testNumeral(
|
|
61
|
+
123.678,
|
|
62
|
+
{
|
|
63
|
+
locale: "pt-BR",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
text: "123,68",
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
// negative values
|
|
70
|
+
testNumeral(
|
|
71
|
+
-1,
|
|
72
|
+
{
|
|
73
|
+
locale: "de-DE",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
text: "-1",
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
testNumeral(
|
|
80
|
+
-12,
|
|
81
|
+
{
|
|
82
|
+
locale: "de-DE",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
text: "-12",
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
testNumeral(
|
|
89
|
+
-123.678,
|
|
90
|
+
{
|
|
91
|
+
locale: "en-US",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
text: "-123.68",
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
testNumeral(
|
|
98
|
+
-123.678,
|
|
99
|
+
{
|
|
100
|
+
locale: "fr-FR",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
text: "-123,68",
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
testNumeral(
|
|
107
|
+
-123.678,
|
|
108
|
+
{
|
|
109
|
+
locale: "de-DE",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
text: "-123,68",
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
testNumeral(
|
|
116
|
+
-123.678,
|
|
117
|
+
{
|
|
118
|
+
locale: "es-ES",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
text: "-123,68",
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
testNumeral(
|
|
125
|
+
-123.678,
|
|
126
|
+
{
|
|
127
|
+
locale: "pt-BR",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
text: "-123,68",
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("... it should work with abbreviation", () => {
|
|
136
|
+
// positive values
|
|
137
|
+
testNumeral(
|
|
138
|
+
12345.678,
|
|
139
|
+
{
|
|
140
|
+
locale: "en-US",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
text: "12.35K",
|
|
144
|
+
tip: "12,345.68",
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
testNumeral(
|
|
148
|
+
12345.678,
|
|
149
|
+
{
|
|
150
|
+
locale: "fr-FR",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
text: "12,35 k",
|
|
154
|
+
tip: "12 345,68",
|
|
155
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
156
|
+
format: "12,35\xa0k",
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
testNumeral(
|
|
160
|
+
12345.678,
|
|
161
|
+
{
|
|
162
|
+
locale: "de-DE",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
text: "12.345,68",
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
testNumeral(
|
|
169
|
+
12345.678,
|
|
170
|
+
{
|
|
171
|
+
locale: "es-ES",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
text: "12,35 mil",
|
|
175
|
+
tip: "12.345,68",
|
|
176
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
177
|
+
format: "12,35\xa0mil",
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
testNumeral(
|
|
181
|
+
12345.678,
|
|
182
|
+
{
|
|
183
|
+
locale: "pt-BR",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
text: "12,35 mil",
|
|
187
|
+
tip: "12.345,68",
|
|
188
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
189
|
+
format: "12,35\xa0mil",
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
testNumeral(
|
|
193
|
+
12345.678,
|
|
194
|
+
{
|
|
195
|
+
locale: "ar-EG",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
text: "١٢٫٣٥ ألف",
|
|
199
|
+
tip: "١٢٬٣٤٥٫٦٨",
|
|
200
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
201
|
+
format: "١٢٫٣٥\xa0ألف",
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
// negative values
|
|
205
|
+
testNumeral(
|
|
206
|
+
-12345.678,
|
|
207
|
+
{
|
|
208
|
+
locale: "en-US",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
text: "-12.35K",
|
|
212
|
+
tip: "-12,345.68",
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
testNumeral(
|
|
216
|
+
-12345.678,
|
|
217
|
+
{
|
|
218
|
+
locale: "fr-FR",
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
text: "-12,35 k",
|
|
222
|
+
tip: "-12 345,68",
|
|
223
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
224
|
+
format: "-12,35\xa0k",
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
testNumeral(
|
|
228
|
+
-12345.678,
|
|
229
|
+
{
|
|
230
|
+
locale: "de-DE",
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
text: "-12.345,68",
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
testNumeral(
|
|
237
|
+
-12345.678,
|
|
238
|
+
{
|
|
239
|
+
locale: "es-ES",
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
text: "-12,35 mil",
|
|
243
|
+
tip: "-12.345,68",
|
|
244
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
245
|
+
format: "-12,35\xa0mil",
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
testNumeral(
|
|
249
|
+
-12345.678,
|
|
250
|
+
{
|
|
251
|
+
locale: "pt-BR",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
text: "-12,35 mil",
|
|
255
|
+
tip: "-12.345,68",
|
|
256
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
257
|
+
format: "-12,35\xa0mil",
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe("... it should work with currency", () => {
|
|
263
|
+
// positive values
|
|
264
|
+
testNumeral(
|
|
265
|
+
12345.678,
|
|
266
|
+
{
|
|
267
|
+
locale: "en-US",
|
|
268
|
+
currency: "EUR",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
text: "€12.35K",
|
|
272
|
+
tip: "€12,345.68",
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
testNumeral(
|
|
276
|
+
12345.678,
|
|
277
|
+
{
|
|
278
|
+
locale: "fr-FR",
|
|
279
|
+
currency: "EUR",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
text: "12,35 k €",
|
|
283
|
+
tip: "12 345,68 €",
|
|
284
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
285
|
+
format: "12,35\xa0k\xa0€",
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
testNumeral(
|
|
289
|
+
12345.678,
|
|
290
|
+
{
|
|
291
|
+
locale: "de-DE",
|
|
292
|
+
currency: "EUR",
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
text: "12.345,68 €",
|
|
296
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
297
|
+
format: "12.345,68\xa0€",
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
testNumeral(
|
|
301
|
+
12345.678,
|
|
302
|
+
{
|
|
303
|
+
locale: "es-ES",
|
|
304
|
+
currency: "EUR",
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
text: "12,35 mil €",
|
|
308
|
+
tip: "12.345,68 €",
|
|
309
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
310
|
+
format: "12,35\xa0mil\xa0€",
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
testNumeral(
|
|
314
|
+
12345.678,
|
|
315
|
+
{
|
|
316
|
+
locale: "pt-BR",
|
|
317
|
+
currency: "EUR",
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
text: "€ 12,35 mil",
|
|
321
|
+
tip: "€ 12.345,68",
|
|
322
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
323
|
+
format: "€\xa012,35\xa0mil",
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
testNumeral(
|
|
327
|
+
12345.678,
|
|
328
|
+
{
|
|
329
|
+
locale: "ar-EG",
|
|
330
|
+
currency: "EUR",
|
|
331
|
+
abbreviate: false,
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
// [DS-2332] Due to issues with non-breaking spaces, this fails when using strict text matching, so a looser regex is needed.
|
|
335
|
+
text: /١٢٬٣٤٥٫٦٨ €/i,
|
|
336
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
337
|
+
format: "\u200f١٢٬٣٤٥٫٦٨\xa0€",
|
|
338
|
+
}
|
|
339
|
+
);
|
|
340
|
+
// negative values
|
|
341
|
+
testNumeral(
|
|
342
|
+
-12345.678,
|
|
343
|
+
{
|
|
344
|
+
locale: "en-US",
|
|
345
|
+
currency: "EUR",
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
text: "-€12.35K",
|
|
349
|
+
tip: "-€12,345.68",
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
testNumeral(
|
|
353
|
+
-12345.678,
|
|
354
|
+
{
|
|
355
|
+
locale: "fr-FR",
|
|
356
|
+
currency: "EUR",
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
text: "-12,35 k €",
|
|
360
|
+
tip: "-12 345,68 €",
|
|
361
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
362
|
+
format: "-12,35\xa0k\xa0€",
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
testNumeral(
|
|
366
|
+
-12345.678,
|
|
367
|
+
{
|
|
368
|
+
locale: "de-DE",
|
|
369
|
+
currency: "EUR",
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
text: "-12.345,68 €",
|
|
373
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
374
|
+
format: "-12.345,68\xa0€",
|
|
375
|
+
}
|
|
376
|
+
);
|
|
377
|
+
testNumeral(
|
|
378
|
+
-12345.678,
|
|
379
|
+
{
|
|
380
|
+
locale: "es-ES",
|
|
381
|
+
currency: "EUR",
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
text: "-12,35 mil €",
|
|
385
|
+
tip: "-12.345,68 €",
|
|
386
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
387
|
+
format: "-12,35\xa0mil\xa0€",
|
|
388
|
+
}
|
|
389
|
+
);
|
|
390
|
+
testNumeral(
|
|
391
|
+
-12345.678,
|
|
392
|
+
{
|
|
393
|
+
locale: "pt-BR",
|
|
394
|
+
currency: "EUR",
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
text: "-€ 12,35 mil",
|
|
398
|
+
tip: "-€ 12.345,68",
|
|
399
|
+
// see this article as to why the \xa0 is needed: https://stackoverflow.com/a/66409196
|
|
400
|
+
format: "-€\xa012,35\xa0mil",
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
xdescribe("NOTE: This test misbehaves in node/jest!!!", () => {
|
|
404
|
+
testNumeral(
|
|
405
|
+
12345.678,
|
|
406
|
+
{
|
|
407
|
+
locale: "ar-EG",
|
|
408
|
+
currency: "EUR",
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
text: "١٢٫٣٥ ألف €",
|
|
412
|
+
tip: "١٢٬٣٤٥٫٦٨ €",
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
});
|