@onivoro/isomorphic-common 0.4.2 → 0.4.3

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.
Files changed (31) hide show
  1. package/dist/cjs/index.d.ts +3 -0
  2. package/dist/cjs/index.js +3 -0
  3. package/dist/cjs/lib/constants/decimal-regex.constant.d.ts +1 -0
  4. package/dist/cjs/lib/constants/decimal-regex.constant.js +4 -0
  5. package/dist/cjs/lib/functions/money.function.d.ts +1 -0
  6. package/dist/cjs/lib/functions/money.function.js +20 -0
  7. package/dist/cjs/lib/functions/remove-alpha-chars.function.d.ts +1 -0
  8. package/dist/cjs/lib/functions/remove-alpha-chars.function.js +11 -0
  9. package/dist/cjs/lib/functions/to-dollars-and-cents.function.d.ts +1 -1
  10. package/dist/cjs/lib/functions/to-dollars-and-cents.function.js +3 -1
  11. package/dist/cjs/lib/functions/to-words.function.d.ts +1 -1
  12. package/dist/cjs/lib/functions/to-words.function.js +3 -1
  13. package/dist/esm/index.d.ts +3 -0
  14. package/dist/esm/index.js +3 -0
  15. package/dist/esm/lib/constants/decimal-regex.constant.d.ts +1 -0
  16. package/dist/esm/lib/constants/decimal-regex.constant.js +4 -0
  17. package/dist/esm/lib/functions/money.function.d.ts +1 -0
  18. package/dist/esm/lib/functions/money.function.js +20 -0
  19. package/dist/esm/lib/functions/remove-alpha-chars.function.d.ts +1 -0
  20. package/dist/esm/lib/functions/remove-alpha-chars.function.js +11 -0
  21. package/dist/esm/lib/functions/to-dollars-and-cents.function.d.ts +1 -1
  22. package/dist/esm/lib/functions/to-dollars-and-cents.function.js +3 -1
  23. package/dist/esm/lib/functions/to-words.function.d.ts +1 -1
  24. package/dist/esm/lib/functions/to-words.function.js +3 -1
  25. package/dist/types/index.d.ts +3 -0
  26. package/dist/types/lib/constants/decimal-regex.constant.d.ts +1 -0
  27. package/dist/types/lib/functions/money.function.d.ts +1 -0
  28. package/dist/types/lib/functions/remove-alpha-chars.function.d.ts +1 -0
  29. package/dist/types/lib/functions/to-dollars-and-cents.function.d.ts +1 -1
  30. package/dist/types/lib/functions/to-words.function.d.ts +1 -1
  31. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ export * from './lib/constants/decimal-regex.constant';
1
2
  export * from './lib/constants/millis-per-day.constant';
2
3
  export * from './lib/constants/millis-per-hour.constant';
3
4
  export * from './lib/constants/millis-per-minute.constant';
@@ -8,8 +9,10 @@ export * from './lib/functions/from-boolean-string.function';
8
9
  export * from './lib/functions/from-calendar-date.function';
9
10
  export * from './lib/functions/from-csv-string.function';
10
11
  export * from './lib/functions/kebab-case.function';
12
+ export * from './lib/functions/money.function';
11
13
  export * from './lib/functions/parse-bool.function';
12
14
  export * from './lib/functions/properties-to-array.function';
15
+ export * from './lib/functions/remove-alpha-chars.function';
13
16
  export * from './lib/functions/sleep.function';
14
17
  export * from './lib/functions/sanitize-filename.function';
15
18
  export * from './lib/functions/snake-case.function';
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/constants/decimal-regex.constant"), exports);
17
18
  __exportStar(require("./lib/constants/millis-per-day.constant"), exports);
18
19
  __exportStar(require("./lib/constants/millis-per-hour.constant"), exports);
19
20
  __exportStar(require("./lib/constants/millis-per-minute.constant"), exports);
@@ -24,8 +25,10 @@ __exportStar(require("./lib/functions/from-boolean-string.function"), exports);
24
25
  __exportStar(require("./lib/functions/from-calendar-date.function"), exports);
25
26
  __exportStar(require("./lib/functions/from-csv-string.function"), exports);
26
27
  __exportStar(require("./lib/functions/kebab-case.function"), exports);
28
+ __exportStar(require("./lib/functions/money.function"), exports);
27
29
  __exportStar(require("./lib/functions/parse-bool.function"), exports);
28
30
  __exportStar(require("./lib/functions/properties-to-array.function"), exports);
31
+ __exportStar(require("./lib/functions/remove-alpha-chars.function"), exports);
29
32
  __exportStar(require("./lib/functions/sleep.function"), exports);
30
33
  __exportStar(require("./lib/functions/sanitize-filename.function"), exports);
31
34
  __exportStar(require("./lib/functions/snake-case.function"), exports);
