@ws-ui/formatter 0.1.4 → 0.1.6

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/date.js CHANGED
@@ -1,83 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "formatDate", {
6
- enumerable: true,
7
- get: function() {
8
- return formatDate;
9
- }
10
- });
11
- const _format = /*#__PURE__*/ _interop_require_default(require("date-fns/format"));
12
- const _intl = /*#__PURE__*/ _interop_require_default(require("@ws-ui/intl"));
13
- function _interop_require_default(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
16
- };
17
- }
18
- function _getRequireWildcardCache(nodeInterop) {
19
- if (typeof WeakMap !== "function") return null;
20
- var cacheBabelInterop = new WeakMap();
21
- var cacheNodeInterop = new WeakMap();
22
- return (_getRequireWildcardCache = function(nodeInterop) {
23
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
24
- })(nodeInterop);
25
- }
26
- function _interop_require_wildcard(obj, nodeInterop) {
27
- if (!nodeInterop && obj && obj.__esModule) {
28
- return obj;
29
- }
30
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
31
- return {
32
- default: obj
33
- };
34
- }
35
- var cache = _getRequireWildcardCache(nodeInterop);
36
- if (cache && cache.has(obj)) {
37
- return cache.get(obj);
38
- }
39
- var newObj = {};
40
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
41
- for(var key in obj){
42
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
43
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
44
- if (desc && (desc.get || desc.set)) {
45
- Object.defineProperty(newObj, key, desc);
46
- } else {
47
- newObj[key] = obj[key];
48
- }
49
- }
50
- }
51
- newObj.default = obj;
52
- if (cache) {
53
- cache.set(obj, newObj);
54
- }
55
- return newObj;
56
- }
57
- Promise.resolve(`@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p)));
1
+ import formatFn from 'date-fns/format';
2
+ import Intl from '@ws-ui/intl';
3
+ import(`@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`);
58
4
  function getFormat(options) {
59
- return new _intl.default.DateTimeFormat(undefined, options).resolvedOptions().resolvedFormat;
5
+ return new Intl.DateTimeFormat(undefined, options).resolvedOptions().resolvedFormat;
60
6
  }
61
- function formatDate(value, format) {
7
+ export function formatDate(value, format) {
62
8
  switch(format){
63
9
  case 'Date short':
64
- return (0, _format.default)(value, getFormat());
10
+ return formatFn(value, getFormat());
65
11
  case 'Date long':
66
- return (0, _format.default)(value, getFormat({
12
+ return formatFn(value, getFormat({
67
13
  weekday: 'long',
68
14
  year: 'numeric',
69
15
  month: 'long',
70
16
  day: 'numeric'
71
17
  }));
72
18
  case 'Date abbreviated':
73
- return (0, _format.default)(value, getFormat({
19
+ return formatFn(value, getFormat({
74
20
  weekday: 'short',
75
21
  year: 'numeric',
76
22
  month: 'short',
77
23
  day: 'numeric'
78
24
  }));
79
25
  default:
80
- return (0, _format.default)(value, format);
26
+ return formatFn(value, format);
81
27
  }
82
28
  }
83
29
 
package/dist/date.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/date.ts"],"sourcesContent":["import formatFn from 'date-fns/format';\nimport Intl from '@ws-ui/intl';\nimport(\n `@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`\n);\n\ntype ResolvedDateTimeFormatOptions = Intl.ResolvedDateTimeFormatOptions & {\n pattern?: string;\n resolvedFormat: string;\n};\n\nfunction getFormat(options?: Intl.DateTimeFormatOptions) {\n return (\n new Intl.DateTimeFormat(undefined, options).resolvedOptions() as ResolvedDateTimeFormatOptions\n ).resolvedFormat;\n}\n\nexport function formatDate(value: Date | number, format: string) {\n switch (format) {\n case 'Date short':\n return formatFn(value, getFormat());\n case 'Date long':\n return formatFn(\n value,\n getFormat({\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n }),\n );\n case 'Date abbreviated':\n return formatFn(\n value,\n getFormat({\n weekday: 'short',\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n }),\n );\n default:\n return formatFn(value, format);\n }\n}\n"],"names":["formatDate","navigator","language","getFormat","options","Intl","DateTimeFormat","undefined","resolvedOptions","resolvedFormat","value","format","formatFn","weekday","year","month","day"],"mappings":";;;;+BAiBgBA;;;eAAAA;;;+DAjBK;6DACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,gBACE,CAAC,8BAA8B,EAAE,OAAOC,cAAc,cAAcA,UAAUC,QAAQ,GAAG,KAAK,CAAC,oDADjG;AASA,SAASC,UAAUC,OAAoC;IACrD,OAAO,AACL,IAAIC,aAAI,CAACC,cAAc,CAACC,WAAWH,SAASI,eAAe,GAC3DC,cAAc;AAClB;AAEO,SAAST,WAAWU,KAAoB,EAAEC,MAAc;IAC7D,OAAQA;QACN,KAAK;YACH,OAAOC,IAAAA,eAAQ,EAACF,OAAOP;QACzB,KAAK;YACH,OAAOS,IAAAA,eAAQ,EACbF,OACAP,UAAU;gBACRU,SAAS;gBACTC,MAAM;gBACNC,OAAO;gBACPC,KAAK;YACP;QAEJ,KAAK;YACH,OAAOJ,IAAAA,eAAQ,EACbF,OACAP,UAAU;gBACRU,SAAS;gBACTC,MAAM;gBACNC,OAAO;gBACPC,KAAK;YACP;QAEJ;YACE,OAAOJ,IAAAA,eAAQ,EAACF,OAAOC;IAC3B;AACF"}
1
+ {"version":3,"sources":["../src/date.ts"],"sourcesContent":["import formatFn from 'date-fns/format';\nimport Intl from '@ws-ui/intl';\nimport(\n `@ws-ui/intl/locale-data/jsonp/${typeof navigator !== 'undefined' ? navigator.language : 'en'}`\n);\n\ntype ResolvedDateTimeFormatOptions = Intl.ResolvedDateTimeFormatOptions & {\n pattern?: string;\n resolvedFormat: string;\n};\n\nfunction getFormat(options?: Intl.DateTimeFormatOptions) {\n return (\n new Intl.DateTimeFormat(undefined, options).resolvedOptions() as ResolvedDateTimeFormatOptions\n ).resolvedFormat;\n}\n\nexport function formatDate(value: Date | number, format: string) {\n switch (format) {\n case 'Date short':\n return formatFn(value, getFormat());\n case 'Date long':\n return formatFn(\n value,\n getFormat({\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n }),\n );\n case 'Date abbreviated':\n return formatFn(\n value,\n getFormat({\n weekday: 'short',\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n }),\n );\n default:\n return formatFn(value, format);\n }\n}\n"],"names":["formatFn","Intl","navigator","language","getFormat","options","DateTimeFormat","undefined","resolvedOptions","resolvedFormat","formatDate","value","format","weekday","year","month","day"],"mappings":"AAAA,OAAOA,cAAc,kBAAkB;AACvC,OAAOC,UAAU,cAAc;AAC/B,MAAM,CACJ,CAAC,8BAA8B,EAAE,OAAOC,cAAc,cAAcA,UAAUC,QAAQ,GAAG,KAAK,CAAC;AAQjG,SAASC,UAAUC,OAAoC;IACrD,OAAO,AACL,IAAIJ,KAAKK,cAAc,CAACC,WAAWF,SAASG,eAAe,GAC3DC,cAAc;AAClB;AAEA,OAAO,SAASC,WAAWC,KAAoB,EAAEC,MAAc;IAC7D,OAAQA;QACN,KAAK;YACH,OAAOZ,SAASW,OAAOP;QACzB,KAAK;YACH,OAAOJ,SACLW,OACAP,UAAU;gBACRS,SAAS;gBACTC,MAAM;gBACNC,OAAO;gBACPC,KAAK;YACP;QAEJ,KAAK;YACH,OAAOhB,SACLW,OACAP,UAAU;gBACRS,SAAS;gBACTC,MAAM;gBACNC,OAAO;gBACPC,KAAK;YACP;QAEJ;YACE,OAAOhB,SAASW,OAAOC;IAC3B;AACF"}
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' | 'duration', 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
@@ -1,35 +1,20 @@
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 _string = require("./string");
13
- const _date = require("./date");
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
18
- }
19
- function format(rawValue, dataType, format) {
1
+ import numfmt from 'numfmt';
2
+ import { formatString } from './string';
3
+ import { formatDate } from './date';
4
+ export function format(rawValue, dataType, format) {
20
5
  switch(dataType){
21
6
  // string formatting
22
7
  case 'string':
23
- return (0, _string.formatString)(rawValue, format);
8
+ return formatString(rawValue, format);
24
9
  // date formatting
25
10
  case 'date':
26
- return (0, _date.formatDate)(rawValue instanceof Date ? rawValue : new Date(rawValue), format);
11
+ return formatDate(rawValue instanceof Date ? rawValue : new Date(rawValue), format);
27
12
  // number formatting
28
13
  case 'number':
29
- return (0, _numfmt.default)(format)(+rawValue);
14
+ return numfmt(format)(rawValue);
30
15
  // duration formatting
31
16
  case 'duration':
32
- return (0, _date.formatDate)(+rawValue, format || 'HH:mm:ss');
17
+ return formatDate(+rawValue, format || 'HH:mm:ss');
33
18
  }
34
19
  }
35
20
 
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 } from './date';\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 // duration formatting\n case 'duration':\n return formatDate(+rawValue, format || 'HH:mm:ss');\n }\n}\n"],"names":["format","rawValue","dataType","formatString","formatDate","Date","numfmt"],"mappings":";;;;+BAIgBA;;;eAAAA;;;+DAJG;wBACkB;sBACV;;;;;;AAEpB,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,gBAAU,EAACH,oBAAoBI,OAAOJ,WAAW,IAAII,KAAKJ,WAAqBD;QACxF,oBAAoB;QACpB,KAAK;YACH,OAAOM,IAAAA,eAAM,EAACN,QAAQ,CAACC;QACzB,sBAAsB;QACtB,KAAK;YACH,OAAOG,IAAAA,gBAAU,EAAC,CAACH,UAAUD,UAAU;IAC3C;AACF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import numfmt from 'numfmt';\nimport { Format, formatString } from './string';\nimport { formatDate } from './date';\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 // duration formatting\n case 'duration':\n return formatDate(+rawValue, format || 'HH:mm:ss');\n }\n}\n"],"names":["numfmt","formatString","formatDate","format","rawValue","dataType","Date"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAAiBC,YAAY,QAAQ,WAAW;AAChD,SAASC,UAAU,QAAQ,SAAS;AAEpC,OAAO,SAASC,OACdC,QAAiB,EACjBC,QAAmD,EACnDF,MAAwB;IAExB,OAAQE;QACN,oBAAoB;QACpB,KAAK;YACH,OAAOJ,aAAaG,UAAoBD;QAC1C,kBAAkB;QAClB,KAAK;YACH,OAAOD,WAAWE,oBAAoBE,OAAOF,WAAW,IAAIE,KAAKF,WAAqBD;QACxF,oBAAoB;QACpB,KAAK;YACH,OAAOH,OAAOG,QAAQC;QACxB,sBAAsB;QACtB,KAAK;YACH,OAAOF,WAAW,CAACE,UAAUD,UAAU;IAC3C;AACF"}
package/dist/string.js CHANGED
@@ -1,13 +1,3 @@
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
1
  function _capitalizeEachWord(value) {
12
2
  return value.split(' ').map(_toLower).map(_capitalize).join(' ');
13
3
  }
@@ -20,7 +10,7 @@ function _toLower(value) {
20
10
  function _capitalize(value) {
21
11
  return value ? value.charAt(0).toUpperCase() + value.slice(1).toLowerCase() : '';
22
12
  }
23
- function formatString(value, format) {
13
+ export function formatString(value, format) {
24
14
  switch(format){
25
15
  case 'U':
26
16
  return _upperCase(_toLower(value));
@@ -1 +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"}
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":["_capitalizeEachWord","value","split","map","_toLower","_capitalize","join","_upperCase","toUpperCase","toLowerCase","charAt","slice","formatString","format"],"mappings":"AAAA,SAASA,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;AAIA,OAAO,SAASG,aAAaX,KAAa,EAAEY,MAAc;IACxD,OAAQA;QACN,KAAK;YACH,OAAON,WAAWH,SAASH;QAC7B,KAAK;YACH,OAAOG,SAASH;QAClB,KAAK;YACH,OAAOI,YAAYD,SAASH;QAC9B,KAAK;YACH,OAAOD,oBAAoBC;QAC7B;YACE,OAAOA;IACX;AACF"}