@ws-ui/formatter 0.1.20 → 0.1.22
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 -0
- package/dist/duration.js +5 -0
- package/dist/duration.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/out/bundle.min.js +2 -2
- package/out/bundle.min.js.map +3 -3
- package/package.json +1 -1
- package/dist/waiter.js +0 -27
- package/dist/waiter.js.map +0 -1
package/dist/duration.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export type Format = 'Simple' | 'Distance' | 'Distance With Suffix' | 'Strict Distance' | 'Strict Distance With Suffix';
|
|
2
2
|
export declare function formatDuration(value: string | number | Date, format?: Format): string;
|
|
3
|
+
export declare function parseDuration(value: string): number;
|
package/dist/duration.js
CHANGED
|
@@ -47,5 +47,10 @@ export function formatDuration(value, format = 'Simple') {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
export function parseDuration(value) {
|
|
51
|
+
const [hours = 0, minutes = 0, seconds = 0] = value.split(':').map(Number);
|
|
52
|
+
const duration = Math.abs(hours) * HOURS + minutes * MINUTES + seconds * SECONDS;
|
|
53
|
+
return hours < 0 ? -duration : duration;
|
|
54
|
+
}
|
|
50
55
|
|
|
51
56
|
//# sourceMappingURL=duration.js.map
|
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 | 'Simple'\n | 'Distance'\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 (format === 'Simple') {\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 return `${isNegative ? '-' : ''}${padNumber(hours)}:${padNumber(minutes)}:${padNumber(\n seconds,\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"],"names":["formatDistance","formatDistanceStrict","locale","SECONDS","MINUTES","HOURS","padNumber","value","digits","String","padStart","sanitizeLocale","language","region","split","toLowerCase","toUpperCase","formatDuration","format","v","isNegative","hours","Math","floor","minutes","seconds","d1","Date","d2","getTime","l","navigator","enUS","addSuffix"],"mappings":"AAAA,SAASA,cAAc,EAAEC,oBAAoB,QAAQ,WAAW;AAChE,YAAYC,YAAY,kBAAkB;AAS1C,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,SA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;AACF"}
|
|
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 | '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 (format === 'Simple') {\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 return `${isNegative ? '-' : ''}${padNumber(hours)}:${padNumber(minutes)}:${padNumber(\n seconds,\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","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;AAS1C,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,IAAIA,WAAW,UAAU;QACvB,IAAIC,IAAI,CAACZ;QACT,IAAIa,aAAa;QAEjB,IAAID,IAAI,GAAG;YACTA,IAAI,CAACA;YACLC,aAAa;QACf;QAEA,MAAMC,QAAQC,KAAKC,KAAK,CAACJ,IAAId;QAC7B,MAAMmB,UAAUF,KAAKC,KAAK,CAAC,AAACJ,IAAId,QAASD;QACzC,MAAMqB,UAAUH,KAAKC,KAAK,CAAC,AAACJ,IAAIf,UAAWD;QAE3C,OAAO,CAAC,EAAEiB,aAAa,MAAM,GAAG,EAAEd,UAAUe,OAAO,CAAC,EAAEf,UAAUkB,SAAS,CAAC,EAAElB,UAC1EmB,SACA,CAAC;IACL;IAEA,MAAMC,KAAK,IAAIC;IACf,MAAMC,KAAKrB,iBAAiBoB,OAAOpB,QAAQ,IAAIoB,KAAKD,GAAGG,OAAO,KAAK,CAACtB;IACpE,MAAMuB,IACJ,OAAOC,cAAc,eAAe7B,MAAM,CAACS,eAAeoB,UAAUnB,QAAQ,EAAE,GAC1EV,MAAM,CAACS,eAAeoB,UAAUnB,QAAQ,EAAE,GAC1CV,OAAO8B,IAAI;IAEjB,OAAQd;QACN,KAAK;YACH,OAAOlB,eAAe4B,IAAIF,IAAI;gBAC5BxB,QAAQ4B;YACV;QACF,KAAK;YACH,OAAO9B,eAAe4B,IAAIF,IAAI;gBAC5BO,WAAW;gBACX/B,QAAQ4B;YACV;QACF,KAAK;YACH,OAAO7B,qBAAqB2B,IAAIF,IAAI;gBAClCxB,QAAQ4B;YACV;QACF,KAAK;YACH,OAAO7B,qBAAqB2B,IAAIF,IAAI;gBAClCO,WAAW;gBACX/B,QAAQ4B;YACV;IACJ;AACF;AAEA,OAAO,SAASI,cAAc3B,KAAa;IACzC,MAAM,CAACc,QAAQ,CAAC,EAAEG,UAAU,CAAC,EAAEC,UAAU,CAAC,CAAC,GAAGlB,MAAMO,KAAK,CAAC,KAAKqB,GAAG,CAACC;IAEnE,MAAMC,WAAWf,KAAKgB,GAAG,CAACjB,SAAShB,QAAQmB,UAAUpB,UAAUqB,UAAUtB;IAEzE,OAAOkB,QAAQ,IAAI,CAACgB,WAAWA;AACjC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Format } from './string';
|
|
2
2
|
import { parseDateFormat, isValidDate, INVALID_DATE } from './date';
|
|
3
|
+
import { parseDuration } from './duration';
|
|
3
4
|
export type DataType = 'string' | 'date' | 'number' | 'duration';
|
|
4
5
|
declare function format(rawValue: unknown, dataType: DataType, format?: string | Format): string;
|
|
5
6
|
declare function getStyle(dataType: DataType, format: string | Format, value: unknown): {
|
|
@@ -7,4 +8,4 @@ declare function getStyle(dataType: DataType, format: string | Format, value: un
|
|
|
7
8
|
} | {
|
|
8
9
|
color: any;
|
|
9
10
|
};
|
|
10
|
-
export { format, parseDateFormat, isValidDate, INVALID_DATE, getStyle };
|
|
11
|
+
export { format, parseDateFormat, parseDuration, isValidDate, INVALID_DATE, getStyle };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import numfmt from 'numfmt';
|
|
2
2
|
import { formatString } from './string';
|
|
3
3
|
import { formatDate, parseDateFormat, isValidDate, INVALID_DATE } from './date';
|
|
4
|
-
import { formatDuration } from './duration';
|
|
4
|
+
import { formatDuration, parseDuration } from './duration';
|
|
5
5
|
function format(rawValue, dataType, format) {
|
|
6
6
|
switch(dataType){
|
|
7
7
|
// string formatting
|
|
@@ -34,6 +34,6 @@ function getStyle(dataType, format, value) {
|
|
|
34
34
|
return {};
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
export { format, parseDateFormat, isValidDate, INVALID_DATE, getStyle };
|
|
37
|
+
export { format, parseDateFormat, parseDuration, isValidDate, INVALID_DATE, getStyle };
|
|
38
38
|
|
|
39
39
|
//# 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, parseDateFormat, isValidDate, INVALID_DATE } from './date';\nimport { formatDuration, Format as DurationFormat } from './duration';\n\nexport type DataType = 'string' | 'date' | 'number' | 'duration';\n\nfunction format(rawValue: unknown, dataType: DataType, format?: string | Format): 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 formatDuration(rawValue as string | number | Date, format as DurationFormat);\n default:\n return rawValue as string;\n }\n}\n\nfunction getStyle(dataType: DataType, format: string | Format, value: unknown) {\n switch (dataType) {\n case 'number': {\n const color = numfmt(format).color(isNaN(value as number) ? value : +value);\n if (color === 'black' && !format.toLowerCase().includes('[black]')) return {};\n return { color };\n }\n default:\n return {};\n }\n}\n\nexport { format, parseDateFormat, isValidDate, INVALID_DATE, getStyle };\n"],"names":["numfmt","formatString","formatDate","parseDateFormat","isValidDate","INVALID_DATE","formatDuration","format","rawValue","dataType","Date","isNaN","getStyle","value","color","toLowerCase","includes"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAAiBC,YAAY,QAAQ,WAAW;AAChD,SAASC,UAAU,EAAEC,eAAe,EAAEC,WAAW,EAAEC,YAAY,QAAQ,SAAS;AAChF,SAASC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import numfmt from 'numfmt';\nimport { Format, formatString } from './string';\nimport { formatDate, parseDateFormat, isValidDate, INVALID_DATE } from './date';\nimport { formatDuration, Format as DurationFormat, parseDuration } from './duration';\n\nexport type DataType = 'string' | 'date' | 'number' | 'duration';\n\nfunction format(rawValue: unknown, dataType: DataType, format?: string | Format): 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 formatDuration(rawValue as string | number | Date, format as DurationFormat);\n default:\n return rawValue as string;\n }\n}\n\nfunction getStyle(dataType: DataType, format: string | Format, value: unknown) {\n switch (dataType) {\n case 'number': {\n const color = numfmt(format).color(isNaN(value as number) ? value : +value);\n if (color === 'black' && !format.toLowerCase().includes('[black]')) return {};\n return { color };\n }\n default:\n return {};\n }\n}\n\nexport { format, parseDateFormat, parseDuration, isValidDate, INVALID_DATE, getStyle };\n"],"names":["numfmt","formatString","formatDate","parseDateFormat","isValidDate","INVALID_DATE","formatDuration","parseDuration","format","rawValue","dataType","Date","isNaN","getStyle","value","color","toLowerCase","includes"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAAiBC,YAAY,QAAQ,WAAW;AAChD,SAASC,UAAU,EAAEC,eAAe,EAAEC,WAAW,EAAEC,YAAY,QAAQ,SAAS;AAChF,SAASC,cAAc,EAA4BC,aAAa,QAAQ,aAAa;AAIrF,SAASC,OAAOC,QAAiB,EAAEC,QAAkB,EAAEF,MAAwB;IAC7E,OAAQE;QACN,oBAAoB;QACpB,KAAK;YACH,OAAOT,aAAaQ,UAAoBD;QAC1C,kBAAkB;QAClB,KAAK;YACH,OAAON,WAAWO,oBAAoBE,OAAOF,WAAW,IAAIE,KAAKF,WAAqBD;QACxF,oBAAoB;QACpB,KAAK;YACH,OAAOR,OAAOQ,QAAQI,MAAMH,YAAsBA,WAAW,CAACA;QAChE,sBAAsB;QACtB,KAAK;YACH,OAAOH,eAAeG,UAAoCD;QAC5D;YACE,OAAOC;IACX;AACF;AAEA,SAASI,SAASH,QAAkB,EAAEF,MAAuB,EAAEM,KAAc;IAC3E,OAAQJ;QACN,KAAK;YAAU;gBACb,MAAMK,QAAQf,OAAOQ,QAAQO,KAAK,CAACH,MAAME,SAAmBA,QAAQ,CAACA;gBACrE,IAAIC,UAAU,WAAW,CAACP,OAAOQ,WAAW,GAAGC,QAAQ,CAAC,YAAY,OAAO,CAAC;gBAC5E,OAAO;oBAAEF;gBAAM;YACjB;QACA;YACE,OAAO,CAAC;IACZ;AACF;AAEA,SAASP,MAAM,EAAEL,eAAe,EAAEI,aAAa,EAAEH,WAAW,EAAEC,YAAY,EAAEQ,QAAQ,GAAG"}
|