@indodev/toolkit 0.3.3 → 0.3.4
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/LICENCE +21 -0
- package/dist/currency/index.cjs +158 -25
- package/dist/currency/index.cjs.map +1 -1
- package/dist/currency/index.d.cts +50 -354
- package/dist/currency/index.d.ts +50 -354
- package/dist/currency/index.js +154 -26
- package/dist/currency/index.js.map +1 -1
- package/dist/index.cjs +65 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +65 -25
- package/dist/index.js.map +1 -1
- package/dist/utils-OG1yMaAa.d.cts +485 -0
- package/dist/utils-OG1yMaAa.d.ts +485 -0
- package/package.json +18 -18
package/dist/index.d.cts
CHANGED
|
@@ -4,5 +4,5 @@ export { NPWPInfo, MaskOptions as NPWPMaskOptions, formatNPWP, maskNPWP, parseNP
|
|
|
4
4
|
export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from './utils-DDVlOusI.cjs';
|
|
5
5
|
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.cjs';
|
|
6
6
|
export { c as EmailInfo, b as EmailMaskOptions, E as EmailValidationOptions, a as EmailValidationResult, g as getEmailInfo, m as maskEmail, n as normalizeEmail, v as validateEmail } from './email-validator-R9L5unIw.cjs';
|
|
7
|
-
export { RupiahOptions, WordOptions, addRupiahSymbol, calculateTax, formatAccounting, formatCompact, formatRupiah, parseRupiah, roundToClean, toWords } from './
|
|
7
|
+
export { R as RupiahOptions, W as WordOptions, d as addRupiahSymbol, c as calculateTax, b as formatAccounting, a as formatCompact, f as formatRupiah, p as parseRupiah, r as roundToClean, t as toWords } from './utils-OG1yMaAa.cjs';
|
|
8
8
|
export { C as CompareOptions, E as ExtractOptions, m as SanitizeOptions, S as SlugifyOptions, T as TitleCaseOptions, o as TruncateOptions, c as capitalize, k as compareStrings, d as contractAbbreviation, e as expandAbbreviation, g as extractWords, j as isAlay, n as normalizeWhitespace, p as profanityFilter, r as removeAccents, h as removeStopwords, b as sanitize, l as similarity, s as slugify, i as toFormal, a as toSentenceCase, t as toTitleCase, f as truncate } from './compare-Ku_8OhuU.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { NPWPInfo, MaskOptions as NPWPMaskOptions, formatNPWP, maskNPWP, parseNP
|
|
|
4
4
|
export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from './utils-DDVlOusI.js';
|
|
5
5
|
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.js';
|
|
6
6
|
export { c as EmailInfo, b as EmailMaskOptions, E as EmailValidationOptions, a as EmailValidationResult, g as getEmailInfo, m as maskEmail, n as normalizeEmail, v as validateEmail } from './email-validator-R9L5unIw.js';
|
|
7
|
-
export { RupiahOptions, WordOptions, addRupiahSymbol, calculateTax, formatAccounting, formatCompact, formatRupiah, parseRupiah, roundToClean, toWords } from './
|
|
7
|
+
export { R as RupiahOptions, W as WordOptions, d as addRupiahSymbol, c as calculateTax, b as formatAccounting, a as formatCompact, f as formatRupiah, p as parseRupiah, r as roundToClean, t as toWords } from './utils-OG1yMaAa.js';
|
|
8
8
|
export { C as CompareOptions, E as ExtractOptions, m as SanitizeOptions, S as SlugifyOptions, T as TitleCaseOptions, o as TruncateOptions, c as capitalize, k as compareStrings, d as contractAbbreviation, e as expandAbbreviation, g as extractWords, j as isAlay, n as normalizeWhitespace, p as profanityFilter, r as removeAccents, h as removeStopwords, b as sanitize, l as similarity, s as slugify, i as toFormal, a as toSentenceCase, t as toTitleCase, f as truncate } from './compare-Ku_8OhuU.js';
|
package/dist/index.js
CHANGED
|
@@ -1332,7 +1332,7 @@ function formatRupiah(amount, options) {
|
|
|
1332
1332
|
spaceAfterSymbol = true
|
|
1333
1333
|
} = options || {};
|
|
1334
1334
|
const precision = options?.precision !== void 0 ? options.precision : decimal ? 2 : 0;
|
|
1335
|
-
const isNegative = amount < 0;
|
|
1335
|
+
const isNegative = amount < 0 && amount !== 0;
|
|
1336
1336
|
const absAmount = Math.abs(amount);
|
|
1337
1337
|
let result;
|
|
1338
1338
|
if (decimal) {
|
|
@@ -1350,17 +1350,21 @@ function formatRupiah(amount, options) {
|
|
|
1350
1350
|
const intAmount = Math.floor(absAmount);
|
|
1351
1351
|
result = intAmount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
1352
1352
|
}
|
|
1353
|
-
if (isNegative) {
|
|
1354
|
-
result = `-${result}`;
|
|
1355
|
-
}
|
|
1356
1353
|
if (symbol) {
|
|
1357
1354
|
const space = spaceAfterSymbol ? " " : "";
|
|
1358
|
-
|
|
1355
|
+
if (isNegative) {
|
|
1356
|
+
result = `-Rp${space}${result}`;
|
|
1357
|
+
} else {
|
|
1358
|
+
result = `Rp${space}${result}`;
|
|
1359
|
+
}
|
|
1360
|
+
} else if (isNegative) {
|
|
1361
|
+
result = `-${result}`;
|
|
1359
1362
|
}
|
|
1360
1363
|
return result;
|
|
1361
1364
|
}
|
|
1362
|
-
function formatCompact(amount) {
|
|
1363
|
-
const
|
|
1365
|
+
function formatCompact(amount, options) {
|
|
1366
|
+
const { symbol = true, spaceAfterSymbol = true } = options || {};
|
|
1367
|
+
const isNegative = amount < 0 && amount !== 0;
|
|
1364
1368
|
const abs = Math.abs(amount);
|
|
1365
1369
|
let result;
|
|
1366
1370
|
if (abs >= 1e12) {
|
|
@@ -1376,10 +1380,17 @@ function formatCompact(amount) {
|
|
|
1376
1380
|
} else {
|
|
1377
1381
|
result = abs.toString();
|
|
1378
1382
|
}
|
|
1379
|
-
if (
|
|
1383
|
+
if (symbol) {
|
|
1384
|
+
const space = spaceAfterSymbol ? " " : "";
|
|
1385
|
+
if (isNegative) {
|
|
1386
|
+
result = `-Rp${space}${result}`;
|
|
1387
|
+
} else {
|
|
1388
|
+
result = `Rp${space}${result}`;
|
|
1389
|
+
}
|
|
1390
|
+
} else if (isNegative) {
|
|
1380
1391
|
result = `-${result}`;
|
|
1381
1392
|
}
|
|
1382
|
-
return
|
|
1393
|
+
return result;
|
|
1383
1394
|
}
|
|
1384
1395
|
function formatCompactValue(value, unit) {
|
|
1385
1396
|
const rounded = Math.round(value * 10) / 10;
|
|
@@ -1476,20 +1487,42 @@ var TENS = [
|
|
|
1476
1487
|
"sembilan puluh"
|
|
1477
1488
|
];
|
|
1478
1489
|
function toWords(amount, options) {
|
|
1479
|
-
const {
|
|
1490
|
+
const {
|
|
1491
|
+
uppercase = false,
|
|
1492
|
+
withCurrency = true,
|
|
1493
|
+
withDecimals = false
|
|
1494
|
+
} = options || {};
|
|
1480
1495
|
if (amount === 0) {
|
|
1481
1496
|
let result = "nol";
|
|
1482
1497
|
if (withCurrency) result += " rupiah";
|
|
1483
1498
|
return uppercase ? capitalize(result) : result;
|
|
1484
1499
|
}
|
|
1485
1500
|
const isNegative = amount < 0;
|
|
1486
|
-
const absAmount = Math.
|
|
1501
|
+
const absAmount = Math.abs(amount);
|
|
1502
|
+
const intPart = Math.floor(absAmount);
|
|
1503
|
+
let words = convertInteger(intPart);
|
|
1504
|
+
if (isNegative) {
|
|
1505
|
+
words = "minus " + words;
|
|
1506
|
+
}
|
|
1507
|
+
if (withCurrency) {
|
|
1508
|
+
words += " rupiah";
|
|
1509
|
+
}
|
|
1510
|
+
if (withDecimals) {
|
|
1511
|
+
const decimalPart = Math.round((absAmount - intPart) * 100);
|
|
1512
|
+
if (decimalPart > 0) {
|
|
1513
|
+
words += " koma " + convertDecimal(decimalPart);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return uppercase ? capitalize(words) : words;
|
|
1517
|
+
}
|
|
1518
|
+
function convertInteger(num) {
|
|
1519
|
+
if (num === 0) return "nol";
|
|
1487
1520
|
let words = "";
|
|
1488
|
-
const triliun = Math.floor(
|
|
1489
|
-
const miliar = Math.floor(
|
|
1490
|
-
const juta = Math.floor(
|
|
1491
|
-
const ribu = Math.floor(
|
|
1492
|
-
const sisa =
|
|
1521
|
+
const triliun = Math.floor(num / 1e12);
|
|
1522
|
+
const miliar = Math.floor(num % 1e12 / 1e9);
|
|
1523
|
+
const juta = Math.floor(num % 1e9 / 1e6);
|
|
1524
|
+
const ribu = Math.floor(num % 1e6 / 1e3);
|
|
1525
|
+
const sisa = num % 1e3;
|
|
1493
1526
|
if (triliun > 0) {
|
|
1494
1527
|
words += convertGroup(triliun) + " triliun";
|
|
1495
1528
|
}
|
|
@@ -1509,13 +1542,19 @@ function toWords(amount, options) {
|
|
|
1509
1542
|
if (words) words += " ";
|
|
1510
1543
|
words += convertGroup(sisa);
|
|
1511
1544
|
}
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
if (
|
|
1516
|
-
|
|
1545
|
+
return words;
|
|
1546
|
+
}
|
|
1547
|
+
function convertDecimal(num) {
|
|
1548
|
+
if (num === 0) return "";
|
|
1549
|
+
if (num < 10) return BASIC_NUMBERS[num];
|
|
1550
|
+
if (num < 20) return TEENS[num - 10];
|
|
1551
|
+
const tens = Math.floor(num / 10);
|
|
1552
|
+
const ones = num % 10;
|
|
1553
|
+
let result = TENS[tens];
|
|
1554
|
+
if (ones > 0) {
|
|
1555
|
+
result += " " + BASIC_NUMBERS[ones];
|
|
1517
1556
|
}
|
|
1518
|
-
return
|
|
1557
|
+
return result;
|
|
1519
1558
|
}
|
|
1520
1559
|
function convertGroup(num) {
|
|
1521
1560
|
if (num === 0) return "";
|
|
@@ -1565,15 +1604,16 @@ function formatAccounting(amount, options) {
|
|
|
1565
1604
|
}
|
|
1566
1605
|
return formatted;
|
|
1567
1606
|
}
|
|
1568
|
-
function calculateTax(amount, rate
|
|
1607
|
+
function calculateTax(amount, rate) {
|
|
1569
1608
|
return amount * rate;
|
|
1570
1609
|
}
|
|
1571
1610
|
function addRupiahSymbol(amount) {
|
|
1572
1611
|
if (typeof amount === "number") {
|
|
1573
|
-
|
|
1612
|
+
const formatted = amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
1613
|
+
return `Rp ${formatted}`;
|
|
1574
1614
|
}
|
|
1575
1615
|
if (amount.trim().startsWith("Rp")) {
|
|
1576
|
-
return amount;
|
|
1616
|
+
return amount.trim();
|
|
1577
1617
|
}
|
|
1578
1618
|
return `Rp ${amount.trim()}`;
|
|
1579
1619
|
}
|