@samline/date 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/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/browser/global.d.ts +13 -0
- package/dist/browser/global.js +153 -0
- package/dist/browser/global.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.js +166 -0
- package/dist/react/index.js.map +1 -0
- package/dist/svelte/index.d.ts +19 -0
- package/dist/svelte/index.js +169 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vanilla/index.d.ts +1 -0
- package/dist/vanilla/index.js +146 -0
- package/dist/vanilla/index.js.map +1 -0
- package/dist/vue/index.d.ts +16 -0
- package/dist/vue/index.js +167 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/react/index.ts
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// src/core/date.ts
|
|
5
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
|
|
8
|
+
// src/core/locales.ts
|
|
9
|
+
var SUPPORTED_LOCALES = [
|
|
10
|
+
"en",
|
|
11
|
+
"es",
|
|
12
|
+
"es-mx",
|
|
13
|
+
"fr",
|
|
14
|
+
"pt",
|
|
15
|
+
"pt-br",
|
|
16
|
+
"de",
|
|
17
|
+
"it",
|
|
18
|
+
"ja"
|
|
19
|
+
];
|
|
20
|
+
var localeLoaders = {
|
|
21
|
+
en: null,
|
|
22
|
+
es: () => import("dayjs/locale/es.js"),
|
|
23
|
+
"es-mx": () => import("dayjs/locale/es-mx.js"),
|
|
24
|
+
fr: () => import("dayjs/locale/fr.js"),
|
|
25
|
+
pt: () => import("dayjs/locale/pt.js"),
|
|
26
|
+
"pt-br": () => import("dayjs/locale/pt-br.js"),
|
|
27
|
+
de: () => import("dayjs/locale/de.js"),
|
|
28
|
+
it: () => import("dayjs/locale/it.js"),
|
|
29
|
+
ja: () => import("dayjs/locale/ja.js")
|
|
30
|
+
};
|
|
31
|
+
var isSupportedLocale = (locale) => {
|
|
32
|
+
return SUPPORTED_LOCALES.includes(locale);
|
|
33
|
+
};
|
|
34
|
+
var ensureLocaleLoaded = async (locale) => {
|
|
35
|
+
const load = localeLoaders[locale];
|
|
36
|
+
if (!load) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await load();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/core/date.ts
|
|
43
|
+
dayjs.extend(customParseFormat);
|
|
44
|
+
dayjs.locale("en");
|
|
45
|
+
var DEFAULT_FORMAT = "YYYY-MM-DD";
|
|
46
|
+
var DEFAULT_LOCALE = "en";
|
|
47
|
+
var DEFAULT_INVALID_DATE = "Invalid Date";
|
|
48
|
+
var getInvalidDateText = (config, props) => {
|
|
49
|
+
return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE;
|
|
50
|
+
};
|
|
51
|
+
var getTargetLocale = (currentLocale, props) => {
|
|
52
|
+
return props?.locale ?? currentLocale;
|
|
53
|
+
};
|
|
54
|
+
var parseDateValue = (value, input, locale, strict) => {
|
|
55
|
+
if (!input) {
|
|
56
|
+
return dayjs(value).locale(locale);
|
|
57
|
+
}
|
|
58
|
+
if (typeof input === "string") {
|
|
59
|
+
return dayjs(value, input, locale, strict).locale(locale);
|
|
60
|
+
}
|
|
61
|
+
return dayjs(value, [...input], locale, strict).locale(locale);
|
|
62
|
+
};
|
|
63
|
+
var createFormatterParseDate = (getConfig) => {
|
|
64
|
+
return (props) => {
|
|
65
|
+
const config = getConfig();
|
|
66
|
+
const locale = getTargetLocale(config.locale, props);
|
|
67
|
+
const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict);
|
|
68
|
+
if (!parsed.isValid()) {
|
|
69
|
+
return {
|
|
70
|
+
isValid: false,
|
|
71
|
+
locale,
|
|
72
|
+
date: null,
|
|
73
|
+
iso: null,
|
|
74
|
+
timestamp: null,
|
|
75
|
+
error: getInvalidDateText(config, props)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
isValid: true,
|
|
80
|
+
locale,
|
|
81
|
+
date: parsed.toDate(),
|
|
82
|
+
iso: parsed.toISOString(),
|
|
83
|
+
timestamp: parsed.valueOf(),
|
|
84
|
+
format: (output = DEFAULT_FORMAT) => parsed.format(output)
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var createFormatterIsValidDate = (parseDate) => {
|
|
89
|
+
return (props) => parseDate(props).isValid;
|
|
90
|
+
};
|
|
91
|
+
var createFormatterGetDate = (getConfig) => {
|
|
92
|
+
const parseDate = createFormatterParseDate(getConfig);
|
|
93
|
+
return (props) => {
|
|
94
|
+
const config = getConfig();
|
|
95
|
+
const locale = getTargetLocale(config.locale, props);
|
|
96
|
+
const output = props?.output ?? DEFAULT_FORMAT;
|
|
97
|
+
if (!props) {
|
|
98
|
+
return dayjs().locale(locale).format(DEFAULT_FORMAT);
|
|
99
|
+
}
|
|
100
|
+
if (props.date === void 0) {
|
|
101
|
+
return dayjs().locale(locale).format(output);
|
|
102
|
+
}
|
|
103
|
+
const parsed = parseDate({
|
|
104
|
+
date: props.date,
|
|
105
|
+
input: props.input,
|
|
106
|
+
locale: props.locale,
|
|
107
|
+
strict: props.strict
|
|
108
|
+
});
|
|
109
|
+
if (!parsed.isValid) {
|
|
110
|
+
return props.invalid ?? parsed.error;
|
|
111
|
+
}
|
|
112
|
+
return parsed.format(output);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
function assertSupportedLocale(locale) {
|
|
116
|
+
if (!isSupportedLocale(locale)) {
|
|
117
|
+
throw new Error(`Unsupported locale: ${locale}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var getSupportedLocales = () => SUPPORTED_LOCALES;
|
|
121
|
+
var createDateFormatter = (config) => {
|
|
122
|
+
let currentLocale = config?.locale ?? DEFAULT_LOCALE;
|
|
123
|
+
const getConfig = () => ({
|
|
124
|
+
locale: currentLocale,
|
|
125
|
+
strict: config?.strict ?? false,
|
|
126
|
+
invalid: config?.invalid ?? DEFAULT_INVALID_DATE
|
|
127
|
+
});
|
|
128
|
+
const ready = ensureLocaleLoaded(currentLocale);
|
|
129
|
+
const parseDate = createFormatterParseDate(getConfig);
|
|
130
|
+
return {
|
|
131
|
+
getDate: createFormatterGetDate(getConfig),
|
|
132
|
+
parseDate,
|
|
133
|
+
isValidDate: createFormatterIsValidDate(parseDate),
|
|
134
|
+
getSupportedLocales,
|
|
135
|
+
getCurrentLocale: () => currentLocale,
|
|
136
|
+
setLocale: async (locale) => {
|
|
137
|
+
assertSupportedLocale(locale);
|
|
138
|
+
await ensureLocaleLoaded(locale);
|
|
139
|
+
currentLocale = locale;
|
|
140
|
+
},
|
|
141
|
+
ready
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/react/index.ts
|
|
146
|
+
var useDateFormatter = (options) => {
|
|
147
|
+
const formatterRef = useRef(createDateFormatter(options));
|
|
148
|
+
const [locale, setLocaleState] = useState(formatterRef.current.getCurrentLocale());
|
|
149
|
+
return {
|
|
150
|
+
locale,
|
|
151
|
+
currentLocale: locale,
|
|
152
|
+
getDate: (props) => formatterRef.current.getDate(props),
|
|
153
|
+
parseDate: (props) => formatterRef.current.parseDate(props),
|
|
154
|
+
isValidDate: (props) => formatterRef.current.isValidDate(props),
|
|
155
|
+
getSupportedLocales,
|
|
156
|
+
ready: formatterRef.current.ready,
|
|
157
|
+
setLocale: async (nextLocale) => {
|
|
158
|
+
await formatterRef.current.setLocale(nextLocale);
|
|
159
|
+
setLocaleState(nextLocale);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
export {
|
|
164
|
+
useDateFormatter
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts","../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import { useRef, useState } from 'react'\n\nimport {\n createDateFormatter,\n getSupportedLocales,\n type DateFormatterConfig,\n type DateParsingOptions,\n type GetDateOptions,\n type SupportedLocale\n} from '../index.js'\n\nexport type UseDateFormatterOptions = DateFormatterConfig\n\nexport const useDateFormatter = (options?: UseDateFormatterOptions) => {\n const formatterRef = useRef(createDateFormatter(options))\n const [locale, setLocaleState] = useState<SupportedLocale>(formatterRef.current.getCurrentLocale())\n\n return {\n locale,\n currentLocale: locale,\n getDate: (props?: GetDateOptions) => formatterRef.current.getDate(props),\n parseDate: (props: DateParsingOptions) => formatterRef.current.parseDate(props),\n isValidDate: (props: DateParsingOptions) => formatterRef.current.isValidDate(props),\n getSupportedLocales,\n ready: formatterRef.current.ready,\n setLocale: async (nextLocale: SupportedLocale) => {\n await formatterRef.current.setLocale(nextLocale)\n setLocaleState(nextLocale)\n }\n }\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, isSupportedLocale, SUPPORTED_LOCALES, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: SupportedLocale\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: SupportedLocale\n strict?: boolean\n invalid?: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: SupportedLocale) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n return props?.locale ?? currentLocale\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => Required<DateFormatterConfig>) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => Required<DateFormatterConfig>) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction assertSupportedLocale(locale: string): asserts locale is SupportedLocale {\n if (!isSupportedLocale(locale)) {\n throw new Error(`Unsupported locale: ${locale}`)\n }\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ?? DEFAULT_LOCALE\n\n const getConfig = (): Required<DateFormatterConfig> => ({\n locale: currentLocale,\n strict: config?.strict ?? false,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n })\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: SupportedLocale) => {\n assertSupportedLocale(locale)\n await ensureLocaleLoaded(locale)\n currentLocale = locale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nexport const isSupportedLocale = (locale: string): locale is SupportedLocale => {\n return SUPPORTED_LOCALES.includes(locale as SupportedLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n"],"mappings":";AAAA,SAAS,QAAQ,gBAAgB;;;ACAjC,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEO,IAAM,oBAAoB,CAAC,WAA8C;AAC9E,SAAO,kBAAkB,SAAS,MAAyB;AAC7D;AAEO,IAAM,qBAAqB,OAAO,WAA2C;AAClF,QAAM,OAAO,cAAc,MAAM;AAEjC,MAAI,CAAC,MAAM;AACT;AAAA,EACF;AAEA,QAAM,KAAK;AACb;;;ADhCA,MAAM,OAAO,iBAAiB;AAC9B,MAAM,OAAO,IAAI;AAwDjB,I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B,YAAM,mBAAmB,MAAM;AAC/B,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;;;AD/KO,IAAM,mBAAmB,CAAC,YAAsC;AACrE,QAAM,eAAe,OAAO,oBAAoB,OAAO,CAAC;AACxD,QAAM,CAAC,QAAQ,cAAc,IAAI,SAA0B,aAAa,QAAQ,iBAAiB,CAAC;AAElG,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,IACf,SAAS,CAAC,UAA2B,aAAa,QAAQ,QAAQ,KAAK;AAAA,IACvE,WAAW,CAAC,UAA8B,aAAa,QAAQ,UAAU,KAAK;AAAA,IAC9E,aAAa,CAAC,UAA8B,aAAa,QAAQ,YAAY,KAAK;AAAA,IAClF;AAAA,IACA,OAAO,aAAa,QAAQ;AAAA,IAC5B,WAAW,OAAO,eAAgC;AAChD,YAAM,aAAa,QAAQ,UAAU,UAAU;AAC/C,qBAAe,UAAU;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateFormatterConfig, GetDateOptions, DateParsingOptions, ParseDateResult, SupportedLocale } from '../index.js';
|
|
2
|
+
import * as svelte_store from 'svelte/store';
|
|
3
|
+
|
|
4
|
+
type CreateDateFormatterStoreOptions = DateFormatterConfig;
|
|
5
|
+
declare const createDateFormatterStore: (options?: CreateDateFormatterStoreOptions) => {
|
|
6
|
+
locale: {
|
|
7
|
+
subscribe: (this: void, run: svelte_store.Subscriber<"en" | "es" | "es-mx" | "fr" | "pt" | "pt-br" | "de" | "it" | "ja">, invalidate?: () => void) => svelte_store.Unsubscriber;
|
|
8
|
+
};
|
|
9
|
+
currentLocale: () => "en" | "es" | "es-mx" | "fr" | "pt" | "pt-br" | "de" | "it" | "ja";
|
|
10
|
+
getDate: (props?: GetDateOptions) => string;
|
|
11
|
+
parseDate: (props: DateParsingOptions) => ParseDateResult;
|
|
12
|
+
isValidDate: (props: DateParsingOptions) => boolean;
|
|
13
|
+
getSupportedLocales: () => readonly SupportedLocale[];
|
|
14
|
+
ready: Promise<void>;
|
|
15
|
+
setLocale: (nextLocale: SupportedLocale) => Promise<void>;
|
|
16
|
+
getLocale: () => "en" | "es" | "es-mx" | "fr" | "pt" | "pt-br" | "de" | "it" | "ja";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { type CreateDateFormatterStoreOptions, createDateFormatterStore };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/svelte/index.ts
|
|
2
|
+
import { get, writable } from "svelte/store";
|
|
3
|
+
|
|
4
|
+
// src/core/date.ts
|
|
5
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
|
|
8
|
+
// src/core/locales.ts
|
|
9
|
+
var SUPPORTED_LOCALES = [
|
|
10
|
+
"en",
|
|
11
|
+
"es",
|
|
12
|
+
"es-mx",
|
|
13
|
+
"fr",
|
|
14
|
+
"pt",
|
|
15
|
+
"pt-br",
|
|
16
|
+
"de",
|
|
17
|
+
"it",
|
|
18
|
+
"ja"
|
|
19
|
+
];
|
|
20
|
+
var localeLoaders = {
|
|
21
|
+
en: null,
|
|
22
|
+
es: () => import("dayjs/locale/es.js"),
|
|
23
|
+
"es-mx": () => import("dayjs/locale/es-mx.js"),
|
|
24
|
+
fr: () => import("dayjs/locale/fr.js"),
|
|
25
|
+
pt: () => import("dayjs/locale/pt.js"),
|
|
26
|
+
"pt-br": () => import("dayjs/locale/pt-br.js"),
|
|
27
|
+
de: () => import("dayjs/locale/de.js"),
|
|
28
|
+
it: () => import("dayjs/locale/it.js"),
|
|
29
|
+
ja: () => import("dayjs/locale/ja.js")
|
|
30
|
+
};
|
|
31
|
+
var isSupportedLocale = (locale) => {
|
|
32
|
+
return SUPPORTED_LOCALES.includes(locale);
|
|
33
|
+
};
|
|
34
|
+
var ensureLocaleLoaded = async (locale) => {
|
|
35
|
+
const load = localeLoaders[locale];
|
|
36
|
+
if (!load) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await load();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/core/date.ts
|
|
43
|
+
dayjs.extend(customParseFormat);
|
|
44
|
+
dayjs.locale("en");
|
|
45
|
+
var DEFAULT_FORMAT = "YYYY-MM-DD";
|
|
46
|
+
var DEFAULT_LOCALE = "en";
|
|
47
|
+
var DEFAULT_INVALID_DATE = "Invalid Date";
|
|
48
|
+
var getInvalidDateText = (config, props) => {
|
|
49
|
+
return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE;
|
|
50
|
+
};
|
|
51
|
+
var getTargetLocale = (currentLocale, props) => {
|
|
52
|
+
return props?.locale ?? currentLocale;
|
|
53
|
+
};
|
|
54
|
+
var parseDateValue = (value, input, locale, strict) => {
|
|
55
|
+
if (!input) {
|
|
56
|
+
return dayjs(value).locale(locale);
|
|
57
|
+
}
|
|
58
|
+
if (typeof input === "string") {
|
|
59
|
+
return dayjs(value, input, locale, strict).locale(locale);
|
|
60
|
+
}
|
|
61
|
+
return dayjs(value, [...input], locale, strict).locale(locale);
|
|
62
|
+
};
|
|
63
|
+
var createFormatterParseDate = (getConfig) => {
|
|
64
|
+
return (props) => {
|
|
65
|
+
const config = getConfig();
|
|
66
|
+
const locale = getTargetLocale(config.locale, props);
|
|
67
|
+
const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict);
|
|
68
|
+
if (!parsed.isValid()) {
|
|
69
|
+
return {
|
|
70
|
+
isValid: false,
|
|
71
|
+
locale,
|
|
72
|
+
date: null,
|
|
73
|
+
iso: null,
|
|
74
|
+
timestamp: null,
|
|
75
|
+
error: getInvalidDateText(config, props)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
isValid: true,
|
|
80
|
+
locale,
|
|
81
|
+
date: parsed.toDate(),
|
|
82
|
+
iso: parsed.toISOString(),
|
|
83
|
+
timestamp: parsed.valueOf(),
|
|
84
|
+
format: (output = DEFAULT_FORMAT) => parsed.format(output)
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var createFormatterIsValidDate = (parseDate) => {
|
|
89
|
+
return (props) => parseDate(props).isValid;
|
|
90
|
+
};
|
|
91
|
+
var createFormatterGetDate = (getConfig) => {
|
|
92
|
+
const parseDate = createFormatterParseDate(getConfig);
|
|
93
|
+
return (props) => {
|
|
94
|
+
const config = getConfig();
|
|
95
|
+
const locale = getTargetLocale(config.locale, props);
|
|
96
|
+
const output = props?.output ?? DEFAULT_FORMAT;
|
|
97
|
+
if (!props) {
|
|
98
|
+
return dayjs().locale(locale).format(DEFAULT_FORMAT);
|
|
99
|
+
}
|
|
100
|
+
if (props.date === void 0) {
|
|
101
|
+
return dayjs().locale(locale).format(output);
|
|
102
|
+
}
|
|
103
|
+
const parsed = parseDate({
|
|
104
|
+
date: props.date,
|
|
105
|
+
input: props.input,
|
|
106
|
+
locale: props.locale,
|
|
107
|
+
strict: props.strict
|
|
108
|
+
});
|
|
109
|
+
if (!parsed.isValid) {
|
|
110
|
+
return props.invalid ?? parsed.error;
|
|
111
|
+
}
|
|
112
|
+
return parsed.format(output);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
function assertSupportedLocale(locale) {
|
|
116
|
+
if (!isSupportedLocale(locale)) {
|
|
117
|
+
throw new Error(`Unsupported locale: ${locale}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var getSupportedLocales = () => SUPPORTED_LOCALES;
|
|
121
|
+
var createDateFormatter = (config) => {
|
|
122
|
+
let currentLocale = config?.locale ?? DEFAULT_LOCALE;
|
|
123
|
+
const getConfig = () => ({
|
|
124
|
+
locale: currentLocale,
|
|
125
|
+
strict: config?.strict ?? false,
|
|
126
|
+
invalid: config?.invalid ?? DEFAULT_INVALID_DATE
|
|
127
|
+
});
|
|
128
|
+
const ready = ensureLocaleLoaded(currentLocale);
|
|
129
|
+
const parseDate = createFormatterParseDate(getConfig);
|
|
130
|
+
return {
|
|
131
|
+
getDate: createFormatterGetDate(getConfig),
|
|
132
|
+
parseDate,
|
|
133
|
+
isValidDate: createFormatterIsValidDate(parseDate),
|
|
134
|
+
getSupportedLocales,
|
|
135
|
+
getCurrentLocale: () => currentLocale,
|
|
136
|
+
setLocale: async (locale) => {
|
|
137
|
+
assertSupportedLocale(locale);
|
|
138
|
+
await ensureLocaleLoaded(locale);
|
|
139
|
+
currentLocale = locale;
|
|
140
|
+
},
|
|
141
|
+
ready
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/svelte/index.ts
|
|
146
|
+
var createDateFormatterStore = (options) => {
|
|
147
|
+
const formatter = createDateFormatter(options);
|
|
148
|
+
const locale = writable(formatter.getCurrentLocale());
|
|
149
|
+
return {
|
|
150
|
+
locale: {
|
|
151
|
+
subscribe: locale.subscribe
|
|
152
|
+
},
|
|
153
|
+
currentLocale: () => get(locale),
|
|
154
|
+
getDate: (props) => formatter.getDate(props),
|
|
155
|
+
parseDate: (props) => formatter.parseDate(props),
|
|
156
|
+
isValidDate: (props) => formatter.isValidDate(props),
|
|
157
|
+
getSupportedLocales,
|
|
158
|
+
ready: formatter.ready,
|
|
159
|
+
setLocale: async (nextLocale) => {
|
|
160
|
+
await formatter.setLocale(nextLocale);
|
|
161
|
+
locale.set(nextLocale);
|
|
162
|
+
},
|
|
163
|
+
getLocale: () => get(locale)
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
export {
|
|
167
|
+
createDateFormatterStore
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/svelte/index.ts","../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import { get, writable } from 'svelte/store'\n\nimport {\n createDateFormatter,\n getSupportedLocales,\n type DateFormatterConfig,\n type DateParsingOptions,\n type GetDateOptions,\n type SupportedLocale\n} from '../index.js'\n\nexport type CreateDateFormatterStoreOptions = DateFormatterConfig\n\nexport const createDateFormatterStore = (options?: CreateDateFormatterStoreOptions) => {\n const formatter = createDateFormatter(options)\n const locale = writable<SupportedLocale>(formatter.getCurrentLocale())\n\n return {\n locale: {\n subscribe: locale.subscribe\n },\n currentLocale: () => get(locale),\n getDate: (props?: GetDateOptions) => formatter.getDate(props),\n parseDate: (props: DateParsingOptions) => formatter.parseDate(props),\n isValidDate: (props: DateParsingOptions) => formatter.isValidDate(props),\n getSupportedLocales,\n ready: formatter.ready,\n setLocale: async (nextLocale: SupportedLocale) => {\n await formatter.setLocale(nextLocale)\n locale.set(nextLocale)\n },\n getLocale: () => get(locale)\n }\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, isSupportedLocale, SUPPORTED_LOCALES, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: SupportedLocale\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: SupportedLocale\n strict?: boolean\n invalid?: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: SupportedLocale) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n return props?.locale ?? currentLocale\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => Required<DateFormatterConfig>) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => Required<DateFormatterConfig>) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction assertSupportedLocale(locale: string): asserts locale is SupportedLocale {\n if (!isSupportedLocale(locale)) {\n throw new Error(`Unsupported locale: ${locale}`)\n }\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ?? DEFAULT_LOCALE\n\n const getConfig = (): Required<DateFormatterConfig> => ({\n locale: currentLocale,\n strict: config?.strict ?? false,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n })\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: SupportedLocale) => {\n assertSupportedLocale(locale)\n await ensureLocaleLoaded(locale)\n currentLocale = locale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nexport const isSupportedLocale = (locale: string): locale is SupportedLocale => {\n return SUPPORTED_LOCALES.includes(locale as SupportedLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n"],"mappings":";AAAA,SAAS,KAAK,gBAAgB;;;ACA9B,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEO,IAAM,oBAAoB,CAAC,WAA8C;AAC9E,SAAO,kBAAkB,SAAS,MAAyB;AAC7D;AAEO,IAAM,qBAAqB,OAAO,WAA2C;AAClF,QAAM,OAAO,cAAc,MAAM;AAEjC,MAAI,CAAC,MAAM;AACT;AAAA,EACF;AAEA,QAAM,KAAK;AACb;;;ADhCA,MAAM,OAAO,iBAAiB;AAC9B,MAAM,OAAO,IAAI;AAwDjB,IAAM,iBAAiB;AACvB,IAAM,iBAAkC;AACxC,IAAM,uBAAuB;AAE7B,IAAM,qBAAqB,CAAC,QAA8B,UAAmC;AAC3F,SAAO,OAAO,WAAW,QAAQ,WAAW;AAC9C;AAEA,IAAM,kBAAkB,CAAC,eAAgC,UAA4C;AACnG,SAAO,OAAO,UAAU;AAC1B;AAEA,IAAM,iBAAiB,CACrB,OACA,OACA,QACA,WACU;AACV,MAA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,eAAe,MAAM,IAAI,MAAM;AAAA,IAC/B,SAAS,CAAC,UAA2B,UAAU,QAAQ,KAAK;AAAA,IAC5D,WAAW,CAAC,UAA8B,UAAU,UAAU,KAAK;AAAA,IACnE,aAAa,CAAC,UAA8B,UAAU,YAAY,KAAK;AAAA,IACvE;AAAA,IACA,OAAO,UAAU;AAAA,IACjB,WAAW,OAAO,eAAgC;AAChD,YAAM,UAAU,UAAU,UAAU;AACpC,aAAO,IAAI,UAAU;AAAA,IACvB;AAAA,IACA,WAAW,MAAM,IAAI,MAAM;AAAA,EAC7B;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DateFormatter, DateFormatterConfig, DateParsingOptions, DateValue, GetDateOptions, ParseDateFailure, ParseDateResult, ParseDateSuccess, SUPPORTED_LOCALES, SupportedLocale, createDateFormatter, getSupportedLocales } from '../index.js';
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// src/core/date.ts
|
|
2
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
|
|
5
|
+
// src/core/locales.ts
|
|
6
|
+
var SUPPORTED_LOCALES = [
|
|
7
|
+
"en",
|
|
8
|
+
"es",
|
|
9
|
+
"es-mx",
|
|
10
|
+
"fr",
|
|
11
|
+
"pt",
|
|
12
|
+
"pt-br",
|
|
13
|
+
"de",
|
|
14
|
+
"it",
|
|
15
|
+
"ja"
|
|
16
|
+
];
|
|
17
|
+
var localeLoaders = {
|
|
18
|
+
en: null,
|
|
19
|
+
es: () => import("dayjs/locale/es.js"),
|
|
20
|
+
"es-mx": () => import("dayjs/locale/es-mx.js"),
|
|
21
|
+
fr: () => import("dayjs/locale/fr.js"),
|
|
22
|
+
pt: () => import("dayjs/locale/pt.js"),
|
|
23
|
+
"pt-br": () => import("dayjs/locale/pt-br.js"),
|
|
24
|
+
de: () => import("dayjs/locale/de.js"),
|
|
25
|
+
it: () => import("dayjs/locale/it.js"),
|
|
26
|
+
ja: () => import("dayjs/locale/ja.js")
|
|
27
|
+
};
|
|
28
|
+
var isSupportedLocale = (locale) => {
|
|
29
|
+
return SUPPORTED_LOCALES.includes(locale);
|
|
30
|
+
};
|
|
31
|
+
var ensureLocaleLoaded = async (locale) => {
|
|
32
|
+
const load = localeLoaders[locale];
|
|
33
|
+
if (!load) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await load();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/core/date.ts
|
|
40
|
+
dayjs.extend(customParseFormat);
|
|
41
|
+
dayjs.locale("en");
|
|
42
|
+
var DEFAULT_FORMAT = "YYYY-MM-DD";
|
|
43
|
+
var DEFAULT_LOCALE = "en";
|
|
44
|
+
var DEFAULT_INVALID_DATE = "Invalid Date";
|
|
45
|
+
var getInvalidDateText = (config, props) => {
|
|
46
|
+
return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE;
|
|
47
|
+
};
|
|
48
|
+
var getTargetLocale = (currentLocale, props) => {
|
|
49
|
+
return props?.locale ?? currentLocale;
|
|
50
|
+
};
|
|
51
|
+
var parseDateValue = (value, input, locale, strict) => {
|
|
52
|
+
if (!input) {
|
|
53
|
+
return dayjs(value).locale(locale);
|
|
54
|
+
}
|
|
55
|
+
if (typeof input === "string") {
|
|
56
|
+
return dayjs(value, input, locale, strict).locale(locale);
|
|
57
|
+
}
|
|
58
|
+
return dayjs(value, [...input], locale, strict).locale(locale);
|
|
59
|
+
};
|
|
60
|
+
var createFormatterParseDate = (getConfig) => {
|
|
61
|
+
return (props) => {
|
|
62
|
+
const config = getConfig();
|
|
63
|
+
const locale = getTargetLocale(config.locale, props);
|
|
64
|
+
const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict);
|
|
65
|
+
if (!parsed.isValid()) {
|
|
66
|
+
return {
|
|
67
|
+
isValid: false,
|
|
68
|
+
locale,
|
|
69
|
+
date: null,
|
|
70
|
+
iso: null,
|
|
71
|
+
timestamp: null,
|
|
72
|
+
error: getInvalidDateText(config, props)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
isValid: true,
|
|
77
|
+
locale,
|
|
78
|
+
date: parsed.toDate(),
|
|
79
|
+
iso: parsed.toISOString(),
|
|
80
|
+
timestamp: parsed.valueOf(),
|
|
81
|
+
format: (output = DEFAULT_FORMAT) => parsed.format(output)
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
var createFormatterIsValidDate = (parseDate) => {
|
|
86
|
+
return (props) => parseDate(props).isValid;
|
|
87
|
+
};
|
|
88
|
+
var createFormatterGetDate = (getConfig) => {
|
|
89
|
+
const parseDate = createFormatterParseDate(getConfig);
|
|
90
|
+
return (props) => {
|
|
91
|
+
const config = getConfig();
|
|
92
|
+
const locale = getTargetLocale(config.locale, props);
|
|
93
|
+
const output = props?.output ?? DEFAULT_FORMAT;
|
|
94
|
+
if (!props) {
|
|
95
|
+
return dayjs().locale(locale).format(DEFAULT_FORMAT);
|
|
96
|
+
}
|
|
97
|
+
if (props.date === void 0) {
|
|
98
|
+
return dayjs().locale(locale).format(output);
|
|
99
|
+
}
|
|
100
|
+
const parsed = parseDate({
|
|
101
|
+
date: props.date,
|
|
102
|
+
input: props.input,
|
|
103
|
+
locale: props.locale,
|
|
104
|
+
strict: props.strict
|
|
105
|
+
});
|
|
106
|
+
if (!parsed.isValid) {
|
|
107
|
+
return props.invalid ?? parsed.error;
|
|
108
|
+
}
|
|
109
|
+
return parsed.format(output);
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
function assertSupportedLocale(locale) {
|
|
113
|
+
if (!isSupportedLocale(locale)) {
|
|
114
|
+
throw new Error(`Unsupported locale: ${locale}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
var getSupportedLocales = () => SUPPORTED_LOCALES;
|
|
118
|
+
var createDateFormatter = (config) => {
|
|
119
|
+
let currentLocale = config?.locale ?? DEFAULT_LOCALE;
|
|
120
|
+
const getConfig = () => ({
|
|
121
|
+
locale: currentLocale,
|
|
122
|
+
strict: config?.strict ?? false,
|
|
123
|
+
invalid: config?.invalid ?? DEFAULT_INVALID_DATE
|
|
124
|
+
});
|
|
125
|
+
const ready = ensureLocaleLoaded(currentLocale);
|
|
126
|
+
const parseDate = createFormatterParseDate(getConfig);
|
|
127
|
+
return {
|
|
128
|
+
getDate: createFormatterGetDate(getConfig),
|
|
129
|
+
parseDate,
|
|
130
|
+
isValidDate: createFormatterIsValidDate(parseDate),
|
|
131
|
+
getSupportedLocales,
|
|
132
|
+
getCurrentLocale: () => currentLocale,
|
|
133
|
+
setLocale: async (locale) => {
|
|
134
|
+
assertSupportedLocale(locale);
|
|
135
|
+
await ensureLocaleLoaded(locale);
|
|
136
|
+
currentLocale = locale;
|
|
137
|
+
},
|
|
138
|
+
ready
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
export {
|
|
142
|
+
SUPPORTED_LOCALES,
|
|
143
|
+
createDateFormatter,
|
|
144
|
+
getSupportedLocales
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, isSupportedLocale, SUPPORTED_LOCALES, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: SupportedLocale\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: SupportedLocale\n strict?: boolean\n invalid?: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: SupportedLocale) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n return props?.locale ?? currentLocale\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => Required<DateFormatterConfig>) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => Required<DateFormatterConfig>) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction assertSupportedLocale(locale: string): asserts locale is SupportedLocale {\n if (!isSupportedLocale(locale)) {\n throw new Error(`Unsupported locale: ${locale}`)\n }\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ?? DEFAULT_LOCALE\n\n const getConfig = (): Required<DateFormatterConfig> => ({\n locale: currentLocale,\n strict: config?.strict ?? false,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n })\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: SupportedLocale) => {\n assertSupportedLocale(locale)\n await ensureLocaleLoaded(locale)\n currentLocale = locale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nexport const isSupportedLocale = (locale: string): locale is SupportedLocale => {\n return SUPPORTED_LOCALES.includes(locale as SupportedLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n"],"mappings":";AAAA,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEO,IAAM,oBAAoB,CAAC,WAA8C;AAC9E,SAAO,kBAAkB,SAAS,MAAyB;AAC7D;AAEO,IAAM,qBAAqB,OAAO,WAA2C;AAClF,QAAM,OAAO,cAAc,MAAM;AAEjC,MAAI,CAAC,MAAM;AACT;AAAA,EACF;AAEA,QAAM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IACA,kBAAkB,MAAM;AAAA,IACxB,WAAW,OAAO,WAA4B;AAC5C,4BAAsB,MAAM;AAC5B,YAAM,mBAAmB,MAAM;AAC/B,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DateFormatterConfig, GetDateOptions, DateParsingOptions, ParseDateResult, SupportedLocale } from '../index.js';
|
|
2
|
+
import * as vue from 'vue';
|
|
3
|
+
|
|
4
|
+
type UseDateFormatterOptions = DateFormatterConfig;
|
|
5
|
+
declare const useDateFormatter: (options?: UseDateFormatterOptions) => {
|
|
6
|
+
locale: vue.Ref<"en" | "es" | "es-mx" | "fr" | "pt" | "pt-br" | "de" | "it" | "ja", "en" | "es" | "es-mx" | "fr" | "pt" | "pt-br" | "de" | "it" | "ja">;
|
|
7
|
+
currentLocale: vue.ComputedRef<"en" | "es" | "es-mx" | "fr" | "pt" | "pt-br" | "de" | "it" | "ja">;
|
|
8
|
+
getDate: (props?: GetDateOptions) => string;
|
|
9
|
+
parseDate: (props: DateParsingOptions) => ParseDateResult;
|
|
10
|
+
isValidDate: (props: DateParsingOptions) => boolean;
|
|
11
|
+
getSupportedLocales: () => readonly SupportedLocale[];
|
|
12
|
+
ready: Promise<void>;
|
|
13
|
+
setLocale: (nextLocale: SupportedLocale) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { type UseDateFormatterOptions, useDateFormatter };
|