@ws-ui/formatter 0.1.2 → 0.1.3
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 +1 -1
- package/dist/index.js +15 -12
- package/dist/index.js.map +1 -1
- package/out/bundle.min.js +1 -2
- package/out/bundle.min.js.map +4 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Format } from './string';
|
|
2
|
-
export declare function format(rawValue: unknown, dataType: 'string' | 'date' | 'number', format: string | Format): string;
|
|
2
|
+
export declare function format(rawValue: unknown, dataType: 'string' | 'date' | 'number' | 'duration', format: string | Format): string;
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "format", {
|
|
|
8
8
|
return format;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _format = /*#__PURE__*/ _interop_require_default(require("date-fns/format"));
|
|
11
12
|
const _numfmt = /*#__PURE__*/ _interop_require_default(require("numfmt"));
|
|
12
|
-
const _datefns = require("date-fns");
|
|
13
13
|
const _string = require("./string");
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
@@ -17,17 +17,20 @@ function _interop_require_default(obj) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function format(rawValue, dataType, format) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
switch(dataType){
|
|
21
|
+
// string formatting
|
|
22
|
+
case 'string':
|
|
23
|
+
return (0, _string.formatString)(rawValue, format);
|
|
24
|
+
// date formatting
|
|
25
|
+
case 'date':
|
|
26
|
+
return (0, _format.default)(rawValue instanceof Date ? rawValue : new Date(rawValue), format);
|
|
27
|
+
// number formatting
|
|
28
|
+
case 'number':
|
|
29
|
+
return (0, _numfmt.default)(format)(+rawValue);
|
|
30
|
+
case 'duration':
|
|
31
|
+
{
|
|
32
|
+
return (0, _format.default)(+rawValue, format || 'HH:mm:ss');
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import formatDate from 'date-fns/format';\nimport numfmt from 'numfmt';\n\nimport { Format, formatString } from './string';\n\nexport function 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);\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)(+rawValue);\n case 'duration': {\n return formatDate(+rawValue, format || 'HH:mm:ss');\n }\n }\n}\n"],"names":["format","rawValue","dataType","formatString","formatDate","Date","numfmt"],"mappings":";;;;+BAKgBA;;;eAAAA;;;+DALO;+DACJ;wBAEkB;;;;;;AAE9B,SAASA,OACdC,QAAiB,EACjBC,QAAmD,EACnDF,MAAuB;IAEvB,OAAQE;QACN,oBAAoB;QACpB,KAAK;YACH,OAAOC,IAAAA,oBAAY,EAACF,UAAoBD;QAC1C,kBAAkB;QAClB,KAAK;YACH,OAAOI,IAAAA,eAAU,EAACH,oBAAoBI,OAAOJ,WAAW,IAAII,KAAKJ,WAAqBD;QACxF,oBAAoB;QACpB,KAAK;YACH,OAAOM,IAAAA,eAAM,EAACN,QAAQ,CAACC;QACzB,KAAK;YAAY;gBACf,OAAOG,IAAAA,eAAU,EAAC,CAACH,UAAUD,UAAU;YACzC;IACF;AACF"}
|