@rzl-zone/utils-js 3.0.2-beta.2 → 3.1.0-beta.2
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/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +96 -116
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-25G6B35W.js +1 -0
- package/dist/chunk-2AUUPGMN.js +1 -0
- package/dist/chunk-2JQQQ625.js +1 -0
- package/dist/chunk-445TAVT4.cjs +1 -0
- package/dist/chunk-467VEMJH.js +1 -0
- package/dist/chunk-6Q4I2RPC.cjs +1 -0
- package/dist/chunk-6SMJMZ7G.cjs +1 -0
- package/dist/chunk-BLCANGFS.js +1 -0
- package/dist/chunk-CK3BZGEU.js +1 -0
- package/dist/{chunk-JWHM3WZQ.cjs → chunk-D43GV6EF.cjs} +1 -1
- package/dist/chunk-DFSTVQFI.cjs +1 -0
- package/dist/chunk-DYRDBYPF.cjs +1 -0
- package/dist/chunk-EXXLUO7L.cjs +1 -0
- package/dist/chunk-G72VSVGO.js +1 -0
- package/dist/chunk-GAJTFCUA.js +1 -0
- package/dist/chunk-GOJNH55O.cjs +1 -0
- package/dist/chunk-HXST7RJB.js +1 -0
- package/dist/{chunk-BYZAD3XN.cjs → chunk-HXTACM3O.cjs} +1 -1
- package/dist/chunk-IJTZWWRJ.cjs +1 -0
- package/dist/chunk-ISJ33O2J.cjs +1 -0
- package/dist/chunk-JISH2VGG.js +1 -0
- package/dist/{chunk-FF76ISQ2.js → chunk-JQZUWBIX.js} +1 -1
- package/dist/{chunk-XH6MCRLP.js → chunk-K4PLGD7C.js} +1 -1
- package/dist/chunk-KZQB7H4E.cjs +1 -0
- package/dist/chunk-LUVV5KSD.cjs +2 -0
- package/dist/chunk-LVUSFXQS.cjs +1 -0
- package/dist/chunk-ME5OV5HN.js +1 -0
- package/dist/chunk-MF5Y5K4N.cjs +1 -0
- package/dist/chunk-MJAW5RAK.js +1 -0
- package/dist/chunk-MWLEM7ED.js +1 -0
- package/dist/chunk-NSVLG7NY.js +4 -0
- package/dist/chunk-NUHOOAUN.cjs +1 -0
- package/dist/chunk-NUVGETPD.js +2 -0
- package/dist/chunk-O5VXBNUQ.cjs +4 -0
- package/dist/chunk-O7SJR4CY.cjs +1 -0
- package/dist/chunk-OX6RLS2F.cjs +1 -0
- package/dist/chunk-PFLNHD4B.cjs +1 -0
- package/dist/chunk-PSWITZK5.js +1 -0
- package/dist/chunk-PYUVKHUF.cjs +1 -0
- package/dist/chunk-REFMEB4A.js +1 -0
- package/dist/chunk-RHE3M2NJ.cjs +1 -0
- package/dist/chunk-RHIBYOFQ.js +1 -0
- package/dist/chunk-S7GMG4TB.js +1 -0
- package/dist/chunk-TQMZ2LPI.js +1 -0
- package/dist/{chunk-RN3TP3S3.js → chunk-U4TZO7WV.js} +1 -1
- package/dist/chunk-UUMKL74S.js +1 -0
- package/dist/{chunk-EXZ47NOW.js → chunk-VQLAPEL3.js} +1 -1
- package/dist/chunk-VTR75UID.cjs +1 -0
- package/dist/chunk-XFCJDSB2.cjs +1 -0
- package/dist/chunk-XOYX4PLZ.cjs +1 -0
- package/dist/chunk-Z6FLCEN6.js +1 -0
- package/dist/chunk-ZO5364A6.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +396 -593
- package/dist/conversions/index.js +1 -1
- package/dist/env/index.d.ts +5 -8
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +80 -77
- package/dist/events/index.js +1 -1
- package/dist/{array-CIZRbqTF.d.ts → extends-Bk_SBGdT.d.ts} +145 -1
- package/dist/formatting/index.cjs +1 -1
- package/dist/formatting/index.d.ts +478 -440
- package/dist/formatting/index.js +1 -1
- package/dist/generator/index.cjs +1 -1
- package/dist/generator/index.d.ts +135 -112
- package/dist/generator/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{is-array-Ckm_47hw.d.ts → is-array--YjXV-Wx.d.ts} +2 -352
- package/dist/{isPlainObject-BKYaI6a8.d.ts → isPlainObject-BVhBAPHX.d.ts} +49 -62
- package/dist/next/index.cjs +6 -6
- package/dist/next/index.d.ts +125 -105
- package/dist/next/index.js +5 -5
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +8 -22
- package/dist/next/server/index.js +1 -1
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +72 -127
- package/dist/operations/index.js +1 -1
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +26 -27
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +686 -660
- package/dist/predicates/index.js +1 -1
- package/dist/promise/index.cjs +1 -1
- package/dist/promise/index.d.ts +14 -23
- package/dist/promise/index.js +1 -1
- package/dist/rzl-utils.global.js +3 -3
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +301 -376
- package/dist/strings/index.js +1 -1
- package/dist/stylings/index.cjs +1 -1
- package/dist/stylings/index.d.ts +15 -23
- package/dist/stylings/index.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +276 -301
- package/dist/urls/index.js +1 -1
- package/package.json +53 -11
- package/dist/chunk-2TRAPBZ7.cjs +0 -1
- package/dist/chunk-3D74QO5D.cjs +0 -1
- package/dist/chunk-4DK3RCC4.js +0 -2
- package/dist/chunk-4JOQ45HL.js +0 -1
- package/dist/chunk-55CZALRS.js +0 -1
- package/dist/chunk-5JFV3GDE.cjs +0 -4
- package/dist/chunk-62HX5Z45.cjs +0 -1
- package/dist/chunk-7NA6DUHR.cjs +0 -2
- package/dist/chunk-BVPMMWDL.cjs +0 -1
- package/dist/chunk-CEFYHEM4.cjs +0 -1
- package/dist/chunk-CN53M4QZ.cjs +0 -1
- package/dist/chunk-D47MHBSD.cjs +0 -1
- package/dist/chunk-DGH75GJD.js +0 -1
- package/dist/chunk-E5NUI7PN.js +0 -1
- package/dist/chunk-FDITZ5C6.cjs +0 -1
- package/dist/chunk-FSSV24W7.cjs +0 -1
- package/dist/chunk-GCGU2WB7.js +0 -1
- package/dist/chunk-GECI2YBP.js +0 -1
- package/dist/chunk-GQE4OVHC.cjs +0 -1
- package/dist/chunk-GRVZXQXL.cjs +0 -1
- package/dist/chunk-I4AVNHPA.cjs +0 -1
- package/dist/chunk-JFRL7NKU.js +0 -4
- package/dist/chunk-KCQDDZJE.cjs +0 -1
- package/dist/chunk-L54ZPSYJ.js +0 -1
- package/dist/chunk-LVKAYEZ4.js +0 -1
- package/dist/chunk-MBDWTK54.cjs +0 -1
- package/dist/chunk-MNGGDB2G.js +0 -1
- package/dist/chunk-MY7BA4GI.cjs +0 -1
- package/dist/chunk-N2IJPIND.cjs +0 -1
- package/dist/chunk-NIMNTEGV.js +0 -1
- package/dist/chunk-PVJF2JHM.js +0 -1
- package/dist/chunk-QCFXEUKL.js +0 -1
- package/dist/chunk-QFCGBBSY.js +0 -1
- package/dist/chunk-QQYAUPSK.cjs +0 -1
- package/dist/chunk-TC4VBE4Y.cjs +0 -1
- package/dist/chunk-TUXDINHF.cjs +0 -1
- package/dist/chunk-U5Y2FXMN.cjs +0 -1
- package/dist/chunk-UUPQI6ND.cjs +0 -1
- package/dist/chunk-VYCGZ2S6.js +0 -1
- package/dist/chunk-W5EDKJK3.js +0 -1
- package/dist/chunk-WHAVUFEU.js +0 -1
- package/dist/chunk-XCFIOTCV.js +0 -1
- package/dist/chunk-XE27XPJR.js +0 -1
- package/dist/chunk-XVB3ZZEB.js +0 -1
- package/dist/chunk-ZBSIGJFO.cjs +0 -1
- package/dist/chunk-ZYAML74V.js +0 -1
- package/dist/extends-Mp81Hq9-.d.ts +0 -145
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{O as OmitStrict}from'../omit-VvmIsZmX.js';import{Locale}from'date-fns
|
|
1
|
+
import{O as OmitStrict}from'../omit-VvmIsZmX.js';import{FormatOptions,Locale}from'date-fns';import{A as AnyString}from'../string-XA-til3C.js';import{P as Prettify}from'../prettify-C4xLcYOP.js';import'../if-CvT4R7Kh.js';import'../never-BfayMBF9.js';import'../type-data-DDs-u2kq.js';type ValueFormatPhoneNumber=string|number|null;type FormatPhoneNumberProps={
|
|
2
2
|
/** @default " " */
|
|
3
3
|
separator?:string;
|
|
4
4
|
/** @default "" */
|
|
@@ -66,8 +66,7 @@ separator?:string;
|
|
|
66
66
|
/** ---------------------------------------------------------------------------
|
|
67
67
|
* * ***Prefix currency string.***
|
|
68
68
|
* ---------------------------------------------------------------------------
|
|
69
|
-
*
|
|
70
|
-
* If `false`, rounds to integer.
|
|
69
|
+
* Whether to show decimals. If `false`, decimals are truncated.
|
|
71
70
|
*
|
|
72
71
|
* *DefaultValue: `false`.*
|
|
73
72
|
*
|
|
@@ -169,263 +168,318 @@ negativeFormat?:NegativeFormatOption;
|
|
|
169
168
|
*/
|
|
170
169
|
indianFormat?:boolean;};
|
|
171
170
|
/** -------------------------------------------------------
|
|
172
|
-
* * ***
|
|
173
|
-
* beautifully formatted currency string, with highly
|
|
174
|
-
* customizable separators, decimal control, rounding,
|
|
175
|
-
* currency symbols, and negative styling.***
|
|
171
|
+
* * ***Utility: `formatCurrency`.***
|
|
176
172
|
* -------------------------------------------------------
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
173
|
+
* **Formats a number or messy currency string into a
|
|
174
|
+
* beautifully formatted currency string, with highly
|
|
175
|
+
* customizable separators, decimal control, rounding,
|
|
176
|
+
* currency symbols, and negative styling.**
|
|
177
|
+
* - **✅ Highlights:**
|
|
178
|
+
* - ***Accepts:***
|
|
179
|
+
* - Pure numbers: `15300.95`.
|
|
180
|
+
* - Messy currency strings from **any locale**:
|
|
181
|
+
* - `"Rp 15.000,21"` ***(Indonesian / Euro)***.
|
|
182
|
+
* - `"$12,345.60"` ***(US)***.
|
|
183
|
+
* - `"CHF 12'345.60"` ***(Swiss)***.
|
|
184
|
+
* - `"1,23,456.78"` ***(Indian)***.
|
|
186
185
|
* - Auto extracts numeric value with smart multi-locale parsing
|
|
187
|
-
* via `parseCurrencyString
|
|
188
|
-
* - Handles
|
|
189
|
-
* - Thousands separators: `.`, `,`, `'`, `
|
|
190
|
-
* - Decimal separators: `,`,
|
|
191
|
-
* - Decimal suffix (eg. `".-"`, `" USD"`)
|
|
192
|
-
* - Currency prefix (eg. `"Rp "`, `"$ "`)
|
|
193
|
-
* - Rounding: `"round"`, `"ceil"`, `"floor"`, or truncate
|
|
194
|
-
* - Negative styling: dash `-`, brackets `( )`, absolute, or custom
|
|
186
|
+
* via ***{@link parseCurrencyString | `parseCurrencyString`}***.
|
|
187
|
+
* - **Handles:**
|
|
188
|
+
* - Thousands separators: `.`, `,`, `'`, ` `.
|
|
189
|
+
* - Decimal separators: `,`, `.`.
|
|
190
|
+
* - Decimal suffix (eg. `".-"`, `" USD"`).
|
|
191
|
+
* - Currency prefix (eg. `"Rp "`, `"$ "`).
|
|
192
|
+
* - Rounding: `"round"`, `"ceil"`, `"floor"`, or truncate.
|
|
193
|
+
* - Negative styling: dash `-`, brackets `( )`, absolute, or custom.
|
|
195
194
|
* - Strong type checks & clear errors for misconfigured options.
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* -
|
|
202
|
-
*
|
|
203
|
-
*
|
|
195
|
+
* - **✅ How input is parsed:**
|
|
196
|
+
* - Removes all non-digit except `.`, `,`, `'` and spaces.
|
|
197
|
+
* - Detects bracket negatives: `"(15.000,10)"` ➔ `-15000.10`.
|
|
198
|
+
* - Uses last `,` or `.` as decimal separator (others are thousands).
|
|
199
|
+
* - Ignores currency symbols like `Rp`, `$` (must re-apply with `suffixCurrency`).
|
|
200
|
+
* - **ℹ️ Note:**
|
|
201
|
+
* - Always re-apply symbols via `suffixCurrency`.
|
|
202
|
+
* - `parseCurrencyString` smartly detects last decimal,
|
|
203
|
+
* so `"1.121.234,56"` and `"1,121,234.56"` both parsed correctly.
|
|
204
204
|
* @param {string|number} value The input value to format, examples:
|
|
205
|
-
* - `"Rp 15.000,21"
|
|
206
|
-
* - `"$12,345.60"
|
|
207
|
-
* - `"CHF 12'345.60"
|
|
208
|
-
* - `15300.95
|
|
209
|
-
*
|
|
205
|
+
* - `"Rp 15.000,21"`.
|
|
206
|
+
* - `"$12,345.60"`.
|
|
207
|
+
* - `"CHF 12'345.60"`.
|
|
208
|
+
* - `15300.95`.
|
|
210
209
|
* @param {FormatCurrencyOptions} [options] Optional configuration object.
|
|
211
|
-
*
|
|
212
|
-
* @param {string} [options.separator] Thousands separator:
|
|
210
|
+
* @param {FormatCurrencyOptions["separator"]} [options.separator] Thousands separator:
|
|
213
211
|
* - `{ separator: "." }` ➔ `1.000.000`.
|
|
214
212
|
* - ***DefaultValue: `"."`***.
|
|
215
|
-
*
|
|
216
|
-
* @param {string} [options.separatorDecimals] Decimal separator:
|
|
213
|
+
* @param {FormatCurrencyOptions["separatorDecimals"]} [options.separatorDecimals] Decimal separator:
|
|
217
214
|
* - `{ separatorDecimals: "," }` ➔ `1.000,10`.
|
|
218
215
|
* - ***DefaultValue: `","`***.
|
|
219
|
-
*
|
|
220
|
-
* @param {string} [options.suffixCurrency] Prefix currency string:
|
|
216
|
+
* @param {FormatCurrencyOptions["suffixCurrency"]} [options.suffixCurrency] Prefix currency string:
|
|
221
217
|
* - Does **not auto-keep input symbols**.
|
|
222
218
|
* - Must set manually e.g: `{ suffixCurrency: "Rp " }`.
|
|
223
219
|
* - `{ suffixCurrency: "Rp " }` ➔ `Rp 1.000`.
|
|
224
220
|
* - ***DefaultValue: `""`***.
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* - If `false`, rounds to integer.
|
|
221
|
+
* @param {FormatCurrencyOptions["decimal"]} [options.decimal] Whether to show decimals. If `false`, decimals are truncated:
|
|
222
|
+
* - If `false`, cut the decimal.
|
|
228
223
|
* - ***DefaultValue: `false`***.
|
|
229
|
-
*
|
|
230
|
-
* @param {number} [options.totalDecimal] Total decimal digits:
|
|
224
|
+
* @param {FormatCurrencyOptions["totalDecimal"]} [options.totalDecimal] Total decimal digits:
|
|
231
225
|
* - If `decimal: true` & `roundedDecimal: false`, simply cuts.
|
|
232
226
|
* - ***DefaultValue: `2`***.
|
|
233
|
-
*
|
|
234
|
-
* @param {string} [options.suffixDecimal] Text appended after decimals:
|
|
227
|
+
* @param {FormatCurrencyOptions["separatorDecimals"]} [options.suffixDecimal] Text appended after decimals:
|
|
235
228
|
* - E.g: (`".-"`, `" USD"`).
|
|
236
229
|
* - Example 1: `".-"` ➔ `1.000,00.-`.
|
|
237
230
|
* - Example 2: `" USD"` ➔ `1.000,00 USD`.
|
|
238
231
|
* - ***DefaultValue: `""`***.
|
|
239
|
-
*
|
|
240
|
-
* @param {boolean} [options.endDecimal] Actually append `suffixDecimal`:
|
|
232
|
+
* @param {FormatCurrencyOptions["endDecimal"]} [options.endDecimal] Actually append `suffixDecimal`:
|
|
241
233
|
* - ***DefaultValue: `true`***.
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* - `"
|
|
245
|
-
* - `"
|
|
246
|
-
* - `
|
|
247
|
-
* - `false` ➔ truncate
|
|
234
|
+
* @param {FormatCurrencyOptions["roundedDecimal"]} [options.roundedDecimal] Rounding mode:
|
|
235
|
+
* - `"round"` ➔ nearest.
|
|
236
|
+
* - `"ceil"` ➔ always up.
|
|
237
|
+
* - `"floor"` ➔ always down.
|
|
238
|
+
* - `false` ➔ truncate.
|
|
248
239
|
* - ***DefaultValue: `"round"`***.
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* - `"dash"` ➔ `-15.000
|
|
252
|
-
* - `"brackets"` ➔ `(15.000)
|
|
253
|
-
* - `"abs"` ➔ `15.000` (always positive)
|
|
254
|
-
* - Or object:
|
|
255
|
-
* `{
|
|
256
|
-
* style: "dash"|"brackets"|"abs",
|
|
257
|
-
* space: true|false,
|
|
258
|
-
* custom: (formatted) => string
|
|
259
|
-
* }`.
|
|
240
|
+
* @param {FormatCurrencyOptions["negativeFormat"]} [options.negativeFormat]
|
|
241
|
+
* - How to format negatives:
|
|
242
|
+
* - `"dash"` ➔ `-15.000`.
|
|
243
|
+
* - `"brackets"` ➔ `(15.000)`.
|
|
244
|
+
* - `"abs"` ➔ `15.000` (always positive).
|
|
245
|
+
* - Or object: `{ style: "dash"|"brackets"|"abs", space: true|false, custom: (formatted) => string }`.
|
|
260
246
|
* - ***DefaultValue: `"dash"`.***
|
|
261
|
-
*
|
|
262
|
-
* @param {boolean} [options.indianFormat] Applies Indian Format:
|
|
247
|
+
* @param {FormatCurrencyOptions["indianFormat"]} [options.indianFormat] Applies Indian Format:
|
|
263
248
|
* - If `true`, formats as Indian: `12,34,567`.
|
|
264
249
|
* - Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
265
|
-
*
|
|
266
250
|
* @returns {string} Nicely formatted currency string, examples:
|
|
267
|
-
* - `"15.000,10"
|
|
268
|
-
* - `"Rp 15.000,10.-"
|
|
269
|
-
* - `"15'000.10 USD"
|
|
270
|
-
* - `"12,34,567.89"
|
|
271
|
-
*
|
|
251
|
+
* - `"15.000,10"`.
|
|
252
|
+
* - `"Rp 15.000,10.-"`.
|
|
253
|
+
* - `"15'000.10 USD"`.
|
|
254
|
+
* - `"12,34,567.89"`.
|
|
272
255
|
* @throws {TypeError} Will throw TypeError If:
|
|
273
|
-
* - `value` is not string or number
|
|
274
|
-
* - cannot parse to valid number
|
|
275
|
-
* - options have invalid types
|
|
256
|
+
* - `value` is not string or number.
|
|
257
|
+
* - cannot parse to valid number.
|
|
258
|
+
* - options have invalid types.
|
|
259
|
+
* @example
|
|
260
|
+
* // --- Number input (default, decimals off) ---
|
|
261
|
+
* formatCurrency(1234567.89);
|
|
262
|
+
* // ➔ "1.234.567"
|
|
263
|
+
*
|
|
264
|
+
* // --- Decimals enabled ---
|
|
265
|
+
* formatCurrency(1234567.89, { decimal: true });
|
|
266
|
+
* // ➔ "1.234.567,89"
|
|
267
|
+
*
|
|
268
|
+
* // --- Indian format ---
|
|
269
|
+
* formatCurrency(1234567.89, { decimal: true, indianFormat: true });
|
|
270
|
+
* // ➔ "12,34,567.89"
|
|
271
|
+
*
|
|
272
|
+
* // --- String input (Indonesian style) ---
|
|
273
|
+
* formatCurrency("Rp 15.000,21", { decimal: true });
|
|
274
|
+
* // ➔ "15.000,21"
|
|
275
|
+
*
|
|
276
|
+
* // --- String input (US style) ---
|
|
277
|
+
* formatCurrency("$12,345.60", { decimal: true });
|
|
278
|
+
* // ➔ "12.345,60"
|
|
279
|
+
*
|
|
280
|
+
* // --- String input (Swiss style) ---
|
|
281
|
+
* formatCurrency("CHF 12'345.60", { decimal: true });
|
|
282
|
+
* // ➔ "12'345,60"
|
|
283
|
+
*
|
|
284
|
+
* // --- String input (Indian style) ---
|
|
285
|
+
* formatCurrency("1,23,456.78", { decimal: true, indianFormat: true });
|
|
286
|
+
* // ➔ "12,34,567.78"
|
|
287
|
+
*
|
|
288
|
+
* // --- Negative numbers (dash) ---
|
|
289
|
+
* formatCurrency(-1234.56, { decimal: true });
|
|
290
|
+
* // ➔ "-1.234,56"
|
|
291
|
+
*
|
|
292
|
+
* // --- Negative numbers (brackets) ---
|
|
293
|
+
* formatCurrency(-1234.56, {
|
|
294
|
+
* decimal: true,
|
|
295
|
+
* negativeFormat: "brackets"
|
|
296
|
+
* });
|
|
297
|
+
* // ➔ "(1.234,56)"
|
|
276
298
|
*
|
|
277
|
-
* ---
|
|
299
|
+
* // --- Negative numbers (custom object style) ---
|
|
300
|
+
* formatCurrency(-1234.56, {
|
|
301
|
+
* decimal: true,
|
|
302
|
+
* negativeFormat: { style: "brackets", space: true }
|
|
303
|
+
* });
|
|
304
|
+
* // ➔ "( 1.234,56 )"
|
|
278
305
|
*
|
|
279
|
-
*
|
|
280
|
-
* -
|
|
281
|
-
*
|
|
282
|
-
*
|
|
306
|
+
* // --- Negative numbers (custom function) ---
|
|
307
|
+
* formatCurrency(-1234.56, {
|
|
308
|
+
* decimal: true,
|
|
309
|
+
* negativeFormat: { custom: (val) => `NEGATIVE[${val}]` }
|
|
310
|
+
* });
|
|
311
|
+
* // ➔ "NEGATIVE[1.234,56]"
|
|
312
|
+
*
|
|
313
|
+
* // --- With prefix currency ---
|
|
314
|
+
* formatCurrency(1234.56, {
|
|
315
|
+
* decimal: true,
|
|
316
|
+
* suffixCurrency: "Rp "
|
|
317
|
+
* });
|
|
318
|
+
* // ➔ "Rp 1.234,56"
|
|
319
|
+
*
|
|
320
|
+
* // --- With suffix decimal ---
|
|
321
|
+
* formatCurrency(1234.56, {
|
|
322
|
+
* decimal: true,
|
|
323
|
+
* suffixDecimal: ".-"
|
|
324
|
+
* });
|
|
325
|
+
* // ➔ "1.234,56.-"
|
|
326
|
+
*
|
|
327
|
+
* // --- With suffix currency + suffix decimal ---
|
|
328
|
+
* formatCurrency(1234.56, {
|
|
329
|
+
* decimal: true,
|
|
330
|
+
* suffixCurrency: "Rp ",
|
|
331
|
+
* suffixDecimal: ".-"
|
|
332
|
+
* });
|
|
333
|
+
* // ➔ "Rp 1.234,56.-"
|
|
334
|
+
*
|
|
335
|
+
* // --- Custom separators ---
|
|
336
|
+
* formatCurrency(1234567.89, {
|
|
337
|
+
* decimal: true,
|
|
338
|
+
* separator: "'",
|
|
339
|
+
* separatorDecimals: "."
|
|
340
|
+
* });
|
|
341
|
+
* // ➔ "1'234'567.89"
|
|
342
|
+
*
|
|
343
|
+
* // --- Rounding: ceil ---
|
|
344
|
+
* formatCurrency(1234.561, {
|
|
345
|
+
* decimal: true,
|
|
346
|
+
* roundedDecimal: "ceil"
|
|
347
|
+
* });
|
|
348
|
+
* // ➔ "1.234,57"
|
|
349
|
+
*
|
|
350
|
+
* // --- Rounding: floor ---
|
|
351
|
+
* formatCurrency(1234.569, {
|
|
352
|
+
* decimal: true,
|
|
353
|
+
* roundedDecimal: "floor"
|
|
354
|
+
* });
|
|
355
|
+
* // ➔ "1.234,56"
|
|
356
|
+
*
|
|
357
|
+
* // --- Rounding: truncate (false) ---
|
|
358
|
+
* formatCurrency(1234.569, {
|
|
359
|
+
* decimal: true,
|
|
360
|
+
* roundedDecimal: false
|
|
361
|
+
* });
|
|
362
|
+
* // ➔ "1.234,56"
|
|
363
|
+
*
|
|
364
|
+
* // --- Force no decimals (decimal: false) ---
|
|
365
|
+
* formatCurrency(1234.567, { decimal: false });
|
|
366
|
+
* // ➔ "1.235"
|
|
367
|
+
*
|
|
368
|
+
* // --- Edge case: messy input with dots & commas ---
|
|
369
|
+
* formatCurrency("1.121.234,561", {
|
|
370
|
+
* decimal: true,
|
|
371
|
+
* totalDecimal: 2,
|
|
372
|
+
* roundedDecimal: "ceil",
|
|
373
|
+
* suffixCurrency: "Rp ",
|
|
374
|
+
* negativeFormat: { style: "brackets" }
|
|
375
|
+
* });
|
|
376
|
+
* // ➔ "(Rp 1.121.234,57)"
|
|
377
|
+
*
|
|
378
|
+
* // --- Edge case: integer string input ---
|
|
379
|
+
* formatCurrency("1.121.234", {
|
|
380
|
+
* decimal: true,
|
|
381
|
+
* suffixCurrency: "Rp ",
|
|
382
|
+
* roundedDecimal: "ceil"
|
|
383
|
+
* });
|
|
384
|
+
* // ➔ "Rp 1.121.234,00"
|
|
283
385
|
*/
|
|
284
386
|
declare const formatCurrency:(value:string|number,options?:FormatCurrencyOptions)=>string;
|
|
285
387
|
/** ----------------------------------------------------------
|
|
286
|
-
* * ***
|
|
287
|
-
* every three digits (thousands separator), and intelligently
|
|
288
|
-
* flips the decimal separator according to the chosen separator.***
|
|
388
|
+
* * ***Utility: `formatNumber`.***
|
|
289
389
|
* ----------------------------------------------------------
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* -
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
390
|
+
* **Formats a number or numeric string by adding a custom separator
|
|
391
|
+
* every three digits (thousands separator), and intelligently flips
|
|
392
|
+
* the decimal separator according to the chosen separator.**
|
|
393
|
+
* - **Features:**
|
|
394
|
+
* - Converts a number to string before formatting.
|
|
395
|
+
* - Defaults to using `,` as the thousands separator.
|
|
396
|
+
* - If `.` is used as the separator, the decimal will automatically
|
|
397
|
+
* become `,`, and vice versa.
|
|
398
|
+
* - Handles input with existing formatting (e.g. "1,234,567.89") and normalizes it.
|
|
399
|
+
* - Supports custom separators, including spaces.
|
|
400
|
+
* - Preserves decimals even if more than 2 digits.
|
|
401
|
+
* @param {string | number} value - The numeric value or string to format, can be plain numbers, or already formatted strings like `"1,234,567.89"`.
|
|
402
|
+
* @param {string} [separator=","] - The thousands separator to use, examples: `","` ***(default)***, `"."`, `" "`, etc.
|
|
303
403
|
* @returns {string} The formatted string with thousands separators and
|
|
304
404
|
* appropriate decimal separator.
|
|
305
|
-
*
|
|
306
405
|
* @throws {TypeError} If `value` is not a string or number,
|
|
307
406
|
* or `separator` is not a string.
|
|
308
|
-
*
|
|
309
407
|
* @example
|
|
310
408
|
* formatNumber(1000000);
|
|
311
|
-
* //
|
|
312
|
-
*
|
|
409
|
+
* // ➔ "1,000,000"
|
|
313
410
|
* formatNumber("987654321");
|
|
314
|
-
* //
|
|
315
|
-
*
|
|
411
|
+
* // ➔ "987,654,321"
|
|
316
412
|
* formatNumber(1234567.89);
|
|
317
|
-
* //
|
|
318
|
-
*
|
|
413
|
+
* // ➔ "1,234,567.89"
|
|
319
414
|
* formatNumber("1234567,89");
|
|
320
|
-
* //
|
|
321
|
-
*
|
|
415
|
+
* // ➔ "1,234,567.89"
|
|
322
416
|
* formatNumber("1234567.892");
|
|
323
|
-
* //
|
|
324
|
-
*
|
|
417
|
+
* // ➔ "1,234,567.892"
|
|
325
418
|
* formatNumber("1234567.89", ".");
|
|
326
|
-
* //
|
|
327
|
-
*
|
|
419
|
+
* // ➔ "1.234.567,89"
|
|
328
420
|
* formatNumber("1234567,89", ",");
|
|
329
|
-
* //
|
|
330
|
-
*
|
|
421
|
+
* // ➔ "1,234,567.89"
|
|
331
422
|
* formatNumber("987654321", " ");
|
|
332
|
-
* //
|
|
333
|
-
*
|
|
423
|
+
* // ➔ "987 654 321"
|
|
334
424
|
* formatNumber("1,234,567.89");
|
|
335
|
-
* //
|
|
336
|
-
*
|
|
425
|
+
* // ➔ "1,234,567.89"
|
|
337
426
|
* formatNumber("1.234.567,89", ",");
|
|
338
|
-
* //
|
|
339
|
-
*
|
|
427
|
+
* // ➔ "1,234,567.89"
|
|
340
428
|
* formatNumber("1.234.567,893", ".");
|
|
341
|
-
* //
|
|
342
|
-
*
|
|
429
|
+
* // ➔ "1.234.567,893"
|
|
343
430
|
* formatNumber("1234.56", ".");
|
|
344
|
-
* //
|
|
345
|
-
*
|
|
431
|
+
* // ➔ "1.234,56"
|
|
346
432
|
* formatNumber("1234,56", ",");
|
|
347
|
-
* //
|
|
348
|
-
*
|
|
433
|
+
* // ➔ "1,234.56"
|
|
349
434
|
*/
|
|
350
435
|
declare const formatNumber:(value:string|number,separator?:string)=>string;
|
|
351
436
|
/** -------------------------------------------------------
|
|
352
|
-
* * ***
|
|
437
|
+
* * ***Utility: `formatPhoneNumber`.***
|
|
353
438
|
* -------------------------------------------------------
|
|
354
|
-
*
|
|
355
|
-
* Can also
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* Example:
|
|
439
|
+
* **Formats a phone number into a customizable local or international style.**
|
|
440
|
+
* - **Can also:**
|
|
441
|
+
* - Return only digits (`takeNumberOnly`).
|
|
442
|
+
* - Check validity (`checkValidOnly`) using a regex for international-style phone numbers.
|
|
443
|
+
* - **Validation (`checkValidOnly: true`):**
|
|
444
|
+
* - ***Valid if:***
|
|
445
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`,
|
|
446
|
+
* hyphens `-`, or dots `.`.
|
|
447
|
+
* - Digits-only length < 24.
|
|
448
|
+
* @example
|
|
365
449
|
* ```js
|
|
366
450
|
* formatPhoneNumber("081234567890")
|
|
367
|
-
* //
|
|
368
|
-
* ```
|
|
369
|
-
*
|
|
370
|
-
* Example:
|
|
371
|
-
* ```js
|
|
451
|
+
* // ➔ "0812 3456 7890"
|
|
372
452
|
* formatPhoneNumber("(0812) 3456-7890", { takeNumberOnly: true })
|
|
373
|
-
* //
|
|
374
|
-
* ```
|
|
375
|
-
*
|
|
376
|
-
* Example:
|
|
377
|
-
* ```js
|
|
453
|
+
* // ➔ "081234567890"
|
|
378
454
|
* formatPhoneNumber("(0812) 3456-7890", { checkValidOnly: true })
|
|
379
|
-
* //
|
|
380
|
-
* ```
|
|
381
|
-
*
|
|
382
|
-
* Example:
|
|
383
|
-
* ```js
|
|
455
|
+
* // ➔ true
|
|
384
456
|
* formatPhoneNumber("+6281234567890", { checkValidOnly: true })
|
|
385
|
-
* //
|
|
386
|
-
* ```
|
|
387
|
-
*
|
|
388
|
-
* Example:
|
|
389
|
-
* ```js
|
|
457
|
+
* // ➔ true
|
|
390
458
|
* formatPhoneNumber("+1 (800) 123-4567", { checkValidOnly: true })
|
|
391
|
-
* //
|
|
459
|
+
* // ➔ true
|
|
392
460
|
* formatPhoneNumber("+44 20 7946 0958", { checkValidOnly: true })
|
|
393
|
-
* //
|
|
394
|
-
* ```
|
|
395
|
-
*
|
|
396
|
-
* Example:
|
|
397
|
-
* ```js
|
|
461
|
+
* // ➔ true
|
|
398
462
|
* formatPhoneNumber("0812-3456-7890", { checkValidOnly: true })
|
|
399
|
-
* //
|
|
463
|
+
* // ➔ true
|
|
400
464
|
* formatPhoneNumber("(0812) 3456 7890", { checkValidOnly: true })
|
|
401
|
-
* //
|
|
465
|
+
* // ➔ true
|
|
402
466
|
* formatPhoneNumber("0812 3456 7890", { checkValidOnly: true })
|
|
403
|
-
* //
|
|
404
|
-
* ```
|
|
405
|
-
*
|
|
406
|
-
* Example:
|
|
407
|
-
* ```js
|
|
467
|
+
* // ➔ true
|
|
408
468
|
* formatPhoneNumber("+62abc123", { checkValidOnly: true })
|
|
409
|
-
* //
|
|
469
|
+
* // ➔ false
|
|
410
470
|
* formatPhoneNumber("0812-3456-hello", { checkValidOnly: true })
|
|
411
|
-
* //
|
|
471
|
+
* // ➔ false
|
|
412
472
|
* formatPhoneNumber("+62 123456789012345678901234", { checkValidOnly: true })
|
|
413
|
-
* //
|
|
473
|
+
* // ➔ false
|
|
414
474
|
* formatPhoneNumber("++6281234567890", { checkValidOnly: true })
|
|
415
|
-
* //
|
|
475
|
+
* // ➔ false
|
|
416
476
|
* formatPhoneNumber("invalid@@@", { checkValidOnly: true })
|
|
417
|
-
* //
|
|
418
|
-
* ```
|
|
419
|
-
*
|
|
420
|
-
* Example:
|
|
421
|
-
* ```js
|
|
477
|
+
* // ➔ false
|
|
422
478
|
* formatPhoneNumber("+62.812.3456.7890", { checkValidOnly: true })
|
|
423
|
-
* //
|
|
479
|
+
* // ➔ true
|
|
424
480
|
* formatPhoneNumber("+62(812)3456-7890", { checkValidOnly: true })
|
|
425
|
-
* //
|
|
481
|
+
* // ➔ true
|
|
426
482
|
* ```
|
|
427
|
-
*
|
|
428
|
-
* Example:
|
|
429
483
|
* ```js
|
|
430
484
|
* formatPhoneNumber("081234567890", {
|
|
431
485
|
* separator: "-",
|
|
@@ -433,30 +487,28 @@ declare const formatNumber:(value:string|number,separator?:string)=>string;
|
|
|
433
487
|
* openingNumberCountry: "(",
|
|
434
488
|
* closingNumberCountry: ")",
|
|
435
489
|
* })
|
|
436
|
-
* //
|
|
490
|
+
* // ➔ "(+44) 8123-4567-890"
|
|
437
491
|
* ```
|
|
438
|
-
*
|
|
439
492
|
* @throws {TypeError} If `value` is not string, number, null or undefined.
|
|
440
493
|
* @throws {TypeError} If `options` is not an object or contains wrong types.
|
|
441
494
|
*
|
|
442
|
-
* @overload
|
|
443
|
-
* @param value The phone number input (string or number).
|
|
444
|
-
* @param options With `checkValidOnly: true`.
|
|
445
|
-
* @returns A boolean indicating whether the input is a valid phone number.
|
|
495
|
+
* @overload Return a boolean if options With `checkValidOnly: true`.
|
|
496
|
+
* @param {ValueFormatPhoneNumber} [value] The phone number input (string or number).
|
|
497
|
+
* @param {FormatPhoneNumberPropsBoolean} [options] With `checkValidOnly: true`.
|
|
498
|
+
* @returns {boolean} A boolean indicating whether the input is a valid phone number.
|
|
446
499
|
*
|
|
447
|
-
* @overload
|
|
448
|
-
* @param value The phone number input (string or number).
|
|
449
|
-
* @param options With `takeNumberOnly: true`.
|
|
450
|
-
* @returns A string of digits only.
|
|
500
|
+
* @overload Return a string of digits only, if options With `takeNumberOnly: true`.
|
|
501
|
+
* @param {ValueFormatPhoneNumber} [value] The phone number input (string or number).
|
|
502
|
+
* @param {FormatPhoneNumberPropsTransform} [options] With `takeNumberOnly: true`.
|
|
503
|
+
* @returns {string} A string of digits only.
|
|
451
504
|
*
|
|
452
|
-
* @overload
|
|
453
|
-
* @param value The phone number input (string or number).
|
|
454
|
-
* @param options Options to customize format output (country code, separator, etc).
|
|
455
|
-
* @returns A formatted phone number string.
|
|
505
|
+
* @overload Return a formatted phone number string, if options Options to customize format output (country code, separator, etc).
|
|
506
|
+
* @param {ValueFormatPhoneNumber} [value] The phone number input (string or number).
|
|
507
|
+
* @param {FormatPhoneNumberPropsString} [options] Options to customize format output (country code, separator, etc).
|
|
508
|
+
* @returns {string} A formatted phone number string.
|
|
456
509
|
*/
|
|
457
510
|
declare function formatPhoneNumber(value?:ValueFormatPhoneNumber,options?:FormatPhoneNumberPropsString):string;declare function formatPhoneNumber(value?:ValueFormatPhoneNumber,options?:FormatPhoneNumberPropsBoolean):boolean;declare function formatPhoneNumber(value?:ValueFormatPhoneNumber,options?:FormatPhoneNumberPropsTransform):string;
|
|
458
|
-
/**
|
|
459
|
-
* -------------------------------------------------------------
|
|
511
|
+
/** -------------------------------------------------------------
|
|
460
512
|
* * ***Supported IETF BCP-47 locale codes for Intl API.***
|
|
461
513
|
* -------------------------------------------------------------
|
|
462
514
|
*
|
|
@@ -474,258 +526,268 @@ declare function formatPhoneNumber(value?:ValueFormatPhoneNumber,options?:Format
|
|
|
474
526
|
* new Intl.DateTimeFormat(locale).format(new Date());
|
|
475
527
|
*/
|
|
476
528
|
type SupportedLocales="en-US"|"en-GB"|"en-AU"|"en-CA"|"en-NZ"|"en-ZA"|"en-IN"|"en-IE"|"en-SG"|"en-HK"|"en-PH"|"en-MY"|"en-PK"|"en-KE"|"en-TZ"|"en-NG"|"en-LK"|"en-BW"|"en-ZM"|"id-ID"|"ms-MY"|"th-TH"|"vi-VN"|"tl-PH"|"ms-BN"|"zh-CN"|"zh-HK"|"zh-TW"|"zh-SG"|"zh-MO"|"ja-JP"|"ko-KR"|"fr-FR"|"fr-CA"|"fr-BE"|"fr-CH"|"fr-LU"|"fr-MA"|"fr-SN"|"fr-CM"|"fr-CI"|"fr-HT"|"fr-DZ"|"fr-TN"|"fr-ML"|"fr-NC"|"fr-PF"|"fr-GP"|"fr-MQ"|"fr-GF"|"de-DE"|"de-AT"|"de-CH"|"de-LU"|"de-LI"|"es-ES"|"es-MX"|"es-AR"|"es-CL"|"es-CO"|"es-PE"|"es-UY"|"es-VE"|"es-CR"|"es-EC"|"es-GT"|"es-HN"|"es-NI"|"es-PA"|"es-PR"|"es-SV"|"es-BO"|"es-PY"|"es-DO"|"es-CU"|"es-GQ"|"pt-BR"|"pt-PT"|"pt-MZ"|"pt-AO"|"pt-GW"|"pt-CV"|"pt-ST"|"it-IT"|"it-CH"|"it-SM"|"it-VA"|"nl-NL"|"nl-BE"|"nl-SR"|"nl-AW"|"nl-CW"|"ru-RU"|"uk-UA"|"kk-KZ"|"uz-UZ"|"ky-KG"|"tt-RU"|"ba-RU"|"cv-RU"|"sah-RU"|"pl-PL"|"cs-CZ"|"sk-SK"|"hu-HU"|"sl-SI"|"sv-SE"|"da-DK"|"no-NO"|"fi-FI"|"is-IS"|"ro-RO"|"bg-BG"|"hr-HR"|"sr-RS"|"mk-MK"|"bs-BA"|"me-ME"|"sq-AL"|"sq-XK"|"el-GR"|"el-CY"|"tr-TR"|"tr-CY"|"he-IL"|"ar-SA"|"ar-AE"|"ar-EG"|"ar-MA"|"ar-JO"|"ar-LB"|"ar-QA"|"ar-KW"|"ar-OM"|"ar-BH"|"ar-IQ"|"ar-LY"|"ar-TN"|"ar-YE"|"ar-SY"|"ar-PS"|"ar-SD"|"ar-DZ"|"ar-MR"|"ar-DJ"|"ar-SO"|"lt-LT"|"lv-LV"|"et-EE"|"hi-IN"|"bn-BD"|"pa-IN"|"ta-IN"|"te-IN"|"ml-IN"|"gu-IN"|"kn-IN"|"mr-IN"|"or-IN"|"as-IN"|"ne-IN"|"fa-IR"|"ur-PK"|"ps-AF"|"dv-MV"|"sw-KE"|"sw-TZ"|"zu-ZA"|"af-ZA"|"xh-ZA"|"ss-SZ"|"ts-ZA"|"tn-BW"|"ny-MW"|"lo-LA"|"mt-MT"|"ga-IE"|"cy-GB"|"ne-NP"|"si-LK"|"am-ET"|"om-ET"|"ti-ER"|"km-KH"|"my-MM"|"mn-MN"|"tg-TJ"|"tk-TM"|"hy-AM"|"ka-GE"|"az-AZ"|"be-BY"|"mo-MD"|"ro-MD"|"ht-HT"|"jw-ID"|"su-ID"|"to-TO"|"sm-WS"|"mi-NZ"|"bi-VU"|"fj-FJ"|"ty-PF"|"pau-PW"|"niu-NU"|"ck-CK"|"rw-RW"|"ln-CD"|"kg-CD"|"ha-NE"|"yo-NG"|"ig-NG"|"ak-GH"|"lg-UG"|"bo-CN"|"dz-BT"|"iu-CA"|"kl-GL"|"cv-RU"|"pap-AW"|"chr-US"|"haw-US"|"gv-IM"|"gd-GB"|"br-FR"|"co-FR"|"rm-CH"|"wa-BE"|"lb-LU"|"fur-IT"|"sc-IT"|"vec-IT"|"nap-IT"|"gsw-CH"|"rha-CH"|({}& string);
|
|
477
|
-
/**
|
|
478
|
-
* * ***
|
|
479
|
-
*
|
|
529
|
+
/** ----------------------------------------------------------------
|
|
530
|
+
* * ***Options for formatting dates with `Intl.DateTimeFormat`.***
|
|
531
|
+
* ----------------------------------------------------------------
|
|
480
532
|
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* - Defaults to `"YYYY-MM-DD hh:mm:ss"` format if none is specified.
|
|
533
|
+
* Extends the native
|
|
534
|
+
* **{@link Intl.DateTimeFormatOptions | `Intl.DateTimeFormatOptions`}** with
|
|
535
|
+
* an additional `locale` property that is validated against **{@link SupportedLocales | `SupportedLocales`}**.
|
|
485
536
|
*
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
537
|
+
*/
|
|
538
|
+
type FormatDateIntlOptions=Intl.DateTimeFormatOptions &{
|
|
539
|
+
/** ------------------------------------------------------------
|
|
540
|
+
* * Locale for date formatting.
|
|
541
|
+
* ------------------------------------------------------------
|
|
542
|
+
*
|
|
543
|
+
* - Must be a valid [***BCP-47 locale***](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument),
|
|
544
|
+
* validated against {@link SupportedLocales | **`SupportedLocales`**}.
|
|
545
|
+
* - If `locale` is `undefined` or an empty string (after trimming),
|
|
546
|
+
* it will **default to `"en-US"`**.
|
|
489
547
|
*
|
|
548
|
+
* @default "en-US"
|
|
490
549
|
* @example
|
|
491
|
-
*
|
|
492
|
-
* //
|
|
550
|
+
* { year: "numeric", month: "long" }
|
|
551
|
+
* // Unset locale, default locale ➔ "en-US"
|
|
552
|
+
* { locale: "fr-FR", ...}
|
|
553
|
+
* // Explicit locale
|
|
554
|
+
* { locale: " ", ...}
|
|
555
|
+
* // Empty string locale ➔ defaults to "en-US"
|
|
556
|
+
* { locale: " en-GB ", ...}
|
|
557
|
+
* // Value will trimming ➔ "en-GB"
|
|
493
558
|
*
|
|
494
|
-
|
|
495
|
-
|
|
559
|
+
*/
|
|
560
|
+
locale?:SupportedLocales;};
|
|
561
|
+
/** ----------------------------------------------------------------------
|
|
562
|
+
* * ***Options for formatting dates with `date-fns/format`.***
|
|
563
|
+
* ----------------------------------------------------------------------
|
|
496
564
|
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
565
|
+
* Extends the base **{@link FormatOptions | *`FormatOptions`*}** (without **`locale`**) with extra options
|
|
566
|
+
* for handling output formatting, localization, and parsing non-standard inputs.
|
|
499
567
|
*
|
|
500
|
-
|
|
501
|
-
|
|
568
|
+
*/
|
|
569
|
+
type FormatDateFnsOptions=Prettify<OmitStrict<FormatOptions,"locale",true,false>&{
|
|
570
|
+
/** ------------------------------------------------------------
|
|
571
|
+
* * Output format string passed to `date-fns/format`.
|
|
572
|
+
* ------------------------------------------------------------
|
|
502
573
|
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
574
|
+
* - Determines how the date will be rendered.
|
|
575
|
+
* - Uses the full power of `date-fns` tokens.
|
|
505
576
|
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
577
|
+
* ***Default Value***: `"dd MMM yyyy - HH:mm:ss"`.
|
|
578
|
+
* @example
|
|
579
|
+
* "dd MMMM yyyy, HH:mm:ss" // ➔ "03 September 2025, 10:25:42"
|
|
580
|
+
* @default "dd MMM yyyy - HH:mm:ss"
|
|
581
|
+
*/
|
|
582
|
+
format?:string;
|
|
583
|
+
/** ------------------------------------------------------------
|
|
584
|
+
* * Locale used for formatting.
|
|
585
|
+
* ------------------------------------------------------------
|
|
508
586
|
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
587
|
+
* - If `string`: only accepts `"id"` (Indonesian) or `"en"` (English) - **(default)**.
|
|
588
|
+
* - If `Locale`: accepts a locale object from `date-fns/locale`.
|
|
511
589
|
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
590
|
+
* ***Default Value***: `"en"`.
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { ar } from "date-fns/locale";
|
|
514
593
|
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
594
|
+
* formatDateFns(new Date(), {
|
|
595
|
+
* locale: ar,
|
|
596
|
+
* format: "dd MMMM yyyy"
|
|
597
|
+
* });
|
|
598
|
+
* // ➔ "03 سبتمبر 2025"
|
|
599
|
+
* ```
|
|
600
|
+
* @default "en"
|
|
601
|
+
*/
|
|
602
|
+
locale?:"id"|"en"|AnyString|Locale;
|
|
603
|
+
/** ------------------------------------------------------------
|
|
604
|
+
* * Input locale used when parsing non-standard string dates.
|
|
605
|
+
* ------------------------------------------------------------
|
|
517
606
|
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
607
|
+
* - Required if `date` is a **localized string**
|
|
608
|
+
* (e.g. `"03 Mei 2025 10:25:42"` in Indonesian).
|
|
609
|
+
* - Same accepted types as `locale` parameter.
|
|
520
610
|
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
611
|
+
* ***Default Value***: `"en"`.
|
|
612
|
+
* ```ts
|
|
613
|
+
* import { ar } from "date-fns/locale";
|
|
523
614
|
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
615
|
+
* formatDateFns("03 مايو 2025 10:25:42", {
|
|
616
|
+
* inputFormat: "dd MMMM yyyy HH:mm:ss",
|
|
617
|
+
* inputLocale: ar,
|
|
618
|
+
* format: "PPpp"
|
|
619
|
+
* });
|
|
620
|
+
* // ➔ "May 3, 2025 at 10:25:42 AM"
|
|
621
|
+
* ```
|
|
622
|
+
* @default "en"
|
|
623
|
+
*/
|
|
624
|
+
inputLocale?:"id"|"en"|AnyString|Locale;
|
|
625
|
+
/** ------------------------------------------------------------
|
|
626
|
+
* * Input format string for parsing non-ISO string dates.
|
|
627
|
+
* ------------------------------------------------------------
|
|
526
628
|
*
|
|
629
|
+
* - Required if `date` is **not ISO-8601** and not a native `Date`.
|
|
630
|
+
* - Works together with `inputLocale` parameter.
|
|
631
|
+
*
|
|
632
|
+
* ***Default Value***: `undefined`.
|
|
633
|
+
* @default undefined
|
|
634
|
+
* @example
|
|
635
|
+
* "dd MMMM yyyy HH:mm:ss" // ➔ "03 May 2025 10:25:42"
|
|
636
|
+
*/
|
|
637
|
+
inputFormat?:string;}>;
|
|
638
|
+
/** ----------------------------------------------------------
|
|
639
|
+
* * ***Utility: `formatDateTime`.***
|
|
640
|
+
* ----------------------------------------------------------
|
|
641
|
+
* **Formats a date and time into a custom string format.**
|
|
642
|
+
* - **Features:**
|
|
643
|
+
* - Supports only `YYYY`, `MM`, `DD`, `hh`, `mm`, and `ss` as placeholders.
|
|
644
|
+
* - Uses a simple string replace (no locale).
|
|
645
|
+
* - Returns `null` if the date is invalid or not provided.
|
|
646
|
+
* - Defaults to `"YYYY-MM-DD hh:mm:ss"` format if none is specified.
|
|
647
|
+
* @param {string | Date | null| undefined} date - The date to format.
|
|
648
|
+
* @param {string} [format="YYYY-MM-DD hh:mm:ss"] - The desired date format, if format is `null` or `undefined` will force to defaultValue, defaultValue: `"YYYY-MM-DD hh:mm:ss"`.
|
|
649
|
+
* @returns {string | null} The formatted date string or `null` if invalid.
|
|
650
|
+
* @example
|
|
651
|
+
* formatDateTime(new Date());
|
|
652
|
+
* // ➔ "2024-02-09 14:30:45" (example output with current time)
|
|
653
|
+
* formatDateTime("2023-07-01T14:30:45");
|
|
654
|
+
* // ➔ "2023-07-01 14:30:45"
|
|
655
|
+
* formatDateTime("2023-07-01T14:30:45", "DD/MM/YYYY");
|
|
656
|
+
* // ➔ "01/07/2023"
|
|
657
|
+
* formatDateTime("2023-07-01T14:30:45", "YYYY/MM/DD hh-mm-ss");
|
|
658
|
+
* // ➔ "2023/07/01 14-30-45"
|
|
659
|
+
* formatDateTime("2023-07-01T14:30:45", "hh:mm");
|
|
660
|
+
* // ➔ "14:30"
|
|
661
|
+
* formatDateTime("2023-07-01T14:30:45", "DATE: YYYY.MM.DD");
|
|
662
|
+
* // ➔ "DATE: 2023.07.01"
|
|
663
|
+
* formatDateTime("2023-07-01T14:30:45", "Year: YYYY, Time: hh:mm:ss");
|
|
664
|
+
* // ➔ "Year: 2023, Time: 14:30:45"
|
|
665
|
+
* formatDateTime("2023-07-01T14:30:45", "YYYY-MM");
|
|
666
|
+
* // ➔ "2023-07"
|
|
667
|
+
* formatDateTime("2023-07-01T14:30:45", "YYYYYYYY");
|
|
668
|
+
* // ➔ "20232023"
|
|
669
|
+
* formatDateTime("2023-07-01T14:30:45", "hh:mm:ss:ss");
|
|
670
|
+
* // ➔ "14:30:45:45"
|
|
671
|
+
* formatDateTime("invalid-date");
|
|
672
|
+
* // ➔ null
|
|
673
|
+
* formatDateTime(null);
|
|
674
|
+
* // ➔ null
|
|
527
675
|
* formatDateTime(undefined);
|
|
528
|
-
* //
|
|
676
|
+
* // ➔ null
|
|
529
677
|
*/
|
|
530
|
-
declare const formatDateTime:(date
|
|
531
|
-
/** @default "YYYY-MM-DD hh:mm:ss" */
|
|
532
|
-
format?:string)=>string|null;
|
|
678
|
+
declare const formatDateTime:(date:string|Date|null|undefined,format?:string)=>string|null;
|
|
533
679
|
/** ----------------------------------------------------------
|
|
534
|
-
* * ***
|
|
680
|
+
* * ***Utility: `formatDateIntl`.***
|
|
535
681
|
* ----------------------------------------------------------
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
* @param {string | Date | null | undefined}
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
* @param {
|
|
682
|
+
* **Formats a date using the `Intl.DateTimeFormat` API.**
|
|
683
|
+
* - **Features:**
|
|
684
|
+
* - Supports custom locales (type-safe `SupportedLocales`).
|
|
685
|
+
* - Accepts additional `Intl.DateTimeFormatOptions` like `timeZone`, `hour12`, etc.
|
|
686
|
+
* - Defaults to `"en-US"` if `locale` is not provided or is an empty string.
|
|
687
|
+
* - Returns `null` if the date is invalid, not provided, or options are invalid.
|
|
688
|
+
* @param {string | Date | null | undefined} date The date to format.
|
|
689
|
+
* - Can be a `Date` object or an ISO string.
|
|
690
|
+
* - If invalid or not provided, returns `null`.
|
|
691
|
+
* @param {FormatDateIntlOptions} [options]
|
|
546
692
|
* - Optional formatting options for `Intl.DateTimeFormat`.
|
|
547
693
|
* - Use `locale` to specify the language & region format.
|
|
548
|
-
*
|
|
549
694
|
* @returns {string | null}
|
|
550
695
|
* - Formatted date string.
|
|
551
696
|
* - Returns `null` if date is invalid or options are of wrong type.
|
|
552
|
-
*
|
|
553
697
|
* @example
|
|
554
698
|
* formatDateIntl(new Date());
|
|
555
|
-
* //
|
|
556
|
-
*
|
|
699
|
+
* // ➔ "7/14/2025"
|
|
557
700
|
* formatDateIntl("2025-07-14T00:00:00Z", { locale: "fr-FR", dateStyle: "long" });
|
|
558
|
-
* //
|
|
559
|
-
*
|
|
701
|
+
* // ➔ "14 juillet 2025"
|
|
560
702
|
* formatDateIntl(null);
|
|
561
|
-
* //
|
|
562
|
-
*
|
|
703
|
+
* // ➔ null
|
|
563
704
|
* formatDateIntl(new Date(), { timeZone: "UTC", hour: "2-digit", minute: "2-digit" });
|
|
564
|
-
* //
|
|
705
|
+
* // ➔ "01:30 AM"
|
|
565
706
|
*/
|
|
566
|
-
declare const formatDateIntl:(date
|
|
707
|
+
declare const formatDateIntl:(date:string|Date|null|undefined,options?:FormatDateIntlOptions)=>string|null;
|
|
567
708
|
/** ----------------------------------------------------------
|
|
568
|
-
* * ***
|
|
709
|
+
* * ***Utility: `formatDateFns`.***
|
|
569
710
|
* ----------------------------------------------------------
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
* @param {string | Date | null}
|
|
711
|
+
* Formats a date into a human-readable string using `date-fns`.
|
|
712
|
+
* - **Features:**
|
|
713
|
+
* - Supports custom output formats using `date-fns/format`.
|
|
714
|
+
* - Can parse localized non-ISO strings via `inputFormat` & `inputLocale`.
|
|
715
|
+
* - Supports `locale` as `"id"`, `"en"` or `date-fns` `Locale` objects (like `id` or `enUS`).
|
|
716
|
+
* - Returns `null` if the date is invalid, not provided, or parsing fails.
|
|
717
|
+
* @param {string | Date | null | undefined} date - The date input to format. Can be:
|
|
577
718
|
* - A `Date` object
|
|
578
719
|
* - An ISO string (e.g. `"2024-01-01T12:00:00Z"`)
|
|
579
720
|
* - A localized string (requires `inputFormat` + `inputLocale`)
|
|
580
|
-
*
|
|
581
|
-
* @param {
|
|
582
|
-
*
|
|
583
|
-
* @param {string} [options.format="dd MMM yyyy - HH:mm:ss"]
|
|
721
|
+
* @param {FormatDateFnsOptions} [options] - Options for formatting and parsing.
|
|
722
|
+
* @param {FormatDateFnsOptions["format"]} [options.format="dd MMM yyyy - HH:mm:ss"]
|
|
584
723
|
* The output format string (passed to `date-fns/format`).
|
|
585
|
-
* E.g. `"dd MMMM yyyy, HH:mm:ss"
|
|
586
|
-
*
|
|
587
|
-
* @param {"id" | "en" | (string & {}) | Locale} [options.locale="id"]
|
|
724
|
+
* E.g. `"dd MMMM yyyy, HH:mm:ss" ➔ "14 Juli 2025, 17:25:42"`
|
|
725
|
+
* @param {FormatDateFnsOptions["locale"]} [options.locale="id"]
|
|
588
726
|
* The output locale. If string, only `"id"` (Indonesian) or `"en"` (English)
|
|
589
727
|
* is recognized. Or you can pass a `date-fns` `Locale` object.
|
|
590
|
-
* Example:
|
|
728
|
+
* - Example:
|
|
591
729
|
* ```ts
|
|
592
730
|
* import { ar } from "date-fns/locale";
|
|
593
731
|
* formatDateFns(new Date(), { locale: ar, format: "PPPppp" });
|
|
594
732
|
* ```
|
|
595
|
-
*
|
|
596
|
-
* @param {"id" | "en" | (string & {}) | Locale} [options.inputLocale]
|
|
733
|
+
* @param {FormatDateFnsOptions["inputLocale"]} [options.inputLocale]
|
|
597
734
|
* Required if `date` is a localized non-ISO string. Used with `inputFormat`.
|
|
598
|
-
* Example for Indonesian string:
|
|
735
|
+
* - Example for Indonesian string:
|
|
599
736
|
* ```ts
|
|
600
|
-
* formatDateFns("14 Juli 2025 10:25:42", {
|
|
601
|
-
* inputFormat: "dd MMMM yyyy HH:mm:ss",
|
|
602
|
-
* inputLocale: "id",
|
|
603
|
-
* });
|
|
737
|
+
* formatDateFns("14 Juli 2025 10:25:42", { inputFormat: "dd MMMM yyyy HH:mm:ss", inputLocale: "id" });
|
|
604
738
|
* ```
|
|
605
|
-
*
|
|
606
|
-
* @param {string} [options.inputFormat]
|
|
739
|
+
* @param {FormatDateFnsOptions["inputFormat"]} [options.inputFormat]
|
|
607
740
|
* The format string to parse `date` if it is a non-ISO string.
|
|
608
741
|
* Required together with `inputLocale`.
|
|
609
|
-
*
|
|
610
742
|
* @returns {string | null} A formatted date string or `null` if input is invalid.
|
|
611
|
-
*
|
|
612
743
|
* @example
|
|
613
744
|
* formatDateFns(new Date());
|
|
614
|
-
* // "14 Jul 2025 - 17:25:42"
|
|
615
|
-
*
|
|
745
|
+
* // ➔ "14 Jul 2025 - 17:25:42"
|
|
616
746
|
* formatDateFns("2025-07-14T10:25:42Z", { format: "dd/MM/yyyy", locale: "en" });
|
|
617
|
-
* // "14/07/2025"
|
|
618
|
-
*
|
|
747
|
+
* // ➔ "14/07/2025"
|
|
619
748
|
* formatDateFns("14 Juli 2025 10:25:42", {
|
|
620
749
|
* inputFormat: "dd MMMM yyyy HH:mm:ss",
|
|
621
750
|
* inputLocale: "id",
|
|
622
751
|
* format: "yyyy-MM-dd"
|
|
623
752
|
* });
|
|
624
|
-
* // "2025-07-14"
|
|
625
|
-
*
|
|
753
|
+
* // ➔ "2025-07-14"
|
|
626
754
|
* formatDateFns(null);
|
|
627
|
-
* // null
|
|
628
|
-
*/
|
|
629
|
-
declare const formatDateFns:(date?:string|Date|null,
|
|
630
|
-
/**
|
|
631
|
-
* Options for formatting and parsing a date using `date-fns`.
|
|
632
|
-
*/
|
|
633
|
-
options?:OmitStrict<FormatOptions,"locale",true,false>&{
|
|
634
|
-
/**
|
|
635
|
-
* Output format string using `date-fns/format`.
|
|
636
|
-
* @default "dd MMM yyyy - HH:mm:ss"
|
|
637
|
-
* @example "dd MMMM yyyy, HH:mm:ss"
|
|
638
|
-
*/
|
|
639
|
-
format?:string;
|
|
640
|
-
/**
|
|
641
|
-
* The locale to be used for formatting.
|
|
642
|
-
* If `string` Only Accepts "id" for Indonesian or "en" for English.
|
|
643
|
-
* Or you can put props `Locale` from `date-fns/locale`, e.g :
|
|
644
|
-
*
|
|
645
|
-
* ```ts
|
|
646
|
-
* import { ar } from "date-fns/locale";
|
|
647
|
-
*
|
|
648
|
-
* // then passing `ar` to this props.
|
|
649
|
-
* formatDateFns(
|
|
650
|
-
* // your date input...,
|
|
651
|
-
* {
|
|
652
|
-
* locale: ar,
|
|
653
|
-
* //.... other options.
|
|
654
|
-
* });
|
|
655
|
-
*
|
|
656
|
-
* ```
|
|
657
|
-
* @default "id"
|
|
755
|
+
* // ➔ null
|
|
658
756
|
*/
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* The Input locale to be used for parsing `inputFormat`.
|
|
662
|
-
* If `string` Only Accepts "id" for Indonesian or "en" for English.
|
|
663
|
-
* Required if `date` is a non-standard string like "03 Mei 2025 10:25:42").
|
|
664
|
-
*
|
|
665
|
-
* Or you can put props `Locale` from `date-fns/locale`, e.g :
|
|
666
|
-
*
|
|
667
|
-
* ```ts
|
|
668
|
-
* import { ar } from "date-fns/locale";
|
|
669
|
-
*
|
|
670
|
-
* // then passing `ar` to this props.
|
|
671
|
-
* formatDateFns(
|
|
672
|
-
* // your date input...,
|
|
673
|
-
* {
|
|
674
|
-
* inputLocale: ar,
|
|
675
|
-
* //.... other options.
|
|
676
|
-
* });
|
|
677
|
-
*```
|
|
678
|
-
|
|
679
|
-
* @default undefined
|
|
680
|
-
*/
|
|
681
|
-
inputLocale?:"id"|"en"|(string &{})|Locale;
|
|
682
|
-
/**
|
|
683
|
-
* Input format string for parsing non-ISO string dates
|
|
684
|
-
* (e.g., localized strings like "03 Mei 2025 10:25:42").
|
|
685
|
-
* Required if `date` is a non-standard string.
|
|
686
|
-
* @example "dd MMMM yyyy HH:mm:ss"
|
|
687
|
-
*/
|
|
688
|
-
inputFormat?:string;})=>string|null;
|
|
757
|
+
declare const formatDateFns:(date:string|Date|null|undefined,options?:FormatDateFnsOptions)=>string|null;
|
|
689
758
|
/** ----------------------------------------------------------
|
|
690
|
-
* * ***
|
|
759
|
+
* * ***Utility: `getGMTOffset`.***
|
|
691
760
|
* ----------------------------------------------------------
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
761
|
+
* Returns the formatted GMT offset (e.g., `+0700`, `-0500`) for a given date.
|
|
762
|
+
* - **Features:**
|
|
763
|
+
* - If `date` is **not provided** or empty string, it defaults to the current date/time.
|
|
764
|
+
* - If `date` is **invalid** or of wrong type (like object or number), it returns `"0"`.
|
|
765
|
+
* - The returned string follows the **GMT offset format** (`±HHMM`), where:
|
|
766
|
+
* - `±` is `+` if ahead of UTC, `-` if behind.
|
|
767
|
+
* - `HH` is two-digit hours.
|
|
768
|
+
* - `MM` is two-digit minutes.
|
|
700
769
|
* @param {string | Date | null} [date] - The date to get the GMT offset from.
|
|
701
770
|
* - Accepts `Date` object or ISO date string (e.g., `"2024-01-01T12:00:00Z"`).
|
|
702
771
|
* - If `null`, `undefined`, or empty string, uses current system date.
|
|
703
772
|
* - If invalid date or wrong type (like `123` or `{}`), returns `"0"`.
|
|
704
|
-
*
|
|
705
773
|
* @returns {string} The GMT offset string in format `±HHMM`,
|
|
706
774
|
* e.g. `"+0700"`, `"-0530"`, or `"0"` if invalid.
|
|
707
|
-
*
|
|
708
775
|
* @example
|
|
709
776
|
* getGMTOffset();
|
|
710
|
-
* //
|
|
711
|
-
*
|
|
777
|
+
* // ➔ "+0700" (depends on your system timezone)
|
|
712
778
|
* getGMTOffset(new Date("2024-02-09T12:00:00Z"));
|
|
713
|
-
* //
|
|
714
|
-
*
|
|
779
|
+
* // ➔ "+0000"
|
|
715
780
|
* getGMTOffset("2024-02-09");
|
|
716
|
-
* //
|
|
717
|
-
*
|
|
781
|
+
* // ➔ "+0700" (depends on your system timezone)
|
|
718
782
|
* getGMTOffset("invalid-date");
|
|
719
|
-
* //
|
|
720
|
-
*
|
|
783
|
+
* // ➔ "0"
|
|
721
784
|
* getGMTOffset(123);
|
|
722
|
-
* //
|
|
785
|
+
* // ➔ "0"
|
|
723
786
|
*/
|
|
724
787
|
declare const getGMTOffset:(date?:string|Date|null)=>string;type CensorEmailOptions={
|
|
725
788
|
/** ----------------------------------------------------------
|
|
726
789
|
* * ***Censorship Mode.***
|
|
727
790
|
* ----------------------------------------------------------
|
|
728
|
-
*
|
|
729
791
|
* **Valid value:**
|
|
730
792
|
* - `"fixed"` (default) – Deterministic censorship based on a hash of the email.
|
|
731
793
|
* The same input always produces the same output.
|
|
@@ -733,24 +795,19 @@ declare const getGMTOffset:(date?:string|Date|null)=>string;type CensorEmailOpti
|
|
|
733
795
|
*/
|
|
734
796
|
mode?:"random"|"fixed";};
|
|
735
797
|
/** ----------------------------------------------------------
|
|
736
|
-
* * ***
|
|
798
|
+
* * ***Utility: `censorEmail`.***
|
|
737
799
|
* ----------------------------------------------------------
|
|
738
|
-
*
|
|
739
|
-
* This function replaces parts of an email with asterisks to protect privacy
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
* @param {string | null | undefined} [email] - The email address to censor.
|
|
800
|
+
* **Censors an email by replacing characters with "\*" while supporting random or fixed mode.**
|
|
801
|
+
* - **This function replaces parts of an email with asterisks to protect privacy.**
|
|
802
|
+
* - **Modes:**
|
|
803
|
+
* - `"fixed"` (default) – Deterministic censorship based on a hash of the email, same input always produces the same output.
|
|
804
|
+
* - `"random"` – Each character is randomly replaced every time the function is called.
|
|
805
|
+
* - **ℹ️ Note:**
|
|
806
|
+
* - Invalid emails or non-string input will return an empty string.
|
|
807
|
+
* @param {string | null | undefined} email - The email address to censor.
|
|
748
808
|
* @param {CensorEmailOptions} [options={}] - Options object for mode.
|
|
749
|
-
*
|
|
750
809
|
* @returns {string} The censored email, or an empty string if input is invalid.
|
|
751
|
-
*
|
|
752
810
|
* @throws {TypeError} If `options` is not a plain object or `mode` is invalid.
|
|
753
|
-
*
|
|
754
811
|
* @example
|
|
755
812
|
* // Fixed mode (default, deterministic)
|
|
756
813
|
* censorEmail("john.doe@gmail.com");
|
|
@@ -768,9 +825,8 @@ mode?:"random"|"fixed";};
|
|
|
768
825
|
* censorEmail("invalid-email");
|
|
769
826
|
* // ➔ ""
|
|
770
827
|
*/
|
|
771
|
-
declare const censorEmail:(email
|
|
772
|
-
/**
|
|
773
|
-
* The separator string to insert between characters or words.
|
|
828
|
+
declare const censorEmail:(email:string|null|undefined,options?:CensorEmailOptions)=>string;type ChunkStringOptions={
|
|
829
|
+
/** The separator string to insert between characters or words.
|
|
774
830
|
*
|
|
775
831
|
* - Used when inserting separators every `limiter` characters.
|
|
776
832
|
* - Default is a single space `" "`.
|
|
@@ -778,60 +834,52 @@ declare const censorEmail:(email?:string|null,options?:CensorEmailOptions)=>stri
|
|
|
778
834
|
* @default " "
|
|
779
835
|
*/
|
|
780
836
|
separator?:string;
|
|
781
|
-
/**
|
|
782
|
-
* Determines whether counting for `limiter` resets after each space.
|
|
837
|
+
/** Determines whether counting for `limiter` resets after each space.
|
|
783
838
|
*
|
|
784
839
|
* - If `true`, the string is treated as words separated by spaces,
|
|
785
840
|
* and separators are applied within words, then words are grouped.
|
|
786
|
-
* - If `false
|
|
841
|
+
* - If `false` ***(default)***, counting is continuous across the whole string,
|
|
787
842
|
* treating spaces as normal characters.
|
|
788
843
|
*
|
|
789
844
|
* @default false
|
|
790
845
|
*/
|
|
791
846
|
reCountAfterSpace?:boolean;};
|
|
792
847
|
/** ----------------------------------------------
|
|
793
|
-
* * ***
|
|
848
|
+
* * ***Utility: `chunkString`.***
|
|
794
849
|
* ----------------------------------------------
|
|
795
|
-
*
|
|
796
|
-
* This function handles two main behaviors based on `reCountAfterSpace
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
* Words within the same group are joined by the specified `separator`.
|
|
812
|
-
* - Finally, these groups are joined by a single space, preserving the original word separation structure
|
|
813
|
-
* between groups.
|
|
814
|
-
*
|
|
850
|
+
* **Chunks a string by inserting a separator every `limiter` characters.**
|
|
851
|
+
* - **This function handles two main behaviors based on `reCountAfterSpace`:**
|
|
852
|
+
* 1. ***If `reCountAfterSpace` is `false` (default):***
|
|
853
|
+
* - The separator is inserted strictly every `limiter` characters throughout the entire string, regardless of spaces, spaces are treated as regular characters in the count.
|
|
854
|
+
* - Example: `chunkString("1234567890", 3, "-")` ➔ `"123-456-789-0"`.
|
|
855
|
+
* - Example: `chunkString("Hello World", 3, "-")` ➔ `"Hel-lo -Wor-ld"`.
|
|
856
|
+
* 2. ***If `reCountAfterSpace` is `true`:***
|
|
857
|
+
* - The function first processes the input string to replace any multiple consecutive spaces with a
|
|
858
|
+
* single space (e.g., "A B" becomes "A B").
|
|
859
|
+
* Then, it treats the string as a sequence of "words" (segments separated by single spaces).
|
|
860
|
+
* - Each word is processed independently:
|
|
861
|
+
* - if a word's length exceeds the `limiter`, separators are inserted internally within that word.
|
|
862
|
+
* - Words are then grouped. Each group will contain `limiter` number of words.
|
|
863
|
+
* - Words within the same group are joined by the specified `separator`.
|
|
864
|
+
* - Finally, these groups are joined by a single space, preserving the original word separation
|
|
865
|
+
* structure between groups.
|
|
815
866
|
* @param {string} subject - The target string to chunk.
|
|
816
867
|
* @param {number} limiter - The interval (number of characters) for inserting separators.
|
|
817
868
|
* - If `reCountAfterSpace = false`, it counts characters.
|
|
818
869
|
* - If `reCountAfterSpace = true`, it counts both characters within words and words per group.
|
|
819
870
|
* @param {ChunkStringOptions} [options={}] - Optional settings for separator and counting behavior.
|
|
820
|
-
* @returns {string}
|
|
821
|
-
*
|
|
871
|
+
* @returns {string} Return the formatted string with separators.
|
|
822
872
|
* @example
|
|
823
873
|
* // Basic usage
|
|
824
874
|
* chunkString("1234567890", 3);
|
|
825
875
|
* // ➔ "123 456 789 0"
|
|
826
876
|
*
|
|
827
|
-
* @example
|
|
828
877
|
* // Basic usage `reCountAfterSpace = false` (default)
|
|
829
878
|
* chunkString("1234567890", 3, { separator: "-");
|
|
830
879
|
* // ➔ "123-456-789-0"
|
|
831
880
|
* chunkString("HelloWorld", 2, { separator: "_", reCountAfterSpace: false });
|
|
832
881
|
* // ➔ "He_ll_oW_or_ld"
|
|
833
882
|
*
|
|
834
|
-
* @example
|
|
835
883
|
* // Usage with reCountAfterSpace = true:
|
|
836
884
|
* // Multiple spaces are normalized to single spaces before processing.
|
|
837
885
|
* chunkString("AB CD EF GH", 2, { separator: "-", reCountAfterSpace: true });
|
|
@@ -839,7 +887,6 @@ reCountAfterSpace?:boolean;};
|
|
|
839
887
|
* // Words "AB" and "CD" form a group and are joined by "-", "EF" and "GH" form another group.
|
|
840
888
|
* // The groups "AB-CD" and "EF-GH" are then joined by a space.
|
|
841
889
|
*
|
|
842
|
-
* @example
|
|
843
890
|
* // Another usage with reCountAfterSpace = true:
|
|
844
891
|
* chunkString("ABC DEF GHI JKL", 3, { separator: "-", reCountAfterSpace: true });
|
|
845
892
|
* // ➔ "ABC-DEF-GHI JKL"
|
|
@@ -866,47 +913,38 @@ ending?:string;
|
|
|
866
913
|
*/
|
|
867
914
|
trim?:boolean;};
|
|
868
915
|
/** ----------------------------------------------------------
|
|
869
|
-
* * ***
|
|
870
|
-
* * ***Supports trimming the input before truncation.***
|
|
871
|
-
* * ***If truncation occurs, trailing spaces before the ending are removed.***
|
|
872
|
-
* * ***The `ending` parameter is always trimmed first; if empty, it defaults to `"..."`.***
|
|
916
|
+
* * ***Utility: `truncateString`.***
|
|
873
917
|
* ----------------------------------------------------------
|
|
874
|
-
*
|
|
918
|
+
* **Features:**
|
|
919
|
+
* - Truncates a string to a specified length and optionally appends an ending.
|
|
920
|
+
* - Supports trimming the input before truncation.
|
|
921
|
+
* - If truncation occurs, trailing spaces before the ending are removed.
|
|
922
|
+
* - The `ending` parameter is always trimmed first; if empty, it defaults to `"..."`.
|
|
875
923
|
* @param {string|null|undefined} text - The input string to truncate.
|
|
876
924
|
* If `null`, `undefined`, or empty after trim, returns `""`.
|
|
877
925
|
* @param {TruncateStringOptions} [options] - Optional settings:
|
|
878
926
|
* - `length` (number, default 10): Maximum length of the truncated string.
|
|
879
927
|
* - `ending` (string, default `"..."`): String to append if truncation occurs.
|
|
880
|
-
* - `trim` (boolean, default true): Whether to trim the input before truncation.
|
|
881
|
-
*
|
|
928
|
+
* - `trim` (boolean, default `true`): Whether to trim the input before truncation.
|
|
882
929
|
* @returns {string} The truncated string with optional trimming and ending.
|
|
883
930
|
* Returns `""` if input is empty or length < 1.
|
|
884
|
-
*
|
|
885
931
|
* @throws {TypeError} If `options.length` is not a finite number,
|
|
886
932
|
* or if `options.ending` is not a string,
|
|
887
933
|
* or if `options.trim` is not a boolean.
|
|
888
|
-
*
|
|
889
934
|
* @example
|
|
890
935
|
* truncateString("hello world", { length: 5 });
|
|
891
936
|
* // ➔ "hello..."
|
|
892
|
-
*
|
|
893
937
|
* truncateString("hello world", { length: 5, ending: "---" });
|
|
894
938
|
* // ➔ "hello---"
|
|
895
|
-
*
|
|
896
939
|
* truncateString("hello world", { length: 5, ending: " " });
|
|
897
940
|
* // ➔ "hello..." (ending trimmed to default)
|
|
898
|
-
*
|
|
899
941
|
* truncateString("hello world", { length: 5, ending: " !!! " });
|
|
900
942
|
* // ➔ "hello!!!" (ending trimmed)
|
|
901
|
-
*
|
|
902
943
|
* truncateString(" long data string ", { length: 8, ending: "...", trim: true });
|
|
903
944
|
* // ➔ "long dat..."
|
|
904
|
-
*
|
|
905
945
|
* truncateString(" long data string ", { length: 8, ending: "...", trim: false });
|
|
906
946
|
* // ➔ " long ..."
|
|
907
|
-
*
|
|
908
947
|
* truncateString(null, { length: 5 });
|
|
909
948
|
* // ➔ ""
|
|
910
|
-
*
|
|
911
949
|
*/
|
|
912
|
-
declare const truncateString:(text
|
|
950
|
+
declare const truncateString:(text:string|null|undefined,options?:TruncateStringOptions)=>string;export{censorEmail,chunkString,formatCurrency,formatDateFns,formatDateIntl,formatDateTime,formatNumber,formatPhoneNumber,getGMTOffset,truncateString};
|