@ws-ui/formatter 0.1.3 → 0.1.4

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.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function formatDate(value: Date | number, format: string): string;
package/dist/date.js ADDED
@@ -0,0 +1,84 @@
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)));
58
+ function getFormat(options) {
59
+ return new _intl.default.DateTimeFormat(undefined, options).resolvedOptions().resolvedFormat;
60
+ }
61
+ function formatDate(value, format) {
62
+ switch(format){
63
+ case 'Date short':
64
+ return (0, _format.default)(value, getFormat());
65
+ case 'Date long':
66
+ return (0, _format.default)(value, getFormat({
67
+ weekday: 'long',
68
+ year: 'numeric',
69
+ month: 'long',
70
+ day: 'numeric'
71
+ }));
72
+ case 'Date abbreviated':
73
+ return (0, _format.default)(value, getFormat({
74
+ weekday: 'short',
75
+ year: 'numeric',
76
+ month: 'short',
77
+ day: 'numeric'
78
+ }));
79
+ default:
80
+ return (0, _format.default)(value, format);
81
+ }
82
+ }
83
+
84
+ //# sourceMappingURL=date.js.map
@@ -0,0 +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"}
package/dist/index.js CHANGED
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "format", {
8
8
  return format;
9
9
  }
10
10
  });
11
- const _format = /*#__PURE__*/ _interop_require_default(require("date-fns/format"));
12
11
  const _numfmt = /*#__PURE__*/ _interop_require_default(require("numfmt"));
13
12
  const _string = require("./string");
13
+ const _date = require("./date");
14
14
  function _interop_require_default(obj) {
15
15
  return obj && obj.__esModule ? obj : {
16
16
  default: obj
@@ -23,14 +23,13 @@ function format(rawValue, dataType, format) {
23
23
  return (0, _string.formatString)(rawValue, format);
24
24
  // date formatting
25
25
  case 'date':
26
- return (0, _format.default)(rawValue instanceof Date ? rawValue : new Date(rawValue), format);
26
+ return (0, _date.formatDate)(rawValue instanceof Date ? rawValue : new Date(rawValue), format);
27
27
  // number formatting
28
28
  case 'number':
29
29
  return (0, _numfmt.default)(format)(+rawValue);
30
+ // duration formatting
30
31
  case 'duration':
31
- {
32
- return (0, _format.default)(+rawValue, format || 'HH:mm:ss');
33
- }
32
+ return (0, _date.formatDate)(+rawValue, format || 'HH:mm:ss');
34
33
  }
35
34
  }
36
35
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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"}
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"}