@@ -0,0 +1 @@
1
+ export declare const decimalRegex: RegExp;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decimalRegex = void 0;
4
+ exports.decimalRegex = /(\d|\.)/g;
@@ -0,0 +1 @@
1
+ export declare function money(rawValue: number | string): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.money = void 0;
4
+ const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
5
+ function money(rawValue) {
6
+ if (!rawValue) {
7
+ return;
8
+ }
9
+ const scrubbed = (0, remove_alpha_chars_function_1.removeAlphaChars)(rawValue);
10
+ const amount = Number(scrubbed);
11
+ if (!amount && amount !== 0) {
12
+ return;
13
+ }
14
+ const formatter = new Intl.NumberFormat('en-US', {
15
+ style: 'currency',
16
+ currency: 'USD'
17
+ });
18
+ return formatter.format(Number(amount));
19
+ }
20
+ exports.money = money;
@@ -0,0 +1 @@
1
+ export declare function removeAlphaChars(input?: string | number): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeAlphaChars = void 0;
4
+ const decimal_regex_constant_1 = require("../constants/decimal-regex.constant");
5
+ function removeAlphaChars(input) {
6
+ if (!input) {
7
+ return;
8
+ }
9
+ return input.toString().match(decimal_regex_constant_1.decimalRegex).join('');
10
+ }
11
+ exports.removeAlphaChars = removeAlphaChars;
@@ -1 +1 @@
1
- export declare function toDollarsAndCents(number: any): string;
1
+ export declare function toDollarsAndCents(input: string | number): string;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toDollarsAndCents = void 0;
4
+ const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
4
5
  const to_words_function_1 = require("./to-words.function");
