@onivoro/isomorphic-common 0.0.15 → 0.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/isomorphic-common",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "main": "./src/index.js",
5
5
  "type": "commonjs"
6
6
  }
package/src/index.d.ts CHANGED
@@ -17,9 +17,11 @@ export * from './lib/functions/to-boolean-string.function';
17
17
  export * from './lib/functions/to-calendar-date.function';
18
18
  export * from './lib/functions/to-csv-string.function';
19
19
  export * from './lib/functions/to-decimal-base.function';
20
+ export * from './lib/functions/to-dollars-and-cents.function';
20
21
  export * from './lib/functions/to-locale-date-string.function';
21
22
  export * from './lib/functions/to-locale-time-string.function';
22
23
  export * from './lib/functions/to-unique-array.function';
24
+ export * from './lib/functions/to-words.function';
23
25
  export * from './lib/functions/try-parse-date.function';
24
26
  export * from './lib/functions/unicode-words.const';
25
27
  export * from './lib/functions/upper-first.function';
package/src/index.js CHANGED
@@ -20,9 +20,11 @@ tslib_1.__exportStar(require("./lib/functions/to-boolean-string.function"), expo
20
20
  tslib_1.__exportStar(require("./lib/functions/to-calendar-date.function"), exports);
21
21
  tslib_1.__exportStar(require("./lib/functions/to-csv-string.function"), exports);
22
22
  tslib_1.__exportStar(require("./lib/functions/to-decimal-base.function"), exports);
23
+ tslib_1.__exportStar(require("./lib/functions/to-dollars-and-cents.function"), exports);
23
24
  tslib_1.__exportStar(require("./lib/functions/to-locale-date-string.function"), exports);
24
25
  tslib_1.__exportStar(require("./lib/functions/to-locale-time-string.function"), exports);
25
26
  tslib_1.__exportStar(require("./lib/functions/to-unique-array.function"), exports);
27
+ tslib_1.__exportStar(require("./lib/functions/to-words.function"), exports);
26
28
  tslib_1.__exportStar(require("./lib/functions/try-parse-date.function"), exports);
27
29
  tslib_1.__exportStar(require("./lib/functions/unicode-words.const"), exports);
28
30
  tslib_1.__exportStar(require("./lib/functions/upper-first.function"), exports);
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/isomorphic-common/src/index.ts"],"names":[],"mappings":";;;AAAA,kFAAwD;AACxD,mFAAyD;AACzD,qFAA2D;AAE3D,8EAAoD;AACpD,8EAAoD;AACpD,6FAAmE;AACnE,uFAA6D;AAC7D,sFAA4D;AAC5D,mFAAyD;AACzD,8EAAoD;AACpD,8EAAoD;AACpD,uFAA6D;AAC7D,qFAA2D;AAC3D,8EAAoD;AACpD,mFAAyD;AACzD,qFAA2D;AAC3D,oFAA0D;AAC1D,iFAAuD;AACvD,mFAAyD;AACzD,yFAA+D;AAC/D,yFAA+D;AAC/D,mFAAyD;AACzD,kFAAwD;AACxD,8EAAoD;AACpD,+EAAqD;AACrD,yEAA+C;AAE/C,kGAAwE;AACxE,qFAA2D;AAC3D,wEAA8C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/isomorphic-common/src/index.ts"],"names":[],"mappings":";;;AAAA,kFAAwD;AACxD,mFAAyD;AACzD,qFAA2D;AAE3D,8EAAoD;AACpD,8EAAoD;AACpD,6FAAmE;AACnE,uFAA6D;AAC7D,sFAA4D;AAC5D,mFAAyD;AACzD,8EAAoD;AACpD,8EAAoD;AACpD,uFAA6D;AAC7D,qFAA2D;AAC3D,8EAAoD;AACpD,mFAAyD;AACzD,qFAA2D;AAC3D,oFAA0D;AAC1D,iFAAuD;AACvD,mFAAyD;AACzD,wFAA8D;AAC9D,yFAA+D;AAC/D,yFAA+D;AAC/D,mFAAyD;AACzD,4EAAkD;AAClD,kFAAwD;AACxD,8EAAoD;AACpD,+EAAqD;AACrD,yEAA+C;AAE/C,kGAAwE;AACxE,qFAA2D;AAC3D,wEAA8C"}
@@ -0,0 +1 @@
1
+ export declare function toDollarsAndCents(number: any): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDollarsAndCents = void 0;
4
+ const to_words_function_1 = require("./to-words.function");
5
+ function toDollarsAndCents(number) {
6
+ const num = Number(number);
7
+ const decimal = (Math.round((num % 1) * 100)) / 100;
8
+ const int = num - decimal;
9
+ const dollars = `${(0, to_words_function_1.toWords)(int)} dollars`;
10
+ if (!decimal) {
11
+ return dollars;
12
+ }
13
+ return `${dollars} and ${(0, to_words_function_1.toWords)(decimal * 100)} cents`;
14
+ }
15
+ exports.toDollarsAndCents = toDollarsAndCents;
16
+ //# sourceMappingURL=to-dollars-and-cents.function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-dollars-and-cents.function.js","sourceRoot":"","sources":["../../../../../../libs/isomorphic-common/src/lib/functions/to-dollars-and-cents.function.ts"],"names":[],"mappings":";;;AAAA,2DAA8C;AAE9C,SAAgB,iBAAiB,CAAC,MAAW;IACzC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3B,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;IACpD,MAAM,GAAG,GAAG,GAAG,GAAG,OAAO,CAAC;IAE1B,MAAM,OAAO,GAAG,GAAG,IAAA,2BAAO,EAAC,GAAG,CAAC,UAAU,CAAC;IAE1C,IAAI,CAAC,OAAO,EAAE;QACV,OAAO,OAAO,CAAC;KAClB;IAED,OAAO,GAAG,OAAO,QAAQ,IAAA,2BAAO,EAAC,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC5D,CAAC;AAZD,8CAYC"}
@@ -0,0 +1 @@
1
+ export declare function toWords(number: any): string;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toWords = void 0;
4
+ const MAX_SAFE_INTEGER = 9007199254740991;
5
+ const TEN = 10;
6
+ const ONE_HUNDRED = 100;
7
+ const ONE_THOUSAND = 1000;
8
+ const ONE_MILLION = 1000000;
9
+ const ONE_BILLION = 1000000000;
10
+ const ONE_TRILLION = 1000000000000;
11
+ const ONE_QUADRILLION = 1000000000000000;
12
+ const MAX = MAX_SAFE_INTEGER + 1;
13
+ const LESS_THAN_TWENTY = [
14
+ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
15
+ 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
16
+ ];
17
+ const TENTHS_LESS_THAN_HUNDRED = [
18
+ 'zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'
19
+ ];
20
+ function toWords(number) {
21
+ let words;
22
+ const num = parseInt(number, 10);
23
+ if (!isFinite(num)) {
24
+ throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
25
+ }
26
+ if (!isSafeNumber(num)) {
27
+ throw new RangeError('Input is not a safe number, it\'s either too large or too small.');
28
+ }
29
+ words = generateWords(num);
30
+ return words;
31
+ }
32
+ exports.toWords = toWords;
33
+ function generateWords(number, words) {
34
+ let remainder, word;
35
+ if (number === 0) {
36
+ return !words ? 'zero' : words.join(' ').replace(/,$/, '');
37
+ }
38
+ if (!words) {
39
+ words = [];
40
+ }
41
+ if (number < 0) {
42
+ words.push('minus');
43
+ number = Math.abs(number);
44
+ }
45
+ if (number < 20) {
46
+ remainder = 0;
47
+ word = LESS_THAN_TWENTY[number];
48
+ }
49
+ else if (number < ONE_HUNDRED) {
50
+ remainder = number % TEN;
51
+ word = TENTHS_LESS_THAN_HUNDRED[Math.floor(number / TEN)];
52
+ if (remainder) {
53
+ word += '-' + LESS_THAN_TWENTY[remainder];
54
+ remainder = 0;
55
+ }
56
+ }
57
+ else if (number < ONE_THOUSAND) {
58
+ remainder = number % ONE_HUNDRED;
59
+ word = generateWords(Math.floor(number / ONE_HUNDRED)) + ' hundred';
60
+ }
61
+ else if (number < ONE_MILLION) {
62
+ remainder = number % ONE_THOUSAND;
63
+ word = generateWords(Math.floor(number / ONE_THOUSAND)) + ' thousand,';
64
+ }
65
+ else if (number < ONE_BILLION) {
66
+ remainder = number % ONE_MILLION;
67
+ word = generateWords(Math.floor(number / ONE_MILLION)) + ' million,';
68
+ }
69
+ else if (number < ONE_TRILLION) {
70
+ remainder = number % ONE_BILLION;
71
+ word = generateWords(Math.floor(number / ONE_BILLION)) + ' billion,';
72
+ }
73
+ else if (number < ONE_QUADRILLION) {
74
+ remainder = number % ONE_TRILLION;
75
+ word = generateWords(Math.floor(number / ONE_TRILLION)) + ' trillion,';
76
+ }
77
+ else if (number <= MAX) {
78
+ remainder = number % ONE_QUADRILLION;
79
+ word = generateWords(Math.floor(number / ONE_QUADRILLION)) +
80
+ ' quadrillion,';
81
+ }
82
+ words.push(word);
83
+ return generateWords(remainder, words);
84
+ }
85
+ function isFinite(value) {
86
+ return !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity);
87
+ }
88
+ function isSafeNumber(value) {
89
+ return typeof value === 'number' && Math.abs(value) <= MAX_SAFE_INTEGER;
90
+ }
91
+ //# sourceMappingURL=to-words.function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-words.function.js","sourceRoot":"","sources":["../../../../../../libs/isomorphic-common/src/lib/functions/to-words.function.ts"],"names":[],"mappings":";;;AAAA,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAE1C,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,GAAG,GAAG,gBAAgB,GAAG,CAAC,CAAC;AACjC,MAAM,gBAAgB,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