@rootreeweb/js-lib 4.0.10
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 +49 -0
- package/dist/cjs/browser/dom.cjs +95 -0
- package/dist/cjs/browser/dom.d.ts +44 -0
- package/dist/cjs/browser/dom.d.ts.map +1 -0
- package/dist/cjs/browser/dom.js.map +1 -0
- package/dist/cjs/browser/download.cjs +40 -0
- package/dist/cjs/browser/download.d.ts +16 -0
- package/dist/cjs/browser/download.d.ts.map +1 -0
- package/dist/cjs/browser/download.js.map +1 -0
- package/dist/cjs/browser/index.cjs +20 -0
- package/dist/cjs/browser/index.d.ts +4 -0
- package/dist/cjs/browser/index.d.ts.map +1 -0
- package/dist/cjs/browser/index.js.map +1 -0
- package/dist/cjs/browser/queryOrThrow.cjs +42 -0
- package/dist/cjs/browser/queryOrThrow.d.ts +44 -0
- package/dist/cjs/browser/queryOrThrow.d.ts.map +1 -0
- package/dist/cjs/browser/queryOrThrow.js.map +1 -0
- package/dist/cjs/general/arrays.cjs +151 -0
- package/dist/cjs/general/arrays.d.ts +70 -0
- package/dist/cjs/general/arrays.d.ts.map +1 -0
- package/dist/cjs/general/arrays.js.map +1 -0
- package/dist/cjs/general/boolean.cjs +19 -0
- package/dist/cjs/general/boolean.d.ts +10 -0
- package/dist/cjs/general/boolean.d.ts.map +1 -0
- package/dist/cjs/general/boolean.js.map +1 -0
- package/dist/cjs/general/clock.cjs +22 -0
- package/dist/cjs/general/clock.d.ts +12 -0
- package/dist/cjs/general/clock.d.ts.map +1 -0
- package/dist/cjs/general/clock.js.map +1 -0
- package/dist/cjs/general/dates/create.cjs +81 -0
- package/dist/cjs/general/dates/create.d.ts +54 -0
- package/dist/cjs/general/dates/create.d.ts.map +1 -0
- package/dist/cjs/general/dates/create.js.map +1 -0
- package/dist/cjs/general/dates/dates.cjs +88 -0
- package/dist/cjs/general/dates/dates.d.ts +56 -0
- package/dist/cjs/general/dates/dates.d.ts.map +1 -0
- package/dist/cjs/general/dates/dates.js.map +1 -0
- package/dist/cjs/general/dates/get.cjs +77 -0
- package/dist/cjs/general/dates/get.d.ts +41 -0
- package/dist/cjs/general/dates/get.d.ts.map +1 -0
- package/dist/cjs/general/dates/get.js.map +1 -0
- package/dist/cjs/general/dates/index.cjs +20 -0
- package/dist/cjs/general/dates/index.d.ts +4 -0
- package/dist/cjs/general/dates/index.d.ts.map +1 -0
- package/dist/cjs/general/dates/index.js.map +1 -0
- package/dist/cjs/general/forms.cjs +31 -0
- package/dist/cjs/general/forms.d.ts +17 -0
- package/dist/cjs/general/forms.d.ts.map +1 -0
- package/dist/cjs/general/forms.js.map +1 -0
- package/dist/cjs/general/images.cjs +23 -0
- package/dist/cjs/general/images.d.ts +17 -0
- package/dist/cjs/general/images.d.ts.map +1 -0
- package/dist/cjs/general/images.js.map +1 -0
- package/dist/cjs/general/index.cjs +31 -0
- package/dist/cjs/general/index.d.ts +15 -0
- package/dist/cjs/general/index.d.ts.map +1 -0
- package/dist/cjs/general/index.js.map +1 -0
- package/dist/cjs/general/localization.cjs +199 -0
- package/dist/cjs/general/localization.d.ts +83 -0
- package/dist/cjs/general/localization.d.ts.map +1 -0
- package/dist/cjs/general/localization.js.map +1 -0
- package/dist/cjs/general/maps.cjs +63 -0
- package/dist/cjs/general/maps.d.ts +35 -0
- package/dist/cjs/general/maps.d.ts.map +1 -0
- package/dist/cjs/general/maps.js.map +1 -0
- package/dist/cjs/general/messenger/createMessenger.cjs +68 -0
- package/dist/cjs/general/messenger/createMessenger.d.ts +10 -0
- package/dist/cjs/general/messenger/createMessenger.d.ts.map +1 -0
- package/dist/cjs/general/messenger/createMessenger.js.map +1 -0
- package/dist/cjs/general/messenger/index.cjs +19 -0
- package/dist/cjs/general/messenger/index.d.ts +3 -0
- package/dist/cjs/general/messenger/index.d.ts.map +1 -0
- package/dist/cjs/general/messenger/index.js.map +1 -0
- package/dist/cjs/general/messenger/types.cjs +3 -0
- package/dist/cjs/general/messenger/types.d.ts +26 -0
- package/dist/cjs/general/messenger/types.d.ts.map +1 -0
- package/dist/cjs/general/messenger/types.js.map +1 -0
- package/dist/cjs/general/namedEntities.cjs +260 -0
- package/dist/cjs/general/namedEntities.d.ts +256 -0
- package/dist/cjs/general/namedEntities.d.ts.map +1 -0
- package/dist/cjs/general/namedEntities.js.map +1 -0
- package/dist/cjs/general/numbers.cjs +94 -0
- package/dist/cjs/general/numbers.d.ts +43 -0
- package/dist/cjs/general/numbers.d.ts.map +1 -0
- package/dist/cjs/general/numbers.js.map +1 -0
- package/dist/cjs/general/objects.cjs +98 -0
- package/dist/cjs/general/objects.d.ts +45 -0
- package/dist/cjs/general/objects.d.ts.map +1 -0
- package/dist/cjs/general/objects.js.map +1 -0
- package/dist/cjs/general/sorting.cjs +72 -0
- package/dist/cjs/general/sorting.d.ts +32 -0
- package/dist/cjs/general/sorting.d.ts.map +1 -0
- package/dist/cjs/general/sorting.js.map +1 -0
- package/dist/cjs/general/string.cjs +73 -0
- package/dist/cjs/general/string.d.ts +31 -0
- package/dist/cjs/general/string.d.ts.map +1 -0
- package/dist/cjs/general/string.js.map +1 -0
- package/dist/cjs/general/timeout.cjs +17 -0
- package/dist/cjs/general/timeout.d.ts +8 -0
- package/dist/cjs/general/timeout.d.ts.map +1 -0
- package/dist/cjs/general/timeout.js.map +1 -0
- package/dist/cjs/index.cjs +20 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/node/index.cjs +30 -0
- package/dist/cjs/node/index.d.ts +25 -0
- package/dist/cjs/node/index.d.ts.map +1 -0
- package/dist/cjs/node/index.js.map +1 -0
- package/dist/esm/browser/dom.d.ts +44 -0
- package/dist/esm/browser/dom.d.ts.map +1 -0
- package/dist/esm/browser/dom.js +88 -0
- package/dist/esm/browser/dom.js.map +1 -0
- package/dist/esm/browser/download.d.ts +16 -0
- package/dist/esm/browser/download.d.ts.map +1 -0
- package/dist/esm/browser/download.js +36 -0
- package/dist/esm/browser/download.js.map +1 -0
- package/dist/esm/browser/index.d.ts +4 -0
- package/dist/esm/browser/index.d.ts.map +1 -0
- package/dist/esm/browser/index.js +4 -0
- package/dist/esm/browser/index.js.map +1 -0
- package/dist/esm/browser/queryOrThrow.d.ts +44 -0
- package/dist/esm/browser/queryOrThrow.d.ts.map +1 -0
- package/dist/esm/browser/queryOrThrow.js +39 -0
- package/dist/esm/browser/queryOrThrow.js.map +1 -0
- package/dist/esm/general/arrays.d.ts +70 -0
- package/dist/esm/general/arrays.d.ts.map +1 -0
- package/dist/esm/general/arrays.js +144 -0
- package/dist/esm/general/arrays.js.map +1 -0
- package/dist/esm/general/boolean.d.ts +10 -0
- package/dist/esm/general/boolean.d.ts.map +1 -0
- package/dist/esm/general/boolean.js +16 -0
- package/dist/esm/general/boolean.js.map +1 -0
- package/dist/esm/general/clock.d.ts +12 -0
- package/dist/esm/general/clock.d.ts.map +1 -0
- package/dist/esm/general/clock.js +19 -0
- package/dist/esm/general/clock.js.map +1 -0
- package/dist/esm/general/dates/create.d.ts +54 -0
- package/dist/esm/general/dates/create.d.ts.map +1 -0
- package/dist/esm/general/dates/create.js +73 -0
- package/dist/esm/general/dates/create.js.map +1 -0
- package/dist/esm/general/dates/dates.d.ts +56 -0
- package/dist/esm/general/dates/dates.d.ts.map +1 -0
- package/dist/esm/general/dates/dates.js +82 -0
- package/dist/esm/general/dates/dates.js.map +1 -0
- package/dist/esm/general/dates/get.d.ts +41 -0
- package/dist/esm/general/dates/get.d.ts.map +1 -0
- package/dist/esm/general/dates/get.js +70 -0
- package/dist/esm/general/dates/get.js.map +1 -0
- package/dist/esm/general/dates/index.d.ts +4 -0
- package/dist/esm/general/dates/index.d.ts.map +1 -0
- package/dist/esm/general/dates/index.js +4 -0
- package/dist/esm/general/dates/index.js.map +1 -0
- package/dist/esm/general/forms.d.ts +17 -0
- package/dist/esm/general/forms.d.ts.map +1 -0
- package/dist/esm/general/forms.js +27 -0
- package/dist/esm/general/forms.js.map +1 -0
- package/dist/esm/general/images.d.ts +17 -0
- package/dist/esm/general/images.d.ts.map +1 -0
- package/dist/esm/general/images.js +20 -0
- package/dist/esm/general/images.js.map +1 -0
- package/dist/esm/general/index.d.ts +15 -0
- package/dist/esm/general/index.d.ts.map +1 -0
- package/dist/esm/general/index.js +15 -0
- package/dist/esm/general/index.js.map +1 -0
- package/dist/esm/general/localization.d.ts +83 -0
- package/dist/esm/general/localization.d.ts.map +1 -0
- package/dist/esm/general/localization.js +188 -0
- package/dist/esm/general/localization.js.map +1 -0
- package/dist/esm/general/maps.d.ts +35 -0
- package/dist/esm/general/maps.d.ts.map +1 -0
- package/dist/esm/general/maps.js +59 -0
- package/dist/esm/general/maps.js.map +1 -0
- package/dist/esm/general/messenger/createMessenger.d.ts +10 -0
- package/dist/esm/general/messenger/createMessenger.d.ts.map +1 -0
- package/dist/esm/general/messenger/createMessenger.js +65 -0
- package/dist/esm/general/messenger/createMessenger.js.map +1 -0
- package/dist/esm/general/messenger/index.d.ts +3 -0
- package/dist/esm/general/messenger/index.d.ts.map +1 -0
- package/dist/esm/general/messenger/index.js +3 -0
- package/dist/esm/general/messenger/index.js.map +1 -0
- package/dist/esm/general/messenger/types.d.ts +26 -0
- package/dist/esm/general/messenger/types.d.ts.map +1 -0
- package/dist/esm/general/messenger/types.js +2 -0
- package/dist/esm/general/messenger/types.js.map +1 -0
- package/dist/esm/general/namedEntities.d.ts +256 -0
- package/dist/esm/general/namedEntities.d.ts.map +1 -0
- package/dist/esm/general/namedEntities.js +257 -0
- package/dist/esm/general/namedEntities.js.map +1 -0
- package/dist/esm/general/numbers.d.ts +43 -0
- package/dist/esm/general/numbers.d.ts.map +1 -0
- package/dist/esm/general/numbers.js +87 -0
- package/dist/esm/general/numbers.js.map +1 -0
- package/dist/esm/general/objects.d.ts +45 -0
- package/dist/esm/general/objects.d.ts.map +1 -0
- package/dist/esm/general/objects.js +91 -0
- package/dist/esm/general/objects.js.map +1 -0
- package/dist/esm/general/sorting.d.ts +32 -0
- package/dist/esm/general/sorting.d.ts.map +1 -0
- package/dist/esm/general/sorting.js +67 -0
- package/dist/esm/general/sorting.js.map +1 -0
- package/dist/esm/general/string.d.ts +31 -0
- package/dist/esm/general/string.d.ts.map +1 -0
- package/dist/esm/general/string.js +68 -0
- package/dist/esm/general/string.js.map +1 -0
- package/dist/esm/general/timeout.d.ts +8 -0
- package/dist/esm/general/timeout.d.ts.map +1 -0
- package/dist/esm/general/timeout.js +14 -0
- package/dist/esm/general/timeout.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/node/index.d.ts +25 -0
- package/dist/esm/node/index.d.ts.map +1 -0
- package/dist/esm/node/index.js +27 -0
- package/dist/esm/node/index.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns localized day names of the week based on the specified format.
|
|
3
|
+
*
|
|
4
|
+
* @param format The format of the day names to return.
|
|
5
|
+
* @returns An array of localized day names.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDayNames(format: "long" | "narrow" | "short"): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Provides a way to retrieve the locale from the HTML document or fallback to a
|
|
10
|
+
* default locale if it is unable to determine the locale. It is useful for
|
|
11
|
+
* obtaining the language and region settings of the user's environment.
|
|
12
|
+
*
|
|
13
|
+
* @returns The locale of the HTML document or a default locale.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getLocale(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Provides a way to obtain a localized string representation of a currency
|
|
18
|
+
* value based on the specified value, utilizing a separate currencyFormatter
|
|
19
|
+
* object for the formatting process. It removes the currency code substring and
|
|
20
|
+
* trims any surrounding whitespace from the resulting string.
|
|
21
|
+
*
|
|
22
|
+
* @param value The currency value to be formatted.
|
|
23
|
+
* @returns A localized string representation of the currency value.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getLocalizedCurrency(value: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Provides a way to obtain a localized string representation of a date,
|
|
28
|
+
* including the month, day, and year, based on the specified format and
|
|
29
|
+
* locale.
|
|
30
|
+
*
|
|
31
|
+
* @param date The date to be formatted.
|
|
32
|
+
* @param forceLocale The locale to use for formatting the date. Defaults to the
|
|
33
|
+
* HTM language attribute.
|
|
34
|
+
* @returns A localized string representation of the date.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getLocalizedDate(date: Date | string, forceLocale?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Provides a way to obtain a localized string representation of a day based on
|
|
39
|
+
* the specified date and locale.
|
|
40
|
+
*
|
|
41
|
+
* @param date The date to be formatted.
|
|
42
|
+
* @param forceLocale The locale to use for formatting the day. Defaults to the
|
|
43
|
+
* HTML language attribute.
|
|
44
|
+
* @returns A localized string representation of the day.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getLocalizedDay(date: string, forceLocale?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Provides a way to obtain a localized string representation of a month based
|
|
49
|
+
* on the specified date and locale.
|
|
50
|
+
*
|
|
51
|
+
* @param date The date to be formatted.
|
|
52
|
+
* @param forceLocale The locale to use for formatting the month. Defaults to
|
|
53
|
+
* the HTML language attribute.
|
|
54
|
+
* @returns A localized string representation of the month.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getLocalizedMonth(date: string, forceLocale?: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* In summary, the getLocalizedQuantity function provides a way to obtain a
|
|
59
|
+
* localized string representation of a quantity based on the specified value,
|
|
60
|
+
* utilizing a separate quantityFormatter object for the formatting process.
|
|
61
|
+
*
|
|
62
|
+
* @param value The quantity value to be formatted.
|
|
63
|
+
* @returns A localized string representation of the quantity value.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getLocalizedQuantity(value: number): string;
|
|
66
|
+
/**
|
|
67
|
+
* Provides a way to obtain an array of localized month names based on the
|
|
68
|
+
* specified format.
|
|
69
|
+
*
|
|
70
|
+
* @param format The format of the month names to return.
|
|
71
|
+
* @returns An array of localized month names.
|
|
72
|
+
*/
|
|
73
|
+
export declare function getMonthNames(format?: "2-digit" | "long" | "narrow" | "numeric" | "short"): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Provides a way to obtain a localized string representation of an ordinal.
|
|
76
|
+
*
|
|
77
|
+
* @param date The date to be formatted.
|
|
78
|
+
* @param forceLocale The locale to use for formatting the ordinal. Defaults to
|
|
79
|
+
* the HTML language attribute.
|
|
80
|
+
* @returns A localized string representation of the ordinal.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getLocalizedOrdinal(date: string, forceLocale?: string): string;
|
|
83
|
+
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../../src/general/localization.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,EAAE,CAUzE;AACD;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAQlC;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GAClB,MAAM,CAQR;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAM1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAM5E;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,MAAM,GAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAgB,GAClE,MAAM,EAAE,CAUV;AA2CD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,MAAM,GAClB,MAAM,CAgBR"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { safeishGetProperty } from "./objects.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns localized day names of the week based on the specified format.
|
|
4
|
+
*
|
|
5
|
+
* @param format The format of the day names to return.
|
|
6
|
+
* @returns An array of localized day names.
|
|
7
|
+
*/
|
|
8
|
+
export function getDayNames(format) {
|
|
9
|
+
const formatter = new Intl.DateTimeFormat(getLocale(), {
|
|
10
|
+
timeZone: "UTC",
|
|
11
|
+
weekday: format,
|
|
12
|
+
});
|
|
13
|
+
const days = [1, 2, 3, 4, 5, 6, 7].map((day) => {
|
|
14
|
+
const dd = `0${String(day)}`;
|
|
15
|
+
return new Date(`2017-01-${dd}T00:00:00+00:00`);
|
|
16
|
+
});
|
|
17
|
+
return days.map((date) => formatter.format(date));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Provides a way to retrieve the locale from the HTML document or fallback to a
|
|
21
|
+
* default locale if it is unable to determine the locale. It is useful for
|
|
22
|
+
* obtaining the language and region settings of the user's environment.
|
|
23
|
+
*
|
|
24
|
+
* @returns The locale of the HTML document or a default locale.
|
|
25
|
+
*/
|
|
26
|
+
export function getLocale() {
|
|
27
|
+
if (typeof document === "undefined") {
|
|
28
|
+
return "en-US";
|
|
29
|
+
}
|
|
30
|
+
return (
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
32
|
+
document.getElementsByTagName("html")[0]?.getAttribute("lang") || "en-US");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Provides a way to obtain a localized string representation of a currency
|
|
36
|
+
* value based on the specified value, utilizing a separate currencyFormatter
|
|
37
|
+
* object for the formatting process. It removes the currency code substring and
|
|
38
|
+
* trims any surrounding whitespace from the resulting string.
|
|
39
|
+
*
|
|
40
|
+
* @param value The currency value to be formatted.
|
|
41
|
+
* @returns A localized string representation of the currency value.
|
|
42
|
+
*/
|
|
43
|
+
export function getLocalizedCurrency(value) {
|
|
44
|
+
return getCurrancyFormatter().format(value).replace("US", "").trim();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Provides a way to obtain a localized string representation of a date,
|
|
48
|
+
* including the month, day, and year, based on the specified format and
|
|
49
|
+
* locale.
|
|
50
|
+
*
|
|
51
|
+
* @param date The date to be formatted.
|
|
52
|
+
* @param forceLocale The locale to use for formatting the date. Defaults to the
|
|
53
|
+
* HTM language attribute.
|
|
54
|
+
* @returns A localized string representation of the date.
|
|
55
|
+
*/
|
|
56
|
+
export function getLocalizedDate(date, forceLocale) {
|
|
57
|
+
const formatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {
|
|
58
|
+
day: "numeric",
|
|
59
|
+
month: "long",
|
|
60
|
+
timeZone: "UTC",
|
|
61
|
+
year: "numeric",
|
|
62
|
+
});
|
|
63
|
+
return formatter.format(new Date(date));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Provides a way to obtain a localized string representation of a day based on
|
|
67
|
+
* the specified date and locale.
|
|
68
|
+
*
|
|
69
|
+
* @param date The date to be formatted.
|
|
70
|
+
* @param forceLocale The locale to use for formatting the day. Defaults to the
|
|
71
|
+
* HTML language attribute.
|
|
72
|
+
* @returns A localized string representation of the day.
|
|
73
|
+
*/
|
|
74
|
+
export function getLocalizedDay(date, forceLocale) {
|
|
75
|
+
const formatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {
|
|
76
|
+
timeZone: "UTC",
|
|
77
|
+
weekday: "long",
|
|
78
|
+
});
|
|
79
|
+
return formatter.format(new Date(date));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Provides a way to obtain a localized string representation of a month based
|
|
83
|
+
* on the specified date and locale.
|
|
84
|
+
*
|
|
85
|
+
* @param date The date to be formatted.
|
|
86
|
+
* @param forceLocale The locale to use for formatting the month. Defaults to
|
|
87
|
+
* the HTML language attribute.
|
|
88
|
+
* @returns A localized string representation of the month.
|
|
89
|
+
*/
|
|
90
|
+
export function getLocalizedMonth(date, forceLocale) {
|
|
91
|
+
const formatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {
|
|
92
|
+
month: "long",
|
|
93
|
+
timeZone: "UTC",
|
|
94
|
+
});
|
|
95
|
+
return formatter.format(new Date(date));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* In summary, the getLocalizedQuantity function provides a way to obtain a
|
|
99
|
+
* localized string representation of a quantity based on the specified value,
|
|
100
|
+
* utilizing a separate quantityFormatter object for the formatting process.
|
|
101
|
+
*
|
|
102
|
+
* @param value The quantity value to be formatted.
|
|
103
|
+
* @returns A localized string representation of the quantity value.
|
|
104
|
+
*/
|
|
105
|
+
export function getLocalizedQuantity(value) {
|
|
106
|
+
return getQuantityFormatter().format(value);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Provides a way to obtain an array of localized month names based on the
|
|
110
|
+
* specified format.
|
|
111
|
+
*
|
|
112
|
+
* @param format The format of the month names to return.
|
|
113
|
+
* @returns An array of localized month names.
|
|
114
|
+
*/
|
|
115
|
+
export function getMonthNames(format = "long") {
|
|
116
|
+
const formatter = new Intl.DateTimeFormat(getLocale(), {
|
|
117
|
+
month: format,
|
|
118
|
+
timeZone: "UTC",
|
|
119
|
+
});
|
|
120
|
+
const months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((month) => {
|
|
121
|
+
const mm = month < 10 ? `0${String(month)}` : month;
|
|
122
|
+
return new Date(`2017-${String(mm)}-01T00:00:00+00:00`);
|
|
123
|
+
});
|
|
124
|
+
return months.map((date) => formatter.format(date));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns a currency formatter object that can be used to format currency
|
|
128
|
+
* values.
|
|
129
|
+
*
|
|
130
|
+
* @returns A currency formatter object.
|
|
131
|
+
*/
|
|
132
|
+
function getCurrancyFormatter() {
|
|
133
|
+
return new Intl.NumberFormat(getLocale(), {
|
|
134
|
+
currency: "USD",
|
|
135
|
+
currencyDisplay: "symbol",
|
|
136
|
+
style: "currency",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns a quantity formatter object that can be used to format quantity
|
|
141
|
+
* values.
|
|
142
|
+
*
|
|
143
|
+
* @returns A quantity formatter object.
|
|
144
|
+
*/
|
|
145
|
+
function getQuantityFormatter() {
|
|
146
|
+
return new Intl.NumberFormat(getLocale());
|
|
147
|
+
}
|
|
148
|
+
const suffixes_en = {
|
|
149
|
+
few: "rd",
|
|
150
|
+
many: "th",
|
|
151
|
+
one: "st",
|
|
152
|
+
other: "th",
|
|
153
|
+
two: "nd",
|
|
154
|
+
zero: "",
|
|
155
|
+
};
|
|
156
|
+
const suffixes_fr = {
|
|
157
|
+
few: "e",
|
|
158
|
+
many: "e",
|
|
159
|
+
one: "er",
|
|
160
|
+
other: "e",
|
|
161
|
+
two: "e",
|
|
162
|
+
zero: "",
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Provides a way to obtain a localized string representation of an ordinal.
|
|
166
|
+
*
|
|
167
|
+
* @param date The date to be formatted.
|
|
168
|
+
* @param forceLocale The locale to use for formatting the ordinal. Defaults to
|
|
169
|
+
* the HTML language attribute.
|
|
170
|
+
* @returns A localized string representation of the ordinal.
|
|
171
|
+
*/
|
|
172
|
+
export function getLocalizedOrdinal(date, forceLocale) {
|
|
173
|
+
const locale = forceLocale ?? getLocale();
|
|
174
|
+
const ordinalFormatter = new Intl.PluralRules(locale, {
|
|
175
|
+
type: "ordinal",
|
|
176
|
+
});
|
|
177
|
+
const dateFormatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {
|
|
178
|
+
day: "numeric",
|
|
179
|
+
timeZone: "UTC",
|
|
180
|
+
});
|
|
181
|
+
const number = parseInt(dateFormatter.format(new Date(date)));
|
|
182
|
+
const category = ordinalFormatter.select(number);
|
|
183
|
+
const suffix = locale === "fr-CA"
|
|
184
|
+
? safeishGetProperty(suffixes_fr, category)
|
|
185
|
+
: safeishGetProperty(suffixes_en, category);
|
|
186
|
+
return String(number) + suffix;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../../../src/general/localization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmC;IAC9D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE;QACtD,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,MAAM;KACf,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC9C,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACnD,CAAC;AACD;;;;;;GAMG;AACH,MAAM,UAAU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IAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAChC,CAAC","sourcesContent":["import { safeishGetProperty } from \"./objects.js\";\n\n/**\n * Returns localized day names of the week based on the specified format.\n *\n * @param format The format of the day names to return.\n * @returns An array of localized day names.\n */\nexport function getDayNames(format: \"long\" | \"narrow\" | \"short\"): string[] {\n\tconst formatter = new Intl.DateTimeFormat(getLocale(), {\n\t\ttimeZone: \"UTC\",\n\t\tweekday: format,\n\t});\n\tconst days = [1, 2, 3, 4, 5, 6, 7].map((day) => {\n\t\tconst dd = `0${String(day)}`;\n\t\treturn new Date(`2017-01-${dd}T00:00:00+00:00`);\n\t});\n\treturn days.map((date) => formatter.format(date));\n}\n/**\n * Provides a way to retrieve the locale from the HTML document or fallback to a\n * default locale if it is unable to determine the locale. It is useful for\n * obtaining the language and region settings of the user's environment.\n *\n * @returns The locale of the HTML document or a default locale.\n */\nexport function getLocale(): string {\n\tif (typeof document === \"undefined\") {\n\t\treturn \"en-US\";\n\t}\n\treturn (\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\tdocument.getElementsByTagName(\"html\")[0]?.getAttribute(\"lang\") || \"en-US\"\n\t);\n}\n\n/**\n * Provides a way to obtain a localized string representation of a currency\n * value based on the specified value, utilizing a separate currencyFormatter\n * object for the formatting process. It removes the currency code substring and\n * trims any surrounding whitespace from the resulting string.\n *\n * @param value The currency value to be formatted.\n * @returns A localized string representation of the currency value.\n */\nexport function getLocalizedCurrency(value: number): string {\n\treturn getCurrancyFormatter().format(value).replace(\"US\", \"\").trim();\n}\n\n/**\n * Provides a way to obtain a localized string representation of a date,\n * including the month, day, and year, based on the specified format and\n * locale.\n *\n * @param date The date to be formatted.\n * @param forceLocale The locale to use for formatting the date. Defaults to the\n * HTM language attribute.\n * @returns A localized string representation of the date.\n */\nexport function getLocalizedDate(\n\tdate: Date | string,\n\tforceLocale?: string,\n): string {\n\tconst formatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {\n\t\tday: \"numeric\",\n\t\tmonth: \"long\",\n\t\ttimeZone: \"UTC\",\n\t\tyear: \"numeric\",\n\t});\n\treturn formatter.format(new Date(date));\n}\n\n/**\n * Provides a way to obtain a localized string representation of a day based on\n * the specified date and locale.\n *\n * @param date The date to be formatted.\n * @param forceLocale The locale to use for formatting the day. Defaults to the\n * HTML language attribute.\n * @returns A localized string representation of the day.\n */\nexport function getLocalizedDay(date: string, forceLocale?: string): string {\n\tconst formatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {\n\t\ttimeZone: \"UTC\",\n\t\tweekday: \"long\",\n\t});\n\treturn formatter.format(new Date(date));\n}\n\n/**\n * Provides a way to obtain a localized string representation of a month based\n * on the specified date and locale.\n *\n * @param date The date to be formatted.\n * @param forceLocale The locale to use for formatting the month. Defaults to\n * the HTML language attribute.\n * @returns A localized string representation of the month.\n */\nexport function getLocalizedMonth(date: string, forceLocale?: string): string {\n\tconst formatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {\n\t\tmonth: \"long\",\n\t\ttimeZone: \"UTC\",\n\t});\n\treturn formatter.format(new Date(date));\n}\n\n/**\n * In summary, the getLocalizedQuantity function provides a way to obtain a\n * localized string representation of a quantity based on the specified value,\n * utilizing a separate quantityFormatter object for the formatting process.\n *\n * @param value The quantity value to be formatted.\n * @returns A localized string representation of the quantity value.\n */\nexport function getLocalizedQuantity(value: number): string {\n\treturn getQuantityFormatter().format(value);\n}\n\n/**\n * Provides a way to obtain an array of localized month names based on the\n * specified format.\n *\n * @param format The format of the month names to return.\n * @returns An array of localized month names.\n */\nexport function getMonthNames(\n\tformat: \"2-digit\" | \"long\" | \"narrow\" | \"numeric\" | \"short\" = \"long\",\n): string[] {\n\tconst formatter = new Intl.DateTimeFormat(getLocale(), {\n\t\tmonth: format,\n\t\ttimeZone: \"UTC\",\n\t});\n\tconst months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((month) => {\n\t\tconst mm = month < 10 ? `0${String(month)}` : month;\n\t\treturn new Date(`2017-${String(mm)}-01T00:00:00+00:00`);\n\t});\n\treturn months.map((date) => formatter.format(date));\n}\n\n/**\n * Returns a currency formatter object that can be used to format currency\n * values.\n *\n * @returns A currency formatter object.\n */\nfunction getCurrancyFormatter(): Intl.NumberFormat {\n\treturn new Intl.NumberFormat(getLocale(), {\n\t\tcurrency: \"USD\",\n\t\tcurrencyDisplay: \"symbol\",\n\t\tstyle: \"currency\",\n\t});\n}\n\n/**\n * Returns a quantity formatter object that can be used to format quantity\n * values.\n *\n * @returns A quantity formatter object.\n */\nfunction getQuantityFormatter(): Intl.NumberFormat {\n\treturn new Intl.NumberFormat(getLocale());\n}\n\nconst suffixes_en = {\n\tfew: \"rd\",\n\tmany: \"th\",\n\tone: \"st\",\n\tother: \"th\",\n\ttwo: \"nd\",\n\tzero: \"\",\n};\nconst suffixes_fr = {\n\tfew: \"e\",\n\tmany: \"e\",\n\tone: \"er\",\n\tother: \"e\",\n\ttwo: \"e\",\n\tzero: \"\",\n};\n\n/**\n * Provides a way to obtain a localized string representation of an ordinal.\n *\n * @param date The date to be formatted.\n * @param forceLocale The locale to use for formatting the ordinal. Defaults to\n * the HTML language attribute.\n * @returns A localized string representation of the ordinal.\n */\nexport function getLocalizedOrdinal(\n\tdate: string,\n\tforceLocale?: string,\n): string {\n\tconst locale = forceLocale ?? getLocale();\n\tconst ordinalFormatter = new Intl.PluralRules(locale, {\n\t\ttype: \"ordinal\",\n\t});\n\tconst dateFormatter = new Intl.DateTimeFormat(forceLocale ?? getLocale(), {\n\t\tday: \"numeric\",\n\t\ttimeZone: \"UTC\",\n\t});\n\tconst number = parseInt(dateFormatter.format(new Date(date)));\n\tconst category = ordinalFormatter.select(number);\n\tconst suffix =\n\t\tlocale === \"fr-CA\"\n\t\t\t? safeishGetProperty(suffixes_fr, category)\n\t\t\t: safeishGetProperty(suffixes_en, category);\n\treturn String(number) + suffix;\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array in the map at the given key if it doesn't exist, or appends
|
|
3
|
+
* to the existing one if it does.
|
|
4
|
+
*
|
|
5
|
+
* @template TData The type of the data items.
|
|
6
|
+
* @template TKey The type of the key in the map.
|
|
7
|
+
* @param map The map to modify.
|
|
8
|
+
* @param id The key at which to append or create the array.
|
|
9
|
+
* @param item The data item to append.
|
|
10
|
+
*/
|
|
11
|
+
export declare function appendOrCreate<TData, TKey>(map: Map<TKey, TData[]>, id: TKey, item: TData): void;
|
|
12
|
+
/**
|
|
13
|
+
* Groups an input item into a map, transforming a property from the input into
|
|
14
|
+
* a child array on the map item.
|
|
15
|
+
*
|
|
16
|
+
* @template TKey The type of the key in the map.
|
|
17
|
+
* @template TChildItem The type of the child item (e.g., `number`).
|
|
18
|
+
* @template TInputChildKey The key on the input item (e.g., `"item"`).
|
|
19
|
+
* @template TMapChildKey The key on the map item (e.g., `"items"`).
|
|
20
|
+
* @template TBase The base object type (e.g., `{ name: string }`).
|
|
21
|
+
* @template TInputItem The full input item type (e.g., `{ name: string; item:
|
|
22
|
+
* number }`).
|
|
23
|
+
* @template TMapItem The full map item type (e.g., `{ name: string; items:
|
|
24
|
+
* number[] }`).
|
|
25
|
+
* @param map The map to modify.
|
|
26
|
+
* @param id The key at which to find or create the parent entry.
|
|
27
|
+
* @param item The raw input item to process.
|
|
28
|
+
* @param childKey The property key on `item` to get the child value from.
|
|
29
|
+
* @param childrenFieldName The property key on the _map's_ item to push the
|
|
30
|
+
* child value into.
|
|
31
|
+
* @throws {Error} Will throw an error if `childrenFieldName` does not point to
|
|
32
|
+
* an array on an existing map item.
|
|
33
|
+
*/
|
|
34
|
+
export declare function appendOrCreateWithChildren<TKey, TChildItem, TInputChildKey extends PropertyKey, TMapChildKey extends PropertyKey, TBase extends object, TInputItem extends Record<TInputChildKey, TChildItem> & TBase, TMapItem extends Record<TMapChildKey, TChildItem[]> & TBase>(map: Map<TKey, TMapItem>, id: TKey, item: TInputItem, childKey: TInputChildKey, childrenFieldName: TMapChildKey): void;
|
|
35
|
+
//# sourceMappingURL=maps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maps.d.ts","sourceRoot":"","sources":["../../../src/general/maps.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,EACzC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EACvB,EAAE,EAAE,IAAI,EACR,IAAI,EAAE,KAAK,GACT,IAAI,CAON;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EACJ,UAAU,EACV,cAAc,SAAS,WAAW,EAClC,YAAY,SAAS,WAAW,EAChC,KAAK,SAAS,MAAM,EACpB,UAAU,SAAS,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,GAAG,KAAK,EAC7D,QAAQ,SAAS,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE,CAAC,GAAG,KAAK,EAE3D,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,EACxB,EAAE,EAAE,IAAI,EACR,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,cAAc,EACxB,iBAAiB,EAAE,YAAY,GAC7B,IAAI,CAgBN"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { safeishGetProperty } from "./objects.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array in the map at the given key if it doesn't exist, or appends
|
|
4
|
+
* to the existing one if it does.
|
|
5
|
+
*
|
|
6
|
+
* @template TData The type of the data items.
|
|
7
|
+
* @template TKey The type of the key in the map.
|
|
8
|
+
* @param map The map to modify.
|
|
9
|
+
* @param id The key at which to append or create the array.
|
|
10
|
+
* @param item The data item to append.
|
|
11
|
+
*/
|
|
12
|
+
export function appendOrCreate(map, id, item) {
|
|
13
|
+
const existing = map.get(id);
|
|
14
|
+
if (!existing) {
|
|
15
|
+
map.set(id, [item]);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
existing.push(item);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Groups an input item into a map, transforming a property from the input into
|
|
23
|
+
* a child array on the map item.
|
|
24
|
+
*
|
|
25
|
+
* @template TKey The type of the key in the map.
|
|
26
|
+
* @template TChildItem The type of the child item (e.g., `number`).
|
|
27
|
+
* @template TInputChildKey The key on the input item (e.g., `"item"`).
|
|
28
|
+
* @template TMapChildKey The key on the map item (e.g., `"items"`).
|
|
29
|
+
* @template TBase The base object type (e.g., `{ name: string }`).
|
|
30
|
+
* @template TInputItem The full input item type (e.g., `{ name: string; item:
|
|
31
|
+
* number }`).
|
|
32
|
+
* @template TMapItem The full map item type (e.g., `{ name: string; items:
|
|
33
|
+
* number[] }`).
|
|
34
|
+
* @param map The map to modify.
|
|
35
|
+
* @param id The key at which to find or create the parent entry.
|
|
36
|
+
* @param item The raw input item to process.
|
|
37
|
+
* @param childKey The property key on `item` to get the child value from.
|
|
38
|
+
* @param childrenFieldName The property key on the _map's_ item to push the
|
|
39
|
+
* child value into.
|
|
40
|
+
* @throws {Error} Will throw an error if `childrenFieldName` does not point to
|
|
41
|
+
* an array on an existing map item.
|
|
42
|
+
*/
|
|
43
|
+
export function appendOrCreateWithChildren(map, id, item, childKey, childrenFieldName) {
|
|
44
|
+
const existing = map.get(id);
|
|
45
|
+
const childItem = safeishGetProperty(item, childKey);
|
|
46
|
+
if (!existing) {
|
|
47
|
+
const { [childKey]: _discard, ...base } = item;
|
|
48
|
+
const newMapItem = {
|
|
49
|
+
...base,
|
|
50
|
+
[childrenFieldName]: [childItem],
|
|
51
|
+
};
|
|
52
|
+
map.set(id, newMapItem);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const childArray = safeishGetProperty(existing, childrenFieldName);
|
|
56
|
+
childArray.push(childItem);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|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;IAC5B,CAAC;AACF,CAAC","sourcesContent":["import { safeishGetProperty } from \"./objects.js\";\n\n/**\n * Creates an array in the map at the given key if it doesn't exist, or appends\n * to the existing one if it does.\n *\n * @template TData The type of the data items.\n * @template TKey The type of the key in the map.\n * @param map The map to modify.\n * @param id The key at which to append or create the array.\n * @param item The data item to append.\n */\nexport function appendOrCreate<TData, TKey>(\n\tmap: Map<TKey, TData[]>,\n\tid: TKey,\n\titem: TData,\n): void {\n\tconst existing = map.get(id);\n\tif (!existing) {\n\t\tmap.set(id, [item]);\n\t} else {\n\t\texisting.push(item);\n\t}\n}\n\n/**\n * Groups an input item into a map, transforming a property from the input into\n * a child array on the map item.\n *\n * @template TKey The type of the key in the map.\n * @template TChildItem The type of the child item (e.g., `number`).\n * @template TInputChildKey The key on the input item (e.g., `\"item\"`).\n * @template TMapChildKey The key on the map item (e.g., `\"items\"`).\n * @template TBase The base object type (e.g., `{ name: string }`).\n * @template TInputItem The full input item type (e.g., `{ name: string; item:\n * number }`).\n * @template TMapItem The full map item type (e.g., `{ name: string; items:\n * number[] }`).\n * @param map The map to modify.\n * @param id The key at which to find or create the parent entry.\n * @param item The raw input item to process.\n * @param childKey The property key on `item` to get the child value from.\n * @param childrenFieldName The property key on the _map's_ item to push the\n * child value into.\n * @throws {Error} Will throw an error if `childrenFieldName` does not point to\n * an array on an existing map item.\n */\nexport function appendOrCreateWithChildren<\n\tTKey,\n\tTChildItem,\n\tTInputChildKey extends PropertyKey,\n\tTMapChildKey extends PropertyKey,\n\tTBase extends object,\n\tTInputItem extends Record<TInputChildKey, TChildItem> & TBase,\n\tTMapItem extends Record<TMapChildKey, TChildItem[]> & TBase,\n>(\n\tmap: Map<TKey, TMapItem>,\n\tid: TKey,\n\titem: TInputItem,\n\tchildKey: TInputChildKey,\n\tchildrenFieldName: TMapChildKey,\n): void {\n\tconst existing = map.get(id);\n\tconst childItem = safeishGetProperty(item, childKey);\n\n\tif (!existing) {\n\t\tconst { [childKey]: _discard, ...base } = item;\n\n\t\tconst newMapItem = {\n\t\t\t...(base as TBase),\n\t\t\t[childrenFieldName]: [childItem],\n\t\t} as TMapItem;\n\t\tmap.set(id, newMapItem);\n\t} else {\n\t\tconst childArray = safeishGetProperty(existing, childrenFieldName);\n\t\tchildArray.push(childItem);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MessengerFactory } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for creating a de-bounced/throttled message function.
|
|
4
|
+
*
|
|
5
|
+
* @template T The successful result data type.
|
|
6
|
+
* @param params See MessengerFactory for parameters.
|
|
7
|
+
* @returns The update status function.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMessenger<T>(...params: Parameters<MessengerFactory<T>>): ReturnType<MessengerFactory<T>>;
|
|
10
|
+
//# sourceMappingURL=createMessenger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMessenger.d.ts","sourceRoot":"","sources":["../../../../src/general/messenger/createMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,YAAY,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAChC,GAAG,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACxC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAgEjC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating a de-bounced/throttled message function.
|
|
3
|
+
*
|
|
4
|
+
* @template T The successful result data type.
|
|
5
|
+
* @param params See MessengerFactory for parameters.
|
|
6
|
+
* @returns The update status function.
|
|
7
|
+
*/
|
|
8
|
+
export function createMessenger(...params) {
|
|
9
|
+
const [postMessage, options = {}] = params;
|
|
10
|
+
const { statusTimeout = 100 } = options;
|
|
11
|
+
let timeout;
|
|
12
|
+
let lastMessage = null;
|
|
13
|
+
let lastSent = 0;
|
|
14
|
+
const post = (message) => {
|
|
15
|
+
lastSent = Date.now();
|
|
16
|
+
postMessage(message);
|
|
17
|
+
};
|
|
18
|
+
const clearPending = () => {
|
|
19
|
+
lastMessage = null;
|
|
20
|
+
if (timeout) {
|
|
21
|
+
clearTimeout(timeout);
|
|
22
|
+
timeout = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const updateStatus = (status, force = false) => {
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
lastMessage = status;
|
|
28
|
+
// Immediately send if enough time has passed since last send
|
|
29
|
+
if (force || now - lastSent >= statusTimeout) {
|
|
30
|
+
clearPending();
|
|
31
|
+
post({ status });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Schedule next possible send if not already scheduled
|
|
35
|
+
if (!timeout) {
|
|
36
|
+
const timeSinceLast = now - lastSent;
|
|
37
|
+
const delay = Math.max(statusTimeout - timeSinceLast, 0);
|
|
38
|
+
timeout = setTimeout(() => {
|
|
39
|
+
if (lastMessage) {
|
|
40
|
+
post({ status: lastMessage });
|
|
41
|
+
lastMessage = null;
|
|
42
|
+
}
|
|
43
|
+
timeout = null;
|
|
44
|
+
}, delay);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const sendError = (e) => {
|
|
48
|
+
// Make sure the last thing to happen is communicated to the client.
|
|
49
|
+
if (lastMessage)
|
|
50
|
+
updateStatus(lastMessage, true);
|
|
51
|
+
clearPending();
|
|
52
|
+
if (e instanceof Error) {
|
|
53
|
+
post({ error: e.message });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
post({ error: String(e) });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const sendSuccess = (data) => {
|
|
60
|
+
clearPending();
|
|
61
|
+
post({ data });
|
|
62
|
+
};
|
|
63
|
+
return { sendError, sendSuccess, updateStatus };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=createMessenger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMessenger.js","sourceRoot":"","sources":["../../../../src/general/messenger/createMessenger.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC9B,GAAG,MAAuC;IAE1C,MAAM,CAAC,WAAW,EAAE,OAAO,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,aAAa,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;IACxC,IAAI,OAA6C,CAAC;IAClD,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAM,IAAI,GAAG,CAAC,OAAyB,EAAE,EAAE;QAC1C,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACtB,WAAW,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC,CAAC;IAEF,MAAM,YAAY,GAAG,GAAG,EAAE;QACzB,WAAW,GAAG,IAAI,CAAC;QACnB,IAAI,OAAO,EAAE,CAAC;YACb,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,IAAI,CAAC;QAChB,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,YAAY,GAAoD,CACrE,MAAM,EACN,KAAK,GAAG,KAAK,EACZ,EAAE;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,WAAW,GAAG,MAAM,CAAC;QAErB,6DAA6D;QAC7D,IAAI,KAAK,IAAI,GAAG,GAAG,QAAQ,IAAI,aAAa,EAAE,CAAC;YAC9C,YAAY,EAAE,CAAC;YACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YACjB,OAAO;QACR,CAAC;QAED,uDAAuD;QACvD,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,MAAM,aAAa,GAAG,GAAG,GAAG,QAAQ,CAAC;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,aAAa,EAAE,CAAC,CAAC,CAAC;YAEzD,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzB,IAAI,WAAW,EAAE,CAAC;oBACjB,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;oBAC9B,WAAW,GAAG,IAAI,CAAC;gBACpB,CAAC;gBACD,OAAO,GAAG,IAAI,CAAC;YAChB,CAAC,EAAE,KAAK,CAAC,CAAC;QACX,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,CAAU,EAAE,EAAE;QAChC,oEAAoE;QACpE,IAAI,WAAW;YAAE,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACjD,YAAY,EAAE,CAAC;QACf,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,CAAC,IAAO,EAAE,EAAE;QAC/B,YAAY,EAAE,CAAC;QACf,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;AACjD,CAAC","sourcesContent":["import type { MessengerFactory, WorkerMessage } from \"./types.js\";\n\n/**\n * Factory for creating a de-bounced/throttled message function.\n *\n * @template T The successful result data type.\n * @param params See MessengerFactory for parameters.\n * @returns The update status function.\n */\nexport function createMessenger<T>(\n\t...params: Parameters<MessengerFactory<T>>\n): ReturnType<MessengerFactory<T>> {\n\tconst [postMessage, options = {}] = params;\n\tconst { statusTimeout = 100 } = options;\n\tlet timeout: null | ReturnType<typeof setTimeout>;\n\tlet lastMessage: null | string = null;\n\tlet lastSent = 0;\n\tconst post = (message: WorkerMessage<T>) => {\n\t\tlastSent = Date.now();\n\t\tpostMessage(message);\n\t};\n\n\tconst clearPending = () => {\n\t\tlastMessage = null;\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = null;\n\t\t}\n\t};\n\n\tconst updateStatus: ReturnType<MessengerFactory<T>>[\"updateStatus\"] = (\n\t\tstatus,\n\t\tforce = false,\n\t) => {\n\t\tconst now = Date.now();\n\t\tlastMessage = status;\n\n\t\t// Immediately send if enough time has passed since last send\n\t\tif (force || now - lastSent >= statusTimeout) {\n\t\t\tclearPending();\n\t\t\tpost({ status });\n\t\t\treturn;\n\t\t}\n\n\t\t// Schedule next possible send if not already scheduled\n\t\tif (!timeout) {\n\t\t\tconst timeSinceLast = now - lastSent;\n\t\t\tconst delay = Math.max(statusTimeout - timeSinceLast, 0);\n\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tif (lastMessage) {\n\t\t\t\t\tpost({ status: lastMessage });\n\t\t\t\t\tlastMessage = null;\n\t\t\t\t}\n\t\t\t\ttimeout = null;\n\t\t\t}, delay);\n\t\t}\n\t};\n\n\tconst sendError = (e: unknown) => {\n\t\t// Make sure the last thing to happen is communicated to the client.\n\t\tif (lastMessage) updateStatus(lastMessage, true);\n\t\tclearPending();\n\t\tif (e instanceof Error) {\n\t\t\tpost({ error: e.message });\n\t\t} else {\n\t\t\tpost({ error: String(e) });\n\t\t}\n\t};\n\n\tconst sendSuccess = (data: T) => {\n\t\tclearPending();\n\t\tpost({ data });\n\t};\n\treturn { sendError, sendSuccess, updateStatus };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/general/messenger/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/general/messenger/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./createMessenger.js\";\nexport * from \"./types.js\";\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function for creating a messenger that uses the self.postMessage function
|
|
3
|
+
* for sending messages between workers.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of a successful result.
|
|
6
|
+
* @param postMessage The self.postMessage function.
|
|
7
|
+
* @param options The options for the messenger.
|
|
8
|
+
* @returns UpdateStatus, sendSuccess, and sendError functions.
|
|
9
|
+
*/
|
|
10
|
+
export type MessengerFactory<T> = (postMessage: PostMessageFunction, options?: MessengerOptions) => {
|
|
11
|
+
sendError: (error: unknown) => void;
|
|
12
|
+
sendSuccess: (data: T) => void;
|
|
13
|
+
updateStatus: (status: string, force?: boolean) => void;
|
|
14
|
+
};
|
|
15
|
+
export type MessengerOptions = {
|
|
16
|
+
statusTimeout?: number;
|
|
17
|
+
};
|
|
18
|
+
export type PostMessageFunction = (typeof self)["postMessage"];
|
|
19
|
+
export type WorkerMessage<T> = {
|
|
20
|
+
data: T;
|
|
21
|
+
} | {
|
|
22
|
+
error: string;
|
|
23
|
+
} | {
|
|
24
|
+
status: string;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/general/messenger/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CACjC,WAAW,EAAE,mBAAmB,EAChC,OAAO,CAAC,EAAE,gBAAgB,KACtB;IACJ,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC/B,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC;AAE/D,MAAM,MAAM,aAAa,CAAC,CAAC,IACxB;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GACX;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/general/messenger/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * A function for creating a messenger that uses the self.postMessage function\n * for sending messages between workers.\n *\n * @template T The type of a successful result.\n * @param postMessage The self.postMessage function.\n * @param options The options for the messenger.\n * @returns UpdateStatus, sendSuccess, and sendError functions.\n */\nexport type MessengerFactory<T> = (\n\tpostMessage: PostMessageFunction,\n\toptions?: MessengerOptions,\n) => {\n\tsendError: (error: unknown) => void;\n\tsendSuccess: (data: T) => void;\n\tupdateStatus: (status: string, force?: boolean) => void;\n};\n\nexport type MessengerOptions = { statusTimeout?: number };\n\nexport type PostMessageFunction = (typeof self)[\"postMessage\"];\n\nexport type WorkerMessage<T> =\n\t| { data: T }\n\t| { error: string }\n\t| { status: string };\n"]}
|