5
- function toDollarsAndCents(number) {
6
+ function toDollarsAndCents(input) {
7
+ const number = (0, remove_alpha_chars_function_1.removeAlphaChars)(input);
6
8
  const num = Number(number);
7
9
  const decimal = (Math.round((num % 1) * 100)) / 100;
8
10
  const int = num - decimal;
@@ -1 +1 @@
1
- export declare function toWords(number: any): string;
1
+ export declare function toWords(input: any): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toWords = void 0;
4
+ const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
4
5
  const MAX_SAFE_INTEGER = 9007199254740991;
5
6
  const TEN = 10;
6
7
  const ONE_HUNDRED = 100;
@@ -17,8 +18,9 @@ const LESS_THAN_TWENTY = [
17
18
  const TENTHS_LESS_THAN_HUNDRED = [
18
19
  'zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'
19
20
  ];
20
- function toWords(number) {
21
+ function toWords(input) {
21
22
  let words;
23
+ const number = (0, remove_alpha_chars_function_1.removeAlphaChars)(input);
22
24
  const num = parseInt(number, 10);
23
25
  if (!isFinite(num)) {
24
26
  throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
@@ -1,3 +1,4 @@
1
+ export * from './lib/constants/decimal-regex.constant';
1
2
  export * from './lib/constants/millis-per-day.constant';
2
3
  export * from './lib/constants/millis-per-hour.constant';
3
4
  export * from './lib/constants/millis-per-minute.constant';
@@ -8,8 +9,10 @@ export * from './lib/functions/from-boolean-string.function';
8
9
  export * from './lib/functions/from-calendar-date.function';
9
10
  export * from './lib/functions/from-csv-string.function';
10
11
  export * from './lib/functions/kebab-case.function';
12
+ export * from './lib/functions/money.function';
11
13
  export * from './lib/functions/parse-bool.function';
12
14
  export * from './lib/functions/properties-to-array.function';
15
+ export * from './lib/functions/remove-alpha-chars.function';
13
16
  export * from './lib/functions/sleep.function';
14
17
  export * from './lib/functions/sanitize-filename.function';
15
18
  export * from './lib/functions/snake-case.function';
package/dist/esm/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/constants/decimal-regex.constant"), exports);
17
18
  __exportStar(require("./lib/constants/millis-per-day.constant"), exports);
18
19
  __exportStar(require("./lib/constants/millis-per-hour.constant"), exports);
19
20
  __exportStar(require("./lib/constants/millis-per-minute.constant"), exports);
@@ -24,8 +25,10 @@ __exportStar(require("./lib/functions/from-boolean-string.function"), exports);
24
25
  __exportStar(require("./lib/functions/from-calendar-date.function"), exports);
25
26
  __exportStar(require("./lib/functions/from-csv-string.function"), exports);
26
27
  __exportStar(require("./lib/functions/kebab-case.function"), exports);
28
+ __exportStar(require("./lib/functions/money.function"), exports);
27
29
  __exportStar(require("./lib/functions/parse-bool.function"), exports);
28
30
  __exportStar(require("./lib/functions/properties-to-array.function"), exports);
31
+ __exportStar(require("./lib/functions/remove-alpha-chars.function"), exports);
29
32
  __exportStar(require("./lib/functions/sleep.function"), exports);
30
33
  __exportStar(require("./lib/functions/sanitize-filename.function"), exports);
31
34
  __exportStar(require("./lib/functions/snake-case.function"), exports);
@@ -0,0 +1 @@
1
+ export declare const decimalRegex: RegExp;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decimalRegex = void 0;
4
+ exports.decimalRegex = /(\d|\.)/g;
@@ -0,0 +1 @@
1
+ export declare function money(rawValue: number | string): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.money = void 0;
4
+ const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
5
+ function money(rawValue) {
6
+ if (!rawValue) {
7
+ return;
8
+ }
9
+ const scrubbed = (0, remove_alpha_chars_function_1.removeAlphaChars)(rawValue);
10
+ const amount = Number(scrubbed);
11
+ if (!amount && amount !== 0) {
12
+ return;
13
+ }
14
+ const formatter = new Intl.NumberFormat('en-US', {
15
+ style: 'currency',
16
+ currency: 'USD'
17
+ });
18
+ return formatter.format(Number(amount));
19
+ }
20
+ exports.money = money;
@@ -0,0 +1 @@
1
+ export declare function removeAlphaChars(input?: string | number): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeAlphaChars = void 0;
4
+ const decimal_regex_constant_1 = require("../constants/decimal-regex.constant");
5
+ function removeAlphaChars(input) {
6
+ if (!input) {
7
+ return;
8
+ }
9
+ return input.toString().match(decimal_regex_constant_1.decimalRegex).join('');
10
+ }
11
+ exports.removeAlphaChars = removeAlphaChars;
@@ -1 +1 @@
1
- export declare function toDollarsAndCents(number: any): string;
1
+ export declare function toDollarsAndCents(input: string | number): string;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toDollarsAndCents = void 0;
4
+ const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
4
5
  const to_words_function_1 = require("./to-words.function");
5
- function toDollarsAndCents(number) {
6
+ function toDollarsAndCents(input) {
7
+ const number = (0, remove_alpha_chars_function_1.removeAlphaChars)(input);
6
8
  const num = Number(number);
7
9
  const decimal = (Math.round((num % 1) * 100)) / 100;
8
10
  const int = num - decimal;
@@ -1 +1 @@
1
- export declare function toWords(number: any): string;
1
+ export declare function toWords(input: any): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toWords = void 0;
4
+ const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
4
5
  const MAX_SAFE_INTEGER = 9007199254740991;
5
6
  const TEN = 10;
6
7
  const ONE_HUNDRED = 100;
@@ -17,8 +18,9 @@ const LESS_THAN_TWENTY = [
17
18
  const TENTHS_LESS_THAN_HUNDRED = [
18
19
  'zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'
19
20
  ];
20
- function toWords(number) {
21
+ function toWords(input) {
21
22
  let words;
23
+ const number = (0, remove_alpha_chars_function_1.removeAlphaChars)(input);
22
24
  const num = parseInt(number, 10);
23
25
  if (!isFinite(num)) {
24
26
  throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
@@ -1,3 +1,4 @@
1
+ export * from './lib/constants/decimal-regex.constant';
1
2
  export * from './lib/constants/millis-per-day.constant';
2
3
  export * from './lib/constants/millis-per-hour.constant';
3
4
  export * from './lib/constants/millis-per-minute.constant';
@@ -8,8 +9,10 @@ export * from './lib/functions/from-boolean-string.function';
8
9
  export * from './lib/functions/from-calendar-date.function';
9
10
  export * from './lib/functions/from-csv-string.function';
10
11
  export * from './lib/functions/kebab-case.function';
12
+ export * from './lib/functions/money.function';
11
13
  export * from './lib/functions/parse-bool.function';
12
14
  export * from './lib/functions/properties-to-array.function';
15
+ export * from './lib/functions/remove-alpha-chars.function';
13
16
  export * from './lib/functions/sleep.function';
14
17
  export * from './lib/functions/sanitize-filename.function';
15
18
  export * from './lib/functions/snake-case.function';
@@ -0,0 +1 @@
1
+ export declare const decimalRegex: RegExp;
@@ -0,0 +1 @@
1
+ export declare function money(rawValue: number | string): string;
@@ -0,0 +1 @@
1
+ export declare function removeAlphaChars(input?: string | number): string;
@@ -1 +1 @@
1
- export declare function toDollarsAndCents(number: any): string;
1
+ export declare function toDollarsAndCents(input: string | number): string;
@@ -1 +1 @@
1
- export declare function toWords(number: any): string;
1
+ export declare function toWords(input: any): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/isomorphic-common",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/isomorphic-common.git"
6
6
  },