@qlibs/utils 1.3.0 → 1.4.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.
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/number.d.ts +3 -2
- package/dist/utils/number.js +34 -20
- package/dist/utils/price.d.ts +0 -1
- package/dist/utils/price.js +0 -4
- package/dist/utils/text.d.ts +0 -1
- package/dist/utils/text.js +0 -8
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
@@ -21,6 +21,7 @@ __exportStar(require("./formRules"), exports);
|
|
21
21
|
__exportStar(require("./generateQueryString"), exports);
|
22
22
|
__exportStar(require("./image"), exports);
|
23
23
|
__exportStar(require("./name"), exports);
|
24
|
+
__exportStar(require("./number"), exports);
|
24
25
|
__exportStar(require("./order"), exports);
|
25
26
|
__exportStar(require("./pagination"), exports);
|
26
27
|
__exportStar(require("./price"), exports);
|
package/dist/utils/number.d.ts
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
export declare function formatNumberRange(amountStart: number, amountEnd?: number): string;
|
2
|
-
export declare function formatNumber(
|
1
|
+
export declare function formatNumberRange(amountStart: number, amountEnd?: number, locale?: string): string;
|
2
|
+
export declare function formatNumber(num: string | number | undefined, locale?: string, currency?: 'IDR' | 'USD' | 'EUR'): string;
|
3
|
+
export declare function parseFormattedNumber(formattedString: string, locale?: string, currency?: 'IDR' | 'USD' | 'EUR'): number;
|
package/dist/utils/number.js
CHANGED
@@ -2,37 +2,51 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.formatNumberRange = formatNumberRange;
|
4
4
|
exports.formatNumber = formatNumber;
|
5
|
-
|
5
|
+
exports.parseFormattedNumber = parseFormattedNumber;
|
6
|
+
function formatNumberRange(amountStart, amountEnd, locale = 'id-ID') {
|
6
7
|
if (amountStart === amountEnd) {
|
7
|
-
return formatNumber(amountStart);
|
8
|
+
return formatNumber(amountStart, locale);
|
8
9
|
}
|
9
10
|
else if (amountStart && amountEnd) {
|
10
|
-
return (formatNumber(amountStart) +
|
11
|
+
return (formatNumber(amountStart, locale) +
|
11
12
|
' - ' +
|
12
|
-
formatNumber(amountEnd));
|
13
|
+
formatNumber(amountEnd, locale));
|
13
14
|
}
|
14
15
|
else if (amountStart) {
|
15
|
-
return formatNumber(amountStart) + ' - unlimited';
|
16
|
+
return formatNumber(amountStart, locale) + ' - unlimited';
|
16
17
|
}
|
17
18
|
else if (amountEnd) {
|
18
|
-
return 'up to ' + formatNumber(amountEnd);
|
19
|
+
return 'up to ' + formatNumber(amountEnd, locale);
|
19
20
|
}
|
20
21
|
else {
|
21
22
|
return '';
|
22
23
|
}
|
23
24
|
}
|
24
|
-
function formatNumber(
|
25
|
-
if (
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}
|
37
|
-
|
25
|
+
function formatNumber(num, locale = 'id-ID', currency) {
|
26
|
+
if (!num) {
|
27
|
+
num = 0;
|
28
|
+
}
|
29
|
+
if (num && isNaN(Number(num))) {
|
30
|
+
num = 0;
|
31
|
+
}
|
32
|
+
if (currency) {
|
33
|
+
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(Number(num));
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
return new Intl.NumberFormat(locale).format(Number(num));
|
37
|
+
}
|
38
|
+
}
|
39
|
+
function parseFormattedNumber(formattedString, locale = 'id-ID', currency) {
|
40
|
+
if (!formattedString) {
|
41
|
+
return 0;
|
42
|
+
}
|
43
|
+
const exampleNumber = 12345.6;
|
44
|
+
const formattedExample = new Intl.NumberFormat(locale, currency ? { style: 'currency', currency } : {}).format(exampleNumber);
|
45
|
+
const nonDigitChars = formattedExample.replace(/\d/g, '');
|
46
|
+
const thousandSeparator = nonDigitChars[0] || ',';
|
47
|
+
const decimalSeparator = nonDigitChars[1] || '.';
|
48
|
+
let normalizedString = formattedString.replace(/[^\d.,-]/g, '');
|
49
|
+
normalizedString = normalizedString.replace(new RegExp(`\\${thousandSeparator}`, 'g'), '');
|
50
|
+
normalizedString = normalizedString.replace(new RegExp(`\\${decimalSeparator}`), '.');
|
51
|
+
return parseFloat(normalizedString);
|
38
52
|
}
|
package/dist/utils/price.d.ts
CHANGED
@@ -2,4 +2,3 @@ export declare function formatCurrency(amount: number, currencySymbol?: string,
|
|
2
2
|
export declare function formatCurrencyIndonesia(amount: number): string;
|
3
3
|
export declare function formatCurrencyRangeIndonesia(amountStart: number, amountEnd?: number): string;
|
4
4
|
export declare function parseCurrency(currencyString: string, thousandSep?: string, decimalSep?: string): number;
|
5
|
-
export default function thousandSeparator(x: number | string): string;
|
package/dist/utils/price.js
CHANGED
@@ -4,7 +4,6 @@ exports.formatCurrency = formatCurrency;
|
|
4
4
|
exports.formatCurrencyIndonesia = formatCurrencyIndonesia;
|
5
5
|
exports.formatCurrencyRangeIndonesia = formatCurrencyRangeIndonesia;
|
6
6
|
exports.parseCurrency = parseCurrency;
|
7
|
-
exports.default = thousandSeparator;
|
8
7
|
function formatCurrency(amount, currencySymbol = '$', thousandSep = ',', decimalSep = '.', showDecimal = true) {
|
9
8
|
console.info('formatCurrency', amount);
|
10
9
|
if (typeof amount === 'string')
|
@@ -53,6 +52,3 @@ function parseCurrency(currencyString, thousandSep = ',', decimalSep = '.') {
|
|
53
52
|
const numberWithDecimal = intPart + (decPart ? decimalSep + decPart : '');
|
54
53
|
return parseFloat(numberWithDecimal);
|
55
54
|
}
|
56
|
-
function thousandSeparator(x) {
|
57
|
-
return x && (x === null || x === void 0 ? void 0 : x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.'));
|
58
|
-
}
|
package/dist/utils/text.d.ts
CHANGED
@@ -7,7 +7,6 @@ export type ReadableTextConfig = {
|
|
7
7
|
export declare function showReadableText(str: string, config?: ReadableTextConfig): string;
|
8
8
|
export declare function convertHtmlToText(htmlText: string): string;
|
9
9
|
export declare function convertSlugToText(slug: string): string;
|
10
|
-
export declare function convertTextToRupiah(text: string): string;
|
11
10
|
export declare function exportToCamelCase(str: string): string;
|
12
11
|
export declare const getYouTubeId: (url?: string) => string;
|
13
12
|
export declare function limitDescription(text: any, limit?: number): any;
|
package/dist/utils/text.js
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.getYouTubeId = void 0;
|
7
4
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
8
5
|
exports.showReadableText = showReadableText;
|
9
6
|
exports.convertHtmlToText = convertHtmlToText;
|
10
7
|
exports.convertSlugToText = convertSlugToText;
|
11
|
-
exports.convertTextToRupiah = convertTextToRupiah;
|
12
8
|
exports.exportToCamelCase = exportToCamelCase;
|
13
9
|
exports.limitDescription = limitDescription;
|
14
10
|
exports.replaceDashWithSpace = replaceDashWithSpace;
|
15
11
|
exports.replaceUnderscoreWithSpace = replaceUnderscoreWithSpace;
|
16
|
-
const price_1 = __importDefault(require("./price"));
|
17
12
|
function capitalizeFirstLetter(text) {
|
18
13
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
19
14
|
}
|
@@ -46,9 +41,6 @@ function convertSlugToText(slug) {
|
|
46
41
|
let text = slug.split("-").join(" ");
|
47
42
|
return capitalizeFirstLetter(text);
|
48
43
|
}
|
49
|
-
function convertTextToRupiah(text) {
|
50
|
-
return `Rp ${(0, price_1.default)(text)}`;
|
51
|
-
}
|
52
44
|
function exportToCamelCase(str) {
|
53
45
|
return str
|
54
46
|
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|