nhb-toolbox 4.2.0 → 4.2.1

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.
@@ -14,7 +14,7 @@ exports.ones = [
14
14
  'nine',
15
15
  ];
16
16
  exports.teens = [
17
- '',
17
+ 'ten',
18
18
  'eleven',
19
19
  'twelve',
20
20
  'thirteen',
@@ -45,11 +45,8 @@ exports.thousands = [
45
45
  'trillion',
46
46
  'quadrillion',
47
47
  'quintillion',
48
- 'sextillion',
49
- 'septillion',
50
- 'octillion',
51
- 'nonillion',
52
- 'decillion',
48
+ // ! Needs to modify later, below supports up to 10 sextillion! It's a bug!
49
+ // 'sextillion',
53
50
  ];
54
51
  /** List of ISO 4217 currency codes */
55
52
  exports.CURRENCY_CODES = [
@@ -5,7 +5,8 @@ exports.numberToWords = numberToWords;
5
5
  const constants_1 = require("./constants");
6
6
  const helpers_1 = require("./helpers");
7
7
  /**
8
- * * Converts a number to words
8
+ * * Converts a number to words.
9
+ * @Warning ***Supports numeric values up to `10e19` or `10^20` (one hundred quintillion).***
9
10
  * @param number - The number to convert into words.
10
11
  * @returns The number converted in words.
11
12
  */
@@ -18,6 +19,9 @@ function numberToWords(num) {
18
19
  let i = 0;
19
20
  let result = '';
20
21
  while (number > 0) {
22
+ if (i >= constants_1.thousands.length) {
23
+ return `Number exceeds supported range (max is 10e${constants_1.thousands.length * 3 - 2})`;
24
+ }
21
25
  if (number % 1000 !== 0) {
22
26
  const isLastGroup = i === 0 && number % 100 < 100;
23
27
  const prefix = (0, helpers_1._convertLessThanThousand)(number % 1000, isLastGroup);
@@ -1,7 +1,7 @@
1
1
  export declare const ones: readonly ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
2
- export declare const teens: readonly ["", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
2
+ export declare const teens: readonly ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
3
3
  export declare const tens: readonly ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
4
- export declare const thousands: readonly ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion"];
4
+ export declare const thousands: readonly ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion"];
5
5
  /** List of ISO 4217 currency codes */
6
6
  export declare const CURRENCY_CODES: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWL"];
7
7
  /** List of all supported BCP 47 locales */
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/number/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,uFAWP,CAAC;AAEX,eAAO,MAAM,KAAK,sHAWR,CAAC;AAEX,eAAO,MAAM,IAAI,oGAWP,CAAC;AAEX,eAAO,MAAM,SAAS,8JAaZ,CAAC;AAEX,sCAAsC;AACtC,eAAO,MAAM,cAAc,2mCAiKjB,CAAC;AAEX,2CAA2C;AAC3C,eAAO,MAAM,YAAY,mnCA8Hf,CAAC;AAEX,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiKnB,CAAC;AAEX,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,oOAgCvB,CAAC;AAEX,mDAAmD;AACnD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDR,CAAC;AAEX,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;CAuBrB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/number/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,uFAWP,CAAC;AAEX,eAAO,MAAM,KAAK,yHAWR,CAAC;AAEX,eAAO,MAAM,IAAI,oGAWP,CAAC;AAEX,eAAO,MAAM,SAAS,2FAUZ,CAAC;AAEX,sCAAsC;AACtC,eAAO,MAAM,cAAc,2mCAiKjB,CAAC;AAEX,2CAA2C;AAC3C,eAAO,MAAM,YAAY,mnCA8Hf,CAAC;AAEX,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiKnB,CAAC;AAEX,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,oOAgCvB,CAAC;AAEX,mDAAmD;AACnD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDR,CAAC;AAEX,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;CAuBrB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { Numeric } from '../types';
2
2
  /**
3
- * * Converts a number to words
3
+ * * Converts a number to words.
4
+ * @Warning ***Supports numeric values up to `10e19` or `10^20` (one hundred quintillion).***
4
5
  * @param number - The number to convert into words.
5
6
  * @returns The number converted in words.
6
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/number/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIxC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CA4BlD;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,QAAS,OAAO,KAAG,MA8BrD,CAAC"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/number/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIxC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAgClD;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,QAAS,OAAO,KAAG,MA8BrD,CAAC"}
@@ -11,7 +11,7 @@ export const ones = [
11
11
  'nine',
12
12
  ];
13
13
  export const teens = [
14
- '',
14
+ 'ten',
15
15
  'eleven',
16
16
  'twelve',
17
17
  'thirteen',
@@ -42,11 +42,8 @@ export const thousands = [
42
42
  'trillion',
43
43
  'quadrillion',
44
44
  'quintillion',
45
- 'sextillion',
46
- 'septillion',
47
- 'octillion',
48
- 'nonillion',
49
- 'decillion',
45
+ // ! Needs to modify later, below supports up to 10 sextillion! It's a bug!
46
+ // 'sextillion',
50
47
  ];
51
48
  /** List of ISO 4217 currency codes */
52
49
  export const CURRENCY_CODES = [
@@ -1,7 +1,8 @@
1
1
  import { thousands } from './constants';
2
2
  import { _convertLessThanThousand } from './helpers';
3
3
  /**
4
- * * Converts a number to words
4
+ * * Converts a number to words.
5
+ * @Warning ***Supports numeric values up to `10e19` or `10^20` (one hundred quintillion).***
5
6
  * @param number - The number to convert into words.
6
7
  * @returns The number converted in words.
7
8
  */
@@ -14,6 +15,9 @@ export function numberToWords(num) {
14
15
  let i = 0;
15
16
  let result = '';
16
17
  while (number > 0) {
18
+ if (i >= thousands.length) {
19
+ return `Number exceeds supported range (max is 10e${thousands.length * 3 - 2})`;
20
+ }
17
21
  if (number % 1000 !== 0) {
18
22
  const isLastGroup = i === 0 && number % 100 < 100;
19
23
  const prefix = _convertLessThanThousand(number % 1000, isLastGroup);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -52,7 +52,7 @@
52
52
  "name": "Nazmul Hassan",
53
53
  "email": "nazmulnhb@gmail.com"
54
54
  },
55
- "license": "ISC",
55
+ "license": "Apache-2.0",
56
56
  "devDependencies": {
57
57
  "@eslint/js": "^9.18.0",
58
58
  "@types/jest": "^29.5.14",