store-scrapper-js-common 1.0.173 → 1.0.174

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.
@@ -40,6 +40,10 @@ exports.formatMoney = (money, currency) => {
40
40
  if (!money) {
41
41
  return '';
42
42
  }
43
+ let moneyStr = money.toString();
44
+ if (typeof money === 'number') {
45
+ moneyStr = moneyStr.replace(/\./g, ',');
46
+ }
43
47
  let appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';
44
48
  let prependSign = '';
45
49
  let thousandSeparator = '.';
@@ -57,7 +61,7 @@ exports.formatMoney = (money, currency) => {
57
61
  else if (!currency || !currency.toLowerCase().includes('pts')) {
58
62
  prependSign = '$';
59
63
  }
60
- return prependSign + exports.addThousandSeparator(money.toString(), thousandSeparator) + appendSign;
64
+ return prependSign + exports.addThousandSeparator(moneyStr, thousandSeparator) + appendSign;
61
65
  };
62
66
  exports.formatDate = (str, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss') => {
63
67
  if (!str) {
@@ -1 +1 @@
1
- {"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,0CAA2C;AAE9B,QAAA,oBAAoB,GAAG,CAAC,GAAW,EAAE,SAAS,GAAG,GAAG,EAAE,EAAE;IACnE,IAAI,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACtB,IAAI,IAAI,IAAI,SAAS,KAAK,GAAG,EAAE;QAC7B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KAC/B;IAED,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAChC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC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EAAE,iBAAiB,CAAC,GAAG,UAAU,CAAC;AAC9F,CAAC,CAAC;AAEW,QAAA,UAAU,GAAG,CAAC,GAAW,EAAE,QAAQ,GAAG,kBAAkB,EAAE,MAAM,GAAG,qBAAqB,EAAU,EAAE;IAC/G,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,EAAE,CAAC;KACX;IAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IAE3B,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;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\nexport const addThousandSeparator = (str: string, separator = '.') => {\n let nStr = (`${str}`);\n if (nStr && separator === ',') {\n nStr = nStr.replace(',', '.');\n }\n\n const x = nStr.split(separator);\n let x1 = x[0];\n const x2 = x.length > 1 ? `${separator}${x[1]}` : '';\n const rgx = /(\\d+)(\\d{3})/;\n while (rgx.test(x1)) {\n x1 = x1.replace(rgx, `$1${separator}$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 appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';\n let prependSign = '';\n let thousandSeparator = '.';\n\n if (currency === CurrencyEnum.USD) {\n prependSign = 'U$';\n thousandSeparator = ',';\n } else if (currency === CurrencyEnum.EUR) {\n appendSign = `€ ${appendSign}`.trim();\n } else if (currency === CurrencyEnum.MXN) {\n prependSign = '$';\n thousandSeparator = ',';\n } else if (!currency || !currency.toLowerCase().includes('pts')) {\n prependSign = '$';\n }\n\n return prependSign + addThousandSeparator(money.toString(), thousandSeparator) + 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"]}
1
+ {"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,0CAA2C;AAE9B,QAAA,oBAAoB,GAAG,CAAC,GAAW,EAAE,SAAS,GAAG,GAAG,EAAE,EAAE;IACnE,IAAI,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACtB,IAAI,IAAI,IAAI,SAAS,KAAK,GAAG,EAAE;QAC7B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KAC/B;IAED,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAChC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,MAAM,GAAG,GAAG,cAAc,CAAC;IAC3B,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QACnB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,SAAS,IAAI,CAAC,CAAC;KAC1C;IACD,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,CAAC,KA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AE,CAAC;KACX;IAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IAE3B,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;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\nexport const addThousandSeparator = (str: string, separator = '.') => {\n let nStr = (`${str}`);\n if (nStr && separator === ',') {\n nStr = nStr.replace(',', '.');\n }\n\n const x = nStr.split(separator);\n let x1 = x[0];\n const x2 = x.length > 1 ? `${separator}${x[1]}` : '';\n const rgx = /(\\d+)(\\d{3})/;\n while (rgx.test(x1)) {\n x1 = x1.replace(rgx, `$1${separator}$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 moneyStr = money.toString();\n if (typeof money === 'number') {\n moneyStr = moneyStr.replace(/\\./g, ',');\n }\n\n let appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';\n let prependSign = '';\n let thousandSeparator = '.';\n\n if (currency === CurrencyEnum.USD) {\n prependSign = 'U$';\n thousandSeparator = ',';\n } else if (currency === CurrencyEnum.EUR) {\n appendSign = `€ ${appendSign}`.trim();\n } else if (currency === CurrencyEnum.MXN) {\n prependSign = '$';\n thousandSeparator = ',';\n } else if (!currency || !currency.toLowerCase().includes('pts')) {\n prependSign = '$';\n }\n\n return prependSign + addThousandSeparator(moneyStr, thousandSeparator) + 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.173",
3
+ "version": "1.0.174",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,11 @@ export const formatMoney = (money: number | string, currency?: CurrencyEnum): st
22
22
  return '';
23
23
  }
24
24
 
25
+ let moneyStr = money.toString();
26
+ if (typeof money === 'number') {
27
+ moneyStr = moneyStr.replace(/\./g, ',');
28
+ }
29
+
25
30
  let appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';
26
31
  let prependSign = '';
27
32
  let thousandSeparator = '.';
@@ -38,7 +43,7 @@ export const formatMoney = (money: number | string, currency?: CurrencyEnum): st
38
43
  prependSign = '$';
39
44
  }
40
45
 
41
- return prependSign + addThousandSeparator(money.toString(), thousandSeparator) + appendSign;
46
+ return prependSign + addThousandSeparator(moneyStr, thousandSeparator) + appendSign;
42
47
  };
43
48
 
44
49
  export const formatDate = (str: string, timezone = 'America/Santiago', format = 'DD-MM-YYYY HH:mm:ss'): string => {
@@ -29,6 +29,8 @@ describe('string formatter', () => {
29
29
  expect(formatMoney(100000)).toStrictEqual('$100.000');
30
30
  expect(formatMoney(1000000)).toStrictEqual('$1.000.000');
31
31
 
32
+ expect(formatMoney(1434591.1)).toStrictEqual('$1.434.591,1');
33
+
32
34
  expect(formatMoney(1000, CurrencyEnum.CMR_PTS)).toStrictEqual('1.000 (pts)');
33
35
  expect(formatMoney(1000000, CurrencyEnum.CMR_PTS)).toStrictEqual('1.000.000 (pts)');
34
36
 
@@ -45,6 +47,17 @@ describe('string formatter', () => {
45
47
  expect(formatMoney(1000000, CurrencyEnum.MXN)).toStrictEqual('$1,000,000');
46
48
  });
47
49
 
50
+ it('should return formatted money right separator and decimal', () => {
51
+ expect.hasAssertions();
52
+
53
+ expect(formatMoney(1434591.1)).toStrictEqual('$1.434.591,1');
54
+ expect(formatMoney(1434591.1, CurrencyEnum.CLP)).toStrictEqual('$1.434.591,1');
55
+ expect(formatMoney(1434591.1, CurrencyEnum.ARS)).toStrictEqual('$1.434.591,1');
56
+ expect(formatMoney(1434591.1, CurrencyEnum.COP)).toStrictEqual('$1.434.591,1');
57
+
58
+ expect(formatMoney(1434591.1, CurrencyEnum.MXN)).toStrictEqual('$1,434,591.1');
59
+ });
60
+
48
61
  it('should return date as a formatted CLP Date', () => {
49
62
  expect.hasAssertions();
50
63