@cloudparker/moldex.js 0.0.54 → 0.0.55
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/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/utils/currency-service.d.ts +38 -0
- package/dist/services/utils/currency-service.js +77 -0
- package/dist/services/utils/utils-service.d.ts +0 -19
- package/dist/services/utils/utils-service.js +0 -23
- package/package.json +1 -1
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number into words based on the Indian numbering system.
|
|
3
|
+
* Supports up to Crore level and works for numbers up to 99 Crore.
|
|
4
|
+
*
|
|
5
|
+
* @param num - The number to convert to words.
|
|
6
|
+
* @returns A string representing the number in words.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* numberToWords(190005000) // Output: "Nineteen Crore, Fifty Thousand"
|
|
10
|
+
* numberToWords(123456789) // Output: "Twelve Crore, Thirty-Four Lakh, Fifty-Six Thousand, Seven Hundred and Eighty-Nine"
|
|
11
|
+
*/
|
|
12
|
+
export declare function numberToWords(num: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a two-digit number into words.
|
|
15
|
+
*
|
|
16
|
+
* @param num - The number to convert.
|
|
17
|
+
* @returns The number in words.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertTwoDigits(num: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a number to a currency-formatted string.
|
|
22
|
+
*
|
|
23
|
+
* This function formats a given number as a currency string, using a specified currency symbol
|
|
24
|
+
* (default is '$'). It handles negative values by adding a '-' sign in front of the formatted value.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The numeric value to format as currency.
|
|
27
|
+
* @param symbol - The currency symbol to use. Default is '$'.
|
|
28
|
+
* @returns A formatted string representing the currency value.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const formattedValue = toCurrency(1234.56, '$');
|
|
32
|
+
* console.log(formattedValue); // Output: "$ 1234.56"
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const formattedNegative = toCurrency(-1234.56, '€');
|
|
36
|
+
* console.log(formattedNegative); // Output: "- € 1234.56"
|
|
37
|
+
*/
|
|
38
|
+
export declare function toCurrency(value?: number, symbol?: string): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const belowTwenty = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"];
|
|
2
|
+
const tens = ["", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];
|
|
3
|
+
const scales = ["", "Thousand", "Lakh", "Crore"];
|
|
4
|
+
/**
|
|
5
|
+
* Converts a number into words based on the Indian numbering system.
|
|
6
|
+
* Supports up to Crore level and works for numbers up to 99 Crore.
|
|
7
|
+
*
|
|
8
|
+
* @param num - The number to convert to words.
|
|
9
|
+
* @returns A string representing the number in words.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* numberToWords(190005000) // Output: "Nineteen Crore, Fifty Thousand"
|
|
13
|
+
* numberToWords(123456789) // Output: "Twelve Crore, Thirty-Four Lakh, Fifty-Six Thousand, Seven Hundred and Eighty-Nine"
|
|
14
|
+
*/
|
|
15
|
+
export function numberToWords(num) {
|
|
16
|
+
if (num === 0)
|
|
17
|
+
return "Zero";
|
|
18
|
+
const crore = Math.floor(num / 10000000);
|
|
19
|
+
const lakh = Math.floor((num % 10000000) / 100000);
|
|
20
|
+
const thousand = Math.floor((num % 100000) / 1000);
|
|
21
|
+
const hundred = Math.floor((num % 1000) / 100);
|
|
22
|
+
const remainder = num % 100;
|
|
23
|
+
let result = '';
|
|
24
|
+
if (crore > 0) {
|
|
25
|
+
result += `${convertTwoDigits(crore)} Crore`;
|
|
26
|
+
}
|
|
27
|
+
if (lakh > 0) {
|
|
28
|
+
result += result ? `, ${convertTwoDigits(lakh)} Lakh` : `${convertTwoDigits(lakh)} Lakh`;
|
|
29
|
+
}
|
|
30
|
+
if (thousand > 0) {
|
|
31
|
+
result += result ? `, ${convertTwoDigits(thousand)} Thousand` : `${convertTwoDigits(thousand)} Thousand`;
|
|
32
|
+
}
|
|
33
|
+
if (hundred > 0) {
|
|
34
|
+
result += result ? `, ${convertTwoDigits(hundred)} Hundred` : `${convertTwoDigits(hundred)} Hundred`;
|
|
35
|
+
}
|
|
36
|
+
if (remainder > 0) {
|
|
37
|
+
result += result ? ` and ${convertTwoDigits(remainder)}` : `${convertTwoDigits(remainder)}`;
|
|
38
|
+
}
|
|
39
|
+
return result.trim();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts a two-digit number into words.
|
|
43
|
+
*
|
|
44
|
+
* @param num - The number to convert.
|
|
45
|
+
* @returns The number in words.
|
|
46
|
+
*/
|
|
47
|
+
export function convertTwoDigits(num) {
|
|
48
|
+
if (num < 20) {
|
|
49
|
+
return belowTwenty[num];
|
|
50
|
+
}
|
|
51
|
+
const ten = Math.floor(num / 10);
|
|
52
|
+
const unit = num % 10;
|
|
53
|
+
return `${tens[ten]}${unit ? " " + belowTwenty[unit] : ""}`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Converts a number to a currency-formatted string.
|
|
57
|
+
*
|
|
58
|
+
* This function formats a given number as a currency string, using a specified currency symbol
|
|
59
|
+
* (default is '$'). It handles negative values by adding a '-' sign in front of the formatted value.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The numeric value to format as currency.
|
|
62
|
+
* @param symbol - The currency symbol to use. Default is '$'.
|
|
63
|
+
* @returns A formatted string representing the currency value.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const formattedValue = toCurrency(1234.56, '$');
|
|
67
|
+
* console.log(formattedValue); // Output: "$ 1234.56"
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const formattedNegative = toCurrency(-1234.56, '€');
|
|
71
|
+
* console.log(formattedNegative); // Output: "- € 1234.56"
|
|
72
|
+
*/
|
|
73
|
+
export function toCurrency(value = 0, symbol = '$') {
|
|
74
|
+
const isNegative = value < 0;
|
|
75
|
+
const currencyValue = Math.abs(value).toFixed(2);
|
|
76
|
+
return `${isNegative ? '- ' : ''}${symbol} ${currencyValue}`;
|
|
77
|
+
}
|
|
@@ -223,25 +223,6 @@ export declare function toArrayByKey(key: string, obj?: Record<string, any>): an
|
|
|
223
223
|
* console.log(result); // Output: "bcd"
|
|
224
224
|
*/
|
|
225
225
|
export declare function convertNumToAlphabets(num: number): string;
|
|
226
|
-
/**
|
|
227
|
-
* Converts a number to a currency-formatted string.
|
|
228
|
-
*
|
|
229
|
-
* This function formats a given number as a currency string, using a specified currency symbol
|
|
230
|
-
* (default is '$'). It handles negative values by adding a '-' sign in front of the formatted value.
|
|
231
|
-
*
|
|
232
|
-
* @param value - The numeric value to format as currency.
|
|
233
|
-
* @param symbol - The currency symbol to use. Default is '$'.
|
|
234
|
-
* @returns A formatted string representing the currency value.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* const formattedValue = toCurrency(1234.56, '$');
|
|
238
|
-
* console.log(formattedValue); // Output: "$ 1234.56"
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* const formattedNegative = toCurrency(-1234.56, '€');
|
|
242
|
-
* console.log(formattedNegative); // Output: "- € 1234.56"
|
|
243
|
-
*/
|
|
244
|
-
export declare function toCurrency(value?: number, symbol?: string): string;
|
|
245
226
|
/**
|
|
246
227
|
* Converts a length in inches to pixels based on a DPI of 96.
|
|
247
228
|
*
|
|
@@ -350,29 +350,6 @@ export function convertNumToAlphabets(num) {
|
|
|
350
350
|
.map((digit) => alphabets[parseInt(digit, 10)] || '')
|
|
351
351
|
.join('');
|
|
352
352
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Converts a number to a currency-formatted string.
|
|
355
|
-
*
|
|
356
|
-
* This function formats a given number as a currency string, using a specified currency symbol
|
|
357
|
-
* (default is '$'). It handles negative values by adding a '-' sign in front of the formatted value.
|
|
358
|
-
*
|
|
359
|
-
* @param value - The numeric value to format as currency.
|
|
360
|
-
* @param symbol - The currency symbol to use. Default is '$'.
|
|
361
|
-
* @returns A formatted string representing the currency value.
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* const formattedValue = toCurrency(1234.56, '$');
|
|
365
|
-
* console.log(formattedValue); // Output: "$ 1234.56"
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
* const formattedNegative = toCurrency(-1234.56, '€');
|
|
369
|
-
* console.log(formattedNegative); // Output: "- € 1234.56"
|
|
370
|
-
*/
|
|
371
|
-
export function toCurrency(value = 0, symbol = '$') {
|
|
372
|
-
const isNegative = value < 0;
|
|
373
|
-
const currencyValue = Math.abs(value).toFixed(2);
|
|
374
|
-
return `${isNegative ? '- ' : ''}${symbol} ${currencyValue}`;
|
|
375
|
-
}
|
|
376
353
|
/**
|
|
377
354
|
* Converts a length in inches to pixels based on a DPI of 96.
|
|
378
355
|
*
|