@ws-ui/formatter 0.0.1 → 0.1.0
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.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/string.js +38 -0
- package/dist/string.js.map +1 -0
- package/out/bundle.min.js +3 -0
- package/out/bundle.min.js.map +7 -0
- package/package.json +21 -13
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "format", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return format;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _numfmt = /*#__PURE__*/ _interop_require_default(require("numfmt"));
|
|
12
|
+
const _datefns = require("date-fns");
|
|
13
|
+
const _string = require("./string");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function format(rawValue, dataType, format) {
|
|
20
|
+
// string formatting
|
|
21
|
+
if (dataType === 'string') {
|
|
22
|
+
return (0, _string.formatString)(rawValue, format);
|
|
23
|
+
}
|
|
24
|
+
// number formatting
|
|
25
|
+
if (dataType === 'number') {
|
|
26
|
+
return (0, _numfmt.default)(format)(+rawValue);
|
|
27
|
+
}
|
|
28
|
+
// date formatting
|
|
29
|
+
if (dataType === 'date') {
|
|
30
|
+
return (0, _datefns.format)(rawValue instanceof Date ? rawValue : new Date(rawValue), format);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import numfmt from 'numfmt';\nimport { format as formatDate } from 'date-fns';\n\nimport { formatString, Format } from './string';\n\nexport function format(\n rawValue: unknown,\n dataType: 'string' | 'date' | 'number',\n format: string | Format,\n): string {\n // string formatting\n if (dataType === 'string') {\n return formatString(rawValue as string, format as Format);\n }\n\n // number formatting\n if (dataType === 'number') {\n return numfmt(format)(+rawValue);\n }\n\n // date formatting\n if (dataType === 'date') {\n return formatDate(rawValue instanceof Date ? rawValue : new Date(rawValue as string), format);\n }\n}\n"],"names":["format","rawValue","dataType","formatString","numfmt","formatDate","Date"],"mappings":";;;;+BAKgBA;;;eAAAA;;;+DALG;yBACkB;wBAEA;;;;;;AAE9B,SAASA,OACdC,QAAiB,EACjBC,QAAsC,EACtCF,MAAuB;IAEvB,oBAAoB;IACpB,IAAIE,aAAa,UAAU;QACzB,OAAOC,IAAAA,oBAAY,EAACF,UAAoBD;IAC1C;IAEA,oBAAoB;IACpB,IAAIE,aAAa,UAAU;QACzB,OAAOE,IAAAA,eAAM,EAACJ,QAAQ,CAACC;IACzB;IAEA,kBAAkB;IAClB,IAAIC,aAAa,QAAQ;QACvB,OAAOG,IAAAA,eAAU,EAACJ,oBAAoBK,OAAOL,WAAW,IAAIK,KAAKL,WAAqBD;IACxF;AACF"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "formatString", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return formatString;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _capitalizeEachWord(value) {
|
|
12
|
+
return value.split(' ').map(_toLower).map(_capitalize).join(' ');
|
|
13
|
+
}
|
|
14
|
+
function _upperCase(value) {
|
|
15
|
+
return value.toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
function _toLower(value) {
|
|
18
|
+
return value.toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
function _capitalize(value) {
|
|
21
|
+
return value ? value.charAt(0).toUpperCase() + value.slice(1).toLowerCase() : '';
|
|
22
|
+
}
|
|
23
|
+
function formatString(value, format) {
|
|
24
|
+
switch(format){
|
|
25
|
+
case 'U':
|
|
26
|
+
return _upperCase(_toLower(value));
|
|
27
|
+
case 'l':
|
|
28
|
+
return _toLower(value);
|
|
29
|
+
case 'C':
|
|
30
|
+
return _capitalize(_toLower(value));
|
|
31
|
+
case 'c':
|
|
32
|
+
return _capitalizeEachWord(value);
|
|
33
|
+
default:
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["function _capitalizeEachWord(value: string) {\n return value.split(' ').map(_toLower).map(_capitalize).join(' ');\n}\n\nfunction _upperCase(value: string) {\n return value.toUpperCase();\n}\n\nfunction _toLower(value: string) {\n return value.toLowerCase();\n}\n\nfunction _capitalize(value: string) {\n return value ? value.charAt(0).toUpperCase() + value.slice(1).toLowerCase() : '';\n}\n\nexport type Format = 'U' | 'l' | 'C' | 'c';\n\nexport function formatString(value: string, format: Format) {\n switch (format) {\n case 'U':\n return _upperCase(_toLower(value));\n case 'l':\n return _toLower(value);\n case 'C':\n return _capitalize(_toLower(value));\n case 'c':\n return _capitalizeEachWord(value);\n default:\n return value;\n }\n}\n"],"names":["formatString","_capitalizeEachWord","value","split","map","_toLower","_capitalize","join","_upperCase","toUpperCase","toLowerCase","charAt","slice","format"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;AAlBhB,SAASC,oBAAoBC,KAAa;IACxC,OAAOA,MAAMC,KAAK,CAAC,KAAKC,GAAG,CAACC,UAAUD,GAAG,CAACE,aAAaC,IAAI,CAAC;AAC9D;AAEA,SAASC,WAAWN,KAAa;IAC/B,OAAOA,MAAMO,WAAW;AAC1B;AAEA,SAASJ,SAASH,KAAa;IAC7B,OAAOA,MAAMQ,WAAW;AAC1B;AAEA,SAASJ,YAAYJ,KAAa;IAChC,OAAOA,QAAQA,MAAMS,MAAM,CAAC,GAAGF,WAAW,KAAKP,MAAMU,KAAK,CAAC,GAAGF,WAAW,KAAK;AAChF;AAIO,SAASV,aAAaE,KAAa,EAAEW,MAAc;IACxD,OAAQA;QACN,KAAK;YACH,OAAOL,WAAWH,SAASH;QAC7B,KAAK;YACH,OAAOG,SAASH;QAClB,KAAK;YACH,OAAOI,YAAYD,SAASH;QAC9B,KAAK;YACH,OAAOD,oBAAoBC;QAC7B;YACE,OAAOA;IACX;AACF"}
|