@rzl-zone/utils-js 2.0.1 → 3.0.0-beta.0
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/NumberRangeUnion-DC-C3_Kq.d.ts +26 -0
- package/dist/any-BmdI8UbK.d.ts +67 -0
- package/dist/array-CIZRbqTF.d.ts +223 -0
- package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +72 -0
- package/dist/assertions/index.cjs +1 -0
- package/dist/assertions/index.d.ts +428 -0
- package/dist/assertions/index.js +1 -0
- package/dist/chunk-2TRAPBZ7.cjs +1 -0
- package/dist/chunk-3D74QO5D.cjs +1 -0
- package/dist/chunk-4DK3RCC4.js +2 -0
- package/dist/chunk-4JOQ45HL.js +1 -0
- package/dist/chunk-55CZALRS.js +1 -0
- package/dist/chunk-56QBKKRE.js +1 -0
- package/dist/chunk-5JFV3GDE.cjs +4 -0
- package/dist/chunk-5SZUSNGZ.js +1 -0
- package/dist/chunk-62HX5Z45.cjs +1 -0
- package/dist/chunk-7NA6DUHR.cjs +2 -0
- package/dist/chunk-7YWAQOA4.cjs +1 -0
- package/dist/chunk-BVPMMWDL.cjs +1 -0
- package/dist/chunk-BYZAD3XN.cjs +1 -0
- package/dist/chunk-CEFYHEM4.cjs +1 -0
- package/dist/chunk-CN53M4QZ.cjs +1 -0
- package/dist/chunk-D47MHBSD.cjs +1 -0
- package/dist/chunk-DGH75GJD.js +1 -0
- package/dist/chunk-E5NUI7PN.js +1 -0
- package/dist/chunk-ELDDNERR.js +1 -0
- package/dist/chunk-EXZ47NOW.js +1 -0
- package/dist/chunk-FDITZ5C6.cjs +1 -0
- package/dist/chunk-FF76ISQ2.js +1 -0
- package/dist/chunk-FIEZKTAZ.cjs +1 -0
- package/dist/chunk-FSSV24W7.cjs +1 -0
- package/dist/chunk-G5LXIEFO.js +0 -0
- package/dist/chunk-GCGU2WB7.js +1 -0
- package/dist/chunk-GECI2YBP.js +1 -0
- package/dist/chunk-GQE4OVHC.cjs +1 -0
- package/dist/chunk-GRVZXQXL.cjs +1 -0
- package/dist/chunk-I4AVNHPA.cjs +1 -0
- package/dist/chunk-JFRL7NKU.js +4 -0
- package/dist/chunk-JWHM3WZQ.cjs +1 -0
- package/dist/chunk-KCQDDZJE.cjs +1 -0
- package/dist/chunk-L54ZPSYJ.js +1 -0
- package/dist/chunk-LVKAYEZ4.js +1 -0
- package/dist/chunk-MBDWTK54.cjs +1 -0
- package/dist/chunk-MMSYCIJ2.cjs +1 -0
- package/dist/chunk-MNGGDB2G.js +1 -0
- package/dist/chunk-MY7BA4GI.cjs +1 -0
- package/dist/chunk-N2IJPIND.cjs +1 -0
- package/dist/chunk-NIMNTEGV.js +1 -0
- package/dist/chunk-NNM7QCNB.js +1 -0
- package/dist/chunk-PUQXRLZH.cjs +1 -0
- package/dist/chunk-PVJF2JHM.js +1 -0
- package/dist/chunk-QCFXEUKL.js +1 -0
- package/dist/chunk-QFCGBBSY.js +1 -0
- package/dist/chunk-QQYAUPSK.cjs +1 -0
- package/dist/chunk-RN3TP3S3.js +1 -0
- package/dist/chunk-RV2VULM7.cjs +1 -0
- package/dist/chunk-SW6HYEW7.cjs +1 -0
- package/dist/chunk-SYJC7UAW.js +1 -0
- package/dist/chunk-TC4VBE4Y.cjs +1 -0
- package/dist/chunk-TUXDINHF.cjs +1 -0
- package/dist/chunk-U5Y2FXMN.cjs +1 -0
- package/dist/chunk-UUPQI6ND.cjs +1 -0
- package/dist/chunk-VYCGZ2S6.js +1 -0
- package/dist/chunk-W5EDKJK3.js +1 -0
- package/dist/chunk-WHAVUFEU.js +1 -0
- package/dist/chunk-XCFIOTCV.js +1 -0
- package/dist/chunk-XE27XPJR.js +1 -0
- package/dist/chunk-XH6MCRLP.js +1 -0
- package/dist/chunk-XVB3ZZEB.js +1 -0
- package/dist/chunk-ZBSIGJFO.cjs +1 -0
- package/dist/chunk-ZYAML74V.js +1 -0
- package/dist/conversions/index.cjs +1 -0
- package/dist/conversions/index.d.ts +1633 -0
- package/dist/conversions/index.js +1 -0
- package/dist/env/index.cjs +1 -0
- package/dist/env/index.d.ts +19 -0
- package/dist/env/index.js +1 -0
- package/dist/events/index.cjs +1 -0
- package/dist/events/index.d.ts +119 -0
- package/dist/events/index.js +1 -0
- package/dist/extends-Mp81Hq9-.d.ts +145 -0
- package/dist/formatting/index.cjs +1 -0
- package/dist/formatting/index.d.ts +912 -0
- package/dist/formatting/index.js +1 -0
- package/dist/generator/index.cjs +1 -0
- package/dist/generator/index.d.ts +163 -0
- package/dist/generator/index.js +1 -0
- package/dist/if-CvT4R7Kh.d.ts +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -4313
- package/dist/index.js +1 -1
- package/dist/is-array-Ckm_47hw.d.ts +1557 -0
- package/dist/isPlainObject-BKYaI6a8.d.ts +182 -0
- package/dist/never-BfayMBF9.d.ts +75 -0
- package/dist/next/index.cjs +8 -1
- package/dist/next/index.d.ts +169 -169
- package/dist/next/index.js +8 -1
- package/dist/next/server/index.cjs +2 -1
- package/dist/next/server/index.d.ts +37 -37
- package/dist/next/server/index.js +2 -1
- package/dist/nils-DMz3kU7M.d.ts +177 -0
- package/dist/omit-VvmIsZmX.d.ts +28 -0
- package/dist/operations/index.cjs +1 -0
- package/dist/operations/index.d.ts +182 -0
- package/dist/operations/index.js +1 -0
- package/dist/parsers/index.cjs +1 -0
- package/dist/parsers/index.d.ts +37 -0
- package/dist/parsers/index.js +1 -0
- package/dist/predicates/index.cjs +1 -0
- package/dist/predicates/index.d.ts +1839 -0
- package/dist/predicates/index.js +1 -0
- package/dist/prettify-C4xLcYOP.d.ts +353 -0
- package/dist/promise/index.cjs +1 -0
- package/dist/promise/index.d.ts +40 -0
- package/dist/promise/index.js +1 -0
- package/dist/rzl-utils.global.js +4 -1
- package/dist/strings/index.cjs +1 -0
- package/dist/strings/index.d.ts +816 -0
- package/dist/strings/index.js +1 -0
- package/dist/stylings/index.cjs +1 -0
- package/dist/stylings/index.d.ts +49 -0
- package/dist/stylings/index.js +1 -0
- package/dist/type-data-DDs-u2kq.d.ts +261 -0
- package/dist/types/index.d.ts +3589 -2090
- package/dist/urls/index.cjs +1 -0
- package/dist/urls/index.d.ts +418 -0
- package/dist/urls/index.js +1 -0
- package/package.json +147 -21
|
@@ -0,0 +1,912 @@
|
|
|
1
|
+
import{O as OmitStrict}from'../omit-VvmIsZmX.js';import{Locale}from'date-fns/locale';import{FormatOptions}from'date-fns';import'../prettify-C4xLcYOP.js';import'../if-CvT4R7Kh.js';import'../type-data-DDs-u2kq.js';import'../never-BfayMBF9.js';type ValueFormatPhoneNumber=string|number|null;type FormatPhoneNumberProps={
|
|
2
|
+
/** @default " " */
|
|
3
|
+
separator?:string;
|
|
4
|
+
/** @default "" */
|
|
5
|
+
plusNumberCountry?:string;
|
|
6
|
+
/** @default "" */
|
|
7
|
+
openingNumberCountry?:string;
|
|
8
|
+
/** @default "" */
|
|
9
|
+
closingNumberCountry?:string;
|
|
10
|
+
/** @default false */
|
|
11
|
+
checkValidOnly?:boolean;
|
|
12
|
+
/** @default false */
|
|
13
|
+
takeNumberOnly?:boolean;};type FormatPhoneNumberPropsString=OmitStrict<FormatPhoneNumberProps,"checkValidOnly"|"takeNumberOnly">&{
|
|
14
|
+
/** @default false */
|
|
15
|
+
checkValidOnly?:false;
|
|
16
|
+
/** @default false */
|
|
17
|
+
takeNumberOnly?:false;};type FormatPhoneNumberPropsBoolean=OmitStrict<FormatPhoneNumberProps,"separator"|"plusNumberCountry"|"closingNumberCountry"|"openingNumberCountry"|"takeNumberOnly">;type FormatPhoneNumberPropsTransform=OmitStrict<FormatPhoneNumberProps,"separator"|"plusNumberCountry"|"closingNumberCountry"|"openingNumberCountry"|"checkValidOnly">;type NegativeFormatOptionCustom={
|
|
18
|
+
/** Custom formatter function for the final formatted negative string.
|
|
19
|
+
* If provided, it OVERRIDES style & space entirely. */
|
|
20
|
+
custom:(formatted:string)=>string;style?:never;space?:never;};type NegativeFormatOptionUnCustom={custom?:never;
|
|
21
|
+
/** Use style & optional spacing for negative numbers.
|
|
22
|
+
*
|
|
23
|
+
* @default "dash"
|
|
24
|
+
*/
|
|
25
|
+
style?:"dash"|"brackets"|"abs";
|
|
26
|
+
/** Whether to include space inside brackets or after dash.
|
|
27
|
+
*
|
|
28
|
+
* Default: false
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
space?:boolean;};
|
|
32
|
+
/** ---------------------------------------------------------------------------
|
|
33
|
+
* * ***Type for negative number formatting options.***
|
|
34
|
+
* ---------------------------------------------------------------------------
|
|
35
|
+
*/
|
|
36
|
+
type NegativeFormatOption="dash"|"brackets"|"abs"|NegativeFormatOptionCustom|NegativeFormatOptionUnCustom;
|
|
37
|
+
/** ---------------------------------------------------------------------------
|
|
38
|
+
* * ***Options for `formatCurrency()`***
|
|
39
|
+
* ---------------------------------------------------------------------------
|
|
40
|
+
*/
|
|
41
|
+
type FormatCurrencyOptions={
|
|
42
|
+
/** ---------------------------------------------------------------------------
|
|
43
|
+
* * ***Prefix currency string.***
|
|
44
|
+
* ---------------------------------------------------------------------------
|
|
45
|
+
*
|
|
46
|
+
* Does not auto-keep input symbols.
|
|
47
|
+
*
|
|
48
|
+
* Example: `"Rp "` ➔ `Rp 1.000`.
|
|
49
|
+
*
|
|
50
|
+
* *DefaultValue: `""`.*
|
|
51
|
+
*
|
|
52
|
+
* @default ""
|
|
53
|
+
*/
|
|
54
|
+
suffixCurrency?:string;
|
|
55
|
+
/** ---------------------------------------------------------------------------
|
|
56
|
+
* * ***Thousands separator.***
|
|
57
|
+
* ---------------------------------------------------------------------------
|
|
58
|
+
*
|
|
59
|
+
* Example: `"."` ➔ `1.000.000`.
|
|
60
|
+
*
|
|
61
|
+
* *DefaultValue: `"."`.*
|
|
62
|
+
*
|
|
63
|
+
* @default "."
|
|
64
|
+
*/
|
|
65
|
+
separator?:string;
|
|
66
|
+
/** ---------------------------------------------------------------------------
|
|
67
|
+
* * ***Prefix currency string.***
|
|
68
|
+
* ---------------------------------------------------------------------------
|
|
69
|
+
*
|
|
70
|
+
* If `false`, rounds to integer.
|
|
71
|
+
*
|
|
72
|
+
* *DefaultValue: `false`.*
|
|
73
|
+
*
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
decimal?:boolean;
|
|
77
|
+
/** ---------------------------------------------------------------------------
|
|
78
|
+
* * ***Total decimal digits.***
|
|
79
|
+
* ---------------------------------------------------------------------------
|
|
80
|
+
*
|
|
81
|
+
* If `decimal: true` & `roundedDecimal: false`, simply cuts.
|
|
82
|
+
*
|
|
83
|
+
* *DefaultValue: `2`.*
|
|
84
|
+
*
|
|
85
|
+
* @default 2
|
|
86
|
+
*/
|
|
87
|
+
totalDecimal?:number;
|
|
88
|
+
/** ---------------------------------------------------------------------------
|
|
89
|
+
* * ***Actually append `suffixDecimal`.***
|
|
90
|
+
* ---------------------------------------------------------------------------
|
|
91
|
+
*
|
|
92
|
+
* *DefaultValue: `true`.*
|
|
93
|
+
*
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
endDecimal?:boolean;
|
|
97
|
+
/** ---------------------------------------------------------------------------
|
|
98
|
+
* * ***Text appended after decimals.***
|
|
99
|
+
* ---------------------------------------------------------------------------
|
|
100
|
+
*
|
|
101
|
+
* E.g: (`".-"`, `" USD"`).
|
|
102
|
+
*
|
|
103
|
+
* *Example 1: `".-"` ➔ `1.000,00.-`.*
|
|
104
|
+
*
|
|
105
|
+
* *Example 2: `" USD"` ➔ `1.000,00 USD`.*
|
|
106
|
+
*
|
|
107
|
+
* *DefaultValue: `""`.*
|
|
108
|
+
*
|
|
109
|
+
* @default ""
|
|
110
|
+
*/
|
|
111
|
+
suffixDecimal?:string;
|
|
112
|
+
/** ---------------------------------------------------------------------------
|
|
113
|
+
* * ***Rounding mode for decimals.***
|
|
114
|
+
* ---------------------------------------------------------------------------
|
|
115
|
+
*
|
|
116
|
+
* - `"round"` ➔ nearest
|
|
117
|
+
* - `"ceil"` ➔ always up
|
|
118
|
+
* - `"floor"` ➔ always down
|
|
119
|
+
* - `false` ➔ truncate
|
|
120
|
+
*
|
|
121
|
+
* *DefaultValue: `"round"`.*
|
|
122
|
+
*
|
|
123
|
+
* @default "round"
|
|
124
|
+
*/
|
|
125
|
+
roundedDecimal?:"round"|"ceil"|"floor"|false;
|
|
126
|
+
/** ---------------------------------------------------------------------------
|
|
127
|
+
* * ***Decimal separator.***
|
|
128
|
+
* ---------------------------------------------------------------------------
|
|
129
|
+
*
|
|
130
|
+
* Example: `","` ➔ `1.000,10`
|
|
131
|
+
*
|
|
132
|
+
* *DefaultValue: `","`.*
|
|
133
|
+
*
|
|
134
|
+
* @default ","
|
|
135
|
+
*/
|
|
136
|
+
separatorDecimals?:string;
|
|
137
|
+
/** ---------------------------------------------------------------------------
|
|
138
|
+
* * ***Negative formatting option.***
|
|
139
|
+
* ---------------------------------------------------------------------------
|
|
140
|
+
*
|
|
141
|
+
* Can be string ("dash" | "brackets" | "abs") or object with custom formatter.
|
|
142
|
+
*
|
|
143
|
+
* - `"dash"` ➔ `-15.000`
|
|
144
|
+
* - `"brackets"` ➔ `(15.000)`
|
|
145
|
+
* - `"abs"` ➔ `15.000` (always positive)
|
|
146
|
+
* - Or object:
|
|
147
|
+
* `{
|
|
148
|
+
* style: "dash"|"brackets"|"abs",
|
|
149
|
+
* space: true|false,
|
|
150
|
+
* custom: (formatted) => string
|
|
151
|
+
* }`.
|
|
152
|
+
*
|
|
153
|
+
* *DefaultValue: `"dash"`.*
|
|
154
|
+
*
|
|
155
|
+
* @default "dash"
|
|
156
|
+
*/
|
|
157
|
+
negativeFormat?:NegativeFormatOption;
|
|
158
|
+
/** ---------------------------------------------------------------------------
|
|
159
|
+
* * ***Applies Indian Format.***
|
|
160
|
+
* ---------------------------------------------------------------------------
|
|
161
|
+
*
|
|
162
|
+
* If `true`, formats as Indian: `12,34,567`.
|
|
163
|
+
*
|
|
164
|
+
* Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
165
|
+
*
|
|
166
|
+
* *DefaultValue: `false`.*
|
|
167
|
+
*
|
|
168
|
+
* @default false
|
|
169
|
+
*/
|
|
170
|
+
indianFormat?:boolean;};
|
|
171
|
+
/** -------------------------------------------------------
|
|
172
|
+
* * ***Formats a number or messy currency string into a
|
|
173
|
+
* beautifully formatted currency string, with highly
|
|
174
|
+
* customizable separators, decimal control, rounding,
|
|
175
|
+
* currency symbols, and negative styling.***
|
|
176
|
+
* -------------------------------------------------------
|
|
177
|
+
*
|
|
178
|
+
* ✅ Highlights:
|
|
179
|
+
* - Accepts:
|
|
180
|
+
* - Pure numbers: `15300.95`
|
|
181
|
+
* - Messy currency strings from **any locale**:
|
|
182
|
+
* - `"Rp 15.000,21"` (Indonesian / Euro)
|
|
183
|
+
* - `"$12,345.60"` (US)
|
|
184
|
+
* - `"CHF 12'345.60"` (Swiss)
|
|
185
|
+
* - `"1,23,456.78"` (Indian)
|
|
186
|
+
* - 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
|
|
195
|
+
* - Strong type checks & clear errors for misconfigured options.
|
|
196
|
+
*
|
|
197
|
+
* ✅ How input is parsed:
|
|
198
|
+
* - Removes all non-digit except `.`, `,`, `'` and spaces.
|
|
199
|
+
* - Detects bracket negatives: `"(15.000,10)"` ➔ `-15000.10`
|
|
200
|
+
* - Uses last `,` or `.` as decimal separator (others are thousands).
|
|
201
|
+
* - Ignores currency symbols like `Rp`, `$` (must re-apply with `suffixCurrency`).
|
|
202
|
+
*
|
|
203
|
+
* ✅ Options:
|
|
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
|
+
*
|
|
210
|
+
* @param {FormatCurrencyOptions} [options] Optional configuration object.
|
|
211
|
+
*
|
|
212
|
+
* @param {string} [options.separator] Thousands separator:
|
|
213
|
+
* - `{ separator: "." }` ➔ `1.000.000`.
|
|
214
|
+
* - ***DefaultValue: `"."`***.
|
|
215
|
+
*
|
|
216
|
+
* @param {string} [options.separatorDecimals] Decimal separator:
|
|
217
|
+
* - `{ separatorDecimals: "," }` ➔ `1.000,10`.
|
|
218
|
+
* - ***DefaultValue: `","`***.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} [options.suffixCurrency] Prefix currency string:
|
|
221
|
+
* - Does **not auto-keep input symbols**.
|
|
222
|
+
* - Must set manually e.g: `{ suffixCurrency: "Rp " }`.
|
|
223
|
+
* - `{ suffixCurrency: "Rp " }` ➔ `Rp 1.000`.
|
|
224
|
+
* - ***DefaultValue: `""`***.
|
|
225
|
+
*
|
|
226
|
+
* @param {boolean} [options.decimal] Show decimals:
|
|
227
|
+
* - If `false`, rounds to integer.
|
|
228
|
+
* - ***DefaultValue: `false`***.
|
|
229
|
+
*
|
|
230
|
+
* @param {number} [options.totalDecimal] Total decimal digits:
|
|
231
|
+
* - If `decimal: true` & `roundedDecimal: false`, simply cuts.
|
|
232
|
+
* - ***DefaultValue: `2`***.
|
|
233
|
+
*
|
|
234
|
+
* @param {string} [options.suffixDecimal] Text appended after decimals:
|
|
235
|
+
* - E.g: (`".-"`, `" USD"`).
|
|
236
|
+
* - Example 1: `".-"` ➔ `1.000,00.-`.
|
|
237
|
+
* - Example 2: `" USD"` ➔ `1.000,00 USD`.
|
|
238
|
+
* - ***DefaultValue: `""`***.
|
|
239
|
+
*
|
|
240
|
+
* @param {boolean} [options.endDecimal] Actually append `suffixDecimal`:
|
|
241
|
+
* - ***DefaultValue: `true`***.
|
|
242
|
+
*
|
|
243
|
+
* @param {"round"|"ceil"|"floor"|false} [options.roundedDecimal] Rounding mode:
|
|
244
|
+
* - `"round"` ➔ nearest
|
|
245
|
+
* - `"ceil"` ➔ always up
|
|
246
|
+
* - `"floor"` ➔ always down
|
|
247
|
+
* - `false` ➔ truncate
|
|
248
|
+
* - ***DefaultValue: `"round"`***.
|
|
249
|
+
*
|
|
250
|
+
* @param {"dash"|"brackets"|"abs"|{style?, space?, custom?}} [options.negativeFormat] How to format negatives:
|
|
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
|
+
* }`.
|
|
260
|
+
* - ***DefaultValue: `"dash"`.***
|
|
261
|
+
*
|
|
262
|
+
* @param {boolean} [options.indianFormat] Applies Indian Format:
|
|
263
|
+
* - If `true`, formats as Indian: `12,34,567`.
|
|
264
|
+
* - Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
265
|
+
*
|
|
266
|
+
* @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
|
+
*
|
|
272
|
+
* @throws {TypeError} Will throw TypeError If:
|
|
273
|
+
* - `value` is not string or number
|
|
274
|
+
* - cannot parse to valid number
|
|
275
|
+
* - options have invalid types
|
|
276
|
+
*
|
|
277
|
+
* ---
|
|
278
|
+
*
|
|
279
|
+
* ***✅ Notes:***
|
|
280
|
+
* - Always re-apply symbols via `suffixCurrency`.
|
|
281
|
+
* - `parseCurrencyString` smartly detects last decimal,
|
|
282
|
+
* so `"1.121.234,56"` and `"1,121,234.56"` both parsed correctly.
|
|
283
|
+
*/
|
|
284
|
+
declare const formatCurrency:(value:string|number,options?:FormatCurrencyOptions)=>string;
|
|
285
|
+
/** ----------------------------------------------------------
|
|
286
|
+
* * ***Formats a number or numeric string by adding a custom separator
|
|
287
|
+
* every three digits (thousands separator), and intelligently
|
|
288
|
+
* flips the decimal separator according to the chosen separator.***
|
|
289
|
+
* ----------------------------------------------------------
|
|
290
|
+
*
|
|
291
|
+
* - Converts a number to string before formatting.
|
|
292
|
+
* - Defaults to using `,` as the thousands separator.
|
|
293
|
+
* - If `.` is used as the separator, the decimal will automatically become `,`, and vice versa.
|
|
294
|
+
* - Handles input with existing formatting (e.g. "1,234,567.89") and normalizes it.
|
|
295
|
+
* - Supports custom separators, including spaces.
|
|
296
|
+
* - Preserves decimals even if more than 2 digits.
|
|
297
|
+
*
|
|
298
|
+
* @param {string | number} value - The numeric value or string to format.
|
|
299
|
+
* Can be plain numbers, or already formatted strings like "1,234,567.89".
|
|
300
|
+
* @param {string} [separator=","] - The thousands separator to use.
|
|
301
|
+
* Examples: "," (default), ".", " ", etc.
|
|
302
|
+
*
|
|
303
|
+
* @returns {string} The formatted string with thousands separators and
|
|
304
|
+
* appropriate decimal separator.
|
|
305
|
+
*
|
|
306
|
+
* @throws {TypeError} If `value` is not a string or number,
|
|
307
|
+
* or `separator` is not a string.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* formatNumber(1000000);
|
|
311
|
+
* // → "1,000,000"
|
|
312
|
+
*
|
|
313
|
+
* formatNumber("987654321");
|
|
314
|
+
* // → "987,654,321"
|
|
315
|
+
*
|
|
316
|
+
* formatNumber(1234567.89);
|
|
317
|
+
* // → "1,234,567.89"
|
|
318
|
+
*
|
|
319
|
+
* formatNumber("1234567,89");
|
|
320
|
+
* // → "1,234,567.89"
|
|
321
|
+
*
|
|
322
|
+
* formatNumber("1234567.892");
|
|
323
|
+
* // → "1,234,567.892"
|
|
324
|
+
*
|
|
325
|
+
* formatNumber("1234567.89", ".");
|
|
326
|
+
* // → "1.234.567,89"
|
|
327
|
+
*
|
|
328
|
+
* formatNumber("1234567,89", ",");
|
|
329
|
+
* // → "1,234,567.89"
|
|
330
|
+
*
|
|
331
|
+
* formatNumber("987654321", " ");
|
|
332
|
+
* // → "987 654 321"
|
|
333
|
+
*
|
|
334
|
+
* formatNumber("1,234,567.89");
|
|
335
|
+
* // → "1,234,567.89"
|
|
336
|
+
*
|
|
337
|
+
* formatNumber("1.234.567,89", ",");
|
|
338
|
+
* // → "1,234,567.89"
|
|
339
|
+
*
|
|
340
|
+
* formatNumber("1.234.567,893", ".");
|
|
341
|
+
* // → "1.234.567,893"
|
|
342
|
+
*
|
|
343
|
+
* formatNumber("1234.56", ".");
|
|
344
|
+
* // → "1.234,56"
|
|
345
|
+
*
|
|
346
|
+
* formatNumber("1234,56", ",");
|
|
347
|
+
* // → "1,234.56"
|
|
348
|
+
*
|
|
349
|
+
*/
|
|
350
|
+
declare const formatNumber:(value:string|number,separator?:string)=>string;
|
|
351
|
+
/** -------------------------------------------------------
|
|
352
|
+
* * ***Formats a phone number into a customizable local or international style.***
|
|
353
|
+
* -------------------------------------------------------
|
|
354
|
+
*
|
|
355
|
+
* Can also:
|
|
356
|
+
* - Return only digits (`takeNumberOnly`).
|
|
357
|
+
* - Check validity (`checkValidOnly`) using a regex for international-style phone numbers.
|
|
358
|
+
*
|
|
359
|
+
* Validation (`checkValidOnly: true`)
|
|
360
|
+
* Valid if:
|
|
361
|
+
* - Only contains digits, optional leading `+`, spaces, parentheses `()`, hyphens `-`, or dots `.`.
|
|
362
|
+
* - Digits-only length < 24.
|
|
363
|
+
*
|
|
364
|
+
* Example:
|
|
365
|
+
* ```js
|
|
366
|
+
* formatPhoneNumber("081234567890")
|
|
367
|
+
* // => "0812 3456 7890"
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* Example:
|
|
371
|
+
* ```js
|
|
372
|
+
* formatPhoneNumber("(0812) 3456-7890", { takeNumberOnly: true })
|
|
373
|
+
* // => "081234567890"
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* Example:
|
|
377
|
+
* ```js
|
|
378
|
+
* formatPhoneNumber("(0812) 3456-7890", { checkValidOnly: true })
|
|
379
|
+
* // => true
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* Example:
|
|
383
|
+
* ```js
|
|
384
|
+
* formatPhoneNumber("+6281234567890", { checkValidOnly: true })
|
|
385
|
+
* // => true
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* Example:
|
|
389
|
+
* ```js
|
|
390
|
+
* formatPhoneNumber("+1 (800) 123-4567", { checkValidOnly: true })
|
|
391
|
+
* // => true
|
|
392
|
+
* formatPhoneNumber("+44 20 7946 0958", { checkValidOnly: true })
|
|
393
|
+
* // => true
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* Example:
|
|
397
|
+
* ```js
|
|
398
|
+
* formatPhoneNumber("0812-3456-7890", { checkValidOnly: true })
|
|
399
|
+
* // => true
|
|
400
|
+
* formatPhoneNumber("(0812) 3456 7890", { checkValidOnly: true })
|
|
401
|
+
* // => true
|
|
402
|
+
* formatPhoneNumber("0812 3456 7890", { checkValidOnly: true })
|
|
403
|
+
* // => true
|
|
404
|
+
* ```
|
|
405
|
+
*
|
|
406
|
+
* Example:
|
|
407
|
+
* ```js
|
|
408
|
+
* formatPhoneNumber("+62abc123", { checkValidOnly: true })
|
|
409
|
+
* // => false
|
|
410
|
+
* formatPhoneNumber("0812-3456-hello", { checkValidOnly: true })
|
|
411
|
+
* // => false
|
|
412
|
+
* formatPhoneNumber("+62 123456789012345678901234", { checkValidOnly: true })
|
|
413
|
+
* // => false
|
|
414
|
+
* formatPhoneNumber("++6281234567890", { checkValidOnly: true })
|
|
415
|
+
* // => false
|
|
416
|
+
* formatPhoneNumber("invalid@@@", { checkValidOnly: true })
|
|
417
|
+
* // => false
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* Example:
|
|
421
|
+
* ```js
|
|
422
|
+
* formatPhoneNumber("+62.812.3456.7890", { checkValidOnly: true })
|
|
423
|
+
* // => true
|
|
424
|
+
* formatPhoneNumber("+62(812)3456-7890", { checkValidOnly: true })
|
|
425
|
+
* // => true
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* Example:
|
|
429
|
+
* ```js
|
|
430
|
+
* formatPhoneNumber("081234567890", {
|
|
431
|
+
* separator: "-",
|
|
432
|
+
* plusNumberCountry: "+44",
|
|
433
|
+
* openingNumberCountry: "(",
|
|
434
|
+
* closingNumberCountry: ")",
|
|
435
|
+
* })
|
|
436
|
+
* // => "(+44) 8123-4567-890"
|
|
437
|
+
* ```
|
|
438
|
+
*
|
|
439
|
+
* @throws {TypeError} If `value` is not string, number, null or undefined.
|
|
440
|
+
* @throws {TypeError} If `options` is not an object or contains wrong types.
|
|
441
|
+
*
|
|
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.
|
|
446
|
+
*
|
|
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.
|
|
451
|
+
*
|
|
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.
|
|
456
|
+
*/
|
|
457
|
+
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
|
+
* -------------------------------------------------------------
|
|
460
|
+
* * ***Supported IETF BCP-47 locale codes for Intl API.***
|
|
461
|
+
* -------------------------------------------------------------
|
|
462
|
+
*
|
|
463
|
+
* Includes:
|
|
464
|
+
* - Major global locales (en-US, fr-FR, zh-CN, etc)
|
|
465
|
+
* - Regional & minor locales (mi-NZ, rw-RW, bi-VU, etc)
|
|
466
|
+
* - Useful for `Intl.DateTimeFormat`, `Intl.NumberFormat`, etc.
|
|
467
|
+
* - Still allows fallback via `({} & string)` for arbitrary locales.
|
|
468
|
+
*
|
|
469
|
+
* This type ensures proper autocompletion & validation in TS
|
|
470
|
+
* but does not restrict at runtime (must validate separately).
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* const locale: SupportedLocales = "fr-CA";
|
|
474
|
+
* new Intl.DateTimeFormat(locale).format(new Date());
|
|
475
|
+
*/
|
|
476
|
+
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
|
+
* * ***Formats a date and time into a custom string format.***
|
|
479
|
+
* ----------------------------------------------------------
|
|
480
|
+
*
|
|
481
|
+
* - Supports only `YYYY`, `MM`, `DD`, `hh`, `mm`, and `ss` as placeholders.
|
|
482
|
+
* - Uses a simple string replace (no locale).
|
|
483
|
+
* - Returns `null` if the date is invalid or not provided.
|
|
484
|
+
* - Defaults to `"YYYY-MM-DD hh:mm:ss"` format if none is specified.
|
|
485
|
+
*
|
|
486
|
+
* @param {string | Date | null} [date] - The date to format.
|
|
487
|
+
* @param {string} [format="YYYY-MM-DD hh:mm:ss"] - The desired date format.
|
|
488
|
+
* @returns {string | null} The formatted date string or `null` if invalid.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* formatDateTime(new Date());
|
|
492
|
+
* // => "2024-02-09 14:30:45" (example output with current time)
|
|
493
|
+
*
|
|
494
|
+
* formatDateTime("2023-07-01T14:30:45");
|
|
495
|
+
* // => "2023-07-01 14:30:45"
|
|
496
|
+
*
|
|
497
|
+
* formatDateTime("2023-07-01T14:30:45", "DD/MM/YYYY");
|
|
498
|
+
* // => "01/07/2023"
|
|
499
|
+
*
|
|
500
|
+
* formatDateTime("2023-07-01T14:30:45", "YYYY/MM/DD hh-mm-ss");
|
|
501
|
+
* // => "2023/07/01 14-30-45"
|
|
502
|
+
*
|
|
503
|
+
* formatDateTime("2023-07-01T14:30:45", "hh:mm");
|
|
504
|
+
* // => "14:30"
|
|
505
|
+
*
|
|
506
|
+
* formatDateTime("2023-07-01T14:30:45", "DATE: YYYY.MM.DD");
|
|
507
|
+
* // => "DATE: 2023.07.01"
|
|
508
|
+
*
|
|
509
|
+
* formatDateTime("2023-07-01T14:30:45", "Year: YYYY, Time: hh:mm:ss");
|
|
510
|
+
* // => "Year: 2023, Time: 14:30:45"
|
|
511
|
+
*
|
|
512
|
+
* formatDateTime("2023-07-01T14:30:45", "YYYY-MM");
|
|
513
|
+
* // => "2023-07"
|
|
514
|
+
*
|
|
515
|
+
* formatDateTime("2023-07-01T14:30:45", "YYYYYYYY");
|
|
516
|
+
* // => "20232023"
|
|
517
|
+
*
|
|
518
|
+
* formatDateTime("2023-07-01T14:30:45", "hh:mm:ss:ss");
|
|
519
|
+
* // => "14:30:45:45"
|
|
520
|
+
*
|
|
521
|
+
* formatDateTime("invalid-date");
|
|
522
|
+
* // => null
|
|
523
|
+
*
|
|
524
|
+
* formatDateTime(null);
|
|
525
|
+
* // => null
|
|
526
|
+
*
|
|
527
|
+
* formatDateTime(undefined);
|
|
528
|
+
* // => null
|
|
529
|
+
*/
|
|
530
|
+
declare const formatDateTime:(date?:string|Date|null,
|
|
531
|
+
/** @default "YYYY-MM-DD hh:mm:ss" */
|
|
532
|
+
format?:string)=>string|null;
|
|
533
|
+
/** ----------------------------------------------------------
|
|
534
|
+
* * ***Formats a date using the `Intl.DateTimeFormat` API.***
|
|
535
|
+
* ----------------------------------------------------------
|
|
536
|
+
*
|
|
537
|
+
* - Supports custom locales (type-safe `SupportedLocales`).
|
|
538
|
+
* - Accepts additional `Intl.DateTimeFormatOptions` like `timeZone`, `hour12`, etc.
|
|
539
|
+
* - Defaults to `"en-US"` if `locale` is not provided or is an empty string.
|
|
540
|
+
* - Returns `null` if the date is invalid, not provided, or options are invalid.
|
|
541
|
+
*
|
|
542
|
+
* @param {string | Date | null | undefined} [date] - The date to format.
|
|
543
|
+
* Can be a `Date` object or an ISO string. If invalid or not provided, returns `null`.
|
|
544
|
+
*
|
|
545
|
+
* @param {Intl.DateTimeFormatOptions & { locale?: SupportedLocales | SupportedLocales[] }} [options]
|
|
546
|
+
* - Optional formatting options for `Intl.DateTimeFormat`.
|
|
547
|
+
* - Use `locale` to specify the language & region format.
|
|
548
|
+
*
|
|
549
|
+
* @returns {string | null}
|
|
550
|
+
* - Formatted date string.
|
|
551
|
+
* - Returns `null` if date is invalid or options are of wrong type.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* formatDateIntl(new Date());
|
|
555
|
+
* // => "7/14/2025"
|
|
556
|
+
*
|
|
557
|
+
* formatDateIntl("2025-07-14T00:00:00Z", { locale: "fr-FR", dateStyle: "long" });
|
|
558
|
+
* // => "14 juillet 2025"
|
|
559
|
+
*
|
|
560
|
+
* formatDateIntl(null);
|
|
561
|
+
* // => null
|
|
562
|
+
*
|
|
563
|
+
* formatDateIntl(new Date(), { timeZone: "UTC", hour: "2-digit", minute: "2-digit" });
|
|
564
|
+
* // => "01:30 AM"
|
|
565
|
+
*/
|
|
566
|
+
declare const formatDateIntl:(date?:string|Date|null,options?:Intl.DateTimeFormatOptions &{locale?:SupportedLocales|SupportedLocales[];})=>string|null;
|
|
567
|
+
/** ----------------------------------------------------------
|
|
568
|
+
* * ***Formats a date into a human-readable string using `date-fns`.***
|
|
569
|
+
* ----------------------------------------------------------
|
|
570
|
+
*
|
|
571
|
+
* - Supports custom output formats using `date-fns/format`.
|
|
572
|
+
* - Can parse localized non-ISO strings via `inputFormat` & `inputLocale`.
|
|
573
|
+
* - Supports `locale` as `"id"`, `"en"` or `date-fns` `Locale` objects (like `id` or `enUS`).
|
|
574
|
+
* - Returns `null` if the date is invalid, not provided, or parsing fails.
|
|
575
|
+
*
|
|
576
|
+
* @param {string | Date | null} [date] - The date input to format. Can be:
|
|
577
|
+
* - A `Date` object
|
|
578
|
+
* - An ISO string (e.g. `"2024-01-01T12:00:00Z"`)
|
|
579
|
+
* - A localized string (requires `inputFormat` + `inputLocale`)
|
|
580
|
+
*
|
|
581
|
+
* @param {object} [options] - Options for formatting and parsing.
|
|
582
|
+
*
|
|
583
|
+
* @param {string} [options.format="dd MMM yyyy - HH:mm:ss"]
|
|
584
|
+
* The output format string (passed to `date-fns/format`).
|
|
585
|
+
* E.g. `"dd MMMM yyyy, HH:mm:ss" => "14 Juli 2025, 17:25:42"`
|
|
586
|
+
*
|
|
587
|
+
* @param {"id" | "en" | (string & {}) | Locale} [options.locale="id"]
|
|
588
|
+
* The output locale. If string, only `"id"` (Indonesian) or `"en"` (English)
|
|
589
|
+
* is recognized. Or you can pass a `date-fns` `Locale` object.
|
|
590
|
+
* Example:
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { ar } from "date-fns/locale";
|
|
593
|
+
* formatDateFns(new Date(), { locale: ar, format: "PPPppp" });
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @param {"id" | "en" | (string & {}) | Locale} [options.inputLocale]
|
|
597
|
+
* Required if `date` is a localized non-ISO string. Used with `inputFormat`.
|
|
598
|
+
* Example for Indonesian string:
|
|
599
|
+
* ```ts
|
|
600
|
+
* formatDateFns("14 Juli 2025 10:25:42", {
|
|
601
|
+
* inputFormat: "dd MMMM yyyy HH:mm:ss",
|
|
602
|
+
* inputLocale: "id",
|
|
603
|
+
* });
|
|
604
|
+
* ```
|
|
605
|
+
*
|
|
606
|
+
* @param {string} [options.inputFormat]
|
|
607
|
+
* The format string to parse `date` if it is a non-ISO string.
|
|
608
|
+
* Required together with `inputLocale`.
|
|
609
|
+
*
|
|
610
|
+
* @returns {string | null} A formatted date string or `null` if input is invalid.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* formatDateFns(new Date());
|
|
614
|
+
* // "14 Jul 2025 - 17:25:42"
|
|
615
|
+
*
|
|
616
|
+
* formatDateFns("2025-07-14T10:25:42Z", { format: "dd/MM/yyyy", locale: "en" });
|
|
617
|
+
* // "14/07/2025"
|
|
618
|
+
*
|
|
619
|
+
* formatDateFns("14 Juli 2025 10:25:42", {
|
|
620
|
+
* inputFormat: "dd MMMM yyyy HH:mm:ss",
|
|
621
|
+
* inputLocale: "id",
|
|
622
|
+
* format: "yyyy-MM-dd"
|
|
623
|
+
* });
|
|
624
|
+
* // "2025-07-14"
|
|
625
|
+
*
|
|
626
|
+
* 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"
|
|
658
|
+
*/
|
|
659
|
+
locale?:"id"|"en"|(string &{})|Locale;
|
|
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;
|
|
689
|
+
/** ----------------------------------------------------------
|
|
690
|
+
* * ***Returns the formatted GMT offset (e.g., `+0700`, `-0500`) for a given date.***
|
|
691
|
+
* ----------------------------------------------------------
|
|
692
|
+
*
|
|
693
|
+
* - If `date` is **not provided** or empty string, it defaults to the current date/time.
|
|
694
|
+
* - If `date` is **invalid** or of wrong type (like object or number), it returns `"0"`.
|
|
695
|
+
* - The returned string follows the **GMT offset format** (`±HHMM`), where:
|
|
696
|
+
* - `±` is `+` if ahead of UTC, `-` if behind.
|
|
697
|
+
* - `HH` is two-digit hours.
|
|
698
|
+
* - `MM` is two-digit minutes.
|
|
699
|
+
*
|
|
700
|
+
* @param {string | Date | null} [date] - The date to get the GMT offset from.
|
|
701
|
+
* - Accepts `Date` object or ISO date string (e.g., `"2024-01-01T12:00:00Z"`).
|
|
702
|
+
* - If `null`, `undefined`, or empty string, uses current system date.
|
|
703
|
+
* - If invalid date or wrong type (like `123` or `{}`), returns `"0"`.
|
|
704
|
+
*
|
|
705
|
+
* @returns {string} The GMT offset string in format `±HHMM`,
|
|
706
|
+
* e.g. `"+0700"`, `"-0530"`, or `"0"` if invalid.
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* getGMTOffset();
|
|
710
|
+
* // => "+0700" (depends on system timezone)
|
|
711
|
+
*
|
|
712
|
+
* getGMTOffset(new Date("2024-02-09T12:00:00Z"));
|
|
713
|
+
* // => "+0000"
|
|
714
|
+
*
|
|
715
|
+
* getGMTOffset("2024-02-09");
|
|
716
|
+
* // => "+0700" (depends on your timezone)
|
|
717
|
+
*
|
|
718
|
+
* getGMTOffset("invalid-date");
|
|
719
|
+
* // => "0"
|
|
720
|
+
*
|
|
721
|
+
* getGMTOffset(123);
|
|
722
|
+
* // => "0"
|
|
723
|
+
*/
|
|
724
|
+
declare const getGMTOffset:(date?:string|Date|null)=>string;type CensorEmailOptions={
|
|
725
|
+
/** ----------------------------------------------------------
|
|
726
|
+
* * ***Censorship Mode.***
|
|
727
|
+
* ----------------------------------------------------------
|
|
728
|
+
*
|
|
729
|
+
* **Valid value:**
|
|
730
|
+
* - `"fixed"` (default) – Deterministic censorship based on a hash of the email.
|
|
731
|
+
* The same input always produces the same output.
|
|
732
|
+
* - `"random"` – Each character is randomly replaced every time the function is called.
|
|
733
|
+
*/
|
|
734
|
+
mode?:"random"|"fixed";};
|
|
735
|
+
/** ----------------------------------------------------------
|
|
736
|
+
* * ***Censors an email by replacing characters with "\*" while supporting random or fixed mode.***
|
|
737
|
+
* ----------------------------------------------------------
|
|
738
|
+
*
|
|
739
|
+
* This function replaces parts of an email with asterisks to protect privacy.
|
|
740
|
+
*
|
|
741
|
+
* **Modes:**
|
|
742
|
+
* - `"fixed"` (default) – Deterministic censorship based on a hash of the email. Same input always produces the same output.
|
|
743
|
+
* - `"random"` – Each character is randomly replaced every time the function is called.
|
|
744
|
+
*
|
|
745
|
+
* Invalid emails or non-string input will return an empty string.
|
|
746
|
+
*
|
|
747
|
+
* @param {string | null | undefined} [email] - The email address to censor.
|
|
748
|
+
* @param {CensorEmailOptions} [options={}] - Options object for mode.
|
|
749
|
+
*
|
|
750
|
+
* @returns {string} The censored email, or an empty string if input is invalid.
|
|
751
|
+
*
|
|
752
|
+
* @throws {TypeError} If `options` is not a plain object or `mode` is invalid.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* // Fixed mode (default, deterministic)
|
|
756
|
+
* censorEmail("john.doe@gmail.com");
|
|
757
|
+
* // ➔ "j**n.**e@g***l.com"
|
|
758
|
+
*
|
|
759
|
+
* // Fixed mode explicitly
|
|
760
|
+
* censorEmail("john.doe@gmail.com", { mode: "fixed" });
|
|
761
|
+
* // ➔ "j**n.**e@g***l.com"
|
|
762
|
+
*
|
|
763
|
+
* // Random mode (output may vary each time)
|
|
764
|
+
* censorEmail("john.doe@gmail.com", { mode: "random" });
|
|
765
|
+
* // ➔ "j*hn.***e@g***l.com" (random)
|
|
766
|
+
*
|
|
767
|
+
* // Invalid email returns empty string
|
|
768
|
+
* censorEmail("invalid-email");
|
|
769
|
+
* // ➔ ""
|
|
770
|
+
*/
|
|
771
|
+
declare const censorEmail:(email?:string|null,options?:CensorEmailOptions)=>string;type ChunkStringOptions={
|
|
772
|
+
/**
|
|
773
|
+
* The separator string to insert between characters or words.
|
|
774
|
+
*
|
|
775
|
+
* - Used when inserting separators every `limiter` characters.
|
|
776
|
+
* - Default is a single space `" "`.
|
|
777
|
+
*
|
|
778
|
+
* @default " "
|
|
779
|
+
*/
|
|
780
|
+
separator?:string;
|
|
781
|
+
/**
|
|
782
|
+
* Determines whether counting for `limiter` resets after each space.
|
|
783
|
+
*
|
|
784
|
+
* - If `true`, the string is treated as words separated by spaces,
|
|
785
|
+
* and separators are applied within words, then words are grouped.
|
|
786
|
+
* - If `false`, counting is continuous across the whole string,
|
|
787
|
+
* treating spaces as normal characters.
|
|
788
|
+
*
|
|
789
|
+
* @default false
|
|
790
|
+
*/
|
|
791
|
+
reCountAfterSpace?:boolean;};
|
|
792
|
+
/** ----------------------------------------------
|
|
793
|
+
* * ***Chunks a string by inserting a separator every `limiter` characters.***
|
|
794
|
+
* ----------------------------------------------
|
|
795
|
+
*
|
|
796
|
+
* This function handles two main behaviors based on `reCountAfterSpace`:
|
|
797
|
+
*
|
|
798
|
+
* 1. If `reCountAfterSpace` is `false` (default):
|
|
799
|
+
* The separator is inserted strictly every `limiter` characters throughout the entire string,
|
|
800
|
+
* regardless of spaces. Spaces are treated as regular characters in the count.
|
|
801
|
+
* Example: `chunkString("1234567890", 3, "-")` returns `"123-456-789-0"`.
|
|
802
|
+
* Example: `chunkString("Hello World", 3, "-")` returns `"Hel-lo -Wor-ld"`.
|
|
803
|
+
*
|
|
804
|
+
* 2. If `reCountAfterSpace` is `true`:
|
|
805
|
+
* The function first processes the input string to replace any multiple consecutive spaces
|
|
806
|
+
* with a single space (e.g., "A B" becomes "A B").
|
|
807
|
+
* Then, it treats the string as a sequence of "words" (segments separated by single spaces).
|
|
808
|
+
* - Each word is processed independently: if a word's length exceeds the `limiter`,
|
|
809
|
+
* separators are inserted internally within that word.
|
|
810
|
+
* - Words are then grouped. Each group will contain `limiter` number of words.
|
|
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
|
+
*
|
|
815
|
+
* @param {string} subject - The target string to chunk.
|
|
816
|
+
* @param {number} limiter - The interval (number of characters) for inserting separators.
|
|
817
|
+
* - If `reCountAfterSpace = false`, it counts characters.
|
|
818
|
+
* - If `reCountAfterSpace = true`, it counts both characters within words and words per group.
|
|
819
|
+
* @param {ChunkStringOptions} [options={}] - Optional settings for separator and counting behavior.
|
|
820
|
+
* @returns {string} - The formatted string with separators.
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* // Basic usage
|
|
824
|
+
* chunkString("1234567890", 3);
|
|
825
|
+
* // ➔ "123 456 789 0"
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* // Basic usage `reCountAfterSpace = false` (default)
|
|
829
|
+
* chunkString("1234567890", 3, { separator: "-");
|
|
830
|
+
* // ➔ "123-456-789-0"
|
|
831
|
+
* chunkString("HelloWorld", 2, { separator: "_", reCountAfterSpace: false });
|
|
832
|
+
* // ➔ "He_ll_oW_or_ld"
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* // Usage with reCountAfterSpace = true:
|
|
836
|
+
* // Multiple spaces are normalized to single spaces before processing.
|
|
837
|
+
* chunkString("AB CD EF GH", 2, { separator: "-", reCountAfterSpace: true });
|
|
838
|
+
* // ➔ "AB-CD EF-GH" (after normalization to "AB CD EF GH")
|
|
839
|
+
* // Words "AB" and "CD" form a group and are joined by "-", "EF" and "GH" form another group.
|
|
840
|
+
* // The groups "AB-CD" and "EF-GH" are then joined by a space.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* // Another usage with reCountAfterSpace = true:
|
|
844
|
+
* chunkString("ABC DEF GHI JKL", 3, { separator: "-", reCountAfterSpace: true });
|
|
845
|
+
* // ➔ "ABC-DEF-GHI JKL"
|
|
846
|
+
* // Words "ABC", "DEF", "GHI" form a group and are joined by "-".
|
|
847
|
+
* // The word "JKL" forms its own group (as it's the last word and completes no other group).
|
|
848
|
+
* // The groups "ABC-DEF-GHI" and "JKL" are then joined by a space.
|
|
849
|
+
*/
|
|
850
|
+
declare function chunkString(subject:string,limiter:number,options?:ChunkStringOptions):string;type TruncateStringOptions={
|
|
851
|
+
/** **Maximum length of the truncated string **(default: `10`)**.**
|
|
852
|
+
*
|
|
853
|
+
* @default 10
|
|
854
|
+
*/
|
|
855
|
+
length?:number;
|
|
856
|
+
/** **String to append if truncation occurs.**
|
|
857
|
+
*
|
|
858
|
+
* - Will be trimmed first; defaults to `"..."` if empty.
|
|
859
|
+
*
|
|
860
|
+
* @default "..."
|
|
861
|
+
*/
|
|
862
|
+
ending?:string;
|
|
863
|
+
/** **Whether to trim the input string before truncation ***(default: `true`)***.**
|
|
864
|
+
*
|
|
865
|
+
* @default true
|
|
866
|
+
*/
|
|
867
|
+
trim?:boolean;};
|
|
868
|
+
/** ----------------------------------------------------------
|
|
869
|
+
* * ***Truncates a string to a specified length and optionally appends an ending.***
|
|
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 `"..."`.***
|
|
873
|
+
* ----------------------------------------------------------
|
|
874
|
+
*
|
|
875
|
+
* @param {string|null|undefined} text - The input string to truncate.
|
|
876
|
+
* If `null`, `undefined`, or empty after trim, returns `""`.
|
|
877
|
+
* @param {TruncateStringOptions} [options] - Optional settings:
|
|
878
|
+
* - `length` (number, default 10): Maximum length of the truncated string.
|
|
879
|
+
* - `ending` (string, default `"..."`): String to append if truncation occurs.
|
|
880
|
+
* - `trim` (boolean, default true): Whether to trim the input before truncation.
|
|
881
|
+
*
|
|
882
|
+
* @returns {string} The truncated string with optional trimming and ending.
|
|
883
|
+
* Returns `""` if input is empty or length < 1.
|
|
884
|
+
*
|
|
885
|
+
* @throws {TypeError} If `options.length` is not a finite number,
|
|
886
|
+
* or if `options.ending` is not a string,
|
|
887
|
+
* or if `options.trim` is not a boolean.
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* truncateString("hello world", { length: 5 });
|
|
891
|
+
* // ➔ "hello..."
|
|
892
|
+
*
|
|
893
|
+
* truncateString("hello world", { length: 5, ending: "---" });
|
|
894
|
+
* // ➔ "hello---"
|
|
895
|
+
*
|
|
896
|
+
* truncateString("hello world", { length: 5, ending: " " });
|
|
897
|
+
* // ➔ "hello..." (ending trimmed to default)
|
|
898
|
+
*
|
|
899
|
+
* truncateString("hello world", { length: 5, ending: " !!! " });
|
|
900
|
+
* // ➔ "hello!!!" (ending trimmed)
|
|
901
|
+
*
|
|
902
|
+
* truncateString(" long data string ", { length: 8, ending: "...", trim: true });
|
|
903
|
+
* // ➔ "long dat..."
|
|
904
|
+
*
|
|
905
|
+
* truncateString(" long data string ", { length: 8, ending: "...", trim: false });
|
|
906
|
+
* // ➔ " long ..."
|
|
907
|
+
*
|
|
908
|
+
* truncateString(null, { length: 5 });
|
|
909
|
+
* // ➔ ""
|
|
910
|
+
*
|
|
911
|
+
*/
|
|
912
|
+
declare const truncateString:(text?:string|null,options?:TruncateStringOptions)=>string;export{censorEmail,chunkString,formatCurrency,formatDateFns,formatDateIntl,formatDateTime,formatNumber,formatPhoneNumber,getGMTOffset,truncateString};
|