spotlibs-components 0.1.10 → 0.1.12
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/{chunk-OGJBPTUP.mjs → chunk-F6KSEYVB.mjs} +3 -3
- package/dist/{chunk-OGJBPTUP.mjs.map → chunk-F6KSEYVB.mjs.map} +1 -1
- package/dist/chunk-UFE7HFT2.mjs +60 -0
- package/dist/chunk-UFE7HFT2.mjs.map +1 -0
- package/dist/{chunk-NXFLMH2Q.mjs → chunk-YOSPWY5K.mjs} +3 -4
- package/dist/{chunk-NXFLMH2Q.mjs.map → chunk-YOSPWY5K.mjs.map} +1 -1
- package/dist/{atoms → components/atoms}/icons/index.mjs +2 -2
- package/dist/components/index.d.mts +449 -0
- package/dist/components/index.mjs +7053 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/{mui → components/mui}/index.mjs +1 -1
- package/dist/components/types.d.mts +4 -0
- package/dist/{types-B0iF5xX8.d.mts → types-D1akE7ak.d.mts} +334 -245
- package/dist/utils/index.d.mts +106 -0
- package/dist/utils/index.mjs +477 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +13 -2
- package/src/utils/admin-kuota-nasional/constant.d.ts +23 -0
- package/src/utils/admin-kuota-nasional/constant.js +95 -0
- package/src/utils/asset.d.ts +1 -0
- package/src/utils/asset.js +10 -0
- package/src/utils/booleanUtils.d.ts +2 -0
- package/src/utils/booleanUtils.js +19 -0
- package/src/utils/briguna-digital/constant.d.ts +2 -0
- package/src/utils/briguna-digital/constant.js +12 -0
- package/src/utils/compress.d.ts +2 -0
- package/src/utils/compress.js +24 -0
- package/src/utils/compressImage.d.ts +6 -0
- package/src/utils/compressImage.js +20 -0
- package/src/utils/constants.d.ts +5 -0
- package/src/utils/constants.js +20 -0
- package/src/utils/cookies.d.ts +19 -0
- package/src/utils/cookies.js +102 -0
- package/src/utils/crypto.d.ts +5 -0
- package/src/utils/crypto.js +104 -0
- package/src/utils/decodeString.d.ts +1 -0
- package/src/utils/decodeString.js +17 -0
- package/src/utils/disableFormElements.d.ts +5 -0
- package/src/utils/disableFormElements.js +19 -0
- package/src/utils/excelUtils.d.ts +25 -0
- package/src/utils/excelUtils.js +60 -0
- package/src/utils/exception.d.ts +19 -0
- package/src/utils/exception.js +86 -0
- package/src/utils/formatString.d.ts +25 -0
- package/src/utils/formatString.js +151 -0
- package/src/utils/formatters/account.d.ts +2 -0
- package/src/utils/formatters/account.js +98 -0
- package/src/utils/formatters/currency.d.ts +20 -0
- package/src/utils/formatters/currency.js +125 -0
- package/src/utils/formatters/date.d.ts +12 -0
- package/src/utils/formatters/date.js +219 -0
- package/src/utils/formatters/index.d.ts +47 -0
- package/src/utils/formatters/index.js +47 -0
- package/src/utils/formatters/string.d.ts +6 -0
- package/src/utils/formatters/string.js +114 -0
- package/src/utils/generateImportExcel.d.ts +35 -0
- package/src/utils/generateImportExcel.js +546 -0
- package/src/utils/generateTimestamp.d.ts +1 -0
- package/src/utils/generateTimestamp.js +4 -0
- package/src/utils/handleApiError.d.ts +1 -0
- package/src/utils/handleApiError.js +17 -0
- package/src/utils/index.d.ts +104 -0
- package/src/utils/index.js +92 -0
- package/src/utils/json.d.ts +4 -0
- package/src/utils/json.js +55 -0
- package/src/utils/localStorage.d.ts +1 -0
- package/src/utils/localStorage.js +8 -0
- package/src/utils/logger.d.ts +4 -0
- package/src/utils/logger.js +46 -0
- package/src/utils/schema/globalSchema.d.ts +8 -0
- package/src/utils/schema/globalSchema.js +10 -0
- package/src/utils/signature.d.ts +10 -0
- package/src/utils/signature.js +75 -0
- package/src/utils/specifics/korporasi/prakarsaKorporasiUtils.d.ts +5 -0
- package/src/utils/specifics/korporasi/prakarsaKorporasiUtils.js +87 -0
- package/src/utils/specifics/mikro/validationMaintenanceAgunanUtils.d.ts +2 -0
- package/src/utils/specifics/mikro/validationMaintenanceAgunanUtils.js +214 -0
- package/src/utils/static-data/korporasi/prakarsa/analisa-risiko-kredit-nasabah/analisa-kinerja-keuangan/listStaticData.js +290 -0
- package/src/utils/static-data/korporasi/prakarsa/appendix/proyeksi-laporan-arus-kas/listStaticData.js +7 -0
- package/src/utils/static-data/korporasi/prakarsa/appendix/proyeksi-laporan-keuangan/listStaticData.js +75 -0
- package/src/utils/static-data/korporasi/prakarsa/appendix/total-exposure-group/listStaticData.js +7 -0
- package/src/utils/static-data/korporasi/prakarsa/create/listStaticData.js +21 -0
- package/src/utils/static-data/korporasi/prakarsa/generals/listExcelConfigData.js +11 -0
- package/src/utils/static-data/korporasi/prakarsa/pengajuan-fasilitas-kredit/fasilitas-kredit/listStaticData.js +69 -0
- package/src/utils/static-data/korporasi-internasional/eksternal/listStaticData.js +193 -0
- package/src/utils/static-data/korporasi-internasional/master/listStaticData.js +24 -0
- package/src/utils/static-data/korporasi-internasional/uji-kepatuhan/listStaticData.js +250 -0
- package/src/utils/status.d.ts +37 -0
- package/src/utils/status.js +160 -0
- package/src/utils/store/adminKuotaNasional.js +7 -0
- package/src/utils/store/authStore.js +13 -0
- package/src/utils/store/bankGaransiStore.js +10 -0
- package/src/utils/store/korporasi/approval/interface/interfaceStore.js +10 -0
- package/src/utils/store/korporasi/general/generalKorporasiStore.js +13 -0
- package/src/utils/store/korporasi/loan-disbursement/loanDisbursementStore.js +77 -0
- package/src/utils/store/korporasi/prakarsa/fasilitas-kredit/fasilitasKreditStore.js +141 -0
- package/src/utils/store/migrasi-mandiri/migrasiMandiriStore.js +53 -0
- package/src/utils/store/monitoring-konsumer/monitoring-leads-KPP/monitoring-leads-kpp-internal.js +34 -0
- package/src/utils/store/prakarsaBankGaransiStore.js +21 -0
- package/src/utils/store/prognosa-crr/settingPrognosaROStore.js +9 -0
- package/src/utils/store/prognosaRMStore.js +30 -0
- package/src/utils/store/restrukStore.js +26 -0
- package/src/utils/store/verificationAccessLink.js +11 -0
- package/src/utils/store/warkat-bg-wholesale/warkatBgWholesaleStore.js +22 -0
- package/src/utils/stringUtils.d.ts +22 -0
- package/src/utils/stringUtils.js +226 -0
- package/src/utils/tipeBank.d.ts +3 -0
- package/src/utils/tipeBank.js +14 -0
- package/dist/index.css +0 -32
- package/dist/index.css.map +0 -1
- package/dist/index.d.mts +0 -1726
- package/dist/index.mjs +0 -18560
- package/dist/index.mjs.map +0 -1
- package/dist/types.d.mts +0 -4
- /package/dist/{atoms → components/atoms}/icons/index.d.mts +0 -0
- /package/dist/{atoms → components/atoms}/icons/index.mjs.map +0 -0
- /package/dist/{mui → components/mui}/index.d.mts +0 -0
- /package/dist/{mui → components/mui}/index.mjs.map +0 -0
- /package/dist/{types.mjs → components/types.mjs} +0 -0
- /package/dist/{types.mjs.map → components/types.mjs.map} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function decodeEncodedString(encoded, type) {
|
|
2
|
+
let decoded = Buffer.from(encoded, "base64").toString("binary");
|
|
3
|
+
|
|
4
|
+
// Array buffer from decoded string
|
|
5
|
+
let buffer = Buffer.from(decoded, "binary");
|
|
6
|
+
|
|
7
|
+
// Create Uint8Array from buffer
|
|
8
|
+
// eslint-disable-next-line no-undef
|
|
9
|
+
let uintArray = new Uint8Array(buffer);
|
|
10
|
+
|
|
11
|
+
let blob = new Blob([uintArray], { type: type });
|
|
12
|
+
|
|
13
|
+
// Create URL object from blob
|
|
14
|
+
let url = URL.createObjectURL(blob);
|
|
15
|
+
|
|
16
|
+
return url;
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const disableFormElements = (selector) => {
|
|
2
|
+
const formElements = document.querySelectorAll(selector);
|
|
3
|
+
|
|
4
|
+
formElements.forEach((element) => {
|
|
5
|
+
element.disabled = true;
|
|
6
|
+
element.readOnly = true;
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const disableFormBuilder = (fields, roleAccess) => {
|
|
11
|
+
return fields.map((field) => {
|
|
12
|
+
if (!field) return null;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
...field,
|
|
16
|
+
isDisabled: roleAccess ? true : field.isDisabled,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function truncateText(text: string, maxLength: number): string;
|
|
2
|
+
export declare function applyHeaderStyles(
|
|
3
|
+
sheet: unknown,
|
|
4
|
+
rows: number[],
|
|
5
|
+
fontColorHeader?: string,
|
|
6
|
+
posisiHeader?: string
|
|
7
|
+
): void;
|
|
8
|
+
export declare function applyDataStyles(
|
|
9
|
+
sheet: unknown,
|
|
10
|
+
dataLength: number,
|
|
11
|
+
startRow: number,
|
|
12
|
+
posisiData?: string
|
|
13
|
+
): void;
|
|
14
|
+
export declare function styleGrandTotalRow(
|
|
15
|
+
row: unknown,
|
|
16
|
+
fontColorTotal?: string,
|
|
17
|
+
posisiTotal?: string
|
|
18
|
+
): void;
|
|
19
|
+
export declare function mergeGrandTotalCells(
|
|
20
|
+
sheet: unknown,
|
|
21
|
+
rowNumber: number,
|
|
22
|
+
startCol: string,
|
|
23
|
+
endCol: string
|
|
24
|
+
): void;
|
|
25
|
+
export declare function generateRepeatingWatermark(text: string): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Fungsi truncate teks
|
|
2
|
+
export const truncateText = (text, maxLength) => {
|
|
3
|
+
return text.length > maxLength ? text.substring(0, maxLength) + '...' : text;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// Fungsi styling
|
|
7
|
+
export const applyHeaderStyles = (sheet, rows, fontColorHeader, posisiHeader) => {
|
|
8
|
+
rows.forEach(rowNum => {
|
|
9
|
+
const row = sheet.getRow(rowNum);
|
|
10
|
+
row.eachCell(cell => {
|
|
11
|
+
cell.font = { bold: true, color: { argb: fontColorHeader ?? 'FFFFFF' } };
|
|
12
|
+
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: '00529C' } };
|
|
13
|
+
cell.alignment = { vertical: 'middle', horizontal: posisiHeader ?? 'left', wrapText: true };
|
|
14
|
+
cell.border = {
|
|
15
|
+
top: { style: 'thin' }, left: { style: 'thin' },
|
|
16
|
+
bottom: { style: 'thin' }, right: { style: 'thin' }
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const applyDataStyles = (sheet, dataLength, startRow, posisiData) => {
|
|
23
|
+
for (let i = startRow; i < startRow + dataLength; i++) {
|
|
24
|
+
const row = sheet.getRow(i);
|
|
25
|
+
row.eachCell(cell => {
|
|
26
|
+
cell.border = {
|
|
27
|
+
top: { style: 'thin' }, left: { style: 'thin' },
|
|
28
|
+
bottom: { style: 'thin' }, right: { style: 'thin' }
|
|
29
|
+
};
|
|
30
|
+
cell.alignment = { vertical: 'middle', horizontal: posisiData ?? 'left', wrapText: true };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const styleGrandTotalRow = (row, fontColorTotal, posisiTotal) => {
|
|
36
|
+
row.eachCell(cell => {
|
|
37
|
+
cell.border = {
|
|
38
|
+
top: { style: 'thin' }, left: { style: 'thin' },
|
|
39
|
+
bottom: { style: 'thin' }, right: { style: 'thin' }
|
|
40
|
+
};
|
|
41
|
+
cell.font = { bold: true, color: { argb: fontColorTotal ?? 'FFFFFF'} };
|
|
42
|
+
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: '00529C' } };
|
|
43
|
+
cell.alignment = {
|
|
44
|
+
vertical: 'middle',
|
|
45
|
+
horizontal: posisiTotal ?? 'left',
|
|
46
|
+
wrapText: true, // jika perlu membungkus teks
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const mergeGrandTotalCells = (sheet, rowNumber, startCol, endCol) => {
|
|
52
|
+
sheet.mergeCells(`${startCol}${rowNumber}:${endCol}${rowNumber}`);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Fungsi watermark (dummy implementation)
|
|
56
|
+
export const generateRepeatingWatermark = (text) => {
|
|
57
|
+
// Implementasi asli Anda untuk membuat watermark
|
|
58
|
+
// Return base64 string untuk gambar watermark
|
|
59
|
+
return text; // dummy base64
|
|
60
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const HEADER_EXCEPTION: string;
|
|
2
|
+
export declare const ACCESS_EXCEPTION: string;
|
|
3
|
+
export declare const PARAMETER_EXCEPTION: string;
|
|
4
|
+
export declare const NOTFOUND_EXCEPTION: string;
|
|
5
|
+
export declare const INVALIDRULE_EXCEPTION: string;
|
|
6
|
+
export declare const THIRDPARTY_EXCEPTION: string;
|
|
7
|
+
export declare const WAITING_EXCEPTION: string;
|
|
8
|
+
export declare const UNSUPPORTED_EXCEPTION: string;
|
|
9
|
+
export declare const RUNTIME_EXCEPTION: string;
|
|
10
|
+
export declare const EXCEPTION_MESSAGES: Record<string, string>;
|
|
11
|
+
|
|
12
|
+
export declare class ApiException extends Error {
|
|
13
|
+
responseCode: string;
|
|
14
|
+
responseDesc: string;
|
|
15
|
+
constructor(responseCode: string, responseDesc?: string);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare function isExceptionCode(responseCode: string): boolean;
|
|
19
|
+
export declare function getExceptionMessage(responseCode: string): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception Utilities
|
|
3
|
+
*
|
|
4
|
+
* Standardized exception codes dan ApiException class untuk handling error dari backend API.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ─── Exception Codes ─────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export const HEADER_EXCEPTION = "X0";
|
|
10
|
+
export const ACCESS_EXCEPTION = "X1";
|
|
11
|
+
export const PARAMETER_EXCEPTION = "01";
|
|
12
|
+
export const NOTFOUND_EXCEPTION = "02";
|
|
13
|
+
export const INVALIDRULE_EXCEPTION = "03";
|
|
14
|
+
export const THIRDPARTY_EXCEPTION = "04";
|
|
15
|
+
export const WAITING_EXCEPTION = "05";
|
|
16
|
+
export const UNSUPPORTED_EXCEPTION = "06";
|
|
17
|
+
export const RUNTIME_EXCEPTION = "99";
|
|
18
|
+
|
|
19
|
+
// ─── Exception Messages ──────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
export const EXCEPTION_MESSAGES = {
|
|
22
|
+
[HEADER_EXCEPTION]: "Invalid request header",
|
|
23
|
+
[ACCESS_EXCEPTION]: "Access denied",
|
|
24
|
+
[PARAMETER_EXCEPTION]: "Invalid parameter",
|
|
25
|
+
[NOTFOUND_EXCEPTION]: "Data not found",
|
|
26
|
+
[INVALIDRULE_EXCEPTION]: "Validation rule failed",
|
|
27
|
+
[THIRDPARTY_EXCEPTION]: "Third-party service failure",
|
|
28
|
+
[WAITING_EXCEPTION]: "Process in progress, please wait",
|
|
29
|
+
[UNSUPPORTED_EXCEPTION]: "Unsupported operation",
|
|
30
|
+
[RUNTIME_EXCEPTION]: "Internal system error",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ─── ApiException Class ──────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Custom exception class untuk API errors.
|
|
37
|
+
* Menyimpan responseCode dan responseDesc dari backend.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* throw new ApiException("02", "Prakarsa tidak ditemukan");
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Tanpa custom message — pakai default dari EXCEPTION_MESSAGES
|
|
44
|
+
* throw new ApiException("X1");
|
|
45
|
+
* // Error: [X1] Access denied
|
|
46
|
+
*/
|
|
47
|
+
export class ApiException extends Error {
|
|
48
|
+
constructor(responseCode, responseDesc) {
|
|
49
|
+
const desc =
|
|
50
|
+
responseDesc ||
|
|
51
|
+
EXCEPTION_MESSAGES[responseCode] ||
|
|
52
|
+
"An unexpected error occurred";
|
|
53
|
+
super(`[${responseCode}] ${desc}`);
|
|
54
|
+
this.name = "ApiException";
|
|
55
|
+
this.responseCode = responseCode;
|
|
56
|
+
this.responseDesc = desc;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Cek apakah responseCode termasuk exception.
|
|
62
|
+
* @param {string} responseCode - Response code dari API
|
|
63
|
+
* @returns {boolean} True jika code ada di daftar exception
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* isExceptionCode("00") // false (success)
|
|
67
|
+
* isExceptionCode("X0") // true (header exception)
|
|
68
|
+
* isExceptionCode("02") // true (not found)
|
|
69
|
+
*/
|
|
70
|
+
export function isExceptionCode(responseCode) {
|
|
71
|
+
return Object.keys(EXCEPTION_MESSAGES).includes(responseCode);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get human-readable message dari exception code.
|
|
76
|
+
* @param {string} responseCode - Response code dari API
|
|
77
|
+
* @returns {string} Exception message
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* getExceptionMessage("X1") // "Access denied"
|
|
81
|
+
* getExceptionMessage("99") // "Internal system error"
|
|
82
|
+
* getExceptionMessage("unknown") // "An unexpected error occurred"
|
|
83
|
+
*/
|
|
84
|
+
export function getExceptionMessage(responseCode) {
|
|
85
|
+
return EXCEPTION_MESSAGES[responseCode] || "An unexpected error occurred";
|
|
86
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function formatCurrency(
|
|
2
|
+
value: number | string | null | undefined,
|
|
3
|
+
country?: string,
|
|
4
|
+
curr?: string,
|
|
5
|
+
minFrac?: number,
|
|
6
|
+
maxFrac?: number
|
|
7
|
+
): string;
|
|
8
|
+
|
|
9
|
+
export declare function formatResponseDesc(desc: string): string;
|
|
10
|
+
|
|
11
|
+
export declare function dashedAccount(value: string | null | undefined): string;
|
|
12
|
+
|
|
13
|
+
export declare function formatNominal(
|
|
14
|
+
value: number | string | null | undefined,
|
|
15
|
+
locale?: string,
|
|
16
|
+
minFrac?: number,
|
|
17
|
+
maxFrac?: number,
|
|
18
|
+
commaSeparator?: string
|
|
19
|
+
): string;
|
|
20
|
+
|
|
21
|
+
export declare function titleCase(str: string): string;
|
|
22
|
+
|
|
23
|
+
export declare function stringToBoolean(str: string): boolean | undefined;
|
|
24
|
+
|
|
25
|
+
export declare function dashedNPWP(value: string | null | undefined): string;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* Formatting 500000 to Rp500.000,00
|
|
2
|
+
implementasi di src/pages/prakarsa/prakarsa-korporasi/informasi-nasabah/pengecekan-kredit/dialog-lihat-sicd.jsx
|
|
3
|
+
country dan curr disesuaikan dengan negara dan mata uang
|
|
4
|
+
minFrac dan maxFrac disesuaikan dengan jumlah angka di belakang koma */
|
|
5
|
+
export const formatCurrency = (
|
|
6
|
+
value,
|
|
7
|
+
country = "id-ID",
|
|
8
|
+
curr = "IDR",
|
|
9
|
+
minFrac = 0,
|
|
10
|
+
maxFrac = 0
|
|
11
|
+
) => {
|
|
12
|
+
if (value === undefined || value === null) return "";
|
|
13
|
+
let formattedValue = new Intl.NumberFormat(country, {
|
|
14
|
+
style: "currency",
|
|
15
|
+
currency: curr,
|
|
16
|
+
minimumFractionDigits: minFrac,
|
|
17
|
+
maximumFractionDigits: maxFrac,
|
|
18
|
+
}).format(value);
|
|
19
|
+
|
|
20
|
+
return formattedValue.replace(/\s/g, "");
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const formatResponseDesc = (desc) => {
|
|
24
|
+
return desc
|
|
25
|
+
.replace(/_(\w)/g, (_match, p1) => " " + p1.toUpperCase())
|
|
26
|
+
.replace(/brispot/gi, "BRISPOT");
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function dashedAccount(value) {
|
|
30
|
+
// Remove numeric characters from the input
|
|
31
|
+
const filteredValue = value?.replace(
|
|
32
|
+
/[A-Za-z\s!@#$%^&*_+{}()=`"[\]:;<>,?~\\|\\/-]/g,
|
|
33
|
+
""
|
|
34
|
+
);
|
|
35
|
+
// Replace the matched pattern with the matched group + a dash
|
|
36
|
+
if (filteredValue?.length > 14) {
|
|
37
|
+
const dashedValue = filteredValue.replace(
|
|
38
|
+
/(\d{4})(\d{2})(\d{6})(\d{2})(\d{1})/g,
|
|
39
|
+
"$1-$2-$3-$4-$5"
|
|
40
|
+
);
|
|
41
|
+
return dashedValue ?? "";
|
|
42
|
+
} else if (filteredValue?.length > 12) {
|
|
43
|
+
const dashedValue = filteredValue.replace(
|
|
44
|
+
/(\d{4})(\d{2})(\d{6})(\d{1})/g,
|
|
45
|
+
"$1-$2-$3-$4"
|
|
46
|
+
);
|
|
47
|
+
return dashedValue ?? "";
|
|
48
|
+
} else if (filteredValue?.length > 6) {
|
|
49
|
+
const dashedValue = filteredValue.replace(
|
|
50
|
+
/(\d{4})(\d{2})(\d{1})/g,
|
|
51
|
+
"$1-$2-$3"
|
|
52
|
+
);
|
|
53
|
+
return dashedValue ?? "";
|
|
54
|
+
} else if (filteredValue?.length > 4) {
|
|
55
|
+
const dashedValue = filteredValue.replace(/(\d{4})(\d{1})/g, "$1-$2");
|
|
56
|
+
return dashedValue ?? "";
|
|
57
|
+
} else {
|
|
58
|
+
return filteredValue ?? "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* Formatting 500000.95 to 500.000,95
|
|
63
|
+
implementasi di src/pages/prakarsa/prakarsa-bg/index.jsx
|
|
64
|
+
minFrac dan maxFrac disesuaikan dengan jumlah angka di belakang koma */
|
|
65
|
+
export const formatNominal = (
|
|
66
|
+
value,
|
|
67
|
+
locale = "id-ID",
|
|
68
|
+
minFrac = 0,
|
|
69
|
+
maxFrac = 0,
|
|
70
|
+
commaSeparator = ","
|
|
71
|
+
) => {
|
|
72
|
+
if (value === undefined || value === null || value === "") return "";
|
|
73
|
+
|
|
74
|
+
let numberValue;
|
|
75
|
+
if (typeof value === "number") {
|
|
76
|
+
numberValue = value;
|
|
77
|
+
} else if (typeof value === "string") {
|
|
78
|
+
if (value.includes(",")) {
|
|
79
|
+
numberValue = Number(value.replace(/\./g, "").replace(",", "."));
|
|
80
|
+
} else {
|
|
81
|
+
numberValue = Number(value);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isNaN(numberValue)) return value;
|
|
88
|
+
|
|
89
|
+
const formatted = numberValue.toLocaleString(locale, {
|
|
90
|
+
minimumFractionDigits: minFrac,
|
|
91
|
+
maximumFractionDigits: maxFrac,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return formatted.replace(/,/g, commaSeparator);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const titleCase = (str) => {
|
|
98
|
+
return str
|
|
99
|
+
.toLowerCase()
|
|
100
|
+
.split(" ")
|
|
101
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
102
|
+
.join(" ");
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const stringToBoolean = (str) => {
|
|
106
|
+
if (str === "true" || str === "false") {
|
|
107
|
+
return str === "true";
|
|
108
|
+
} else {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export function dashedNPWP(value) {
|
|
114
|
+
// Hapus karakter non-numerik dari input
|
|
115
|
+
const filteredValue = value?.replace(/[^\d]/g, "");
|
|
116
|
+
|
|
117
|
+
// Terapkan format sesuai panjang angka
|
|
118
|
+
if (filteredValue?.length > 15) {
|
|
119
|
+
const dashedValue = filteredValue.replace(
|
|
120
|
+
/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})(\d{4})/,
|
|
121
|
+
"$1.$2.$3.$4-$5.$6"
|
|
122
|
+
);
|
|
123
|
+
return dashedValue ?? "";
|
|
124
|
+
} else if (filteredValue?.length > 12) {
|
|
125
|
+
const dashedValue = filteredValue.replace(
|
|
126
|
+
/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})/,
|
|
127
|
+
"$1.$2.$3.$4-$5"
|
|
128
|
+
);
|
|
129
|
+
return dashedValue ?? "";
|
|
130
|
+
} else if (filteredValue?.length > 9) {
|
|
131
|
+
const dashedValue = filteredValue.replace(
|
|
132
|
+
/(\d{2})(\d{3})(\d{3})(\d{1})/,
|
|
133
|
+
"$1.$2.$3.$4"
|
|
134
|
+
);
|
|
135
|
+
return dashedValue ?? "";
|
|
136
|
+
} else if (filteredValue?.length > 6) {
|
|
137
|
+
const dashedValue = filteredValue.replace(
|
|
138
|
+
/(\d{2})(\d{3})(\d{1})/,
|
|
139
|
+
"$1.$2.$3"
|
|
140
|
+
);
|
|
141
|
+
return dashedValue ?? "";
|
|
142
|
+
} else if (filteredValue?.length > 2) {
|
|
143
|
+
const dashedValue = filteredValue.replace(
|
|
144
|
+
/(\d{2})(\d{3})/,
|
|
145
|
+
"$1.$2"
|
|
146
|
+
);
|
|
147
|
+
return dashedValue ?? "";
|
|
148
|
+
} else {
|
|
149
|
+
return filteredValue ?? "";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account & ID Number Formatting Utilities
|
|
3
|
+
*
|
|
4
|
+
* Konsolidasi dari:
|
|
5
|
+
* - formatString.js (dashedAccount, dashedNPWP)
|
|
6
|
+
* - formatters.js (formatAccountNumber)
|
|
7
|
+
* - stringUtils.js (rekeningFormatter, npwpFormatter)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Format nomor rekening dengan dash separator.
|
|
12
|
+
* Mendukung berbagai panjang nomor rekening (progressive formatting).
|
|
13
|
+
* @param {string} value - Nomor rekening (bisa mengandung karakter non-numerik)
|
|
14
|
+
* @returns {string} Nomor rekening terformat (e.g., "0012-01-123456-01-1")
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* formatAccountNumber("001201123456011") // "0012-01-123456-01-1"
|
|
18
|
+
* formatAccountNumber("00120112345601") // "0012-01-123456-01"
|
|
19
|
+
* formatAccountNumber("0012011") // "0012-01-1"
|
|
20
|
+
*/
|
|
21
|
+
export function formatAccountNumber(value) {
|
|
22
|
+
if (!value) return "";
|
|
23
|
+
|
|
24
|
+
// Remove non-numeric characters
|
|
25
|
+
const filteredValue = value
|
|
26
|
+
.toString()
|
|
27
|
+
.replace(/[^0-9]/g, "");
|
|
28
|
+
|
|
29
|
+
if (filteredValue.length > 14) {
|
|
30
|
+
return filteredValue.replace(
|
|
31
|
+
/(\d{4})(\d{2})(\d{6})(\d{2})(\d{1})/,
|
|
32
|
+
"$1-$2-$3-$4-$5"
|
|
33
|
+
);
|
|
34
|
+
} else if (filteredValue.length > 12) {
|
|
35
|
+
return filteredValue.replace(
|
|
36
|
+
/(\d{4})(\d{2})(\d{6})(\d{1})/,
|
|
37
|
+
"$1-$2-$3-$4"
|
|
38
|
+
);
|
|
39
|
+
} else if (filteredValue.length > 6) {
|
|
40
|
+
return filteredValue.replace(
|
|
41
|
+
/(\d{4})(\d{2})(\d{1})/,
|
|
42
|
+
"$1-$2-$3"
|
|
43
|
+
);
|
|
44
|
+
} else if (filteredValue.length > 4) {
|
|
45
|
+
return filteredValue.replace(/(\d{4})(\d{1})/, "$1-$2");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return filteredValue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Format nomor NPWP dengan dot dan dash separator.
|
|
53
|
+
* Mendukung format NPWP 15 digit dan 16 digit (format baru).
|
|
54
|
+
* @param {string} value - Nomor NPWP
|
|
55
|
+
* @returns {string} NPWP terformat (e.g., "01.234.567.8-901.234")
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* formatNPWP("0123456789012345") // "01.234.567.8-901.2345"
|
|
59
|
+
* formatNPWP("012345678901234") // "01.234.567.8-901.234"
|
|
60
|
+
* formatNPWP("012345678") // "01.234.567.8"
|
|
61
|
+
*/
|
|
62
|
+
export function formatNPWP(value) {
|
|
63
|
+
if (!value) return "";
|
|
64
|
+
|
|
65
|
+
// Remove non-numeric characters
|
|
66
|
+
const filteredValue = value
|
|
67
|
+
.toString()
|
|
68
|
+
.replace(/\D/g, "");
|
|
69
|
+
|
|
70
|
+
if (filteredValue.length > 15) {
|
|
71
|
+
return filteredValue.replace(
|
|
72
|
+
/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})(\d{4})/,
|
|
73
|
+
"$1.$2.$3.$4-$5.$6"
|
|
74
|
+
);
|
|
75
|
+
} else if (filteredValue.length > 12) {
|
|
76
|
+
return filteredValue.replace(
|
|
77
|
+
/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})/,
|
|
78
|
+
"$1.$2.$3.$4-$5"
|
|
79
|
+
);
|
|
80
|
+
} else if (filteredValue.length > 9) {
|
|
81
|
+
return filteredValue.replace(
|
|
82
|
+
/(\d{2})(\d{3})(\d{3})(\d{1})/,
|
|
83
|
+
"$1.$2.$3.$4"
|
|
84
|
+
);
|
|
85
|
+
} else if (filteredValue.length > 6) {
|
|
86
|
+
return filteredValue.replace(
|
|
87
|
+
/(\d{2})(\d{3})(\d{1})/,
|
|
88
|
+
"$1.$2.$3"
|
|
89
|
+
);
|
|
90
|
+
} else if (filteredValue.length > 2) {
|
|
91
|
+
return filteredValue.replace(
|
|
92
|
+
/(\d{2})(\d{3})/,
|
|
93
|
+
"$1.$2"
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return filteredValue;
|
|
98
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function formatCurrency(
|
|
2
|
+
value: number | string | null | undefined,
|
|
3
|
+
options?: {
|
|
4
|
+
locale?: string;
|
|
5
|
+
currency?: string;
|
|
6
|
+
minFractionDigits?: number;
|
|
7
|
+
maxFractionDigits?: number;
|
|
8
|
+
}
|
|
9
|
+
): string;
|
|
10
|
+
export declare function formatRupiah(value: number | string | null | undefined): string;
|
|
11
|
+
export declare function formatNominal(
|
|
12
|
+
value: number | string | null | undefined,
|
|
13
|
+
options?: {
|
|
14
|
+
locale?: string;
|
|
15
|
+
minFractionDigits?: number;
|
|
16
|
+
maxFractionDigits?: number;
|
|
17
|
+
decimalSeparator?: string;
|
|
18
|
+
}
|
|
19
|
+
): string;
|
|
20
|
+
export declare function formatDigit(value: number | string): string;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency Formatting Utilities
|
|
3
|
+
*
|
|
4
|
+
* Konsolidasi dari:
|
|
5
|
+
* - formatString.js (formatCurrency, formatNominal)
|
|
6
|
+
* - formatCurrency.js (formatCurrencyRupiah)
|
|
7
|
+
* - stringUtils.js (toCurrency, digitFormatter)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Format angka ke format mata uang dengan locale dan currency yang bisa dikustomisasi.
|
|
12
|
+
* @param {number|string} value - Nilai yang akan diformat
|
|
13
|
+
* @param {object} options - Opsi formatting
|
|
14
|
+
* @param {string} options.locale - Locale (default: "id-ID")
|
|
15
|
+
* @param {string} options.currency - Kode mata uang (default: "IDR")
|
|
16
|
+
* @param {number} options.minFractionDigits - Minimum digit desimal (default: 0)
|
|
17
|
+
* @param {number} options.maxFractionDigits - Maximum digit desimal (default: 0)
|
|
18
|
+
* @returns {string} Nilai terformat
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* formatCurrency(500000) // "Rp500.000"
|
|
22
|
+
* formatCurrency(500000, { minFractionDigits: 2 }) // "Rp500.000,00"
|
|
23
|
+
* formatCurrency(1000, { currency: "USD", locale: "en-US" }) // "$1,000"
|
|
24
|
+
*/
|
|
25
|
+
export const formatCurrency = (
|
|
26
|
+
value,
|
|
27
|
+
{
|
|
28
|
+
locale = "id-ID",
|
|
29
|
+
currency = "IDR",
|
|
30
|
+
minFractionDigits = 0,
|
|
31
|
+
maxFractionDigits = 0,
|
|
32
|
+
} = {}
|
|
33
|
+
) => {
|
|
34
|
+
if (value === undefined || value === null) return "";
|
|
35
|
+
const num = Number(value);
|
|
36
|
+
if (isNaN(num)) return String(value);
|
|
37
|
+
|
|
38
|
+
const formattedValue = new Intl.NumberFormat(locale, {
|
|
39
|
+
style: "currency",
|
|
40
|
+
currency,
|
|
41
|
+
minimumFractionDigits: minFractionDigits,
|
|
42
|
+
maximumFractionDigits: maxFractionDigits,
|
|
43
|
+
}).format(num);
|
|
44
|
+
|
|
45
|
+
return formattedValue.replace(/\s/g, "");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Format angka ke format Rupiah (shorthand untuk formatCurrency dengan default IDR).
|
|
50
|
+
* @param {number|string} value - Nilai yang akan diformat
|
|
51
|
+
* @returns {string} Nilai terformat dalam Rupiah
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* formatRupiah(500000) // "Rp500.000"
|
|
55
|
+
* formatRupiah(1500000) // "Rp1.500.000"
|
|
56
|
+
*/
|
|
57
|
+
export const formatRupiah = (value) => {
|
|
58
|
+
return formatCurrency(value);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Format angka ke format nominal (tanpa simbol mata uang).
|
|
63
|
+
* @param {number|string} value - Nilai yang akan diformat
|
|
64
|
+
* @param {object} options - Opsi formatting
|
|
65
|
+
* @param {string} options.locale - Locale (default: "id-ID")
|
|
66
|
+
* @param {number} options.minFractionDigits - Minimum digit desimal (default: 0)
|
|
67
|
+
* @param {number} options.maxFractionDigits - Maximum digit desimal (default: 0)
|
|
68
|
+
* @param {string} options.decimalSeparator - Separator desimal (default: ",")
|
|
69
|
+
* @returns {string} Nilai terformat
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* formatNominal(500000) // "500.000"
|
|
73
|
+
* formatNominal(500000.95, { minFractionDigits: 2, maxFractionDigits: 2 }) // "500.000,95"
|
|
74
|
+
* formatNominal("1.500.000,50") // "1.500.000,50" (handles string input with Indonesian format)
|
|
75
|
+
*/
|
|
76
|
+
export const formatNominal = (
|
|
77
|
+
value,
|
|
78
|
+
{
|
|
79
|
+
locale = "id-ID",
|
|
80
|
+
minFractionDigits = 0,
|
|
81
|
+
maxFractionDigits = 0,
|
|
82
|
+
decimalSeparator = ",",
|
|
83
|
+
} = {}
|
|
84
|
+
) => {
|
|
85
|
+
if (value === undefined || value === null || value === "") return "";
|
|
86
|
+
|
|
87
|
+
let numberValue;
|
|
88
|
+
if (typeof value === "number") {
|
|
89
|
+
numberValue = value;
|
|
90
|
+
} else if (typeof value === "string") {
|
|
91
|
+
// Handle Indonesian format string (1.500.000,50)
|
|
92
|
+
if (value.includes(",")) {
|
|
93
|
+
numberValue = Number(value.replace(/\./g, "").replace(",", "."));
|
|
94
|
+
} else {
|
|
95
|
+
numberValue = Number(value);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
return String(value);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (isNaN(numberValue)) return String(value);
|
|
102
|
+
|
|
103
|
+
const formatted = numberValue.toLocaleString(locale, {
|
|
104
|
+
minimumFractionDigits: minFractionDigits,
|
|
105
|
+
maximumFractionDigits: maxFractionDigits,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return formatted.replace(/,/g, decimalSeparator);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Format angka ke format digit (tanpa simbol mata uang, tanpa desimal).
|
|
113
|
+
* @param {number|string} value - Nilai yang akan diformat
|
|
114
|
+
* @returns {string} Nilai terformat
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* formatDigit(500000) // "500.000"
|
|
118
|
+
* formatDigit(1500000) // "1.500.000"
|
|
119
|
+
*/
|
|
120
|
+
export const formatDigit = (value) => {
|
|
121
|
+
const num = Number(value);
|
|
122
|
+
return new Intl.NumberFormat("id-ID", { minimumFractionDigits: 0 }).format(
|
|
123
|
+
num || 0
|
|
124
|
+
);
|
|
125
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function toYearFirstDash(value: Date | string): string;
|
|
2
|
+
export declare function toDateFirstSlash(value: Date | string): string;
|
|
3
|
+
export declare function formatDateToDDSlashMMSlashYYYY(date: Date): string;
|
|
4
|
+
export declare function formatDateToDDMMYYYY(date: Date): string;
|
|
5
|
+
export declare function yearFirstDashToDateFirstDash(value: string): string;
|
|
6
|
+
export declare function yearFirstDashToDateFirstSlash(value: string): string;
|
|
7
|
+
export declare function dateFirstSlashToYearFirstDash(value: string): string;
|
|
8
|
+
export declare function sevenDigitToDateFirstSlash(value: string): string;
|
|
9
|
+
export declare function sevenDigitToYearFirstDash(value: string): string;
|
|
10
|
+
export declare function sevenDigitToDateFirstDash(value: string): string;
|
|
11
|
+
export declare function toDateTimeHourMinute(value: string): string;
|
|
12
|
+
export declare function ddmmyyToSlashDate(value: string): string;
|