@ws-ui/formatter 0.1.25 → 0.1.26
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/dist/date.d.ts +1 -1
- package/dist/date.js +11 -19
- package/dist/date.js.map +1 -1
- package/dist/locales.d.ts +1727 -0
- package/dist/locales.js +1729 -0
- package/dist/locales.js.map +1 -0
- package/dist/waiter.js +27 -0
- package/dist/waiter.js.map +1 -0
- package/out/bundle.min.js +2 -16
- package/out/bundle.min.js.map +4 -4
- package/package.json +1 -2
package/dist/date.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const INVALID_DATE: string;
|
|
2
|
-
export declare function parseDateFormat(format: string):
|
|
2
|
+
export declare function parseDateFormat(format: string, locale?: string): any;
|
|
3
3
|
export declare function isValidDate(value: Date | number): boolean;
|
|
4
4
|
export declare function formatDate(value: Date | number, format: string): string;
|
package/dist/date.js
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import formatFn from 'date-fns/format';
|
|
2
|
-
import Intl from '@ws-ui/intl';
|
|
3
2
|
import * as locales from 'date-fns/locale';
|
|
4
3
|
import { sanitizeLocale } from './duration';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { formats } from './locales';
|
|
5
|
+
const language = typeof navigator !== 'undefined' ? navigator.language : 'en';
|
|
6
|
+
function getDateFormat(format, locale) {
|
|
7
|
+
return formats[locale] ? formats[locale][format] : formats[locale.split('-')[0]][format];
|
|
8
8
|
}
|
|
9
9
|
export const INVALID_DATE = new Date('').toString();
|
|
10
|
-
export function parseDateFormat(format) {
|
|
10
|
+
export function parseDateFormat(format, locale = language) {
|
|
11
11
|
switch(format){
|
|
12
12
|
case 'Date short':
|
|
13
|
-
return getDateFormat();
|
|
14
13
|
case 'Date long':
|
|
15
|
-
return getDateFormat({
|
|
16
|
-
weekday: 'long',
|
|
17
|
-
year: 'numeric',
|
|
18
|
-
month: 'long',
|
|
19
|
-
day: 'numeric'
|
|
20
|
-
});
|
|
21
14
|
case 'Date abbreviated':
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
15
|
+
try {
|
|
16
|
+
return getDateFormat(format, locale);
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
return format;
|
|
19
|
+
}
|
|
28
20
|
default:
|
|
29
21
|
return format;
|
|
30
22
|
}
|
|
@@ -36,7 +28,7 @@ export function formatDate(value, format) {
|
|
|
36
28
|
if (!isValidDate(value)) return INVALID_DATE;
|
|
37
29
|
const parsedFormat = parseDateFormat(format);
|
|
38
30
|
return formatFn(value, parsedFormat, {
|
|
39
|
-
locale: locales[sanitizeLocale(
|
|
31
|
+
locale: locales[sanitizeLocale(language)]
|
|
40
32
|
});
|
|
41
33
|
}
|
|
42
34
|
|
package/dist/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import formatFn from 'date-fns/format';\nimport
|
|
1
|
+
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import formatFn from 'date-fns/format';\nimport * as locales from 'date-fns/locale';\nimport { sanitizeLocale } from './duration';\nimport { formats } from './locales';\n\nconst language = typeof navigator !== 'undefined' ? navigator.language : 'en';\n\nfunction getDateFormat(format: string, locale: string) {\n return formats[locale] ? formats[locale][format] : formats[locale.split('-')[0]][format];\n}\n\nexport const INVALID_DATE = new Date('').toString();\n\nexport function parseDateFormat(format: string, locale: string = language) {\n switch (format) {\n case 'Date short':\n case 'Date long':\n case 'Date abbreviated':\n try {\n return getDateFormat(format, locale);\n } catch (ex) {\n return format;\n }\n default:\n return format;\n }\n}\n\nexport function isValidDate(value: Date | number) {\n return value instanceof Date && value.toString() !== INVALID_DATE;\n}\n\nexport function formatDate(value: Date | number, format: string) {\n if (!isValidDate(value)) return INVALID_DATE;\n const parsedFormat = parseDateFormat(format);\n return formatFn(value, parsedFormat, { locale: locales[sanitizeLocale(language)] });\n}\n"],"names":["formatFn","locales","sanitizeLocale","formats","language","navigator","getDateFormat","format","locale","split","INVALID_DATE","Date","toString","parseDateFormat","ex","isValidDate","value","formatDate","parsedFormat"],"mappings":"AAAA,OAAOA,cAAc,kBAAkB;AACvC,YAAYC,aAAa,kBAAkB;AAC3C,SAASC,cAAc,QAAQ,aAAa;AAC5C,SAASC,OAAO,QAAQ,YAAY;AAEpC,MAAMC,WAAW,OAAOC,cAAc,cAAcA,UAAUD,QAAQ,GAAG;AAEzE,SAASE,cAAcC,MAAc,EAAEC,MAAc;IACnD,OAAOL,OAAO,CAACK,OAAO,GAAGL,OAAO,CAACK,OAAO,CAACD,OAAO,GAAGJ,OAAO,CAACK,OAAOC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAACF,OAAO;AAC1F;AAEA,OAAO,MAAMG,eAAe,IAAIC,KAAK,IAAIC,QAAQ,GAAG;AAEpD,OAAO,SAASC,gBAAgBN,MAAc,EAAEC,SAAiBJ,QAAQ;IACvE,OAAQG;QACN,KAAK;QACL,KAAK;QACL,KAAK;YACH,IAAI;gBACF,OAAOD,cAAcC,QAAQC;YAC/B,EAAE,OAAOM,IAAI;gBACX,OAAOP;YACT;QACF;YACE,OAAOA;IACX;AACF;AAEA,OAAO,SAASQ,YAAYC,KAAoB;IAC9C,OAAOA,iBAAiBL,QAAQK,MAAMJ,QAAQ,OAAOF;AACvD;AAEA,OAAO,SAASO,WAAWD,KAAoB,EAAET,MAAc;IAC7D,IAAI,CAACQ,YAAYC,QAAQ,OAAON;IAChC,MAAMQ,eAAeL,gBAAgBN;IACrC,OAAOP,SAASgB,OAAOE,cAAc;QAAEV,QAAQP,OAAO,CAACC,eAAeE,UAAU;IAAC;AACnF"}
|