@rzl-zone/utils-js 3.2.6-beta.0 → 3.3.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/README.md +14 -16
- package/dist/NumberRangeUnion-B6bhM2s7.d.ts +33 -0
- package/dist/{any-BmdI8UbK.d.ts → any-v4TsK9ES.d.ts} +25 -26
- package/dist/{arrays-normalize-recursive-CnjYJ9xg.d.ts → arrays-normalize-recursive-BqmVuFlD.d.ts} +20 -20
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +96 -70
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-2CQX5CBG.js +1 -0
- package/dist/chunk-2IOOEY45.cjs +1 -0
- package/dist/chunk-3IBQ5MOM.js +1 -0
- package/dist/{chunk-OGPPP2S3.js → chunk-3VA554KW.js} +1 -1
- package/dist/{chunk-FV7SEBKD.cjs → chunk-5757UBXJ.cjs} +1 -1
- package/dist/{chunk-MTUBDVJ2.js → chunk-5IGC6PBH.js} +1 -1
- package/dist/{chunk-O7UT5AN3.cjs → chunk-5KJFVIQT.cjs} +1 -1
- package/dist/chunk-6JFCSH7J.js +1 -0
- package/dist/{chunk-VHAPTHEA.cjs → chunk-6JFZL7YE.cjs} +1 -1
- package/dist/chunk-7ODAAXX5.cjs +1 -0
- package/dist/{chunk-6C3ATUGM.cjs → chunk-CAH33WOQ.cjs} +1 -1
- package/dist/{chunk-ECRNH4FW.js → chunk-CKTLUNWX.js} +1 -1
- package/dist/chunk-CMW2TBOQ.js +1 -0
- package/dist/chunk-D3ENH7H6.cjs +1 -0
- package/dist/{chunk-3YCFMGRB.js → chunk-DEZZUYE2.js} +1 -1
- package/dist/chunk-DWF2R5GD.cjs +1 -0
- package/dist/chunk-E55EQK2U.cjs +1 -0
- package/dist/chunk-E74U6CYP.cjs +1 -0
- package/dist/{chunk-XC3QHAK2.cjs → chunk-EL6A35UR.cjs} +1 -1
- package/dist/chunk-F6IPNNSJ.cjs +1 -0
- package/dist/chunk-FJZGG54N.cjs +1 -0
- package/dist/chunk-FWCKOJZM.js +1 -0
- package/dist/{chunk-IMCLPT5V.cjs → chunk-FWHNWL2P.cjs} +1 -1
- package/dist/chunk-GGEADHZO.js +1 -0
- package/dist/{chunk-IRGE5W7L.js → chunk-GQR4R5WY.js} +1 -1
- package/dist/chunk-H66AC7GK.cjs +1 -0
- package/dist/{chunk-M47QIBXI.cjs → chunk-HQWOFR56.cjs} +1 -1
- package/dist/{chunk-VCFXNV3Q.cjs → chunk-HYRQMTRH.cjs} +1 -1
- package/dist/{chunk-EUANTHVN.js → chunk-IRFL4MAX.js} +1 -1
- package/dist/{chunk-GGWPB23G.cjs → chunk-IVL7CKVH.cjs} +1 -1
- package/dist/chunk-IZPBKKPO.js +1 -0
- package/dist/chunk-JBQMXC5I.cjs +1 -0
- package/dist/chunk-JEQEF5WD.js +1 -0
- package/dist/chunk-JMJQCN74.js +1 -0
- package/dist/chunk-JYQTCICM.js +1 -0
- package/dist/chunk-KVAL5PAG.cjs +1 -0
- package/dist/chunk-LS6U7FAY.cjs +1 -0
- package/dist/chunk-NBZWMBO6.js +1 -0
- package/dist/chunk-NRF6LWBC.cjs +1 -0
- package/dist/chunk-OI5XKNZO.js +1 -0
- package/dist/chunk-OYTYSY7G.js +1 -0
- package/dist/chunk-PET42Z7W.js +1 -0
- package/dist/chunk-PZQ6I4JJ.cjs +1 -0
- package/dist/chunk-QBKAEVYG.js +1 -0
- package/dist/{chunk-YV3K2EKJ.js → chunk-RIPKY4RU.js} +1 -1
- package/dist/chunk-RZW35UN5.cjs +1 -0
- package/dist/chunk-SBFNXGTJ.js +1 -0
- package/dist/{chunk-T4CIAKEK.js → chunk-SBKGWRS5.js} +1 -1
- package/dist/{chunk-5Z2G23WP.js → chunk-SIM77PU4.js} +1 -1
- package/dist/chunk-T2T7K3KR.js +1 -0
- package/dist/chunk-T7PU2V7X.cjs +1 -0
- package/dist/chunk-V45XJKHW.cjs +1 -0
- package/dist/chunk-W2WNBUDE.js +1 -0
- package/dist/chunk-XABCB3Y7.cjs +1 -0
- package/dist/chunk-XEDXFSGI.js +1 -0
- package/dist/chunk-YKPSRP5G.js +1 -0
- package/dist/chunk-YLA3DURS.cjs +1 -0
- package/dist/chunk-ZETAZZLD.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +515 -321
- package/dist/conversions/index.js +1 -1
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +25 -20
- package/dist/events/index.js +1 -1
- package/dist/{extends-Bk_SBGdT.d.ts → extends-DtdRjDyU.d.ts} +63 -87
- package/dist/{formatting → formatters}/index.cjs +1 -1
- package/dist/formatters/index.d.ts +2106 -0
- package/dist/formatters/index.js +1 -0
- package/dist/generators/index.cjs +1 -0
- package/dist/{generator → generators}/index.d.ts +57 -59
- package/dist/generators/index.js +1 -0
- package/dist/{if-CvT4R7Kh.d.ts → if-ChM35c_q.d.ts} +6 -5
- package/dist/index.d.ts +14 -0
- package/dist/{is-array--YjXV-Wx.d.ts → is-array-BJeHxPM3.d.ts} +287 -542
- package/dist/{isPlainObject-BVhBAPHX.d.ts → isPlainObject-DGJkcFYw.d.ts} +6 -6
- package/dist/{never-BfayMBF9.d.ts → never-D89PbPh5.d.ts} +10 -19
- package/dist/next/index.cjs +1 -1
- package/dist/next/index.d.ts +15 -12
- package/dist/next/index.js +1 -1
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +1 -1
- package/dist/next/server/index.js +1 -1
- package/dist/{nils-DMz3kU7M.d.ts → nils-CO8zLHSB.d.ts} +39 -65
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +4 -4
- package/dist/operations/index.js +1 -1
- package/dist/or-C6qzKt2I.d.ts +82 -0
- package/dist/override-CL2olHE5.d.ts +59 -0
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.js +1 -1
- package/dist/pick-BSMX6Xe2.d.ts +15 -0
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +425 -106
- package/dist/predicates/index.js +1 -1
- package/dist/prettify-3o8_Kw6b.d.ts +564 -0
- package/dist/promises/index.cjs +1 -0
- package/dist/promises/index.d.ts +107 -0
- package/dist/promises/index.js +1 -0
- package/dist/promises-LU7K00H0.d.ts +72 -0
- package/dist/rzl-utils.global.js +1 -1
- package/dist/{string-XA-til3C.d.ts → string-B1jlOnws.d.ts} +82 -121
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +209 -210
- package/dist/strings/index.js +1 -1
- package/dist/tailwind/index.cjs +1 -1
- package/dist/tailwind/index.d.ts +23 -17
- package/dist/tailwind/index.js +1 -1
- package/dist/types/index.d.ts +899 -1181
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +113 -108
- package/dist/urls/index.js +1 -1
- package/package.json +33 -40
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +0 -26
- package/dist/chunk-2HSNUPEO.cjs +0 -1
- package/dist/chunk-4Z75R3IT.cjs +0 -1
- package/dist/chunk-AJ25PWXX.cjs +0 -1
- package/dist/chunk-BHIBDDQF.js +0 -1
- package/dist/chunk-CE4JI2YB.js +0 -1
- package/dist/chunk-CMJ6UYWW.cjs +0 -1
- package/dist/chunk-D3VSHABU.cjs +0 -1
- package/dist/chunk-DG2GWBTS.cjs +0 -1
- package/dist/chunk-EKS4IZJR.cjs +0 -1
- package/dist/chunk-EOZKYR5S.cjs +0 -1
- package/dist/chunk-EW3I4O7X.js +0 -1
- package/dist/chunk-F3E77L46.js +0 -1
- package/dist/chunk-G5LXIEFO.js +0 -0
- package/dist/chunk-GVWGQNLF.js +0 -1
- package/dist/chunk-H3FXL4DU.cjs +0 -1
- package/dist/chunk-HHPDLSX2.cjs +0 -1
- package/dist/chunk-JARPXKBM.cjs +0 -1
- package/dist/chunk-JFJUPYDT.cjs +0 -1
- package/dist/chunk-JLP56WSM.js +0 -1
- package/dist/chunk-K3MV4AIN.cjs +0 -1
- package/dist/chunk-KOVO72OM.js +0 -1
- package/dist/chunk-LJ4M3VGE.js +0 -1
- package/dist/chunk-LJVGJLP4.js +0 -1
- package/dist/chunk-MISCBZJC.js +0 -1
- package/dist/chunk-MMSYCIJ2.cjs +0 -1
- package/dist/chunk-OLPKAX7F.cjs +0 -1
- package/dist/chunk-ORZFHBEY.js +0 -1
- package/dist/chunk-OWV2P376.js +0 -1
- package/dist/chunk-RV2WK5E6.js +0 -1
- package/dist/chunk-SBF43G3B.cjs +0 -1
- package/dist/chunk-X74TUJSE.cjs +0 -1
- package/dist/chunk-XLDAIZRK.js +0 -1
- package/dist/chunk-XZJ7C4N6.js +0 -1
- package/dist/chunk-ZHV5ZYVN.cjs +0 -1
- package/dist/chunk-ZL7J6GTP.js +0 -1
- package/dist/chunk-ZTCLKKMB.js +0 -1
- package/dist/env/index.cjs +0 -1
- package/dist/env/index.d.ts +0 -16
- package/dist/env/index.js +0 -1
- package/dist/formatting/index.d.ts +0 -950
- package/dist/formatting/index.js +0 -1
- package/dist/generator/index.cjs +0 -1
- package/dist/generator/index.js +0 -1
- package/dist/omit-VvmIsZmX.d.ts +0 -28
- package/dist/prettify-C4xLcYOP.d.ts +0 -353
- package/dist/promise/index.cjs +0 -1
- package/dist/promise/index.d.ts +0 -31
- package/dist/promise/index.js +0 -1
- package/dist/type-data-DDs-u2kq.d.ts +0 -261
- /package/dist/{chunk-5C2SMIGX.cjs → chunk-BAV5T2E3.cjs} +0 -0
- /package/dist/{chunk-MC3LXMCQ.js → chunk-L5RDAVVH.js} +0 -0
- /package/dist/{chunk-J2RGTPGK.cjs → chunk-VJDDGRIK.cjs} +0 -0
- /package/dist/{chunk-FIAAX3UE.js → chunk-YWHHVDT4.js} +0 -0
|
@@ -1,950 +0,0 @@
|
|
|
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
|
-
/** @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
|
-
* Whether to show decimals. If `false`, decimals are truncated.
|
|
70
|
-
*
|
|
71
|
-
* *DefaultValue: `false`.*
|
|
72
|
-
*
|
|
73
|
-
* @default false
|
|
74
|
-
*/
|
|
75
|
-
decimal?:boolean;
|
|
76
|
-
/** ---------------------------------------------------------------------------
|
|
77
|
-
* * ***Total decimal digits.***
|
|
78
|
-
* ---------------------------------------------------------------------------
|
|
79
|
-
*
|
|
80
|
-
* If `decimal: true` & `roundedDecimal: false`, simply cuts.
|
|
81
|
-
*
|
|
82
|
-
* *DefaultValue: `2`.*
|
|
83
|
-
*
|
|
84
|
-
* @default 2
|
|
85
|
-
*/
|
|
86
|
-
totalDecimal?:number;
|
|
87
|
-
/** ---------------------------------------------------------------------------
|
|
88
|
-
* * ***Actually append `suffixDecimal`.***
|
|
89
|
-
* ---------------------------------------------------------------------------
|
|
90
|
-
*
|
|
91
|
-
* *DefaultValue: `true`.*
|
|
92
|
-
*
|
|
93
|
-
* @default true
|
|
94
|
-
*/
|
|
95
|
-
endDecimal?:boolean;
|
|
96
|
-
/** ---------------------------------------------------------------------------
|
|
97
|
-
* * ***Text appended after decimals.***
|
|
98
|
-
* ---------------------------------------------------------------------------
|
|
99
|
-
*
|
|
100
|
-
* E.g: (`".-"`, `" USD"`).
|
|
101
|
-
*
|
|
102
|
-
* *Example 1: `".-"` ➔ `1.000,00.-`.*
|
|
103
|
-
*
|
|
104
|
-
* *Example 2: `" USD"` ➔ `1.000,00 USD`.*
|
|
105
|
-
*
|
|
106
|
-
* *DefaultValue: `""`.*
|
|
107
|
-
*
|
|
108
|
-
* @default ""
|
|
109
|
-
*/
|
|
110
|
-
suffixDecimal?:string;
|
|
111
|
-
/** ---------------------------------------------------------------------------
|
|
112
|
-
* * ***Rounding mode for decimals.***
|
|
113
|
-
* ---------------------------------------------------------------------------
|
|
114
|
-
*
|
|
115
|
-
* - `"round"` ➔ nearest
|
|
116
|
-
* - `"ceil"` ➔ always up
|
|
117
|
-
* - `"floor"` ➔ always down
|
|
118
|
-
* - `false` ➔ truncate
|
|
119
|
-
*
|
|
120
|
-
* *DefaultValue: `"round"`.*
|
|
121
|
-
*
|
|
122
|
-
* @default "round"
|
|
123
|
-
*/
|
|
124
|
-
roundedDecimal?:"round"|"ceil"|"floor"|false;
|
|
125
|
-
/** ---------------------------------------------------------------------------
|
|
126
|
-
* * ***Decimal separator.***
|
|
127
|
-
* ---------------------------------------------------------------------------
|
|
128
|
-
*
|
|
129
|
-
* Example: `","` ➔ `1.000,10`
|
|
130
|
-
*
|
|
131
|
-
* *DefaultValue: `","`.*
|
|
132
|
-
*
|
|
133
|
-
* @default ","
|
|
134
|
-
*/
|
|
135
|
-
separatorDecimals?:string;
|
|
136
|
-
/** ---------------------------------------------------------------------------
|
|
137
|
-
* * ***Negative formatting option.***
|
|
138
|
-
* ---------------------------------------------------------------------------
|
|
139
|
-
*
|
|
140
|
-
* Can be string ("dash" | "brackets" | "abs") or object with custom formatter.
|
|
141
|
-
*
|
|
142
|
-
* - `"dash"` ➔ `-15.000`
|
|
143
|
-
* - `"brackets"` ➔ `(15.000)`
|
|
144
|
-
* - `"abs"` ➔ `15.000` (always positive)
|
|
145
|
-
* - Or object:
|
|
146
|
-
* `{
|
|
147
|
-
* style: "dash"|"brackets"|"abs",
|
|
148
|
-
* space: true|false,
|
|
149
|
-
* custom: (formatted) => string
|
|
150
|
-
* }`.
|
|
151
|
-
*
|
|
152
|
-
* *DefaultValue: `"dash"`.*
|
|
153
|
-
*
|
|
154
|
-
* @default "dash"
|
|
155
|
-
*/
|
|
156
|
-
negativeFormat?:NegativeFormatOption;
|
|
157
|
-
/** ---------------------------------------------------------------------------
|
|
158
|
-
* * ***Applies Indian Format.***
|
|
159
|
-
* ---------------------------------------------------------------------------
|
|
160
|
-
*
|
|
161
|
-
* If `true`, formats as Indian: `12,34,567`.
|
|
162
|
-
*
|
|
163
|
-
* Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
164
|
-
*
|
|
165
|
-
* *DefaultValue: `false`.*
|
|
166
|
-
*
|
|
167
|
-
* @default false
|
|
168
|
-
*/
|
|
169
|
-
indianFormat?:boolean;};
|
|
170
|
-
/** -------------------------------------------------------
|
|
171
|
-
* * ***Utility: `formatCurrency`.***
|
|
172
|
-
* -------------------------------------------------------
|
|
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)***.
|
|
185
|
-
* - Auto extracts numeric value with smart multi-locale parsing
|
|
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.
|
|
194
|
-
* - Strong type checks & clear errors for misconfigured options.
|
|
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
|
-
* @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
|
-
* @param {FormatCurrencyOptions} [options] Optional configuration object.
|
|
210
|
-
* @param {FormatCurrencyOptions["separator"]} [options.separator] Thousands separator:
|
|
211
|
-
* - `{ separator: "." }` ➔ `1.000.000`.
|
|
212
|
-
* - ***DefaultValue: `"."`***.
|
|
213
|
-
* @param {FormatCurrencyOptions["separatorDecimals"]} [options.separatorDecimals] Decimal separator:
|
|
214
|
-
* - `{ separatorDecimals: "," }` ➔ `1.000,10`.
|
|
215
|
-
* - ***DefaultValue: `","`***.
|
|
216
|
-
* @param {FormatCurrencyOptions["suffixCurrency"]} [options.suffixCurrency] Prefix currency string:
|
|
217
|
-
* - Does **not auto-keep input symbols**.
|
|
218
|
-
* - Must set manually e.g: `{ suffixCurrency: "Rp " }`.
|
|
219
|
-
* - `{ suffixCurrency: "Rp " }` ➔ `Rp 1.000`.
|
|
220
|
-
* - ***DefaultValue: `""`***.
|
|
221
|
-
* @param {FormatCurrencyOptions["decimal"]} [options.decimal] Whether to show decimals. If `false`, decimals are truncated:
|
|
222
|
-
* - If `false`, cut the decimal.
|
|
223
|
-
* - ***DefaultValue: `false`***.
|
|
224
|
-
* @param {FormatCurrencyOptions["totalDecimal"]} [options.totalDecimal] Total decimal digits:
|
|
225
|
-
* - If `decimal: true` & `roundedDecimal: false`, simply cuts.
|
|
226
|
-
* - ***DefaultValue: `2`***.
|
|
227
|
-
* @param {FormatCurrencyOptions["separatorDecimals"]} [options.suffixDecimal] Text appended after decimals:
|
|
228
|
-
* - E.g: (`".-"`, `" USD"`).
|
|
229
|
-
* - Example 1: `".-"` ➔ `1.000,00.-`.
|
|
230
|
-
* - Example 2: `" USD"` ➔ `1.000,00 USD`.
|
|
231
|
-
* - ***DefaultValue: `""`***.
|
|
232
|
-
* @param {FormatCurrencyOptions["endDecimal"]} [options.endDecimal] Actually append `suffixDecimal`:
|
|
233
|
-
* - ***DefaultValue: `true`***.
|
|
234
|
-
* @param {FormatCurrencyOptions["roundedDecimal"]} [options.roundedDecimal] Rounding mode:
|
|
235
|
-
* - `"round"` ➔ nearest.
|
|
236
|
-
* - `"ceil"` ➔ always up.
|
|
237
|
-
* - `"floor"` ➔ always down.
|
|
238
|
-
* - `false` ➔ truncate.
|
|
239
|
-
* - ***DefaultValue: `"round"`***.
|
|
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 }`.
|
|
246
|
-
* - ***DefaultValue: `"dash"`.***
|
|
247
|
-
* @param {FormatCurrencyOptions["indianFormat"]} [options.indianFormat] Applies Indian Format:
|
|
248
|
-
* - If `true`, formats as Indian: `12,34,567`.
|
|
249
|
-
* - Also forces `separator: ","`, `separatorDecimals: "."`.
|
|
250
|
-
* @returns {string} Nicely formatted currency string, examples:
|
|
251
|
-
* - `"15.000,10"`.
|
|
252
|
-
* - `"Rp 15.000,10.-"`.
|
|
253
|
-
* - `"15'000.10 USD"`.
|
|
254
|
-
* - `"12,34,567.89"`.
|
|
255
|
-
* @throws {TypeError} Will throw TypeError If:
|
|
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)"
|
|
298
|
-
*
|
|
299
|
-
* // --- Negative numbers (custom object style) ---
|
|
300
|
-
* formatCurrency(-1234.56, {
|
|
301
|
-
* decimal: true,
|
|
302
|
-
* negativeFormat: { style: "brackets", space: true }
|
|
303
|
-
* });
|
|
304
|
-
* // ➔ "( 1.234,56 )"
|
|
305
|
-
*
|
|
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"
|
|
385
|
-
*/
|
|
386
|
-
declare const formatCurrency:(value:string|number,options?:FormatCurrencyOptions)=>string;
|
|
387
|
-
/** ----------------------------------------------------------
|
|
388
|
-
* * ***Utility: `formatNumber`.***
|
|
389
|
-
* ----------------------------------------------------------
|
|
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.
|
|
403
|
-
* @returns {string} The formatted string with thousands separators and
|
|
404
|
-
* appropriate decimal separator.
|
|
405
|
-
* @throws {TypeError} If `value` is not a string or number,
|
|
406
|
-
* or `separator` is not a string.
|
|
407
|
-
* @example
|
|
408
|
-
* formatNumber(1000000);
|
|
409
|
-
* // ➔ "1,000,000"
|
|
410
|
-
* formatNumber("987654321");
|
|
411
|
-
* // ➔ "987,654,321"
|
|
412
|
-
* formatNumber(1234567.89);
|
|
413
|
-
* // ➔ "1,234,567.89"
|
|
414
|
-
* formatNumber("1234567,89");
|
|
415
|
-
* // ➔ "1,234,567.89"
|
|
416
|
-
* formatNumber("1234567.892");
|
|
417
|
-
* // ➔ "1,234,567.892"
|
|
418
|
-
* formatNumber("1234567.89", ".");
|
|
419
|
-
* // ➔ "1.234.567,89"
|
|
420
|
-
* formatNumber("1234567,89", ",");
|
|
421
|
-
* // ➔ "1,234,567.89"
|
|
422
|
-
* formatNumber("987654321", " ");
|
|
423
|
-
* // ➔ "987 654 321"
|
|
424
|
-
* formatNumber("1,234,567.89");
|
|
425
|
-
* // ➔ "1,234,567.89"
|
|
426
|
-
* formatNumber("1.234.567,89", ",");
|
|
427
|
-
* // ➔ "1,234,567.89"
|
|
428
|
-
* formatNumber("1.234.567,893", ".");
|
|
429
|
-
* // ➔ "1.234.567,893"
|
|
430
|
-
* formatNumber("1234.56", ".");
|
|
431
|
-
* // ➔ "1.234,56"
|
|
432
|
-
* formatNumber("1234,56", ",");
|
|
433
|
-
* // ➔ "1,234.56"
|
|
434
|
-
*/
|
|
435
|
-
declare const formatNumber:(value:string|number,separator?:string)=>string;
|
|
436
|
-
/** -------------------------------------------------------
|
|
437
|
-
* * ***Utility: `formatPhoneNumber`.***
|
|
438
|
-
* -------------------------------------------------------
|
|
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
|
|
449
|
-
* ```js
|
|
450
|
-
* formatPhoneNumber("081234567890")
|
|
451
|
-
* // ➔ "0812 3456 7890"
|
|
452
|
-
* formatPhoneNumber("(0812) 3456-7890", { takeNumberOnly: true })
|
|
453
|
-
* // ➔ "081234567890"
|
|
454
|
-
* formatPhoneNumber("(0812) 3456-7890", { checkValidOnly: true })
|
|
455
|
-
* // ➔ true
|
|
456
|
-
* formatPhoneNumber("+6281234567890", { checkValidOnly: true })
|
|
457
|
-
* // ➔ true
|
|
458
|
-
* formatPhoneNumber("+1 (800) 123-4567", { checkValidOnly: true })
|
|
459
|
-
* // ➔ true
|
|
460
|
-
* formatPhoneNumber("+44 20 7946 0958", { checkValidOnly: true })
|
|
461
|
-
* // ➔ true
|
|
462
|
-
* formatPhoneNumber("0812-3456-7890", { checkValidOnly: true })
|
|
463
|
-
* // ➔ true
|
|
464
|
-
* formatPhoneNumber("(0812) 3456 7890", { checkValidOnly: true })
|
|
465
|
-
* // ➔ true
|
|
466
|
-
* formatPhoneNumber("0812 3456 7890", { checkValidOnly: true })
|
|
467
|
-
* // ➔ true
|
|
468
|
-
* formatPhoneNumber("+62abc123", { checkValidOnly: true })
|
|
469
|
-
* // ➔ false
|
|
470
|
-
* formatPhoneNumber("0812-3456-hello", { checkValidOnly: true })
|
|
471
|
-
* // ➔ false
|
|
472
|
-
* formatPhoneNumber("+62 123456789012345678901234", { checkValidOnly: true })
|
|
473
|
-
* // ➔ false
|
|
474
|
-
* formatPhoneNumber("++6281234567890", { checkValidOnly: true })
|
|
475
|
-
* // ➔ false
|
|
476
|
-
* formatPhoneNumber("invalid@@@", { checkValidOnly: true })
|
|
477
|
-
* // ➔ false
|
|
478
|
-
* formatPhoneNumber("+62.812.3456.7890", { checkValidOnly: true })
|
|
479
|
-
* // ➔ true
|
|
480
|
-
* formatPhoneNumber("+62(812)3456-7890", { checkValidOnly: true })
|
|
481
|
-
* // ➔ true
|
|
482
|
-
* ```
|
|
483
|
-
* ```js
|
|
484
|
-
* formatPhoneNumber("081234567890", {
|
|
485
|
-
* separator: "-",
|
|
486
|
-
* plusNumberCountry: "+44",
|
|
487
|
-
* openingNumberCountry: "(",
|
|
488
|
-
* closingNumberCountry: ")",
|
|
489
|
-
* })
|
|
490
|
-
* // ➔ "(+44) 8123-4567-890"
|
|
491
|
-
* ```
|
|
492
|
-
* @throws {TypeError} If `value` is not string, number, null or undefined.
|
|
493
|
-
* @throws {TypeError} If `options` is not an object or contains wrong types.
|
|
494
|
-
*
|
|
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.
|
|
499
|
-
*
|
|
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.
|
|
504
|
-
*
|
|
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.
|
|
509
|
-
*/
|
|
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;
|
|
511
|
-
/** -------------------------------------------------------------
|
|
512
|
-
* * ***Supported IETF BCP-47 locale codes for Intl API.***
|
|
513
|
-
* -------------------------------------------------------------
|
|
514
|
-
*
|
|
515
|
-
* Includes:
|
|
516
|
-
* - Major global locales (en-US, fr-FR, zh-CN, etc)
|
|
517
|
-
* - Regional & minor locales (mi-NZ, rw-RW, bi-VU, etc)
|
|
518
|
-
* - Useful for `Intl.DateTimeFormat`, `Intl.NumberFormat`, etc.
|
|
519
|
-
* - Still allows fallback via `({} & string)` for arbitrary locales.
|
|
520
|
-
*
|
|
521
|
-
* This type ensures proper autocompletion & validation in TS
|
|
522
|
-
* but does not restrict at runtime (must validate separately).
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* const locale: SupportedLocales = "fr-CA";
|
|
526
|
-
* new Intl.DateTimeFormat(locale).format(new Date());
|
|
527
|
-
*/
|
|
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);
|
|
529
|
-
/** ----------------------------------------------------------------
|
|
530
|
-
* * ***Options for formatting dates with `Intl.DateTimeFormat`.***
|
|
531
|
-
* ----------------------------------------------------------------
|
|
532
|
-
*
|
|
533
|
-
* Extends the native
|
|
534
|
-
* **{@link Intl.DateTimeFormatOptions | `Intl.DateTimeFormatOptions`}** with
|
|
535
|
-
* an additional `locale` property that is validated against **{@link SupportedLocales | `SupportedLocales`}**.
|
|
536
|
-
*
|
|
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"`**.
|
|
547
|
-
*
|
|
548
|
-
* @default "en-US"
|
|
549
|
-
* @example
|
|
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"
|
|
558
|
-
*
|
|
559
|
-
*/
|
|
560
|
-
locale?:SupportedLocales;};
|
|
561
|
-
/** ----------------------------------------------------------------------
|
|
562
|
-
* * ***Options for formatting dates with `date-fns/format`.***
|
|
563
|
-
* ----------------------------------------------------------------------
|
|
564
|
-
*
|
|
565
|
-
* Extends the base **{@link FormatOptions | *`FormatOptions`*}** (without **`locale`**) with extra options
|
|
566
|
-
* for handling output formatting, localization, and parsing non-standard inputs.
|
|
567
|
-
*
|
|
568
|
-
*/
|
|
569
|
-
type FormatDateFnsOptions=Prettify<OmitStrict<FormatOptions,"locale",true,false>&{
|
|
570
|
-
/** ------------------------------------------------------------
|
|
571
|
-
* * Output format string passed to `date-fns/format`.
|
|
572
|
-
* ------------------------------------------------------------
|
|
573
|
-
*
|
|
574
|
-
* - Determines how the date will be rendered.
|
|
575
|
-
* - Uses the full power of `date-fns` tokens.
|
|
576
|
-
*
|
|
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
|
-
* ------------------------------------------------------------
|
|
586
|
-
*
|
|
587
|
-
* - If `string`: only accepts `"id"` (Indonesian) or `"en"` (English) - **(default)**.
|
|
588
|
-
* - If `Locale`: accepts a locale object from `date-fns/locale`.
|
|
589
|
-
*
|
|
590
|
-
* ***Default Value***: `"en"`.
|
|
591
|
-
* ```ts
|
|
592
|
-
* import { ar } from "date-fns/locale";
|
|
593
|
-
*
|
|
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
|
-
* ------------------------------------------------------------
|
|
606
|
-
*
|
|
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.
|
|
610
|
-
*
|
|
611
|
-
* ***Default Value***: `"en"`.
|
|
612
|
-
* ```ts
|
|
613
|
-
* import { ar } from "date-fns/locale";
|
|
614
|
-
*
|
|
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
|
-
* ------------------------------------------------------------
|
|
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
|
|
675
|
-
* formatDateTime(undefined);
|
|
676
|
-
* // ➔ null
|
|
677
|
-
*/
|
|
678
|
-
declare const formatDateTime:(date:string|Date|null|undefined,format?:string)=>string|null;
|
|
679
|
-
/** ----------------------------------------------------------
|
|
680
|
-
* * ***Utility: `formatDateIntl`.***
|
|
681
|
-
* ----------------------------------------------------------
|
|
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]
|
|
692
|
-
* - Optional formatting options for `Intl.DateTimeFormat`.
|
|
693
|
-
* - Use `locale` to specify the language & region format.
|
|
694
|
-
* @returns {string | null}
|
|
695
|
-
* - Formatted date string.
|
|
696
|
-
* - Returns `null` if date is invalid or options are of wrong type.
|
|
697
|
-
* @example
|
|
698
|
-
* formatDateIntl(new Date());
|
|
699
|
-
* // ➔ "7/14/2025"
|
|
700
|
-
* formatDateIntl("2025-07-14T00:00:00Z", { locale: "fr-FR", dateStyle: "long" });
|
|
701
|
-
* // ➔ "14 juillet 2025"
|
|
702
|
-
* formatDateIntl(null);
|
|
703
|
-
* // ➔ null
|
|
704
|
-
* formatDateIntl(new Date(), { timeZone: "UTC", hour: "2-digit", minute: "2-digit" });
|
|
705
|
-
* // ➔ "01:30 AM"
|
|
706
|
-
*/
|
|
707
|
-
declare const formatDateIntl:(date:string|Date|null|undefined,options?:FormatDateIntlOptions)=>string|null;
|
|
708
|
-
/** ----------------------------------------------------------
|
|
709
|
-
* * ***Utility: `formatDateFns`.***
|
|
710
|
-
* ----------------------------------------------------------
|
|
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:
|
|
718
|
-
* - A `Date` object
|
|
719
|
-
* - An ISO string (e.g. `"2024-01-01T12:00:00Z"`)
|
|
720
|
-
* - A localized string (requires `inputFormat` + `inputLocale`)
|
|
721
|
-
* @param {FormatDateFnsOptions} [options] - Options for formatting and parsing.
|
|
722
|
-
* @param {FormatDateFnsOptions["format"]} [options.format="dd MMM yyyy - HH:mm:ss"]
|
|
723
|
-
* The output format string (passed to `date-fns/format`).
|
|
724
|
-
* E.g. `"dd MMMM yyyy, HH:mm:ss" ➔ "14 Juli 2025, 17:25:42"`
|
|
725
|
-
* @param {FormatDateFnsOptions["locale"]} [options.locale="id"]
|
|
726
|
-
* The output locale. If string, only `"id"` (Indonesian) or `"en"` (English)
|
|
727
|
-
* is recognized. Or you can pass a `date-fns` `Locale` object.
|
|
728
|
-
* - Example:
|
|
729
|
-
* ```ts
|
|
730
|
-
* import { ar } from "date-fns/locale";
|
|
731
|
-
* formatDateFns(new Date(), { locale: ar, format: "PPPppp" });
|
|
732
|
-
* ```
|
|
733
|
-
* @param {FormatDateFnsOptions["inputLocale"]} [options.inputLocale]
|
|
734
|
-
* Required if `date` is a localized non-ISO string. Used with `inputFormat`.
|
|
735
|
-
* - Example for Indonesian string:
|
|
736
|
-
* ```ts
|
|
737
|
-
* formatDateFns("14 Juli 2025 10:25:42", { inputFormat: "dd MMMM yyyy HH:mm:ss", inputLocale: "id" });
|
|
738
|
-
* ```
|
|
739
|
-
* @param {FormatDateFnsOptions["inputFormat"]} [options.inputFormat]
|
|
740
|
-
* The format string to parse `date` if it is a non-ISO string.
|
|
741
|
-
* Required together with `inputLocale`.
|
|
742
|
-
* @returns {string | null} A formatted date string or `null` if input is invalid.
|
|
743
|
-
* @example
|
|
744
|
-
* formatDateFns(new Date());
|
|
745
|
-
* // ➔ "14 Jul 2025 - 17:25:42"
|
|
746
|
-
* formatDateFns("2025-07-14T10:25:42Z", { format: "dd/MM/yyyy", locale: "en" });
|
|
747
|
-
* // ➔ "14/07/2025"
|
|
748
|
-
* formatDateFns("14 Juli 2025 10:25:42", {
|
|
749
|
-
* inputFormat: "dd MMMM yyyy HH:mm:ss",
|
|
750
|
-
* inputLocale: "id",
|
|
751
|
-
* format: "yyyy-MM-dd"
|
|
752
|
-
* });
|
|
753
|
-
* // ➔ "2025-07-14"
|
|
754
|
-
* formatDateFns(null);
|
|
755
|
-
* // ➔ null
|
|
756
|
-
*/
|
|
757
|
-
declare const formatDateFns:(date:string|Date|null|undefined,options?:FormatDateFnsOptions)=>string|null;
|
|
758
|
-
/** ----------------------------------------------------------
|
|
759
|
-
* * ***Utility: `getGMTOffset`.***
|
|
760
|
-
* ----------------------------------------------------------
|
|
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.
|
|
769
|
-
* @param {string | Date | null} [date] - The date to get the GMT offset from.
|
|
770
|
-
* - Accepts `Date` object or ISO date string (e.g., `"2024-01-01T12:00:00Z"`).
|
|
771
|
-
* - If `null`, `undefined`, or empty string, uses current system date.
|
|
772
|
-
* - If invalid date or wrong type (like `123` or `{}`), returns `"0"`.
|
|
773
|
-
* @returns {string} The GMT offset string in format `±HHMM`,
|
|
774
|
-
* e.g. `"+0700"`, `"-0530"`, or `"0"` if invalid.
|
|
775
|
-
* @example
|
|
776
|
-
* getGMTOffset();
|
|
777
|
-
* // ➔ "+0700" (depends on your system timezone)
|
|
778
|
-
* getGMTOffset(new Date("2024-02-09T12:00:00Z"));
|
|
779
|
-
* // ➔ "+0000"
|
|
780
|
-
* getGMTOffset("2024-02-09");
|
|
781
|
-
* // ➔ "+0700" (depends on your system timezone)
|
|
782
|
-
* getGMTOffset("invalid-date");
|
|
783
|
-
* // ➔ "0"
|
|
784
|
-
* getGMTOffset(123);
|
|
785
|
-
* // ➔ "0"
|
|
786
|
-
*/
|
|
787
|
-
declare const getGMTOffset:(date?:string|Date|null)=>string;type CensorEmailOptions={
|
|
788
|
-
/** ----------------------------------------------------------
|
|
789
|
-
* * ***Censorship Mode.***
|
|
790
|
-
* ----------------------------------------------------------
|
|
791
|
-
* **Valid value:**
|
|
792
|
-
* - `"fixed"` (default) – Deterministic censorship based on a hash of the email.
|
|
793
|
-
* The same input always produces the same output.
|
|
794
|
-
* - `"random"` – Each character is randomly replaced every time the function is called.
|
|
795
|
-
*/
|
|
796
|
-
mode?:"random"|"fixed";};
|
|
797
|
-
/** ----------------------------------------------------------
|
|
798
|
-
* * ***Utility: `censorEmail`.***
|
|
799
|
-
* ----------------------------------------------------------
|
|
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.
|
|
808
|
-
* @param {CensorEmailOptions} [options={}] - Options object for mode.
|
|
809
|
-
* @returns {string} The censored email, or an empty string if input is invalid.
|
|
810
|
-
* @throws {TypeError} If `options` is not a plain object or `mode` is invalid.
|
|
811
|
-
* @example
|
|
812
|
-
* // Fixed mode (default, deterministic)
|
|
813
|
-
* censorEmail("john.doe@gmail.com");
|
|
814
|
-
* // ➔ "j**n.**e@g***l.com"
|
|
815
|
-
*
|
|
816
|
-
* // Fixed mode explicitly
|
|
817
|
-
* censorEmail("john.doe@gmail.com", { mode: "fixed" });
|
|
818
|
-
* // ➔ "j**n.**e@g***l.com"
|
|
819
|
-
*
|
|
820
|
-
* // Random mode (output may vary each time)
|
|
821
|
-
* censorEmail("john.doe@gmail.com", { mode: "random" });
|
|
822
|
-
* // ➔ "j*hn.***e@g***l.com" (random)
|
|
823
|
-
*
|
|
824
|
-
* // Invalid email returns empty string
|
|
825
|
-
* censorEmail("invalid-email");
|
|
826
|
-
* // ➔ ""
|
|
827
|
-
*/
|
|
828
|
-
declare const censorEmail:(email:string|null|undefined,options?:CensorEmailOptions)=>string;type ChunkStringOptions={
|
|
829
|
-
/** The separator string to insert between characters or words.
|
|
830
|
-
*
|
|
831
|
-
* - Used when inserting separators every `limiter` characters.
|
|
832
|
-
* - Default is a single space `" "`.
|
|
833
|
-
*
|
|
834
|
-
* @default " "
|
|
835
|
-
*/
|
|
836
|
-
separator?:string;
|
|
837
|
-
/** Determines whether counting for `limiter` resets after each space.
|
|
838
|
-
*
|
|
839
|
-
* - If `true`, the string is treated as words separated by spaces,
|
|
840
|
-
* and separators are applied within words, then words are grouped.
|
|
841
|
-
* - If `false` ***(default)***, counting is continuous across the whole string,
|
|
842
|
-
* treating spaces as normal characters.
|
|
843
|
-
*
|
|
844
|
-
* @default false
|
|
845
|
-
*/
|
|
846
|
-
reCountAfterSpace?:boolean;};
|
|
847
|
-
/** ----------------------------------------------
|
|
848
|
-
* * ***Utility: `chunkString`.***
|
|
849
|
-
* ----------------------------------------------
|
|
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.
|
|
866
|
-
* @param {string} subject - The target string to chunk.
|
|
867
|
-
* @param {number} limiter - The interval (number of characters) for inserting separators.
|
|
868
|
-
* - If `reCountAfterSpace = false`, it counts characters.
|
|
869
|
-
* - If `reCountAfterSpace = true`, it counts both characters within words and words per group.
|
|
870
|
-
* @param {ChunkStringOptions} [options={}] - Optional settings for separator and counting behavior.
|
|
871
|
-
* @returns {string} Return the formatted string with separators.
|
|
872
|
-
* @example
|
|
873
|
-
* // Basic usage
|
|
874
|
-
* chunkString("1234567890", 3);
|
|
875
|
-
* // ➔ "123 456 789 0"
|
|
876
|
-
*
|
|
877
|
-
* // Basic usage `reCountAfterSpace = false` (default)
|
|
878
|
-
* chunkString("1234567890", 3, { separator: "-");
|
|
879
|
-
* // ➔ "123-456-789-0"
|
|
880
|
-
* chunkString("HelloWorld", 2, { separator: "_", reCountAfterSpace: false });
|
|
881
|
-
* // ➔ "He_ll_oW_or_ld"
|
|
882
|
-
*
|
|
883
|
-
* // Usage with reCountAfterSpace = true:
|
|
884
|
-
* // Multiple spaces are normalized to single spaces before processing.
|
|
885
|
-
* chunkString("AB CD EF GH", 2, { separator: "-", reCountAfterSpace: true });
|
|
886
|
-
* // ➔ "AB-CD EF-GH" (after normalization to "AB CD EF GH")
|
|
887
|
-
* // Words "AB" and "CD" form a group and are joined by "-", "EF" and "GH" form another group.
|
|
888
|
-
* // The groups "AB-CD" and "EF-GH" are then joined by a space.
|
|
889
|
-
*
|
|
890
|
-
* // Another usage with reCountAfterSpace = true:
|
|
891
|
-
* chunkString("ABC DEF GHI JKL", 3, { separator: "-", reCountAfterSpace: true });
|
|
892
|
-
* // ➔ "ABC-DEF-GHI JKL"
|
|
893
|
-
* // Words "ABC", "DEF", "GHI" form a group and are joined by "-".
|
|
894
|
-
* // The word "JKL" forms its own group (as it's the last word and completes no other group).
|
|
895
|
-
* // The groups "ABC-DEF-GHI" and "JKL" are then joined by a space.
|
|
896
|
-
*/
|
|
897
|
-
declare function chunkString(subject:string,limiter:number,options?:ChunkStringOptions):string;type TruncateStringOptions={
|
|
898
|
-
/** **Maximum length of the truncated string **(default: `10`)**.**
|
|
899
|
-
*
|
|
900
|
-
* @default 10
|
|
901
|
-
*/
|
|
902
|
-
length?:number;
|
|
903
|
-
/** **String to append if truncation occurs.**
|
|
904
|
-
*
|
|
905
|
-
* - Will be trimmed first; defaults to `"..."` if empty.
|
|
906
|
-
*
|
|
907
|
-
* @default "..."
|
|
908
|
-
*/
|
|
909
|
-
ending?:string;
|
|
910
|
-
/** **Whether to trim the input string before truncation ***(default: `true`)***.**
|
|
911
|
-
*
|
|
912
|
-
* @default true
|
|
913
|
-
*/
|
|
914
|
-
trim?:boolean;};
|
|
915
|
-
/** ----------------------------------------------------------
|
|
916
|
-
* * ***Utility: `truncateString`.***
|
|
917
|
-
* ----------------------------------------------------------
|
|
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 `"..."`.
|
|
923
|
-
* @param {string|null|undefined} text - The input string to truncate.
|
|
924
|
-
* If `null`, `undefined`, or empty after trim, returns `""`.
|
|
925
|
-
* @param {TruncateStringOptions} [options] - Optional settings:
|
|
926
|
-
* - `length` (number, default 10): Maximum length of the truncated string.
|
|
927
|
-
* - `ending` (string, default `"..."`): String to append if truncation occurs.
|
|
928
|
-
* - `trim` (boolean, default `true`): Whether to trim the input before truncation.
|
|
929
|
-
* @returns {string} The truncated string with optional trimming and ending.
|
|
930
|
-
* Returns `""` if input is empty or length < 1.
|
|
931
|
-
* @throws {TypeError} If `options.length` is not a finite number,
|
|
932
|
-
* or if `options.ending` is not a string,
|
|
933
|
-
* or if `options.trim` is not a boolean.
|
|
934
|
-
* @example
|
|
935
|
-
* truncateString("hello world", { length: 5 });
|
|
936
|
-
* // ➔ "hello..."
|
|
937
|
-
* truncateString("hello world", { length: 5, ending: "---" });
|
|
938
|
-
* // ➔ "hello---"
|
|
939
|
-
* truncateString("hello world", { length: 5, ending: " " });
|
|
940
|
-
* // ➔ "hello..." (ending trimmed to default)
|
|
941
|
-
* truncateString("hello world", { length: 5, ending: " !!! " });
|
|
942
|
-
* // ➔ "hello!!!" (ending trimmed)
|
|
943
|
-
* truncateString(" long data string ", { length: 8, ending: "...", trim: true });
|
|
944
|
-
* // ➔ "long dat..."
|
|
945
|
-
* truncateString(" long data string ", { length: 8, ending: "...", trim: false });
|
|
946
|
-
* // ➔ " long ..."
|
|
947
|
-
* truncateString(null, { length: 5 });
|
|
948
|
-
* // ➔ ""
|
|
949
|
-
*/
|
|
950
|
-
declare const truncateString:(text:string|null|undefined,options?:TruncateStringOptions)=>string;export{censorEmail,chunkString,formatCurrency,formatDateFns,formatDateIntl,formatDateTime,formatNumber,formatPhoneNumber,getGMTOffset,truncateString};
|