store-scrapper-js-common 1.0.166 → 1.0.167

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.
@@ -1,4 +1,4 @@
1
1
  import { CurrencyEnum } from '../entities';
2
2
  export declare const formatMoney: (money: number | string, currency?: CurrencyEnum) => string;
3
- export declare const formatDate: (str: string) => string;
3
+ export declare const formatDate: (str: string, timezone?: string, format?: string) => string;
4
4
  export declare const formatPct: (pct: number | string) => string;
@@ -49,11 +49,12 @@ exports.formatMoney = (money, currency) => {
49
49
  const appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';
50
50
  return prependSign + addThousandSeparator(money.toString()) + appendSign;
51
51
  };
52
- exports.formatDate = (str) => {
52
+ exports.formatDate = (str, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss') => {
53
53
  if (!str) {
54
54
  return '';
55
55
  }
56
- return moment.tz(new Date(str), 'America/Santiago').format('DD-MM-YYYY HH:mm:ss');
56
+ const date = new Date(str);
57
+ return moment.tz(date, timezone).format(format);
57
58
  };
58
59
  exports.formatPct = (pct) => {
59
60
  if (!pct) {
@@ -1 +1 @@
1
- {"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,0CAA2C;AAE3C,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,EAAE;IAC3C,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,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,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import * as moment from 'moment-timezone';\nimport { CurrencyEnum } from '../entities';\n\nconst addThousandSeparator = (str: string) => {\n const nStr = (`${str}`);\n const x = nStr.split('.');\n let x1 = x[0];\n const x2 = x.length > 1 ? `.${x[1]}` : '';\n const rgx = /(\\d+)(\\d{3})/;\n while (rgx.test(x1)) {\n x1 = x1.replace(rgx, '$1.$2');\n }\n return x1 + x2;\n};\n\nexport const formatMoney = (money: number | string, currency?: CurrencyEnum): string => {\n if (!money) {\n return '';\n }\n\n let prependSign = '';\n if (!currency || !currency.toLowerCase().includes('pts')) {\n if (currency === CurrencyEnum.USD) {\n prependSign = 'U$';\n } else {\n prependSign = '$';\n }\n }\n\n const appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';\n\n return prependSign + addThousandSeparator(money.toString()) + appendSign;\n};\n\nexport const formatDate = (str: string): string => {\n if (!str) {\n return '';\n }\n\n return moment.tz(new Date(str), 'America/Santiago').format('DD-MM-YYYY HH:mm:ss');\n};\n\nexport const formatPct = (pct: number | string): string => {\n if (!pct) {\n return '';\n }\n\n return `${pct}%`.replace('.', ',');\n};\n"]}
1
+ {"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,0CAA2C;AAE3C,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,EAAE;IAC3C,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,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AC;AAClD,CAAC,CAAC;AAEW,QAAA,SAAS,GAAG,CAAC,GAAoB,EAAU,EAAE;IACxD,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,EAAE,CAAC;KACX;IAED,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import * as moment from 'moment-timezone';\nimport { CurrencyEnum } from '../entities';\n\nconst addThousandSeparator = (str: string) => {\n const nStr = (`${str}`);\n const x = nStr.split('.');\n let x1 = x[0];\n const x2 = x.length > 1 ? `.${x[1]}` : '';\n const rgx = /(\\d+)(\\d{3})/;\n while (rgx.test(x1)) {\n x1 = x1.replace(rgx, '$1.$2');\n }\n return x1 + x2;\n};\n\nexport const formatMoney = (money: number | string, currency?: CurrencyEnum): string => {\n if (!money) {\n return '';\n }\n\n let prependSign = '';\n if (!currency || !currency.toLowerCase().includes('pts')) {\n if (currency === CurrencyEnum.USD) {\n prependSign = 'U$';\n } else {\n prependSign = '$';\n }\n }\n\n const appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';\n\n return prependSign + addThousandSeparator(money.toString()) + appendSign;\n};\n\nexport const formatDate = (str: string, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss'): string => {\n if (!str) {\n return '';\n }\n\n const date = new Date(str);\n\n return moment.tz(date, timezone).format(format);\n};\n\nexport const formatPct = (pct: number | string): string => {\n if (!pct) {\n return '';\n }\n\n return `${pct}%`.replace('.', ',');\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "store-scrapper-js-common",
3
- "version": "1.0.166",
3
+ "version": "1.0.167",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,12 +32,14 @@ export const formatMoney = (money: number | string, currency?: CurrencyEnum): st
32
32
  return prependSign + addThousandSeparator(money.toString()) + appendSign;
33
33
  };
34
34
 
35
- export const formatDate = (str: string): string => {
35
+ export const formatDate = (str: string, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss'): string => {
36
36
  if (!str) {
37
37
  return '';
38
38
  }
39
39
 
40
- return moment.tz(new Date(str), 'America/Santiago').format('DD-MM-YYYY HH:mm:ss');
40
+ const date = new Date(str);
41
+
42
+ return moment.tz(date, timezone).format(format);
41
43
  };
42
44
 
43
45
  export const formatPct = (pct: number | string): string => {
@@ -28,6 +28,15 @@ describe('string formatter', () => {
28
28
  expect(formatDate(date)).toStrictEqual('16-01-2021 18:35:15');
29
29
  });
30
30
 
31
+ it('should return date as a formatted US Date', () => {
32
+ expect.hasAssertions();
33
+
34
+ const date = '2021-01-16T21:35:15.945Z';
35
+
36
+ expect(formatDate(null)).toStrictEqual('');
37
+ expect(formatDate(date, 'America/New_York', 'YYYY-MM-DD')).toStrictEqual('2021-01-16');
38
+ });
39
+
31
40
  it('should return number as a percentage string', () => {
32
41
  expect.hasAssertions();
33
42