@reykjavik/webtools 0.1.18 → 0.1.19
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/CHANGELOG.md +10 -0
- package/README.md +5 -4
- package/esm/fixIcelandicLocale.privates.js +51 -30
- package/fixIcelandicLocale.privates.js +51 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.1.19
|
|
8
|
+
|
|
9
|
+
_2024-03-11_
|
|
10
|
+
|
|
11
|
+
- fix: Incorrect alphabetization of accented characters as part of a word …
|
|
12
|
+
(not just a single character) This fix corrects the sorting of initial
|
|
13
|
+
letters, but characters inside the string stay mixed in with their
|
|
14
|
+
unaccented base character.
|
|
15
|
+
- fix: Incorrect `Intl.ListFormat` format in narrow+unit mode
|
|
16
|
+
|
|
7
17
|
## 0.1.18
|
|
8
18
|
|
|
9
19
|
_2024-03-11_
|
package/README.md
CHANGED
|
@@ -462,10 +462,11 @@ detection test.)
|
|
|
462
462
|
|
|
463
463
|
**`Intl.Collator` and `localeCompare`:**
|
|
464
464
|
|
|
465
|
-
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
465
|
+
- It incorrectly treats `ð` and `d` as the same letter (most of the time), and
|
|
466
|
+
the acute-accented characters `á`, `é`, `í`, `ó`, `ú` and `ý` get lumped in
|
|
467
|
+
with their non-accented counterparts (unless the compared).
|
|
468
|
+
We fix this only for the first letter in the string, but not for the rest of
|
|
469
|
+
it.
|
|
469
470
|
|
|
470
471
|
**`Intl.NumberFormat` and `toLocaleString`:**
|
|
471
472
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _a;
|
|
1
|
+
var _a, _b;
|
|
2
2
|
const _Collator = Intl.Collator;
|
|
3
3
|
const mapLocales = (locales) => {
|
|
4
4
|
locales = typeof locales === 'string' ? [locales] : locales || [];
|
|
@@ -11,6 +11,8 @@ const mapLocales = (locales) => {
|
|
|
11
11
|
// or "accent" then `ð` is consiered a variant of `d` and the letters
|
|
12
12
|
// á, é, í, ó, ú, and ý are not treated as separate letters but simply
|
|
13
13
|
// variants of a, e, i, o, u, and y.
|
|
14
|
+
// Also when the accented characters are part of a word, they are treated
|
|
15
|
+
// as fully equal to the base letter.
|
|
14
16
|
return ['da'];
|
|
15
17
|
}
|
|
16
18
|
if (_Collator.supportedLocalesOf(loc).length) {
|
|
@@ -19,17 +21,35 @@ const mapLocales = (locales) => {
|
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
23
|
const combineParts = (parts) => parts.map(({ value }) => value).join('');
|
|
22
|
-
// ===========================================================================
|
|
23
|
-
// Collator
|
|
24
|
-
// ===========================================================================
|
|
25
24
|
const PatchedCollator = function Collator(locales, options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
if (!(this instanceof PatchedCollator)) {
|
|
26
|
+
// @ts-expect-error (YOLO! Can't be arsed)
|
|
27
|
+
return new PatchedCollator(locales, options);
|
|
28
|
+
}
|
|
29
|
+
const mappedLocales = mapLocales(locales);
|
|
30
|
+
this.super = _Collator(mappedLocales || locales, options);
|
|
31
|
+
this.mapped = !!mappedLocales;
|
|
32
|
+
};
|
|
33
|
+
// This is all very hacky, but extending the class *AND* preseving the
|
|
34
|
+
// ability to instantiate without `new` is a bit of a pain.
|
|
35
|
+
// Eagerly interested in finding a better way to do this.
|
|
36
|
+
const CollatorProto = {
|
|
37
|
+
constructor: PatchedCollator,
|
|
38
|
+
compare(a, b) {
|
|
39
|
+
const res1 = this.super.compare(a, b);
|
|
40
|
+
const a0 = a.charAt(0);
|
|
41
|
+
const b0 = b.charAt(0);
|
|
42
|
+
if (/\d/.test(a0 + b0)) {
|
|
43
|
+
return res1;
|
|
44
|
+
}
|
|
45
|
+
const res2 = this.super.compare(a0, b0);
|
|
46
|
+
return res2 !== 0 ? res2 : res1;
|
|
47
|
+
},
|
|
48
|
+
resolvedOptions() {
|
|
49
|
+
return this.super.resolvedOptions();
|
|
50
|
+
},
|
|
30
51
|
};
|
|
31
|
-
PatchedCollator.prototype =
|
|
32
|
-
PatchedCollator.prototype.constructor = PatchedCollator;
|
|
52
|
+
PatchedCollator.prototype = CollatorProto;
|
|
33
53
|
// Static methods (not patched since "is" is not ACTUALLY supported.)
|
|
34
54
|
PatchedCollator.supportedLocalesOf = _Collator.supportedLocalesOf;
|
|
35
55
|
PatchedCollator.$original = _Collator;
|
|
@@ -285,28 +305,29 @@ const _ListFormat = Intl.ListFormat;
|
|
|
285
305
|
let PatchedListFormat;
|
|
286
306
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
287
307
|
if (_ListFormat) {
|
|
288
|
-
PatchedListFormat = class ListFormat extends _ListFormat {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
308
|
+
PatchedListFormat = (_b = class ListFormat extends _ListFormat {
|
|
309
|
+
constructor(locales, options) {
|
|
310
|
+
const mappedLocales = mapLocales(locales);
|
|
311
|
+
super(mappedLocales || locales, options);
|
|
312
|
+
this.mapped = !!mappedLocales;
|
|
313
|
+
}
|
|
314
|
+
format(list) {
|
|
315
|
+
return this.mapped ? combineParts(this.formatToParts(list)) : super.format(list);
|
|
316
|
+
}
|
|
317
|
+
formatToParts(list) {
|
|
318
|
+
const parts = super.formatToParts(list);
|
|
319
|
+
if (this.mapped) {
|
|
320
|
+
for (const item of parts) {
|
|
321
|
+
const { value } = item;
|
|
322
|
+
if (item.type === 'literal' && (value === ' el. ' || value === ' eller ')) {
|
|
323
|
+
item.value = ' eða ';
|
|
324
|
+
}
|
|
305
325
|
}
|
|
306
326
|
}
|
|
327
|
+
return parts;
|
|
307
328
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
329
|
+
},
|
|
330
|
+
_b.$original = _ListFormat,
|
|
331
|
+
_b);
|
|
311
332
|
}
|
|
312
333
|
export const _PatchedListFormat = PatchedListFormat;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
2
|
+
var _a, _b;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports._PatchedListFormat = exports._PatchedPluralRules = exports._patchedToLocaleDateString = exports._PatchedDateTimeFormat = exports._patchedToLocaleString = exports._PatchedNumberFormat = exports._patchedLocaleCompare = exports._PatchedCollator = void 0;
|
|
5
5
|
const _Collator = Intl.Collator;
|
|
@@ -14,6 +14,8 @@ const mapLocales = (locales) => {
|
|
|
14
14
|
// or "accent" then `ð` is consiered a variant of `d` and the letters
|
|
15
15
|
// á, é, í, ó, ú, and ý are not treated as separate letters but simply
|
|
16
16
|
// variants of a, e, i, o, u, and y.
|
|
17
|
+
// Also when the accented characters are part of a word, they are treated
|
|
18
|
+
// as fully equal to the base letter.
|
|
17
19
|
return ['da'];
|
|
18
20
|
}
|
|
19
21
|
if (_Collator.supportedLocalesOf(loc).length) {
|
|
@@ -22,17 +24,35 @@ const mapLocales = (locales) => {
|
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
26
|
const combineParts = (parts) => parts.map(({ value }) => value).join('');
|
|
25
|
-
// ===========================================================================
|
|
26
|
-
// Collator
|
|
27
|
-
// ===========================================================================
|
|
28
27
|
const PatchedCollator = function Collator(locales, options) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (!(this instanceof PatchedCollator)) {
|
|
29
|
+
// @ts-expect-error (YOLO! Can't be arsed)
|
|
30
|
+
return new PatchedCollator(locales, options);
|
|
31
|
+
}
|
|
32
|
+
const mappedLocales = mapLocales(locales);
|
|
33
|
+
this.super = _Collator(mappedLocales || locales, options);
|
|
34
|
+
this.mapped = !!mappedLocales;
|
|
35
|
+
};
|
|
36
|
+
// This is all very hacky, but extending the class *AND* preseving the
|
|
37
|
+
// ability to instantiate without `new` is a bit of a pain.
|
|
38
|
+
// Eagerly interested in finding a better way to do this.
|
|
39
|
+
const CollatorProto = {
|
|
40
|
+
constructor: PatchedCollator,
|
|
41
|
+
compare(a, b) {
|
|
42
|
+
const res1 = this.super.compare(a, b);
|
|
43
|
+
const a0 = a.charAt(0);
|
|
44
|
+
const b0 = b.charAt(0);
|
|
45
|
+
if (/\d/.test(a0 + b0)) {
|
|
46
|
+
return res1;
|
|
47
|
+
}
|
|
48
|
+
const res2 = this.super.compare(a0, b0);
|
|
49
|
+
return res2 !== 0 ? res2 : res1;
|
|
50
|
+
},
|
|
51
|
+
resolvedOptions() {
|
|
52
|
+
return this.super.resolvedOptions();
|
|
53
|
+
},
|
|
33
54
|
};
|
|
34
|
-
PatchedCollator.prototype =
|
|
35
|
-
PatchedCollator.prototype.constructor = PatchedCollator;
|
|
55
|
+
PatchedCollator.prototype = CollatorProto;
|
|
36
56
|
// Static methods (not patched since "is" is not ACTUALLY supported.)
|
|
37
57
|
PatchedCollator.supportedLocalesOf = _Collator.supportedLocalesOf;
|
|
38
58
|
PatchedCollator.$original = _Collator;
|
|
@@ -291,28 +311,29 @@ const _ListFormat = Intl.ListFormat;
|
|
|
291
311
|
let PatchedListFormat;
|
|
292
312
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
293
313
|
if (_ListFormat) {
|
|
294
|
-
PatchedListFormat = class ListFormat extends _ListFormat {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
314
|
+
PatchedListFormat = (_b = class ListFormat extends _ListFormat {
|
|
315
|
+
constructor(locales, options) {
|
|
316
|
+
const mappedLocales = mapLocales(locales);
|
|
317
|
+
super(mappedLocales || locales, options);
|
|
318
|
+
this.mapped = !!mappedLocales;
|
|
319
|
+
}
|
|
320
|
+
format(list) {
|
|
321
|
+
return this.mapped ? combineParts(this.formatToParts(list)) : super.format(list);
|
|
322
|
+
}
|
|
323
|
+
formatToParts(list) {
|
|
324
|
+
const parts = super.formatToParts(list);
|
|
325
|
+
if (this.mapped) {
|
|
326
|
+
for (const item of parts) {
|
|
327
|
+
const { value } = item;
|
|
328
|
+
if (item.type === 'literal' && (value === ' el. ' || value === ' eller ')) {
|
|
329
|
+
item.value = ' eða ';
|
|
330
|
+
}
|
|
311
331
|
}
|
|
312
332
|
}
|
|
333
|
+
return parts;
|
|
313
334
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
335
|
+
},
|
|
336
|
+
_b.$original = _ListFormat,
|
|
337
|
+
_b);
|
|
317
338
|
}
|
|
318
339
|
exports._PatchedListFormat = PatchedListFormat;
|
package/package.json
CHANGED