@ws-ui/formatter 0.1.23 → 0.1.24
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/duration.d.ts +1 -1
- package/dist/duration.js +2 -2
- package/dist/duration.js.map +1 -1
- package/out/bundle.min.js +2 -2
- package/out/bundle.min.js.map +3 -3
- package/package.json +12 -11
package/dist/duration.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type Format = '
|
|
1
|
+
export type Format = 'Simple' | 'Distance' | 'Without seconds' | 'Distance With Suffix' | 'Strict Distance' | 'Strict Distance With Suffix';
|
|
2
2
|
export declare function formatDuration(value: string | number | Date, format?: Format): string;
|
|
3
3
|
export declare function parseDuration(value: string): number;
|
package/dist/duration.js
CHANGED
|
@@ -13,7 +13,7 @@ function sanitizeLocale(locale) {
|
|
|
13
13
|
export function formatDuration(value, format = 'Simple') {
|
|
14
14
|
if ([
|
|
15
15
|
'Simple',
|
|
16
|
-
'
|
|
16
|
+
'Without seconds'
|
|
17
17
|
].includes(format)) {
|
|
18
18
|
let v = +value;
|
|
19
19
|
let isNegative = false;
|
|
@@ -27,7 +27,7 @@ export function formatDuration(value, format = 'Simple') {
|
|
|
27
27
|
switch(format){
|
|
28
28
|
case 'Simple':
|
|
29
29
|
return `${isNegative ? '-' : ''}${padNumber(hours)}:${padNumber(minutes)}:${padNumber(seconds)}`;
|
|
30
|
-
case '
|
|
30
|
+
case 'Without seconds':
|
|
31
31
|
return `${isNegative ? '-' : ''}${padNumber(hours)}:${padNumber(minutes)}`;
|
|
32
32
|
}
|
|
33
33
|
}
|
package/dist/duration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/duration.ts"],"sourcesContent":["import { formatDistance, formatDistanceStrict } from 'date-fns';\nimport * as locale from 'date-fns/locale';\n\nexport type Format =\n | '
|
|
1
|
+
{"version":3,"sources":["../src/duration.ts"],"sourcesContent":["import { formatDistance, formatDistanceStrict } from 'date-fns';\nimport * as locale from 'date-fns/locale';\n\nexport type Format =\n | 'Simple'\n | 'Distance'\n | 'Without seconds'\n | 'Distance With Suffix'\n | 'Strict Distance'\n | 'Strict Distance With Suffix';\n\nconst SECONDS = 1000;\nconst MINUTES = SECONDS * 60;\nconst HOURS = MINUTES * 60;\n\nfunction padNumber(value: number, digits: number = 2) {\n return `${String(value).padStart(digits, '0')}`;\n}\n\nfunction sanitizeLocale(locale: string) {\n const [language, region = ''] = locale.split('-');\n return language.toLowerCase() + region.toUpperCase();\n}\n\nexport function formatDuration(value: string | number | Date, format: Format = 'Simple') {\n if (['Simple', 'Without seconds'].includes(format)) {\n let v = +value;\n let isNegative = false;\n\n if (v < 0) {\n v = -v;\n isNegative = true;\n }\n\n const hours = Math.floor(v / HOURS);\n const minutes = Math.floor((v % HOURS) / MINUTES);\n const seconds = Math.floor((v % MINUTES) / SECONDS);\n\n switch (format) {\n case 'Simple':\n return `${isNegative ? '-' : ''}${padNumber(hours)}:${padNumber(minutes)}:${padNumber(\n seconds,\n )}`;\n case 'Without seconds':\n return `${isNegative ? '-' : ''}${padNumber(hours)}:${padNumber(minutes)}`;\n }\n }\n\n const d1 = new Date();\n const d2 = value instanceof Date ? value : new Date(d1.getTime() + +value);\n const l =\n typeof navigator !== 'undefined' && locale[sanitizeLocale(navigator.language)]\n ? locale[sanitizeLocale(navigator.language)]\n : locale.enUS;\n\n switch (format) {\n case 'Distance':\n return formatDistance(d2, d1, {\n locale: l,\n });\n case 'Distance With Suffix':\n return formatDistance(d2, d1, {\n addSuffix: true,\n locale: l,\n });\n case 'Strict Distance':\n return formatDistanceStrict(d2, d1, {\n locale: l,\n });\n case 'Strict Distance With Suffix':\n return formatDistanceStrict(d2, d1, {\n addSuffix: true,\n locale: l,\n });\n }\n}\n\nexport function parseDuration(value: string) {\n const [hours = 0, minutes = 0, seconds = 0] = value.split(':').map(Number);\n\n const duration = Math.abs(hours) * HOURS + minutes * MINUTES + seconds * SECONDS;\n\n return hours < 0 ? -duration : duration;\n}\n"],"names":["formatDistance","formatDistanceStrict","locale","SECONDS","MINUTES","HOURS","padNumber","value","digits","String","padStart","sanitizeLocale","language","region","split","toLowerCase","toUpperCase","formatDuration","format","includes","v","isNegative","hours","Math","floor","minutes","seconds","d1","Date","d2","getTime","l","navigator","enUS","addSuffix","parseDuration","map","Number","duration","abs"],"mappings":"AAAA,SAASA,cAAc,EAAEC,oBAAoB,QAAQ,WAAW;AAChE,YAAYC,YAAY,kBAAkB;AAU1C,MAAMC,UAAU;AAChB,MAAMC,UAAUD,UAAU;AAC1B,MAAME,QAAQD,UAAU;AAExB,SAASE,UAAUC,KAAa,EAAEC,SAAiB,CAAC;IAClD,OAAO,CAAC,EAAEC,OAAOF,OAAOG,QAAQ,CAACF,QAAQ,KAAK,CAAC;AACjD;AAEA,SAASG,eAAeT,MAAc;IACpC,MAAM,CAACU,UAAUC,SAAS,EAAE,CAAC,GAAGX,OAAOY,KAAK,CAAC;IAC7C,OAAOF,SAASG,WAAW,KAAKF,OAAOG,WAAW;AACpD;AAEA,OAAO,SAASC,eAAeV,KAA6B,EAAEW,SAAiB,QAAQ;IACrF,IAAI;QAAC;QAAU;KAAkB,CAACC,QAAQ,CAACD,SAAS;QAClD,IAAIE,IAAI,CAACb;QACT,IAAIc,aAAa;QAEjB,IAAID,IAAI,GAAG;YACTA,IAAI,CAACA;YACLC,aAAa;QACf;QAEA,MAAMC,QAAQC,KAAKC,KAAK,CAACJ,IAAIf;QAC7B,MAAMoB,UAAUF,KAAKC,KAAK,CAAC,AAACJ,IAAIf,QAASD;QACzC,MAAMsB,UAAUH,KAAKC,KAAK,CAAC,AAACJ,IAAIhB,UAAWD;QAE3C,OAAQe;YACN,KAAK;gBACH,OAAO,CAAC,EAAEG,aAAa,MAAM,GAAG,EAAEf,UAAUgB,OAAO,CAAC,EAAEhB,UAAUmB,SAAS,CAAC,EAAEnB,UAC1EoB,SACA,CAAC;YACL,KAAK;gBACH,OAAO,CAAC,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