reslib 1.0.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 +298 -0
- package/build/auth/index.d.ts +2034 -0
- package/build/auth/index.js +5 -0
- package/build/auth/types.d.ts +465 -0
- package/build/auth/types.js +1 -0
- package/build/countries/countries.d.ts +1454 -0
- package/build/countries/countries.js +1 -0
- package/build/countries/index.d.ts +159 -0
- package/build/countries/index.js +5 -0
- package/build/countries/types.d.ts +65 -0
- package/build/countries/types.js +1 -0
- package/build/currency/currencies.d.ts +8 -0
- package/build/currency/currencies.js +1 -0
- package/build/currency/index.d.ts +51 -0
- package/build/currency/index.js +5 -0
- package/build/currency/session.d.ts +23 -0
- package/build/currency/session.js +5 -0
- package/build/currency/types.d.ts +1039 -0
- package/build/currency/types.js +1 -0
- package/build/currency/utils.d.ts +25 -0
- package/build/currency/utils.js +1 -0
- package/build/i18n/index.d.ts +640 -0
- package/build/i18n/index.js +5 -0
- package/build/inputFormatter/index.d.ts +396 -0
- package/build/inputFormatter/index.js +5 -0
- package/build/inputFormatter/types.d.ts +544 -0
- package/build/inputFormatter/types.js +1 -0
- package/build/logger/index.d.ts +235 -0
- package/build/logger/index.js +5 -0
- package/build/observable/index.d.ts +329 -0
- package/build/observable/index.js +1 -0
- package/build/platform/index.d.ts +32 -0
- package/build/platform/index.js +1 -0
- package/build/resources/ResourcePaginationHelper.d.ts +537 -0
- package/build/resources/ResourcePaginationHelper.js +2 -0
- package/build/resources/decorators/create.decorator.d.ts +20 -0
- package/build/resources/decorators/create.decorator.js +1 -0
- package/build/resources/decorators/index.d.ts +41 -0
- package/build/resources/decorators/index.js +1 -0
- package/build/resources/fields/index.d.ts +33 -0
- package/build/resources/fields/index.js +1 -0
- package/build/resources/filters.d.ts +62 -0
- package/build/resources/filters.js +1 -0
- package/build/resources/index.d.ts +854 -0
- package/build/resources/index.js +6 -0
- package/build/resources/types/filters.d.ts +508 -0
- package/build/resources/types/filters.js +1 -0
- package/build/resources/types/index.d.ts +4138 -0
- package/build/resources/types/index.js +1 -0
- package/build/session/index.d.ts +1474 -0
- package/build/session/index.js +1 -0
- package/build/translations/auth.en.d.ts +3 -0
- package/build/translations/auth.en.js +1 -0
- package/build/translations/countries.en.d.ts +6 -0
- package/build/translations/countries.en.js +1 -0
- package/build/translations/currencies.en.d.ts +5 -0
- package/build/translations/currencies.en.js +1 -0
- package/build/translations/date.en.d.ts +19 -0
- package/build/translations/date.en.js +1 -0
- package/build/translations/index.d.ts +1583 -0
- package/build/translations/index.js +5 -0
- package/build/translations/resources.en.d.ts +6 -0
- package/build/translations/resources.en.js +1 -0
- package/build/translations/validator.en.d.ts +104 -0
- package/build/translations/validator.en.js +5 -0
- package/build/types/date.d.ts +44 -0
- package/build/types/date.js +1 -0
- package/build/types/dictionary.d.ts +29 -0
- package/build/types/dictionary.js +1 -0
- package/build/types/i18n.d.ts +121 -0
- package/build/types/i18n.js +1 -0
- package/build/types/index.d.ts +145 -0
- package/build/types/index.js +1 -0
- package/build/utils/areEquals.d.ts +19 -0
- package/build/utils/areEquals.js +1 -0
- package/build/utils/date/dateHelper.d.ts +371 -0
- package/build/utils/date/dateHelper.js +5 -0
- package/build/utils/date/index.d.ts +212 -0
- package/build/utils/date/index.js +5 -0
- package/build/utils/date/isDateObj.d.ts +14 -0
- package/build/utils/date/isDateObj.js +1 -0
- package/build/utils/debounce.d.ts +52 -0
- package/build/utils/debounce.js +1 -0
- package/build/utils/defaultArray.d.ts +18 -0
- package/build/utils/defaultArray.js +1 -0
- package/build/utils/defaultBool.d.ts +14 -0
- package/build/utils/defaultBool.js +1 -0
- package/build/utils/defaultStr.d.ts +17 -0
- package/build/utils/defaultStr.js +1 -0
- package/build/utils/defaultVal.d.ts +18 -0
- package/build/utils/defaultVal.js +1 -0
- package/build/utils/dom/index.d.ts +65 -0
- package/build/utils/dom/index.js +1 -0
- package/build/utils/dom/isDOMElement.d.ts +11 -0
- package/build/utils/dom/isDOMElement.js +1 -0
- package/build/utils/file/index.d.ts +26 -0
- package/build/utils/file/index.js +1 -0
- package/build/utils/global.d.ts +53 -0
- package/build/utils/global.js +1 -0
- package/build/utils/image.d.ts +56 -0
- package/build/utils/image.js +1 -0
- package/build/utils/index.d.ts +39 -0
- package/build/utils/index.js +6 -0
- package/build/utils/interpolate.d.ts +105 -0
- package/build/utils/interpolate.js +1 -0
- package/build/utils/isEmail.d.ts +57 -0
- package/build/utils/isEmail.js +1 -0
- package/build/utils/isEmpty.d.ts +18 -0
- package/build/utils/isEmpty.js +1 -0
- package/build/utils/isNonNullString.d.ts +17 -0
- package/build/utils/isNonNullString.js +1 -0
- package/build/utils/isNullable.d.ts +7 -0
- package/build/utils/isNullable.js +1 -0
- package/build/utils/isNumber.d.ts +36 -0
- package/build/utils/isNumber.js +1 -0
- package/build/utils/isPrimitive.d.ts +16 -0
- package/build/utils/isPrimitive.js +1 -0
- package/build/utils/isPromise.d.ts +14 -0
- package/build/utils/isPromise.js +1 -0
- package/build/utils/isRegex.d.ts +15 -0
- package/build/utils/isRegex.js +1 -0
- package/build/utils/isTime.d.ts +18 -0
- package/build/utils/isTime.js +1 -0
- package/build/utils/json.d.ts +224 -0
- package/build/utils/json.js +1 -0
- package/build/utils/numbers.d.ts +148 -0
- package/build/utils/numbers.js +5 -0
- package/build/utils/object.d.ts +567 -0
- package/build/utils/object.js +1 -0
- package/build/utils/sort.d.ts +67 -0
- package/build/utils/sort.js +1 -0
- package/build/utils/string.d.ts +165 -0
- package/build/utils/string.js +1 -0
- package/build/utils/stringify.d.ts +23 -0
- package/build/utils/stringify.js +1 -0
- package/build/utils/uniqid.d.ts +18 -0
- package/build/utils/uniqid.js +1 -0
- package/build/utils/uri/index.d.ts +333 -0
- package/build/utils/uri/index.js +2 -0
- package/build/validator/index.d.ts +4 -0
- package/build/validator/index.js +6 -0
- package/build/validator/rules/array.d.ts +848 -0
- package/build/validator/rules/array.js +5 -0
- package/build/validator/rules/boolean.d.ts +87 -0
- package/build/validator/rules/boolean.js +5 -0
- package/build/validator/rules/date.d.ts +551 -0
- package/build/validator/rules/date.js +5 -0
- package/build/validator/rules/default.d.ts +367 -0
- package/build/validator/rules/default.js +5 -0
- package/build/validator/rules/enum.d.ts +155 -0
- package/build/validator/rules/enum.js +5 -0
- package/build/validator/rules/file.d.ts +356 -0
- package/build/validator/rules/file.js +5 -0
- package/build/validator/rules/format.d.ts +2825 -0
- package/build/validator/rules/format.js +6 -0
- package/build/validator/rules/index.d.ts +16 -0
- package/build/validator/rules/index.js +6 -0
- package/build/validator/rules/multiRules.d.ts +475 -0
- package/build/validator/rules/multiRules.js +5 -0
- package/build/validator/rules/numeric.d.ts +1135 -0
- package/build/validator/rules/numeric.js +5 -0
- package/build/validator/rules/string.d.ts +504 -0
- package/build/validator/rules/string.js +5 -0
- package/build/validator/rules/target.d.ts +137 -0
- package/build/validator/rules/target.js +5 -0
- package/build/validator/rules/utils.d.ts +1 -0
- package/build/validator/rules/utils.js +1 -0
- package/build/validator/rulesMarkers.d.ts +11 -0
- package/build/validator/rulesMarkers.js +1 -0
- package/build/validator/types.d.ts +2906 -0
- package/build/validator/types.js +1 -0
- package/build/validator/validator.d.ts +3692 -0
- package/build/validator/validator.js +5 -0
- package/lib/cjs/auth.js +1 -0
- package/lib/cjs/countries.js +1 -0
- package/lib/cjs/currency.js +1 -0
- package/lib/cjs/i18n.js +1 -0
- package/lib/cjs/inputFormatter.js +1 -0
- package/lib/cjs/logger.js +1 -0
- package/lib/cjs/observable.js +1 -0
- package/lib/cjs/platform.js +1 -0
- package/lib/cjs/resources.js +1 -0
- package/lib/cjs/session.js +1 -0
- package/lib/cjs/types.js +1 -0
- package/lib/cjs/utils.js +1 -0
- package/lib/cjs/validator.js +1 -0
- package/lib/esm/auth.mjs +1 -0
- package/lib/esm/countries.mjs +1 -0
- package/lib/esm/currency.mjs +1 -0
- package/lib/esm/i18n.mjs +1 -0
- package/lib/esm/inputFormatter.mjs +1 -0
- package/lib/esm/logger.mjs +1 -0
- package/lib/esm/observable.mjs +1 -0
- package/lib/esm/platform.mjs +1 -0
- package/lib/esm/resources.mjs +1 -0
- package/lib/esm/session.mjs +1 -0
- package/lib/esm/types.mjs +1 -0
- package/lib/esm/utils.mjs +1 -0
- package/lib/esm/validator.mjs +1 -0
- package/package.json +244 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { CurrencyFormatName } from '../currency/types';
|
|
2
|
+
import { CountryCode } from '../countries/types';
|
|
3
|
+
import { DateFormat } from '../types/date';
|
|
4
|
+
/**
|
|
5
|
+
* Options for formatting a value into a string representation.
|
|
6
|
+
*
|
|
7
|
+
* This interface is used in the `formatValue` function to specify the options
|
|
8
|
+
* for formatting a given value, allowing for flexible and customizable
|
|
9
|
+
* output based on the provided settings.
|
|
10
|
+
*
|
|
11
|
+
* ### Properties:
|
|
12
|
+
* - `value?`: The value to be formatted. This can be of any type and is the
|
|
13
|
+
* main input for the formatting process.
|
|
14
|
+
* - `type?`: The expected type of the input value, which can help in determining
|
|
15
|
+
* the appropriate formatting logic to apply.
|
|
16
|
+
* - `format?`: A predefined or custom format to be used for formatting the parsed
|
|
17
|
+
* value. This allows for dynamic formatting based on the specified type.
|
|
18
|
+
*
|
|
19
|
+
* ### Example Usage:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const options: InputFormatterOptions = {
|
|
22
|
+
* value: 1234.56,
|
|
23
|
+
* type: "number",
|
|
24
|
+
* format: "money" // Example format for monetary values
|
|
25
|
+
* };
|
|
26
|
+
*
|
|
27
|
+
* const formattedValue = formatValue(options);
|
|
28
|
+
* console.log(formattedValue); // Outputs: "$1,234.56" or similar, depending on the format
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* * ```typescript
|
|
32
|
+
* const options: InputFormatterOptions = {
|
|
33
|
+
* value: 1234.56,
|
|
34
|
+
* type: "number",
|
|
35
|
+
* format: "formatUSD" // Example format for monetary values in $USD
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* const formattedValue = formatValue(options);
|
|
39
|
+
* console.log(formattedValue); // Outputs: "$1,234.56" or similar, depending on the format
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface InputFormatterOptions<InputType = any, ValueType = any> {
|
|
43
|
+
value?: ValueType;
|
|
44
|
+
type?: InputType;
|
|
45
|
+
/**
|
|
46
|
+
* This function is used by default to format the parsed or custom value.
|
|
47
|
+
* In an input field, that function or a string used to format the value displayed in the input field.
|
|
48
|
+
* ```ts
|
|
49
|
+
* format : "moneay", //will format the value to money format
|
|
50
|
+
* format : ({value:any,type:ITextInputType,format?:"custom"}) => any; //will format the value to any format
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
format?: InputFormatterValueFormat;
|
|
54
|
+
/***
|
|
55
|
+
* Format for date types
|
|
56
|
+
*/
|
|
57
|
+
dateFormat?: DateFormat;
|
|
58
|
+
/***
|
|
59
|
+
* The phone country code, in case of formatting a phone number, type="tel"
|
|
60
|
+
*/
|
|
61
|
+
phoneCountryCode?: CountryCode;
|
|
62
|
+
/***
|
|
63
|
+
* Whether to abreviate the number
|
|
64
|
+
*/
|
|
65
|
+
abreviateNumber?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Options for formatting a masked input value.
|
|
69
|
+
*
|
|
70
|
+
* This interface provides a set of properties that can be used to customize the behavior of a masked input field.
|
|
71
|
+
* It includes options for specifying the input value, type, mask, and other formatting settings.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const maskOptions: InputFormatterMaskOptions = {
|
|
76
|
+
* value: '12345',
|
|
77
|
+
* type: 'number',
|
|
78
|
+
* mask: ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
|
|
79
|
+
* obfuscationCharacter: '*', // The character to be used for obfuscating the input value.
|
|
80
|
+
* focused: true,
|
|
81
|
+
* placeholder: '_',
|
|
82
|
+
* };
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export interface InputFormatterMaskOptions {
|
|
86
|
+
/**
|
|
87
|
+
* The input value to be formatted.
|
|
88
|
+
*
|
|
89
|
+
* This property can be a string representing the value to be formatted.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const maskOptions: InputFormatterMaskOptions = {
|
|
94
|
+
* value: '12345',
|
|
95
|
+
* };
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
value?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The type of the input value.
|
|
101
|
+
*
|
|
102
|
+
* This property can be a string representing the type of the input value, such as 'number', 'date', etc.
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
type?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The mask to be applied to the input value.
|
|
108
|
+
*
|
|
109
|
+
* This property can be an instance of `InputFormatterMask` or an array of strings or regular expressions.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const maskOptions: InputFormatterMaskOptions = {
|
|
114
|
+
* mask: ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
|
|
115
|
+
* };
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
mask?: InputFormatterMask;
|
|
119
|
+
/**
|
|
120
|
+
* The character to be used for obfuscating the input value.
|
|
121
|
+
* This property defaults to '*' if not specified. It must have a length of 1 not more than 1.
|
|
122
|
+
*
|
|
123
|
+
* This property defaults to '*' if not specified.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const maskOptions: InputFormatterMaskOptions = {
|
|
128
|
+
* obfuscationCharacter: '*',
|
|
129
|
+
* };
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
obfuscationCharacter?: string;
|
|
133
|
+
/**
|
|
134
|
+
* The character to be used as the fill character for the default placeholder.
|
|
135
|
+
The length of the character must be 1 not more than 1.
|
|
136
|
+
Default value is '_'
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const maskOptions: InputFormatterMaskOptions = {
|
|
141
|
+
* placeholderCharacter: '_',
|
|
142
|
+
* };
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
placeholderCharacter?: string;
|
|
146
|
+
/***
|
|
147
|
+
* A function to validate the input value.
|
|
148
|
+
*
|
|
149
|
+
* This function is called with the input value as an argument and should return `true` if the value is valid, and `false` otherwise.
|
|
150
|
+
* It's called only if the input value matches the specified mask.
|
|
151
|
+
* When this function is provided, the `isValid` property of the returned `InputFormatterMaskResult` object will be the result of that function.
|
|
152
|
+
*/
|
|
153
|
+
validate?: (value: string) => boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Whether to add the next mask characters to the end of the input value.
|
|
156
|
+
*
|
|
157
|
+
* This property defaults to `false` if not specified.
|
|
158
|
+
*/
|
|
159
|
+
maskAutoComplete?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @interface InputFormatterNumberMaskOptions
|
|
163
|
+
* Options for formatting a number mask.
|
|
164
|
+
*
|
|
165
|
+
* This interface provides a set of properties that can be used to customize the behavior of a number mask.
|
|
166
|
+
* It includes options for specifying the thousands delimiter, decimal precision, decimal separator, and prefix.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const numberMaskOptions: InputFormatterNumberMaskOptions = {
|
|
171
|
+
* delimiter: '.',
|
|
172
|
+
* precision: 2,
|
|
173
|
+
* separator: ',',
|
|
174
|
+
* prefix: ['$', ' '],
|
|
175
|
+
* };
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export interface InputFormatterNumberMaskOptions {
|
|
179
|
+
/**
|
|
180
|
+
* The character to be used as the thousands delimiter.
|
|
181
|
+
*
|
|
182
|
+
* This property defaults to `"."` if not specified.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const numberMaskOptions: InputFormatterNumberMaskOptions = {
|
|
187
|
+
* delimiter: '.',
|
|
188
|
+
* };
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
delimiter?: string;
|
|
192
|
+
/**
|
|
193
|
+
* The decimal precision.
|
|
194
|
+
*
|
|
195
|
+
* This property defaults to `2` if not specified.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const numberMaskOptions: InputFormatterNumberMaskOptions = {
|
|
200
|
+
* precision: 2,
|
|
201
|
+
* };
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
precision?: number;
|
|
205
|
+
/**
|
|
206
|
+
* The decimal separator character.
|
|
207
|
+
*
|
|
208
|
+
* This property defaults to `","` if not specified.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const numberMaskOptions: InputFormatterNumberMaskOptions = {
|
|
213
|
+
* separator: ',',
|
|
214
|
+
* };
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
separator?: string;
|
|
218
|
+
/**
|
|
219
|
+
* The prefix to be added to the mask result.
|
|
220
|
+
*
|
|
221
|
+
* This property can be an array of strings or regular expressions that will be added to the beginning of the mask result.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const numberMaskOptions: InputFormatterNumberMaskOptions = {
|
|
226
|
+
* prefix: ['$', ' '],
|
|
227
|
+
* };
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
prefix?: InputFormatterMaskArray;
|
|
231
|
+
}
|
|
232
|
+
/***
|
|
233
|
+
* @typedef InputFormatterMaskWithValidation
|
|
234
|
+
* A type representing a mask and a validation function.
|
|
235
|
+
*
|
|
236
|
+
* This type is used to define a mask and a validation function for an input field.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const maskAndValidate: InputFormatterMaskWithValidation = {
|
|
241
|
+
* mask: ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
|
|
242
|
+
* validate: (value: string) => value.length === 10,
|
|
243
|
+
* };
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export interface InputFormatterMaskWithValidation extends Record<string, any> {
|
|
247
|
+
mask: InputFormatterMaskArray;
|
|
248
|
+
validate: (value: string) => boolean;
|
|
249
|
+
countryCode?: CountryCode;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @typedef InputFormatterMaskArray
|
|
253
|
+
* A type representing an array of mask elements.
|
|
254
|
+
*
|
|
255
|
+
* This type can be used to define a mask for an input field, where each element in the array represents a character or a pattern to be matched.
|
|
256
|
+
* When the placeholderCharacter is provided, the obfuscationCharacter is considered only if it is provided or the obfuscationCharacter is provided when calling the formatWithMask method.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const maskArray: InputFormatterMaskArray = ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/];
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export type InputFormatterMaskArray = Array<string | RegExp | [
|
|
264
|
+
mask: RegExp | string,
|
|
265
|
+
placeholderCharacter?: string,
|
|
266
|
+
obfuscationCharacter?: string | false
|
|
267
|
+
]>;
|
|
268
|
+
/**
|
|
269
|
+
* @typedef InputFormatterMask
|
|
270
|
+
* A type representing a mask for an input field.
|
|
271
|
+
*
|
|
272
|
+
* This type can be either a static array of mask elements or a function that returns a dynamic array of mask elements based on the provided options.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const staticMask: InputFormatterMask = ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/];
|
|
277
|
+
* const dynamicMask: InputFormatterMask = (options: InputFormatterOptions) => {
|
|
278
|
+
* if (options.type === 'number') {
|
|
279
|
+
* return ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/];
|
|
280
|
+
* } else {
|
|
281
|
+
* return ['a', 'a', 'a', 'a', 'a'];
|
|
282
|
+
* }
|
|
283
|
+
* };
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
export type InputFormatterMask = InputFormatterMaskArray | ((options: InputFormatterOptions) => InputFormatterMaskArray);
|
|
287
|
+
/**
|
|
288
|
+
* @interface InputFormatterResult
|
|
289
|
+
* Represents the result of a formatted value obtained via the `formatValue` function.
|
|
290
|
+
*
|
|
291
|
+
* This interface extends the `InputFormatterOptions` interface and contains
|
|
292
|
+
* properties that provide information about the formatted value, its type,
|
|
293
|
+
* and the parsed representation.
|
|
294
|
+
*
|
|
295
|
+
* ### Properties:
|
|
296
|
+
* - `formattedValue`:
|
|
297
|
+
* - **Type**: `string`
|
|
298
|
+
* - The formatted representation of the value, which is returned
|
|
299
|
+
* after applying the formatting logic.
|
|
300
|
+
*
|
|
301
|
+
* - `isDecimalType`:
|
|
302
|
+
* - **Type**: `boolean`
|
|
303
|
+
* - Indicates whether the type associated with the function supports
|
|
304
|
+
* decimal values. This property helps determine how to handle the
|
|
305
|
+
* formatted value correctly.
|
|
306
|
+
*
|
|
307
|
+
* - `parsedValue`:
|
|
308
|
+
* - **Type**: `any`
|
|
309
|
+
* - The raw value that was parsed before formatting. By default,
|
|
310
|
+
* this will be a number when the original value is a numeric type.
|
|
311
|
+
*
|
|
312
|
+
* - `decimalValue`:
|
|
313
|
+
* - **Type**: `number`
|
|
314
|
+
* - The decimal representation of the formatted value. This is useful
|
|
315
|
+
* for calculations or further processing of the value as a number.
|
|
316
|
+
*
|
|
317
|
+
* ### Example Usage:
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const result: InputFormatterResult = {
|
|
320
|
+
* formattedValue: "$1,234.56",
|
|
321
|
+
* isDecimalType: true,
|
|
322
|
+
* parsedValue: 1234.56,
|
|
323
|
+
* decimalValue: 1234.56,
|
|
324
|
+
* };
|
|
325
|
+
* console.log(result.formattedValue); // Outputs: "$1,234.56"
|
|
326
|
+
* console.log(result.isDecimalType); // Outputs: true
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export interface InputFormatterResult extends InputFormatterOptions, Partial<InputFormatterMaskResult> {
|
|
330
|
+
formattedValue: string;
|
|
331
|
+
isDecimalType: boolean;
|
|
332
|
+
parsedValue: any;
|
|
333
|
+
decimalValue: number;
|
|
334
|
+
/***
|
|
335
|
+
The date object corresponding to the input value, when the provided type is date, time or datetime
|
|
336
|
+
*/
|
|
337
|
+
dateValue?: Date;
|
|
338
|
+
/****
|
|
339
|
+
there dateFormat used to format the value
|
|
340
|
+
*/
|
|
341
|
+
dateFormat?: DateFormat;
|
|
342
|
+
/***
|
|
343
|
+
* The dial code of the phone number in case of formatting a phone number
|
|
344
|
+
*/
|
|
345
|
+
dialCode?: string;
|
|
346
|
+
/***
|
|
347
|
+
The international value of the phone number of the input value in case of formatting a phone number
|
|
348
|
+
*/
|
|
349
|
+
phoneNumber?: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Represents the result of a masked input value.
|
|
353
|
+
*
|
|
354
|
+
* This interface provides a set of properties that contain the masked, unmasked, and obfuscated values of the input field, as well as the original mask array.
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* const maskResult: InputFormatterMaskResult = {
|
|
359
|
+
* masked: '12345',
|
|
360
|
+
* unmasked: '12345',
|
|
361
|
+
* obfuscated: '*****',
|
|
362
|
+
* maskArray: ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
|
|
363
|
+
* };
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
export interface InputFormatterMaskResult {
|
|
367
|
+
/**
|
|
368
|
+
* The masked value of the input field.
|
|
369
|
+
*
|
|
370
|
+
* This property contains the value of the input field with the mask applied.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* const maskResult: InputFormatterMaskResult = {
|
|
375
|
+
* masked: '12345',
|
|
376
|
+
* };
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
masked: string;
|
|
380
|
+
/**
|
|
381
|
+
* The unmasked value of the input field.
|
|
382
|
+
*
|
|
383
|
+
* This property contains the original value of the input field without the mask applied.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```typescript
|
|
387
|
+
* const maskResult: InputFormatterMaskResult = {
|
|
388
|
+
* unmasked: '12345',
|
|
389
|
+
* };
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
unmasked: string;
|
|
393
|
+
/**
|
|
394
|
+
* The obfuscated value of the input field.
|
|
395
|
+
*
|
|
396
|
+
* This property contains the value of the input field with all characters replaced with an obfuscation character (e.g. '*').
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```typescript
|
|
400
|
+
* const maskResult: InputFormatterMaskResult = {
|
|
401
|
+
* obfuscated: '*****',
|
|
402
|
+
* };
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
obfuscated: string;
|
|
406
|
+
/***
|
|
407
|
+
The auto completed mask value.
|
|
408
|
+
|
|
409
|
+
This property contains the value of the input field with all characters replaced with an obfuscation character (e.g. '*').
|
|
410
|
+
|
|
411
|
+
@example
|
|
412
|
+
```typescript
|
|
413
|
+
const maskResult: InputFormatterMaskResult = {
|
|
414
|
+
maskedAutoCompleted: '*****',
|
|
415
|
+
};
|
|
416
|
+
*/
|
|
417
|
+
maskedAutoCompleted?: string;
|
|
418
|
+
/**
|
|
419
|
+
* The original mask array used to mask the input value.
|
|
420
|
+
*
|
|
421
|
+
* This property contains the array of mask elements that was used to mask the input value.
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```typescript
|
|
425
|
+
* const maskResult: InputFormatterMaskResult = {
|
|
426
|
+
* maskArray: ['(', /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
|
|
427
|
+
* };
|
|
428
|
+
* ```
|
|
429
|
+
* Obfuscation
|
|
430
|
+
* To mark a character as obfuscated, use the RegExp within an array and the second element of the array is not false, like this:
|
|
431
|
+
* ```typescript
|
|
432
|
+
* const creditCardMask = [/\d/, /\d/, /\d/, /\d/, " " [/\d/], [/\d/], [/\d/], [/\d/], " ", [/\d/], [/\d/], [/\d/], [/\d/], " ", /\d/, /\d/, /\d/, /\d/];
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
maskArray: InputFormatterMaskArray;
|
|
436
|
+
/***
|
|
437
|
+
whether the mask has obfuscation
|
|
438
|
+
*/
|
|
439
|
+
maskHasObfuscation: boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Whether to display the obfuscated value in the input field.
|
|
442
|
+
*
|
|
443
|
+
* This property defaults to `false` if not specified.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* const maskOptions: InputFormatterMaskOptions = {
|
|
448
|
+
* showObfuscatedValue: true,
|
|
449
|
+
* };
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
/***
|
|
453
|
+
The character to be used as the fill character for the default placeholder of the input field.
|
|
454
|
+
*/
|
|
455
|
+
placeholder: string;
|
|
456
|
+
/***
|
|
457
|
+
* The masked placeholder
|
|
458
|
+
*/
|
|
459
|
+
maskedPlaceholder: string;
|
|
460
|
+
/***
|
|
461
|
+
* Whether the input value matches the specified mask.
|
|
462
|
+
*/
|
|
463
|
+
isValid: boolean;
|
|
464
|
+
/***
|
|
465
|
+
* Represent an array of replaced non regex mask char from the input value.
|
|
466
|
+
* index : the index of the replaced char in the value
|
|
467
|
+
* maskIndex : the index of the replaced char in the mask
|
|
468
|
+
* from : the char that was replaced. It represents the original char at index index in the value
|
|
469
|
+
* to : the char that was replaced with. It represents the original char at index maskIndex in the mask
|
|
470
|
+
*/
|
|
471
|
+
nonRegexReplacedChars: {
|
|
472
|
+
index: number;
|
|
473
|
+
maskIndex: number;
|
|
474
|
+
from: string;
|
|
475
|
+
to: string;
|
|
476
|
+
valueChar: string;
|
|
477
|
+
maskChar: string;
|
|
478
|
+
}[];
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* @interface
|
|
482
|
+
* Represents a function that formats a field value according to specified options.
|
|
483
|
+
*
|
|
484
|
+
* The formatting can be customized based on the options provided when
|
|
485
|
+
* the `format` function of the `Field` interface is called. This type
|
|
486
|
+
* allows for greater flexibility in defining how field values should
|
|
487
|
+
* be displayed or manipulated.
|
|
488
|
+
*
|
|
489
|
+
* ### Parameters:
|
|
490
|
+
* - `options`:
|
|
491
|
+
* - **Type**: `InputFormatterOptions`
|
|
492
|
+
* - An object containing options for formatting the value. The options may
|
|
493
|
+
* include the value to be formatted, the expected type of the value,
|
|
494
|
+
* and a custom format specification.
|
|
495
|
+
*
|
|
496
|
+
* ### Returns:
|
|
497
|
+
* - **Type**: `string`
|
|
498
|
+
* - The formatted value as a string, based on the provided options.
|
|
499
|
+
*
|
|
500
|
+
* ### Example Usage:
|
|
501
|
+
* ```typescript
|
|
502
|
+
* const customFormatter: InputFormatterValueFunc = (options) => {
|
|
503
|
+
* const { value, format } = options;
|
|
504
|
+
* if (format === 'money') {
|
|
505
|
+
* return `$${parseFloat(value).toFixed(2)}`; // Formats value as money
|
|
506
|
+
* }
|
|
507
|
+
* return String(value); // Default to string conversion
|
|
508
|
+
* };
|
|
509
|
+
*
|
|
510
|
+
* const formattedValue = customFormatter({
|
|
511
|
+
* value: 1234.567,
|
|
512
|
+
* format: 'money'
|
|
513
|
+
* });
|
|
514
|
+
* console.log(formattedValue); // Outputs: "$1234.57"
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
export type InputFormatterValueFunc = (options: InputFormatterOptions) => string;
|
|
518
|
+
/**
|
|
519
|
+
* Represents the format types for value formatting.
|
|
520
|
+
*
|
|
521
|
+
* This type can be used to specify how values should be formatted in an application, such as:
|
|
522
|
+
* - As a standard number
|
|
523
|
+
* - As a monetary value
|
|
524
|
+
* - Using a custom format defined by the user
|
|
525
|
+
*
|
|
526
|
+
* ### Format Options:
|
|
527
|
+
* - `"number"`: For standard numerical formatting.
|
|
528
|
+
* - `"money"`: For formatting values as monetary amounts, following currency rules.
|
|
529
|
+
* - `"custom"`: For user-defined formatting rules.
|
|
530
|
+
* - `CurrencyFormatName`: Represents a specific currency format that adheres to the structure defined in the `CurrencyFormatName` interface.
|
|
531
|
+
*
|
|
532
|
+
* ### Example Usage:
|
|
533
|
+
* ```typescript
|
|
534
|
+
* // Define a value with a money format
|
|
535
|
+
* const moneyValue: InputFormatterValueFormat = "money";
|
|
536
|
+
*
|
|
537
|
+
* // Define a custom format
|
|
538
|
+
* const customValue: InputFormatterValueFormat = "custom";
|
|
539
|
+
*
|
|
540
|
+
* // Define a value using CurrencyFormatName
|
|
541
|
+
* const currencyValue: InputFormatterValueFormat = "formatUSD" | "formatCAD" | "formatEUR" | "formatAED" | "formatAFN" | "formatALL" | "formatAMD" | "formatARS" |;
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
export type InputFormatterValueFormat = 'number' | 'money' | 'custom' | CurrencyFormatName | InputFormatterValueFunc;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';
|