expensify-common 2.0.187 → 2.0.189
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/CLI.d.ts +160 -0
- package/dist/CLI.js +282 -0
- package/dist/esm/API.d.ts +11 -0
- package/dist/esm/API.js +786 -0
- package/dist/esm/APIDeferred.d.ts +7 -0
- package/dist/esm/APIDeferred.js +216 -0
- package/dist/esm/BrowserDetect.d.ts +19 -0
- package/dist/esm/BrowserDetect.js +105 -0
- package/dist/esm/CLI.d.ts +160 -0
- package/dist/esm/CLI.js +244 -0
- package/dist/esm/CONST.d.ts +1727 -0
- package/dist/esm/CONST.js +1847 -0
- package/dist/esm/Cookie.d.ts +68 -0
- package/dist/esm/Cookie.js +159 -0
- package/dist/esm/CredentialsWrapper.d.ts +32 -0
- package/dist/esm/CredentialsWrapper.js +46 -0
- package/dist/esm/Device.d.ts +8 -0
- package/dist/esm/Device.js +24 -0
- package/dist/esm/ExpenseRule.d.ts +39 -0
- package/dist/esm/ExpenseRule.js +77 -0
- package/dist/esm/ExpensiMark.d.ts +197 -0
- package/dist/esm/ExpensiMark.js +1374 -0
- package/dist/esm/Func.d.ts +40 -0
- package/dist/esm/Func.js +69 -0
- package/dist/esm/Log.d.ts +3 -0
- package/dist/esm/Log.js +35 -0
- package/dist/esm/Logger.d.ts +82 -0
- package/dist/esm/Logger.js +138 -0
- package/dist/esm/Network.d.ts +6 -0
- package/dist/esm/Network.js +168 -0
- package/dist/esm/Num.d.ts +95 -0
- package/dist/esm/Num.js +190 -0
- package/dist/esm/PageEvent.d.ts +25 -0
- package/dist/esm/PageEvent.js +22 -0
- package/dist/esm/PubSub.d.ts +2 -0
- package/dist/esm/PubSub.js +111 -0
- package/dist/esm/ReportHistoryStore.d.ts +8 -0
- package/dist/esm/ReportHistoryStore.js +199 -0
- package/dist/esm/SafeString.d.ts +8 -0
- package/{lib/SafeString.ts → dist/esm/SafeString.js} +8 -13
- package/dist/esm/Templates.d.ts +58 -0
- package/dist/esm/Templates.js +196 -0
- package/dist/esm/Url.d.ts +10 -0
- package/dist/esm/Url.js +15 -0
- package/dist/esm/components/CopyText.d.ts +45 -0
- package/dist/esm/components/CopyText.js +56 -0
- package/dist/esm/components/StepProgressBar.d.ts +26 -0
- package/dist/esm/components/StepProgressBar.js +40 -0
- package/dist/esm/components/form/element/combobox.d.ts +231 -0
- package/dist/esm/components/form/element/combobox.js +812 -0
- package/dist/esm/components/form/element/dropdown.d.ts +35 -0
- package/dist/esm/components/form/element/dropdown.js +61 -0
- package/dist/esm/components/form/element/dropdownItem.d.ts +55 -0
- package/dist/esm/components/form/element/dropdownItem.js +113 -0
- package/dist/esm/components/form/element/onOffSwitch.d.ts +94 -0
- package/dist/esm/components/form/element/onOffSwitch.js +167 -0
- package/dist/esm/components/form/element/switch.d.ts +58 -0
- package/dist/esm/components/form/element/switch.js +98 -0
- package/dist/esm/fastMerge.d.ts +9 -0
- package/dist/esm/fastMerge.js +58 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/jquery.expensifyIframify.d.ts +9 -0
- package/dist/esm/jquery.expensifyIframify.js +397 -0
- package/dist/esm/md5.d.ts +2 -0
- package/dist/esm/md5.js +170 -0
- package/dist/esm/mixins/PubSub.d.ts +20 -0
- package/dist/esm/mixins/PubSub.js +47 -0
- package/dist/esm/mixins/extraClasses.d.ts +8 -0
- package/dist/esm/mixins/extraClasses.js +37 -0
- package/dist/esm/mixins/validationClasses.d.ts +12 -0
- package/dist/esm/mixins/validationClasses.js +30 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/str.d.ts +604 -0
- package/dist/esm/str.js +1036 -0
- package/dist/esm/tlds.d.ts +2 -0
- package/dist/esm/tlds.js +2 -0
- package/dist/esm/utils.d.ts +30 -0
- package/dist/esm/utils.js +65 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -1
- package/package.json +228 -8
- package/lib/CLI.ts +0 -409
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if parameter is a string or function
|
|
3
|
+
* if it is a function then we will call it with
|
|
4
|
+
* any additional arguments.
|
|
5
|
+
*/
|
|
6
|
+
declare function resultFn(parameter: string): string;
|
|
7
|
+
declare function resultFn<R, A extends unknown[]>(parameter: (...args: A) => R, ...args: A): R;
|
|
8
|
+
declare const Str: {
|
|
9
|
+
/**
|
|
10
|
+
* Return true if the string is ending with the provided suffix
|
|
11
|
+
*
|
|
12
|
+
* @param str String ot search in
|
|
13
|
+
* @param suffix What to look for
|
|
14
|
+
*/
|
|
15
|
+
endsWith(str: string, suffix: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a USD string into th number of cents it represents.
|
|
18
|
+
*
|
|
19
|
+
* @param amountStr A string representing a USD value.
|
|
20
|
+
* @param allowFraction Flag indicating if fractions of cents should be
|
|
21
|
+
* allowed in the output.
|
|
22
|
+
*
|
|
23
|
+
* @returns The cent value of the @p amountStr.
|
|
24
|
+
*/
|
|
25
|
+
fromUSDToNumber(amountStr: string, allowFraction: boolean): number;
|
|
26
|
+
/**
|
|
27
|
+
* Truncates the middle section of a string based on the max allowed length
|
|
28
|
+
*/
|
|
29
|
+
truncateInMiddle(fullStr: string, maxLength: number): string;
|
|
30
|
+
/**
|
|
31
|
+
* Convert new line to <br />
|
|
32
|
+
*/
|
|
33
|
+
nl2br(str: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Decodes the given HTML encoded string.
|
|
36
|
+
*
|
|
37
|
+
* @param s The string to decode.
|
|
38
|
+
* @returns The decoded string.
|
|
39
|
+
*/
|
|
40
|
+
htmlDecode(s: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* HTML encodes the given string.
|
|
43
|
+
*
|
|
44
|
+
* @param s The string to encode.
|
|
45
|
+
* @return string @p s HTML encoded.
|
|
46
|
+
*/
|
|
47
|
+
htmlEncode(s: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes the given HTML encoded string.
|
|
50
|
+
*
|
|
51
|
+
* @param s The string to decode.
|
|
52
|
+
* @returns The decoded string.
|
|
53
|
+
*/
|
|
54
|
+
htmlDecodeWithJQueryOrNative(s: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* HTML encodes the given string.
|
|
57
|
+
*
|
|
58
|
+
* @param s The string to encode.
|
|
59
|
+
* @return string @p s HTML encoded.
|
|
60
|
+
*/
|
|
61
|
+
htmlEncodeWithJQueryOrNative(s: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Escape text while preventing any sort of double escape, so 'X & Y' -> 'X & Y' and 'X & Y' -> 'X & Y'
|
|
64
|
+
*
|
|
65
|
+
* @param s The string to escape
|
|
66
|
+
* @returns The escaped string
|
|
67
|
+
*/
|
|
68
|
+
safeEscape(s: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* HTML encoding insensitive equals.
|
|
71
|
+
*
|
|
72
|
+
* @param first string to compare
|
|
73
|
+
* @param second string to compare
|
|
74
|
+
* @returns True when first === second, ignoring HTML encoding
|
|
75
|
+
*/
|
|
76
|
+
htmlEncodingInsensitiveEquals(first: string, second: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Creates an ID that can be used as an HTML attribute from @p str.
|
|
79
|
+
*
|
|
80
|
+
* @param str A string to create an ID from.
|
|
81
|
+
* @returns The ID string made from @p str.
|
|
82
|
+
*/
|
|
83
|
+
makeID(str: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Extracts an ID made with Str.makeID from a larger string.
|
|
86
|
+
*
|
|
87
|
+
* @param str A string containing an id made with Str.makeID
|
|
88
|
+
* @returns The ID string.
|
|
89
|
+
*/
|
|
90
|
+
extractID(str: string): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Modifies the string so the first letter of each word is capitalized and the
|
|
93
|
+
* rest lowercased.
|
|
94
|
+
*
|
|
95
|
+
* @param val The string to modify
|
|
96
|
+
*/
|
|
97
|
+
recapitalize(val: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Replace all the non alphanumerical character by _
|
|
100
|
+
*/
|
|
101
|
+
sanitizeToAlphaNumeric(input: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Strip out all the non numerical characters
|
|
104
|
+
*/
|
|
105
|
+
stripNonNumeric(input: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Strips all non ascii characters from a string
|
|
108
|
+
* @returns The ascii version of the string.
|
|
109
|
+
*/
|
|
110
|
+
stripNonASCIICharacters(input: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Shortens the @p text to @p length and appends an ellipses to it.
|
|
113
|
+
*
|
|
114
|
+
* The ellipses will only be appended if @p text is longer than the @p length
|
|
115
|
+
* given.
|
|
116
|
+
*
|
|
117
|
+
* @param val The string to reduce in size.
|
|
118
|
+
* @param length The maximal length desired.
|
|
119
|
+
* @returns The shortened @p text.
|
|
120
|
+
*/
|
|
121
|
+
shortenText(val: string, length: number): string;
|
|
122
|
+
/**
|
|
123
|
+
* Returns the byte size of a character
|
|
124
|
+
* @param inputChar You can input more than one character, but it will only return the size of the first
|
|
125
|
+
* one.
|
|
126
|
+
* @returns Byte size of the character
|
|
127
|
+
*/
|
|
128
|
+
getRawByteSize(inputChar: string): number;
|
|
129
|
+
/**
|
|
130
|
+
* Gets the length of a string in bytes, including non-ASCII characters
|
|
131
|
+
* @returns The number of bytes used by string
|
|
132
|
+
*/
|
|
133
|
+
getByteLength(input: string): number;
|
|
134
|
+
/**
|
|
135
|
+
* Shortens the input by max byte size instead of by character length
|
|
136
|
+
* @param maxSize The max size in bytes, e.g. 256
|
|
137
|
+
* @returns Returns a shorted input if the input size exceeds the max
|
|
138
|
+
*/
|
|
139
|
+
shortenByByte(input: string, maxSize: number): string;
|
|
140
|
+
/**
|
|
141
|
+
* Returns true if the haystack begins with the needle
|
|
142
|
+
*
|
|
143
|
+
* @param haystack The full string to be searched
|
|
144
|
+
* @param needle The case-sensitive string to search for
|
|
145
|
+
* @returns True if the haystack starts with the needle.
|
|
146
|
+
*/
|
|
147
|
+
startsWith(haystack: string, needle: string): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Gets the textual value of the given string.
|
|
150
|
+
*
|
|
151
|
+
* @param str The string to fetch the text value from.
|
|
152
|
+
* @returns The text from within the HTML string.
|
|
153
|
+
*/
|
|
154
|
+
stripHTML(str: string): string;
|
|
155
|
+
/**
|
|
156
|
+
* Modifies the string so the first letter of the string is capitalized
|
|
157
|
+
*
|
|
158
|
+
* @param str The string to modify.
|
|
159
|
+
* @returns The recapitalized string.
|
|
160
|
+
*/
|
|
161
|
+
UCFirst(str: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Returns a string containing all the characters str from the beginning
|
|
164
|
+
* of str to the first occurrence of substr.
|
|
165
|
+
* Example: Str.cutAfter( 'hello$%world', '$%' ) // returns 'hello'
|
|
166
|
+
*
|
|
167
|
+
* @param str The string to modify.
|
|
168
|
+
* @param substr The substring to search for.
|
|
169
|
+
* @returns The cut/trimmed string.
|
|
170
|
+
*/
|
|
171
|
+
cutAfter(str: string, substr: string): string;
|
|
172
|
+
/**
|
|
173
|
+
* Returns a string containing all the characters str from after the first
|
|
174
|
+
* occurrence of substr to the end of the string.
|
|
175
|
+
* Example: Str.cutBefore( 'hello$%world', '$%' ) // returns 'world'
|
|
176
|
+
*
|
|
177
|
+
* @param str The string to modify.
|
|
178
|
+
* @param substr The substring to search for.
|
|
179
|
+
* @returns The cut/trimmed string.
|
|
180
|
+
*/
|
|
181
|
+
cutBefore(str: string, substr: string): string;
|
|
182
|
+
/**
|
|
183
|
+
* Checks that the string is a domain name (e.g. example.com)
|
|
184
|
+
*
|
|
185
|
+
* @param str The string to check for domainnameness.
|
|
186
|
+
*
|
|
187
|
+
* @returns True if the string is a domain name
|
|
188
|
+
*/
|
|
189
|
+
isValidDomainName(str: string): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Checks that the string is a valid url
|
|
192
|
+
*
|
|
193
|
+
* @returns True if the string is a valid hyperlink
|
|
194
|
+
*/
|
|
195
|
+
isValidURL(str: string): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Checks that the string is an email address.
|
|
198
|
+
* NOTE: TLDs are not just 2-4 characters. Keep this in sync with _inputrules.php
|
|
199
|
+
*
|
|
200
|
+
* @param str The string to check for email validity.
|
|
201
|
+
*
|
|
202
|
+
* @returns True if the string is an email
|
|
203
|
+
*/
|
|
204
|
+
isValidEmail(str: string): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Checks if the string is an valid email address formed during comment markdown formation.
|
|
207
|
+
*
|
|
208
|
+
* @param str The string to check for email validity.
|
|
209
|
+
*
|
|
210
|
+
* @returns True if the string is an valid email created by comment markdown.
|
|
211
|
+
*/
|
|
212
|
+
isValidEmailMarkdown(str: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Remove trailing comma from a string.
|
|
215
|
+
*
|
|
216
|
+
* @param str The string with any trailing comma to be removed.
|
|
217
|
+
*
|
|
218
|
+
* @returns string with the trailing comma removed
|
|
219
|
+
*/
|
|
220
|
+
removeTrailingComma(str: string): string;
|
|
221
|
+
/**
|
|
222
|
+
* Checks that the string is a list of coma separated email addresss.
|
|
223
|
+
*
|
|
224
|
+
* @param str The string to check for emails validity.
|
|
225
|
+
*
|
|
226
|
+
* @returns True if all emails are valid or if input is empty
|
|
227
|
+
*/
|
|
228
|
+
areValidEmails(str: string): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Extract the email addresses from a string
|
|
231
|
+
*/
|
|
232
|
+
extractEmail(str: string): RegExpMatchArray | null;
|
|
233
|
+
/**
|
|
234
|
+
* Extracts the domain name from the given email address
|
|
235
|
+
* (e.g. "domain.com" for "joe@domain.com").
|
|
236
|
+
*
|
|
237
|
+
* @param email The email address.
|
|
238
|
+
*
|
|
239
|
+
* @returns The domain name in the email address.
|
|
240
|
+
*/
|
|
241
|
+
extractEmailDomain(email: string): string;
|
|
242
|
+
/**
|
|
243
|
+
* Tries to extract the company name from the given email address
|
|
244
|
+
* (e.g. "yelp" for "joe@yelp.co.uk").
|
|
245
|
+
*
|
|
246
|
+
* @param email The email address.
|
|
247
|
+
*
|
|
248
|
+
* @returns The company name in the email address or null.
|
|
249
|
+
*/
|
|
250
|
+
extractCompanyNameFromEmailDomain(email: string): string | null;
|
|
251
|
+
/**
|
|
252
|
+
* Extracts the local part from the given email address
|
|
253
|
+
* (e.g. "joe" for "joe@domain.com").
|
|
254
|
+
*
|
|
255
|
+
* @param email The email address.
|
|
256
|
+
*
|
|
257
|
+
* @returns The local part in the email address.
|
|
258
|
+
*/
|
|
259
|
+
extractEmailLocalPart(email: string): string;
|
|
260
|
+
/**
|
|
261
|
+
* Sanitize phone number to return only numbers. Return null if non valid phone number.
|
|
262
|
+
*/
|
|
263
|
+
sanitizePhoneNumber(str: string): string | null;
|
|
264
|
+
/**
|
|
265
|
+
* Sanitize email. Return null if non valid email.
|
|
266
|
+
*/
|
|
267
|
+
sanitizeEmail(str: string): string | null;
|
|
268
|
+
/**
|
|
269
|
+
* Escapes all special RegExp characters from a string
|
|
270
|
+
*
|
|
271
|
+
* @param str The subject
|
|
272
|
+
*
|
|
273
|
+
* @returns The escaped string
|
|
274
|
+
*/
|
|
275
|
+
escapeForRegExp(str: string): string;
|
|
276
|
+
/**
|
|
277
|
+
* Escapes all special RegExp characters from a string except for the period
|
|
278
|
+
*
|
|
279
|
+
* @param str The subject
|
|
280
|
+
* @returns The escaped string
|
|
281
|
+
*/
|
|
282
|
+
escapeForExpenseRule(str: string): string;
|
|
283
|
+
/**
|
|
284
|
+
* Adds a backslash in front of each of colon
|
|
285
|
+
* if they don't already have a backslash in front of them
|
|
286
|
+
*
|
|
287
|
+
* @param str The subject
|
|
288
|
+
* @returns The escaped string
|
|
289
|
+
*/
|
|
290
|
+
addBackslashBeforeColonsForTagNamesComingFromQBD(str: string): string;
|
|
291
|
+
/**
|
|
292
|
+
* Removes backslashes from string
|
|
293
|
+
* eg: myString\[\]\* -> myString[]*
|
|
294
|
+
*/
|
|
295
|
+
stripBackslashes(str: string): string;
|
|
296
|
+
/**
|
|
297
|
+
* Checks if a string's length is in the specified range
|
|
298
|
+
*
|
|
299
|
+
* @returns true if the length is in the range, false otherwise
|
|
300
|
+
*/
|
|
301
|
+
isOfLength(str: string, minimumLength: number, maximumLength: number): boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Count the number of occurences of needle in haystack.
|
|
304
|
+
* This is faster than counting the results of haystack.match( /needle/g )
|
|
305
|
+
* via http://stackoverflow.com/questions/4009756/how-to-count-string-occurrence-in-string
|
|
306
|
+
*
|
|
307
|
+
* @param haystack The string to look inside of
|
|
308
|
+
* @param needle What we're looking for
|
|
309
|
+
* @param allowOverlapping Defaults to false
|
|
310
|
+
*
|
|
311
|
+
* @returns The number of times needle is in haystack.
|
|
312
|
+
*/
|
|
313
|
+
occurences(haystack: string, needle: string, allowOverlapping: boolean): number;
|
|
314
|
+
/**
|
|
315
|
+
* Uppercases the first letter of each word
|
|
316
|
+
* via https://github.com/kvz/phpjs/blob/master/functions/strings/ucwords.js
|
|
317
|
+
*
|
|
318
|
+
* @param str to uppercase words
|
|
319
|
+
* @returns Uppercase worded string
|
|
320
|
+
*/
|
|
321
|
+
ucwords(str: string): string;
|
|
322
|
+
/**
|
|
323
|
+
* Returns true if the haystack contains the needle
|
|
324
|
+
*
|
|
325
|
+
* @param haystack The full string to be searched
|
|
326
|
+
* @param needle The case-sensitive string to search for
|
|
327
|
+
*
|
|
328
|
+
* @returns Returns true if the haystack contains the needle
|
|
329
|
+
*/
|
|
330
|
+
contains(haystack: string, needle: string): boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Returns true if the haystack contains the needle, ignoring case
|
|
333
|
+
*
|
|
334
|
+
* @param haystack The full string to be searched
|
|
335
|
+
* @param needle The case-insensitive string to search for
|
|
336
|
+
*
|
|
337
|
+
* @returns Returns true if the haystack contains the needle, ignoring case
|
|
338
|
+
*/
|
|
339
|
+
caseInsensitiveContains(haystack: string, needle: string): boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Case insensitive compare function
|
|
342
|
+
*
|
|
343
|
+
* @param strA string to compare
|
|
344
|
+
* @param strB string to compare
|
|
345
|
+
*
|
|
346
|
+
* @returns -1 if first string < second string
|
|
347
|
+
* 1 if first string > second string
|
|
348
|
+
* 0 if first string = second string
|
|
349
|
+
*/
|
|
350
|
+
caseInsensitiveCompare(strA: string, strB: string): 1 | 0 | -1;
|
|
351
|
+
/**
|
|
352
|
+
* Case insensitive equals
|
|
353
|
+
*
|
|
354
|
+
* @param strA string to compare
|
|
355
|
+
* @param strB string to compare
|
|
356
|
+
* @returns true when first == second except for case
|
|
357
|
+
*/
|
|
358
|
+
caseInsensitiveEquals(strA: string, strB: string): boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Compare function
|
|
361
|
+
*
|
|
362
|
+
* @param strA string to compare
|
|
363
|
+
* @param strB string to compare
|
|
364
|
+
*
|
|
365
|
+
* @returns -1 if first string < second string
|
|
366
|
+
* 1 if first string > second string
|
|
367
|
+
* 0 if first string = second string
|
|
368
|
+
*/
|
|
369
|
+
compare(strA: string, strB: string): 1 | 0 | -1;
|
|
370
|
+
/**
|
|
371
|
+
* Check if a file extension is supported by SmartReports
|
|
372
|
+
*/
|
|
373
|
+
isFileExtensionSmartReportsValid(filename: string): boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Mask Permanent Account Number (PAN) the same way Auth does
|
|
376
|
+
* @param num account number
|
|
377
|
+
* @returns masked account number
|
|
378
|
+
*/
|
|
379
|
+
maskPAN(num: number | string): string;
|
|
380
|
+
/**
|
|
381
|
+
* Checks if something is a string
|
|
382
|
+
* Stolen from underscore
|
|
383
|
+
*/
|
|
384
|
+
isString(obj: unknown): obj is string;
|
|
385
|
+
/**
|
|
386
|
+
* Checks if something is a number
|
|
387
|
+
* Stolen from underscore
|
|
388
|
+
* @param obj
|
|
389
|
+
*/
|
|
390
|
+
isNumber(obj: unknown): obj is number;
|
|
391
|
+
/**
|
|
392
|
+
* Checks if something is a certain type
|
|
393
|
+
* Stolen from underscore
|
|
394
|
+
*/
|
|
395
|
+
isTypeOf(obj: unknown, type: "Arguments" | "Function" | "String" | "Number" | "Date" | "RegExp" | "Error" | "Symbol" | "Map" | "WeakMap" | "Set" | "WeakSet"): boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Checks to see if something is undefined
|
|
398
|
+
* Stolen from underscore
|
|
399
|
+
*/
|
|
400
|
+
isUndefined(obj: unknown): boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Replace first N characters of the string with maskChar
|
|
403
|
+
* eg: maskFirstNCharacters( '1234567890', 6, 'X' ) yields XXXXXX7890
|
|
404
|
+
* @param str String to mask
|
|
405
|
+
* @param num Number of characters we want to mask from the string
|
|
406
|
+
* @param mask String we want replace the first N chars with
|
|
407
|
+
* @returns Masked string
|
|
408
|
+
*/
|
|
409
|
+
maskFirstNCharacters(str: string, num: number, mask: string): string;
|
|
410
|
+
/**
|
|
411
|
+
* Trim a string
|
|
412
|
+
*/
|
|
413
|
+
trim(str: string): string;
|
|
414
|
+
/**
|
|
415
|
+
* Convert a percentage string like '25%' to 25/
|
|
416
|
+
* @param percentageString The percentage as a string
|
|
417
|
+
*/
|
|
418
|
+
percentageStringToNumber(percentageString: string): number;
|
|
419
|
+
/**
|
|
420
|
+
* Remove all the spaces from a string
|
|
421
|
+
*/
|
|
422
|
+
removeSpaces(input: string): string;
|
|
423
|
+
/**
|
|
424
|
+
* Returns the proper phrase depending on the count that is passed.
|
|
425
|
+
* Example:
|
|
426
|
+
* console.log(Str.pluralize('puppy', 'puppies', 1)) { // puppy
|
|
427
|
+
* console.log(Str.pluralize('puppy', 'puppies', 3)) { // puppies
|
|
428
|
+
*
|
|
429
|
+
* @param singular form of the phrase
|
|
430
|
+
* @param plural form of the phrase
|
|
431
|
+
* @param num the count which determines the plurality
|
|
432
|
+
*/
|
|
433
|
+
pluralize(singular: string, plural: string, num: number): string;
|
|
434
|
+
/**
|
|
435
|
+
* Returns whether or not a string is an encrypted number or not.
|
|
436
|
+
*
|
|
437
|
+
* @param num that we want to see if its encrypted or not
|
|
438
|
+
*
|
|
439
|
+
* @returns Whether or not this string is an encrpypted number
|
|
440
|
+
*/
|
|
441
|
+
isEncryptedCardNumber(num: string): boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Converts a value to boolean, case-insensitive.
|
|
444
|
+
*/
|
|
445
|
+
toBool(value: unknown): boolean;
|
|
446
|
+
/**
|
|
447
|
+
* Checks if a string could be the masked version of another one.
|
|
448
|
+
*
|
|
449
|
+
* @param strA String to compare
|
|
450
|
+
* @param strB String to compare
|
|
451
|
+
* @param [mask] Defaults to X
|
|
452
|
+
* @returns True when first could be the masked version of second
|
|
453
|
+
*/
|
|
454
|
+
maskedEquals(strA: string, strB: string, mask: string): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Bold any word matching the regexp in the text.
|
|
457
|
+
*/
|
|
458
|
+
boldify(text: string, regexp: RegExp): string;
|
|
459
|
+
/**
|
|
460
|
+
* Check for whether a phone number is valid.
|
|
461
|
+
* @deprecated use isValidE164Phone to validate E.164 phone numbers or isValidPhoneFormat to validate phone numbers in general
|
|
462
|
+
*/
|
|
463
|
+
isValidPhone(phone: string): boolean;
|
|
464
|
+
/**
|
|
465
|
+
* Check for whether a phone number is valid.
|
|
466
|
+
*/
|
|
467
|
+
isValidPhoneNumber(phone: string): boolean;
|
|
468
|
+
/**
|
|
469
|
+
* Check for whether a phone number is valid according to E.164 standard.
|
|
470
|
+
*/
|
|
471
|
+
isValidE164Phone(phone: string): boolean;
|
|
472
|
+
/**
|
|
473
|
+
* Check for whether a phone number is valid in different formats/standards. For example:
|
|
474
|
+
* significant: 4404589784
|
|
475
|
+
* international: +1 440-458-9784
|
|
476
|
+
* e164: +14404589784
|
|
477
|
+
* national: (440) 458-9784
|
|
478
|
+
* 123.456.7890
|
|
479
|
+
*/
|
|
480
|
+
isValidPhoneFormat(phone: string): boolean;
|
|
481
|
+
/**
|
|
482
|
+
* We validate mentions by checking if it's first character is an allowed character.
|
|
483
|
+
*/
|
|
484
|
+
isValidMention(mention: string): boolean;
|
|
485
|
+
/**
|
|
486
|
+
* Returns text without our SMS domain
|
|
487
|
+
*/
|
|
488
|
+
removeSMSDomain(text: string): string;
|
|
489
|
+
/**
|
|
490
|
+
* Returns true if the text is a valid E.164 phone number with our SMS domain removed
|
|
491
|
+
*/
|
|
492
|
+
isSMSLogin(text: string): boolean;
|
|
493
|
+
/**
|
|
494
|
+
* This method will return all matches of a single regex like preg_match_all() in PHP. This is not a common part of
|
|
495
|
+
* JS yet, so this is a good way of doing it according to
|
|
496
|
+
* https://github.com/airbnb/javascript/issues/1439#issuecomment-306297399 and doesn't get us in trouble with
|
|
497
|
+
* linting rules.
|
|
498
|
+
*/
|
|
499
|
+
matchAll(str: string, regex: RegExp): Array<RegExpMatchArray & {
|
|
500
|
+
input: string;
|
|
501
|
+
index: number;
|
|
502
|
+
}>;
|
|
503
|
+
/**
|
|
504
|
+
* A simple GUID generator taken from https://stackoverflow.com/a/32760401/9114791
|
|
505
|
+
*
|
|
506
|
+
* @param [prefix] an optional prefix to put in front of the guid
|
|
507
|
+
*/
|
|
508
|
+
guid(prefix?: string): string;
|
|
509
|
+
/**
|
|
510
|
+
* Takes in a URL and returns it with a leading '/'
|
|
511
|
+
*
|
|
512
|
+
* @param url The URL to be formatted
|
|
513
|
+
* @returns The formatted URL
|
|
514
|
+
*/
|
|
515
|
+
normalizeUrl(url: string): string;
|
|
516
|
+
/**
|
|
517
|
+
* Formats a URL by converting the domain name to lowercase and adding the missing 'https://' protocol.
|
|
518
|
+
*
|
|
519
|
+
* @param url The URL to be formatted
|
|
520
|
+
* @param defaultScheme The Scheme to use in the URL
|
|
521
|
+
* @returns The formatted URL
|
|
522
|
+
*/
|
|
523
|
+
sanitizeURL(url: string, defaultScheme?: string): string;
|
|
524
|
+
/**
|
|
525
|
+
* Checks if parameter is a string or function
|
|
526
|
+
* if it is a function then we will call it with
|
|
527
|
+
* any additional arguments.
|
|
528
|
+
*/
|
|
529
|
+
result: typeof resultFn;
|
|
530
|
+
/**
|
|
531
|
+
* Get file extension for a given url with or
|
|
532
|
+
* without query parameters
|
|
533
|
+
*/
|
|
534
|
+
getExtension(url: string): string | undefined;
|
|
535
|
+
/**
|
|
536
|
+
* Takes in a URL and checks if the file extension is PDF
|
|
537
|
+
*
|
|
538
|
+
* @param url The URL to be checked
|
|
539
|
+
* @returns Whether file path is PDF or not
|
|
540
|
+
*/
|
|
541
|
+
isPDF(url: string): boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Takes in a URL and checks if the file extension is an image
|
|
544
|
+
* that can be rendered by React Native. Do NOT add extensions
|
|
545
|
+
* to this list unless they appear in this list and are
|
|
546
|
+
* supported by all platforms.
|
|
547
|
+
*
|
|
548
|
+
* https://reactnative.dev/docs/image#source
|
|
549
|
+
*/
|
|
550
|
+
isImage(url: string): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Takes in a URL and checks if the file extension is a video
|
|
553
|
+
* that can be rendered by React Native. Do NOT add extensions
|
|
554
|
+
* to this list unless they are supported by all platforms.
|
|
555
|
+
*
|
|
556
|
+
* https://developer.android.com/media/platform/supported-formats#video-formats
|
|
557
|
+
* https://developer.apple.com/documentation/coremedia/1564239-video_codec_constants
|
|
558
|
+
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_codecs
|
|
559
|
+
*/
|
|
560
|
+
isVideo(url: string): boolean;
|
|
561
|
+
/**
|
|
562
|
+
* Checks whether the given string is a +@ domain email account, such as
|
|
563
|
+
* +@domain.com
|
|
564
|
+
*
|
|
565
|
+
* @returns True if is a domain account email, otherwise false.
|
|
566
|
+
*/
|
|
567
|
+
isDomainEmail(email: string): boolean;
|
|
568
|
+
/**
|
|
569
|
+
* Find the minimum indentation of any line in the string,
|
|
570
|
+
* and remove that number of leading spaces from every line in the string.
|
|
571
|
+
*
|
|
572
|
+
* It also removes at most one leading newline, to reflect a common usage:
|
|
573
|
+
*
|
|
574
|
+
* ```
|
|
575
|
+
* Str.dedent(`
|
|
576
|
+
* const myIndentedStr = 'Hello, world!';
|
|
577
|
+
* console.log(myIndentedStr);
|
|
578
|
+
* `)
|
|
579
|
+
* ```
|
|
580
|
+
*
|
|
581
|
+
* This implementation assumes you'd want that to be:
|
|
582
|
+
*
|
|
583
|
+
* ```
|
|
584
|
+
* const myIndentedStr = 'Hello, world!';
|
|
585
|
+
* console.log(myIndentedStr);
|
|
586
|
+
*
|
|
587
|
+
* ```
|
|
588
|
+
*
|
|
589
|
+
* Rather than:
|
|
590
|
+
*
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* const myIndentedStr = 'Hello, world!';
|
|
594
|
+
* console.log(myIndentedStr);
|
|
595
|
+
*
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
dedent(str: string): string;
|
|
599
|
+
/**
|
|
600
|
+
* Polyfill for String.prototype.replaceAll
|
|
601
|
+
*/
|
|
602
|
+
replaceAll(text: string, searchValue: string | RegExp, replaceValue: string | ((...args: unknown[]) => string)): string;
|
|
603
|
+
};
|
|
604
|
+
export default Str;
|