@ws-ui/formatter 0.1.10 → 0.1.12
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/index.d.ts +8 -2
- package/dist/index.js +15 -1
- 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/index.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Format } from './string';
|
|
2
2
|
import { parseDateFormat } from './date';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export type DataType = 'string' | 'date' | 'number' | 'duration';
|
|
4
|
+
declare function format(rawValue: unknown, dataType: DataType, format?: string | Format): string;
|
|
5
|
+
declare function getStyle(dataType: DataType, format: string | Format, value: unknown): {
|
|
6
|
+
color?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
color: any;
|
|
9
|
+
};
|
|
10
|
+
export { format, parseDateFormat, getStyle };
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,20 @@ function format(rawValue, dataType, format) {
|
|
|
18
18
|
}
|
|
19
19
|
return rawValue;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
function getStyle(dataType, format, value) {
|
|
22
|
+
switch(dataType){
|
|
23
|
+
case 'number':
|
|
24
|
+
{
|
|
25
|
+
const color = numfmt(format).color(isNaN(value) ? value : +value);
|
|
26
|
+
if (color === 'black' && !format.toLowerCase().includes('[black]')) return {};
|
|
27
|
+
return {
|
|
28
|
+
color
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { format, parseDateFormat, getStyle };
|
|
22
36
|
|
|
23
37
|
//# 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 } 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\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 formatDate(+rawValue, format || 'HH:mm:ss');\n }\n\n return rawValue as string;\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, getStyle };\n"],"names":["numfmt","formatString","formatDate","parseDateFormat","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,QAAQ,SAAS;AAIrD,SAASC,OAAOC,QAAiB,EAAEC,QAAkB,EAAEF,MAAwB;IAC7E,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,SAASI,SAASH,QAAkB,EAAEF,MAAuB,EAAEM,KAAc;IAC3E,OAAQJ;QACN,KAAK;YAAU;gBACb,MAAMK,QAAQX,OAAOI,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,EAAED,eAAe,EAAEM,QAAQ,GAAG"}
|