@kizmann/pico-js 2.1.2 → 2.1.4
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/package.json
CHANGED
|
@@ -57,7 +57,7 @@ export class PicoFormatOption
|
|
|
57
57
|
return Mix.str(key) + div + For.casted(value, false);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
let result = Arr.
|
|
60
|
+
let result = Arr.each(value, (v : any, k : any) => {
|
|
61
61
|
return this.castOption(k, v, key, space);
|
|
62
62
|
});
|
|
63
63
|
|
package/src/utils/Locale.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mix, Obj, Locale } from "../index.esm.ts";
|
|
1
|
+
import { Mix, Obj, Locale, Arr } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export class PicoLocale
|
|
4
4
|
{
|
|
@@ -16,6 +16,13 @@ export class PicoLocale
|
|
|
16
16
|
*/
|
|
17
17
|
static $sort : Intl.Collator = null;
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Number format
|
|
21
|
+
*
|
|
22
|
+
* @type {string[]}
|
|
23
|
+
*/
|
|
24
|
+
static $number : string[] = null;
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* Active locale code
|
|
21
28
|
*
|
|
@@ -124,6 +131,31 @@ export class PicoLocale
|
|
|
124
131
|
return Locale.$sort;
|
|
125
132
|
}
|
|
126
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Get decimal and group separators
|
|
136
|
+
*
|
|
137
|
+
* @returns {string[]} Separators [group, decimal]
|
|
138
|
+
*/
|
|
139
|
+
static decimals() : string[]
|
|
140
|
+
{
|
|
141
|
+
if ( Locale.$number != null ) {
|
|
142
|
+
return Locale.$number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const parts = new Intl.NumberFormat(Locale.code())
|
|
146
|
+
.formatToParts(1234.5);
|
|
147
|
+
|
|
148
|
+
const group = Arr.find(parts, {
|
|
149
|
+
type: 'group'
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const decimal = Arr.find(parts, {
|
|
153
|
+
type: 'decimal'
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return Locale.$number = [group, decimal];
|
|
157
|
+
}
|
|
158
|
+
|
|
127
159
|
/**
|
|
128
160
|
* Replace :tokens in text
|
|
129
161
|
*
|
|
@@ -224,6 +256,46 @@ export class PicoLocale
|
|
|
224
256
|
return splits[0];
|
|
225
257
|
}
|
|
226
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Parse localized number string
|
|
261
|
+
*
|
|
262
|
+
* @example Locale.num("1,234.50") // => 1234.5
|
|
263
|
+
*
|
|
264
|
+
* @param {string} value Localized string
|
|
265
|
+
* @returns {number} Number value
|
|
266
|
+
*/
|
|
267
|
+
static num(value : string) : number
|
|
268
|
+
{
|
|
269
|
+
const [group, decimal] = Locale.decimals();
|
|
270
|
+
|
|
271
|
+
const text = value
|
|
272
|
+
.replaceAll(' ', '')
|
|
273
|
+
.replaceAll(group, '')
|
|
274
|
+
.replaceAll(decimal, '.');
|
|
275
|
+
|
|
276
|
+
return Mix.num(text);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Parse localized integer string
|
|
281
|
+
*
|
|
282
|
+
* @example Locale.int("1,234") // => 1234
|
|
283
|
+
*
|
|
284
|
+
* @param {string} value Localized string
|
|
285
|
+
* @returns {number} Integer value
|
|
286
|
+
*/
|
|
287
|
+
static int(value : string) : number
|
|
288
|
+
{
|
|
289
|
+
const [group, decimal] = Locale.decimals();
|
|
290
|
+
|
|
291
|
+
const text = value
|
|
292
|
+
.replaceAll(' ', '')
|
|
293
|
+
.replaceAll(group, '')
|
|
294
|
+
.replaceAll(decimal, '.');
|
|
295
|
+
|
|
296
|
+
return Mix.int(text);
|
|
297
|
+
}
|
|
298
|
+
|
|
227
299
|
}
|
|
228
300
|
|
|
229
301
|
export default PicoLocale
|
package/types/utils/Locale.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export declare class PicoLocale {
|
|
|
11
11
|
* @type {Intl.Collator}
|
|
12
12
|
*/
|
|
13
13
|
static $sort: Intl.Collator;
|
|
14
|
+
/**
|
|
15
|
+
* Number format
|
|
16
|
+
*
|
|
17
|
+
* @type {string[]}
|
|
18
|
+
*/
|
|
19
|
+
static $number: string[];
|
|
14
20
|
/**
|
|
15
21
|
* Active locale code
|
|
16
22
|
*
|
|
@@ -67,6 +73,12 @@ export declare class PicoLocale {
|
|
|
67
73
|
* @returns {Intl.Collator} Collator instance
|
|
68
74
|
*/
|
|
69
75
|
static collator(): Intl.Collator;
|
|
76
|
+
/**
|
|
77
|
+
* Get decimal and group separators
|
|
78
|
+
*
|
|
79
|
+
* @returns {string[]} Separators [group, decimal]
|
|
80
|
+
*/
|
|
81
|
+
static decimals(): string[];
|
|
70
82
|
/**
|
|
71
83
|
* Replace :tokens in text
|
|
72
84
|
*
|
|
@@ -111,5 +123,23 @@ export declare class PicoLocale {
|
|
|
111
123
|
* @returns {string} Picked text
|
|
112
124
|
*/
|
|
113
125
|
static countpick(splits: string[], count?: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* Parse localized number string
|
|
128
|
+
*
|
|
129
|
+
* @example Locale.num("1,234.50") // => 1234.5
|
|
130
|
+
*
|
|
131
|
+
* @param {string} value Localized string
|
|
132
|
+
* @returns {number} Number value
|
|
133
|
+
*/
|
|
134
|
+
static num(value: string): number;
|
|
135
|
+
/**
|
|
136
|
+
* Parse localized integer string
|
|
137
|
+
*
|
|
138
|
+
* @example Locale.int("1,234") // => 1234
|
|
139
|
+
*
|
|
140
|
+
* @param {string} value Localized string
|
|
141
|
+
* @returns {number} Integer value
|
|
142
|
+
*/
|
|
143
|
+
static int(value: string): number;
|
|
114
144
|
}
|
|
115
145
|
export default PicoLocale;
|