@ws-ui/formatter 0.1.8 → 0.1.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/dist/date.d.ts +1 -0
- package/dist/date.js +12 -8
- package/dist/date.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/out/bundle.min.js +1 -1
- package/out/bundle.min.js.map +3 -3
- package/package.json +1 -1
package/dist/date.d.ts
CHANGED
package/dist/date.js
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import formatFn from 'date-fns/format';
|
|
2
2
|
import Intl from '@ws-ui/intl';
|
|
3
3
|
import(`@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`);
|
|
4
|
-
function
|
|
4
|
+
function getDateFormat(options) {
|
|
5
5
|
return new Intl.DateTimeFormat(undefined, options).resolvedOptions().resolvedFormat;
|
|
6
6
|
}
|
|
7
|
-
export function
|
|
7
|
+
export function parseDateFormat(format) {
|
|
8
8
|
switch(format){
|
|
9
9
|
case 'Date short':
|
|
10
|
-
return
|
|
10
|
+
return getDateFormat();
|
|
11
11
|
case 'Date long':
|
|
12
|
-
return
|
|
12
|
+
return getDateFormat({
|
|
13
13
|
weekday: 'long',
|
|
14
14
|
year: 'numeric',
|
|
15
15
|
month: 'long',
|
|
16
16
|
day: 'numeric'
|
|
17
|
-
})
|
|
17
|
+
});
|
|
18
18
|
case 'Date abbreviated':
|
|
19
|
-
return
|
|
19
|
+
return getDateFormat({
|
|
20
20
|
weekday: 'short',
|
|
21
21
|
year: 'numeric',
|
|
22
22
|
month: 'short',
|
|
23
23
|
day: 'numeric'
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
default:
|
|
26
|
-
return
|
|
26
|
+
return format;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export function formatDate(value, format) {
|
|
30
|
+
const parsedFormat = parseDateFormat(format);
|
|
31
|
+
return formatFn(value, parsedFormat);
|
|
32
|
+
}
|
|
29
33
|
|
|
30
34
|
//# sourceMappingURL=date.js.map
|
package/dist/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import formatFn from 'date-fns/format';\nimport Intl from '@ws-ui/intl';\nimport(\n `@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`\n);\n\ntype ResolvedDateTimeFormatOptions = Intl.ResolvedDateTimeFormatOptions & {\n pattern?: string;\n resolvedFormat: string;\n};\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import formatFn from 'date-fns/format';\nimport Intl from '@ws-ui/intl';\nimport(\n `@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`\n);\n\ntype ResolvedDateTimeFormatOptions = Intl.ResolvedDateTimeFormatOptions & {\n pattern?: string;\n resolvedFormat: string;\n};\n\nfunction getDateFormat(options?: Intl.DateTimeFormatOptions) {\n return (\n new Intl.DateTimeFormat(undefined, options).resolvedOptions() as ResolvedDateTimeFormatOptions\n ).resolvedFormat;\n}\n\nexport function parseDateFormat(format: string) {\n switch (format) {\n case 'Date short':\n return getDateFormat();\n case 'Date long':\n return getDateFormat({\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n });\n case 'Date abbreviated':\n return getDateFormat({\n weekday: 'short',\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n default:\n return format;\n }\n}\n\nexport function formatDate(value: Date | number, format: string) {\n const parsedFormat = parseDateFormat(format);\n return formatFn(value, parsedFormat);\n}\n"],"names":["formatFn","Intl","navigator","language","getDateFormat","options","DateTimeFormat","undefined","resolvedOptions","resolvedFormat","parseDateFormat","format","weekday","year","month","day","formatDate","value","parsedFormat"],"mappings":"AAAA,OAAOA,cAAc,kBAAkB;AACvC,OAAOC,UAAU,cAAc;AAC/B,MAAM,CACJ,CAAC,8BAA8B,EAAE,OAAOC,cAAc,cAAcA,UAAUC,QAAQ,GAAG,KAAK,CAAC;AAQjG,SAASC,cAAcC,OAAoC;IACzD,OAAO,AACL,IAAIJ,KAAKK,cAAc,CAACC,WAAWF,SAASG,eAAe,GAC3DC,cAAc;AAClB;AAEA,OAAO,SAASC,gBAAgBC,MAAc;IAC5C,OAAQA;QACN,KAAK;YACH,OAAOP;QACT,KAAK;YACH,OAAOA,cAAc;gBACnBQ,SAAS;gBACTC,MAAM;gBACNC,OAAO;gBACPC,KAAK;YACP;QACF,KAAK;YACH,OAAOX,cAAc;gBACnBQ,SAAS;gBACTC,MAAM;gBACNC,OAAO;gBACPC,KAAK;YACP;QACF;YACE,OAAOJ;IACX;AACF;AAEA,OAAO,SAASK,WAAWC,KAAoB,EAAEN,MAAc;IAC7D,MAAMO,eAAeR,gBAAgBC;IACrC,OAAOX,SAASiB,OAAOC;AACzB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Format } from './string';
|
|
2
|
-
|
|
2
|
+
import { parseDateFormat } from './date';
|
|
3
|
+
declare function format(rawValue: unknown, dataType: 'string' | 'date' | 'number' | 'duration', format?: string | Format): string;
|
|
4
|
+
export { format, parseDateFormat };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import numfmt from 'numfmt';
|
|
2
2
|
import { formatString } from './string';
|
|
3
|
-
import { formatDate } from './date';
|
|
4
|
-
|
|
3
|
+
import { formatDate, parseDateFormat } from './date';
|
|
4
|
+
function format(rawValue, dataType, format) {
|
|
5
5
|
switch(dataType){
|
|
6
6
|
// string formatting
|
|
7
7
|
case 'string':
|
|
@@ -18,5 +18,6 @@ export function format(rawValue, dataType, format) {
|
|
|
18
18
|
}
|
|
19
19
|
return rawValue;
|
|
20
20
|
}
|
|
21
|
+
export { format, parseDateFormat };
|
|
21
22
|
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import numfmt from 'numfmt';\nimport { Format, formatString } from './string';\nimport { formatDate } from './date';\n\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import numfmt from 'numfmt';\nimport { Format, formatString } from './string';\nimport { formatDate, parseDateFormat } from './date';\n\nfunction format(\n rawValue: unknown,\n dataType: 'string' | 'date' | 'number' | 'duration',\n format?: string | Format,\n): string {\n switch (dataType) {\n // string formatting\n case 'string':\n return formatString(rawValue as string, format as Format) as string;\n // date formatting\n case 'date':\n return formatDate(rawValue instanceof Date ? rawValue : new Date(rawValue as string), format);\n // number formatting\n case 'number':\n return numfmt(format)(isNaN(rawValue as number) ? rawValue : +rawValue);\n // duration formatting\n case 'duration':\n return formatDate(+rawValue, format || 'HH:mm:ss');\n }\n\n return rawValue as string;\n}\n\nexport { format, parseDateFormat };\n"],"names":["numfmt","formatString","formatDate","parseDateFormat","format","rawValue","dataType","Date","isNaN"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAAiBC,YAAY,QAAQ,WAAW;AAChD,SAASC,UAAU,EAAEC,eAAe,QAAQ,SAAS;AAErD,SAASC,OACPC,QAAiB,EACjBC,QAAmD,EACnDF,MAAwB;IAExB,OAAQE;QACN,oBAAoB;QACpB,KAAK;YACH,OAAOL,aAAaI,UAAoBD;QAC1C,kBAAkB;QAClB,KAAK;YACH,OAAOF,WAAWG,oBAAoBE,OAAOF,WAAW,IAAIE,KAAKF,WAAqBD;QACxF,oBAAoB;QACpB,KAAK;YACH,OAAOJ,OAAOI,QAAQI,MAAMH,YAAsBA,WAAW,CAACA;QAChE,sBAAsB;QACtB,KAAK;YACH,OAAOH,WAAW,CAACG,UAAUD,UAAU;IAC3C;IAEA,OAAOC;AACT;AAEA,SAASD,MAAM,EAAED,eAAe,GAAG"}
|