@jsb188/app 1.1.9 → 1.1.11

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.
Files changed (63) hide show
  1. package/package.json +54 -45
  2. package/src/constants/agent.ts +58 -25
  3. package/src/constants/app.ts +18 -14
  4. package/src/constants/billing.ts +92 -92
  5. package/src/constants/emoji.ts +9144 -8936
  6. package/src/constants/other.ts +1 -5
  7. package/src/constants/user.ts +16 -25
  8. package/src/constants/wsActions.ts +35 -0
  9. package/src/i18n/account.ts +129 -107
  10. package/src/i18n/agent.ts +63 -43
  11. package/src/i18n/agentDoc.ts +110 -0
  12. package/src/i18n/app.ts +101 -91
  13. package/src/i18n/auth.ts +119 -102
  14. package/src/i18n/billing.ts +73 -78
  15. package/src/i18n/campaign.ts +217 -0
  16. package/src/i18n/country.ts +248 -248
  17. package/src/i18n/datetime.ts +26 -26
  18. package/src/i18n/error.ts +428 -182
  19. package/src/i18n/field_docs.ts +28 -0
  20. package/src/i18n/form.ts +464 -344
  21. package/src/i18n/index.ts +25 -18
  22. package/src/i18n/log.ts +53 -213
  23. package/src/i18n/memory.ts +39 -0
  24. package/src/i18n/message.ts +3 -4
  25. package/src/i18n/note.ts +17 -0
  26. package/src/i18n/org.ts +115 -109
  27. package/src/i18n/sheet.ts +376 -4
  28. package/src/i18n/workflow.ts +70 -23
  29. package/src/main.ts +66 -62
  30. package/src/platform.ts +25 -24
  31. package/src/types/ai.d.ts +33 -23
  32. package/src/types/app.d.ts +95 -37
  33. package/src/types/auth.d.ts +66 -40
  34. package/src/types/console.d.ts +3 -0
  35. package/src/types/form.d.ts +65 -61
  36. package/src/types/other.d.ts +6 -6
  37. package/src/types.d.ts +12 -14
  38. package/src/utils/account.ts +64 -58
  39. package/src/utils/api.ts +280 -77
  40. package/src/utils/authSession.ts +24 -0
  41. package/src/utils/billing.ts +110 -103
  42. package/src/utils/color.ts +202 -0
  43. package/src/utils/cron.ts +49 -18
  44. package/src/utils/datetime.ts +255 -103
  45. package/src/utils/emoji.ts +107 -84
  46. package/src/utils/expression.ts +867 -0
  47. package/src/utils/interval.ts +80 -0
  48. package/src/utils/logic.ts +209 -36
  49. package/src/utils/managedSession.ts +34 -0
  50. package/src/utils/managedSessionBff.test.ts +60 -0
  51. package/src/utils/managedSessionBff.ts +117 -0
  52. package/src/utils/number.ts +60 -32
  53. package/src/utils/object.ts +198 -30
  54. package/src/utils/promise.ts +27 -0
  55. package/src/utils/queryReset.ts +179 -0
  56. package/src/utils/recurringTask.ts +60 -0
  57. package/src/utils/schema.ts +293 -0
  58. package/src/utils/string.test.ts +220 -208
  59. package/src/utils/string.ts +471 -438
  60. package/src/utils/timeZone.ts +309 -851
  61. package/src/utils/url_client.ts +73 -69
  62. package/tsconfig.json +10 -10
  63. package/src/i18n/product.ts +0 -76
@@ -1,12 +1,12 @@
1
- import i18n from "../i18n/index.ts";
2
- import type { AddressObj } from "../types/other.d.ts";
1
+ import i18n from '../i18n/index.ts';
2
+ import type { AddressObj } from '../types/other.d.ts';
3
3
 
4
4
  /**
5
5
  * Combine list of class names
6
6
  */
7
7
 
8
8
  export function cn(...classNames: (string | boolean | undefined | null)[]) {
9
- return classNames.filter(Boolean).join(" ");
9
+ return classNames.filter(Boolean).join(' ');
10
10
  }
11
11
 
12
12
  /**
@@ -14,25 +14,22 @@ export function cn(...classNames: (string | boolean | undefined | null)[]) {
14
14
  */
15
15
 
16
16
  export function shortenToSpace(
17
- str: string,
18
- len: number = 100,
19
- ellipsis: string = "...",
17
+ str: string,
18
+ len: number = 100,
19
+ ellipsis: string = '...',
20
20
  ): string {
21
- if (!str || str.length < len) {
22
- return str;
23
- }
21
+ if (!str || str.length < len) {
22
+ return str;
23
+ }
24
24
 
25
- const trimmed = str.substring(0, len);
26
- const spaceIndex = trimmed.lastIndexOf(" ");
25
+ const trimmed = str.substring(0, len);
26
+ const spaceIndex = trimmed.lastIndexOf(' ');
27
27
 
28
- if (spaceIndex < 0) {
29
- return trimmed.substring(0, len) + ellipsis;
30
- }
28
+ if (spaceIndex < 0) {
29
+ return trimmed.substring(0, len) + ellipsis;
30
+ }
31
31
 
32
- return (
33
- trimmed.substring(0, Math.min(trimmed.length, spaceIndex)) +
34
- ellipsis
35
- );
32
+ return trimmed.substring(0, Math.min(trimmed.length, spaceIndex)) + ellipsis;
36
33
  }
37
34
 
38
35
  /**
@@ -40,29 +37,30 @@ export function shortenToSpace(
40
37
  */
41
38
 
42
39
  export function guessFirstName(str: string, len: number = 40): string {
43
- let shortened =
44
- str?.replace(/^(a|an|the|da|de|that|there|this|than|then)\b/i, "")
45
- ?.trim() || "";
46
- const spaceIx = shortened.indexOf(" ");
40
+ let shortened =
41
+ str
42
+ ?.replace(/^(a|an|the|da|de|that|there|this|than|then)\b/i, '')
43
+ ?.trim() || '';
44
+ const spaceIx = shortened.indexOf(' ');
47
45
 
48
- if (spaceIx >= 0) {
49
- shortened = shortened.substring(0, spaceIx + 1);
50
- }
46
+ if (spaceIx >= 0) {
47
+ shortened = shortened.substring(0, spaceIx + 1);
48
+ }
51
49
 
52
- if (len < shortened.length) {
53
- shortened = shortened.substring(0, len);
54
- }
50
+ if (len < shortened.length) {
51
+ shortened = shortened.substring(0, len);
52
+ }
55
53
 
56
- const articleReplacedEnd = shortened.replace(
57
- /\b(a|an|the|da|de|that|there|this|than|then)$/i,
58
- "",
59
- );
54
+ const articleReplacedEnd = shortened.replace(
55
+ /\b(a|an|the|da|de|that|there|this|than|then)$/i,
56
+ '',
57
+ );
60
58
 
61
- if (articleReplacedEnd.length < 5) {
62
- return shortened.trim();
63
- }
59
+ if (articleReplacedEnd.length < 5) {
60
+ return shortened.trim();
61
+ }
64
62
 
65
- return articleReplacedEnd.trim();
63
+ return articleReplacedEnd.trim();
66
64
  }
67
65
 
68
66
  /**
@@ -70,24 +68,24 @@ export function guessFirstName(str: string, len: number = 40): string {
70
68
  */
71
69
 
72
70
  export function addIndefiniteArticle(word: string) {
73
- const raw = (word || "").trim().toLowerCase();
74
-
75
- let article;
76
- if (!raw) {
77
- article = "a";
78
- } else if (/^(honest|honor|hour|heir)\b/.test(raw)) {
79
- // Common silent-h words use "an"
80
- article = "an";
81
- } else if (
82
- /^(uni([^nmd]|$)|use|user|euro|one|once|ubiquit|ufo|ukulele)\b/.test(raw)
83
- ) {
84
- // Common "you"/"w" sound starts use "a"
85
- article = "a";
86
- } else {
87
- article = /^[aeiou]/.test(raw) ? "an" : "a";
88
- }
89
-
90
- return `${article} ${word}`;
71
+ const raw = (word || '').trim().toLowerCase();
72
+
73
+ let article;
74
+ if (!raw) {
75
+ article = 'a';
76
+ } else if (/^(honest|honor|hour|heir)\b/.test(raw)) {
77
+ // Common silent-h words use "an"
78
+ article = 'an';
79
+ } else if (
80
+ /^(uni([^nmd]|$)|use|user|euro|one|once|ubiquit|ufo|ukulele)\b/.test(raw)
81
+ ) {
82
+ // Common "you"/"w" sound starts use "a"
83
+ article = 'a';
84
+ } else {
85
+ article = /^[aeiou]/.test(raw) ? 'an' : 'a';
86
+ }
87
+
88
+ return `${article} ${word}`;
91
89
  }
92
90
 
93
91
  /**
@@ -95,10 +93,10 @@ export function addIndefiniteArticle(word: string) {
95
93
  */
96
94
 
97
95
  export function isEmail(str: string) {
98
- // return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str);
99
- const emailRegex =
100
- /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
101
- return !!str && emailRegex.test(str.trim());
96
+ // return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str);
97
+ const emailRegex =
98
+ /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
99
+ return !!str && emailRegex.test(str.trim());
102
100
  }
103
101
 
104
102
  /**
@@ -107,25 +105,22 @@ export function isEmail(str: string) {
107
105
  */
108
106
 
109
107
  export function convertToInternationalPhone(str: string) {
110
- // Check if string has a character that isn't one of [(, ), +, -, " ", 0-9]
111
- if (/[^0-9+\-\s().]/.test(str)) {
112
- // Invalid
113
- return null;
114
- }
115
-
116
- const digits = str.replace(/[^0-9]/g, "");
117
- if (!digits || digits.startsWith("0")) {
118
- // Invalid
119
- return null;
120
- } else if (
121
- !digits.startsWith("1") &&
122
- digits.length === 10
123
- ) {
124
- return "+1" + digits;
125
- }
126
-
127
- // If it doesn't start with a country code, assume it's already in international format
128
- return "+" + digits;
108
+ // Check if string has a character that isn't one of [(, ), +, -, " ", 0-9]
109
+ if (/[^0-9+\-\s().]/.test(str)) {
110
+ // Invalid
111
+ return null;
112
+ }
113
+
114
+ const digits = str.replace(/[^0-9]/g, '');
115
+ if (!digits || digits.startsWith('0')) {
116
+ // Invalid
117
+ return null;
118
+ } else if (!digits.startsWith('1') && digits.length === 10) {
119
+ return '+1' + digits;
120
+ }
121
+
122
+ // If it doesn't start with a country code, assume it's already in international format
123
+ return '+' + digits;
129
124
  }
130
125
 
131
126
  /**
@@ -135,17 +130,17 @@ export function convertToInternationalPhone(str: string) {
135
130
  */
136
131
 
137
132
  export function isPhone(
138
- str: string,
139
- doNotConvertInternational: boolean = false,
133
+ str: string,
134
+ doNotConvertInternational: boolean = false,
140
135
  ) {
141
- let phoneNumber: string | null = str.trim();
142
- if (!doNotConvertInternational) {
143
- phoneNumber = convertToInternationalPhone(phoneNumber);
144
- if (!phoneNumber) {
145
- return false;
146
- }
147
- }
148
- return /^\+[0-9]{7,15}$/.test(phoneNumber);
136
+ let phoneNumber: string | null = str.trim();
137
+ if (!doNotConvertInternational) {
138
+ phoneNumber = convertToInternationalPhone(phoneNumber);
139
+ if (!phoneNumber) {
140
+ return false;
141
+ }
142
+ }
143
+ return /^\+[0-9]{7,15}$/.test(phoneNumber);
149
144
  }
150
145
 
151
146
  /**
@@ -158,22 +153,22 @@ export function isPhone(
158
153
  */
159
154
 
160
155
  export function passwordStrength(str: string, minLength: number = 8) {
161
- const isLongEnough = str.length >= minLength;
162
- const hasLowercase = /[a-z]/.test(str);
163
- const hasUppercase = /[A-Z]/.test(str);
164
- const hasDigit = /\d/.test(str);
165
- const hasSpecial = /\W/.test(str);
166
- const valid = isLongEnough && hasLowercase && hasUppercase && hasDigit &&
167
- hasSpecial;
168
- // return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W)[a-zA-Z\d\W]{8,}$/.test(str);
169
- return {
170
- valid,
171
- isLongEnough,
172
- hasLowercase,
173
- hasUppercase,
174
- hasDigit,
175
- hasSpecial,
176
- };
156
+ const isLongEnough = str.length >= minLength;
157
+ const hasLowercase = /[a-z]/.test(str);
158
+ const hasUppercase = /[A-Z]/.test(str);
159
+ const hasDigit = /\d/.test(str);
160
+ const hasSpecial = /\W/.test(str);
161
+ const valid =
162
+ isLongEnough && hasLowercase && hasUppercase && hasDigit && hasSpecial;
163
+ // return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W)[a-zA-Z\d\W]{8,}$/.test(str);
164
+ return {
165
+ valid,
166
+ isLongEnough,
167
+ hasLowercase,
168
+ hasUppercase,
169
+ hasDigit,
170
+ hasSpecial,
171
+ };
177
172
  }
178
173
 
179
174
  /**
@@ -181,7 +176,7 @@ export function passwordStrength(str: string, minLength: number = 8) {
181
176
  */
182
177
 
183
178
  export function getTimeBasedUnique() {
184
- return Date.now().toString(36) + Math.random().toString(36).substring(2);
179
+ return Date.now().toString(36) + Math.random().toString(36).substring(2);
185
180
  }
186
181
 
187
182
  /**
@@ -189,7 +184,7 @@ export function getTimeBasedUnique() {
189
184
  */
190
185
 
191
186
  export function getAlphanumeric(str: string, space: boolean = false) {
192
- return str.replace(space ? /[^a-z0-9\s]/gi : /[^a-z0-9]/gi, "");
187
+ return str.replace(space ? /[^a-z0-9\s]/gi : /[^a-z0-9]/gi, '');
193
188
  }
194
189
 
195
190
  /**
@@ -197,25 +192,25 @@ export function getAlphanumeric(str: string, space: boolean = false) {
197
192
  */
198
193
 
199
194
  export function getSearchNames(
200
- namesList: (string | null | undefined)[] = [],
195
+ namesList: (string | null | undefined)[] = [],
201
196
  ): string[] {
202
- const parsedNames = (namesList || [])
203
- .flatMap((s) => (s || "").split(/\s*(?:,|;|\n|\band\b)\s*/i))
204
- .map((s) => s.trim())
205
- .filter(Boolean);
197
+ const parsedNames = (namesList || [])
198
+ .flatMap((s) => (s || '').split(/\s*(?:,|;|\n|\band\b)\s*/i))
199
+ .map((s) => s.trim())
200
+ .filter(Boolean);
206
201
 
207
- const uniqueNames: string[] = [];
208
- const seen = new Set<string>();
202
+ const uniqueNames: string[] = [];
203
+ const seen = new Set<string>();
209
204
 
210
- for (const name of parsedNames) {
211
- const key = name.toLowerCase();
212
- if (!seen.has(key)) {
213
- seen.add(key);
214
- uniqueNames.push(name);
215
- }
216
- }
205
+ for (const name of parsedNames) {
206
+ const key = name.toLowerCase();
207
+ if (!seen.has(key)) {
208
+ seen.add(key);
209
+ uniqueNames.push(name);
210
+ }
211
+ }
217
212
 
218
- return uniqueNames;
213
+ return uniqueNames;
219
214
  }
220
215
 
221
216
  /**
@@ -223,17 +218,17 @@ export function getSearchNames(
223
218
  */
224
219
 
225
220
  export function regexFromText(text: string) {
226
- const words = getAlphanumeric(text, true).split(/\s+/).filter((s) =>
227
- s.length >= 2
228
- );
229
- if (!words.length) {
230
- return null;
231
- }
221
+ const words = getAlphanumeric(text, true)
222
+ .split(/\s+/)
223
+ .filter((s) => s.length >= 2);
224
+ if (!words.length) {
225
+ return null;
226
+ }
232
227
 
233
- return new RegExp(
234
- "\\b" + (words.length === 1 ? words[0] : "(?:" + words.join("|") + ")"),
235
- "gi",
236
- );
228
+ return new RegExp(
229
+ '\\b' + (words.length === 1 ? words[0] : '(?:' + words.join('|') + ')'),
230
+ 'gi',
231
+ );
237
232
  }
238
233
 
239
234
  /**
@@ -241,10 +236,10 @@ export function regexFromText(text: string) {
241
236
  */
242
237
 
243
238
  export function ucFirst(str: string) {
244
- if (!str) {
245
- return "";
246
- }
247
- return str.charAt(0).toUpperCase() + str.slice(1);
239
+ if (!str) {
240
+ return '';
241
+ }
242
+ return str.charAt(0).toUpperCase() + str.slice(1);
248
243
  }
249
244
 
250
245
  /**
@@ -252,12 +247,12 @@ export function ucFirst(str: string) {
252
247
  */
253
248
 
254
249
  export function camelCaseToDash(str: string) {
255
- if (/^[A-Z0-9]+$/.test(str)) {
256
- return str.toLowerCase();
257
- }
258
- return str.replace(/[A-Z0-9]/g, (m, i) => {
259
- return `${i ? "-" : ""}${m.toLowerCase()}`;
260
- });
250
+ if (/^[A-Z0-9]+$/.test(str)) {
251
+ return str.toLowerCase();
252
+ }
253
+ return str.replace(/[A-Z0-9]/g, (m, i) => {
254
+ return `${i ? '-' : ''}${m.toLowerCase()}`;
255
+ });
261
256
  }
262
257
 
263
258
  /**
@@ -265,34 +260,40 @@ export function camelCaseToDash(str: string) {
265
260
  */
266
261
 
267
262
  export function shortenToParagraph(
268
- str: string,
269
- len: number,
270
- replaceDoubleLineBreaks?: boolean,
263
+ str: string,
264
+ len: number,
265
+ replaceDoubleLineBreaks?: boolean,
271
266
  ) {
272
- let trimedToParagraph = str || "";
273
- if (replaceDoubleLineBreaks) {
274
- trimedToParagraph = trimedToParagraph.replace(/\n\s*\n/g, "\n");
275
- }
276
-
277
- trimedToParagraph = trimedToParagraph.split("\n").reduce((acc, str) => {
278
- if (acc.done) {
279
- return acc;
280
- }
281
- acc.done = (acc.value.length + str.length) >= len;
282
- acc.value = acc.done ? acc.value : acc.value + "\n" + str;
283
- return acc;
284
- }, {
285
- done: false,
286
- value: "",
287
- }).value.trim();
288
-
289
- if (!trimedToParagraph) {
290
- return shortenToSpace(str || "", len);
291
- } else if (trimedToParagraph.length <= len) {
292
- return trimedToParagraph;
293
- }
294
-
295
- return shortenToSpace(trimedToParagraph, len);
267
+ let trimedToParagraph = str || '';
268
+ if (replaceDoubleLineBreaks) {
269
+ trimedToParagraph = trimedToParagraph.replace(/\n\s*\n/g, '\n');
270
+ }
271
+
272
+ trimedToParagraph = trimedToParagraph
273
+ .split('\n')
274
+ .reduce(
275
+ (acc, str) => {
276
+ if (acc.done) {
277
+ return acc;
278
+ }
279
+ acc.done = acc.value.length + str.length >= len;
280
+ acc.value = acc.done ? acc.value : acc.value + '\n' + str;
281
+ return acc;
282
+ },
283
+ {
284
+ done: false,
285
+ value: '',
286
+ },
287
+ )
288
+ .value.trim();
289
+
290
+ if (!trimedToParagraph) {
291
+ return shortenToSpace(str || '', len);
292
+ } else if (trimedToParagraph.length <= len) {
293
+ return trimedToParagraph;
294
+ }
295
+
296
+ return shortenToSpace(trimedToParagraph, len);
296
297
  }
297
298
 
298
299
  /**
@@ -300,14 +301,14 @@ export function shortenToParagraph(
300
301
  */
301
302
 
302
303
  export function isInvisibleString(str: string) {
303
- if (!str?.trim()) {
304
- return true;
305
- }
304
+ if (!str?.trim()) {
305
+ return true;
306
+ }
306
307
 
307
- // eslint-disable-next-line no-misleading-character-class
308
- const invisRegex = /[ㅤ ️⠀ْٔ]/g;
309
- const checkStr = str.replace(invisRegex, " "); // .replace(/[ㅤ ️⠀]/gi, ' ');
310
- return !checkStr.trim();
308
+ // eslint-disable-next-line no-misleading-character-class
309
+ const invisRegex = /[ㅤ ️⠀ْٔ]/g;
310
+ const checkStr = str.replace(invisRegex, ' '); // .replace(/[ㅤ ️⠀]/gi, ' ');
311
+ return !checkStr.trim();
311
312
  }
312
313
 
313
314
  /**
@@ -317,31 +318,33 @@ export function isInvisibleString(str: string) {
317
318
 
318
319
  type AnyLineItem = string | undefined | false | null;
319
320
  type BuildSingleTextConditionalLine = [
320
- string[],
321
- BuildSingleTextLine | BuildSingleTextLine[],
321
+ string[],
322
+ BuildSingleTextLine | BuildSingleTextLine[],
322
323
  ];
323
324
  type BuildSingleTextConditionalLineGroup = BuildSingleTextConditionalLine[];
324
325
  interface BuildSingleTextFeatureMap {
325
- [key: string]: BuildSingleTextLine | BuildSingleTextLine[];
326
+ [key: string]: BuildSingleTextLine | BuildSingleTextLine[];
326
327
  }
327
328
 
328
329
  export type BuildSingleTextLine =
329
- | AnyLineItem
330
- | BuildSingleTextFeatureMap
331
- | BuildSingleTextConditionalLine
332
- | BuildSingleTextConditionalLineGroup;
330
+ | AnyLineItem
331
+ | BuildSingleTextFeatureMap
332
+ | BuildSingleTextConditionalLine
333
+ | BuildSingleTextConditionalLineGroup;
333
334
 
334
335
  /*
335
336
  * Check whether a buildSingleText line uses the all-features conditional tuple syntax.
336
337
  */
337
338
 
338
339
  function isBuildSingleTextConditionalLine(
339
- line: BuildSingleTextLine | BuildSingleTextLine[],
340
+ line: BuildSingleTextLine | BuildSingleTextLine[],
340
341
  ): line is BuildSingleTextConditionalLine {
341
- return Array.isArray(line) &&
342
- line.length === 2 &&
343
- Array.isArray(line[0]) &&
344
- line[0].every((feature) => typeof feature === "string");
342
+ return (
343
+ Array.isArray(line) &&
344
+ line.length === 2 &&
345
+ Array.isArray(line[0]) &&
346
+ line[0].every((feature) => typeof feature === 'string')
347
+ );
345
348
  }
346
349
 
347
350
  /*
@@ -349,11 +352,13 @@ function isBuildSingleTextConditionalLine(
349
352
  */
350
353
 
351
354
  function isBuildSingleTextConditionalLineGroup(
352
- line: BuildSingleTextLine | BuildSingleTextLine[],
355
+ line: BuildSingleTextLine | BuildSingleTextLine[],
353
356
  ): line is BuildSingleTextConditionalLineGroup {
354
- return Array.isArray(line) &&
355
- line.length > 0 &&
356
- line.every((lineItem) => isBuildSingleTextConditionalLine(lineItem));
357
+ return (
358
+ Array.isArray(line) &&
359
+ line.length > 0 &&
360
+ line.every((lineItem) => isBuildSingleTextConditionalLine(lineItem))
361
+ );
357
362
  }
358
363
 
359
364
  /*
@@ -361,18 +366,18 @@ function isBuildSingleTextConditionalLineGroup(
361
366
  */
362
367
 
363
368
  function doesBuildSingleTextRequirementMatch(
364
- requirement: string,
365
- features: string[],
369
+ requirement: string,
370
+ features: string[],
366
371
  ) {
367
- const isNegatedRequirement = requirement.startsWith("!");
368
- const feature = isNegatedRequirement ? requirement.slice(1) : requirement;
372
+ const isNegatedRequirement = requirement.startsWith('!');
373
+ const feature = isNegatedRequirement ? requirement.slice(1) : requirement;
369
374
 
370
- if (!feature) {
371
- return false;
372
- }
375
+ if (!feature) {
376
+ return false;
377
+ }
373
378
 
374
- const hasFeature = features.includes(feature);
375
- return isNegatedRequirement ? !hasFeature : hasFeature;
379
+ const hasFeature = features.includes(feature);
380
+ return isNegatedRequirement ? !hasFeature : hasFeature;
376
381
  }
377
382
 
378
383
  /*
@@ -380,10 +385,12 @@ function doesBuildSingleTextRequirementMatch(
380
385
  */
381
386
 
382
387
  function doesBuildSingleTextConditionalLineMatch(
383
- conditionalLine: BuildSingleTextConditionalLine,
384
- features: string[],
388
+ conditionalLine: BuildSingleTextConditionalLine,
389
+ features: string[],
385
390
  ) {
386
- return conditionalLine[0].every((feature) => doesBuildSingleTextRequirementMatch(feature, features));
391
+ return conditionalLine[0].every((feature) =>
392
+ doesBuildSingleTextRequirementMatch(feature, features),
393
+ );
387
394
  }
388
395
 
389
396
  /*
@@ -391,88 +398,89 @@ function doesBuildSingleTextConditionalLineMatch(
391
398
  */
392
399
 
393
400
  function getBuildSingleTextConditionalText(
394
- conditionalLines: BuildSingleTextLine | BuildSingleTextLine[],
395
- delemiter: string,
396
- features: string[],
401
+ conditionalLines: BuildSingleTextLine | BuildSingleTextLine[],
402
+ delemiter: string,
403
+ features: string[],
397
404
  ) {
398
- return buildSingleText(
399
- Array.isArray(conditionalLines) &&
400
- !isBuildSingleTextConditionalLine(conditionalLines)
401
- ? conditionalLines
402
- : [conditionalLines],
403
- delemiter,
404
- features,
405
- );
405
+ return buildSingleText(
406
+ Array.isArray(conditionalLines) &&
407
+ !isBuildSingleTextConditionalLine(conditionalLines)
408
+ ? conditionalLines
409
+ : [conditionalLines],
410
+ delemiter,
411
+ features,
412
+ );
406
413
  }
407
414
 
408
415
  export function buildSingleText(
409
- lines: BuildSingleTextLine[],
410
- delemiter: string = "\n",
411
- features: string[] = [],
416
+ lines: BuildSingleTextLine[],
417
+ delemiter: string = '\n',
418
+ features: string[] = [],
412
419
  ) {
413
- return lines
414
- .reduce((acc, line_) => {
415
- const line = line_ || "";
416
- if (isBuildSingleTextConditionalLineGroup(line)) {
417
- const matchedConditionalLine = line.find((conditionalLine) =>
418
- doesBuildSingleTextConditionalLineMatch(conditionalLine, features)
419
- );
420
-
421
- if (!matchedConditionalLine) {
422
- return acc;
423
- }
424
-
425
- const conditionalText = getBuildSingleTextConditionalText(
426
- matchedConditionalLine[1],
427
- delemiter,
428
- features,
429
- );
430
-
431
- if (conditionalText || acc[acc.length - 1] !== "") {
432
- acc.push(conditionalText);
433
- }
434
-
435
- return acc;
436
- }
437
-
438
- if (isBuildSingleTextConditionalLine(line)) {
439
- const [, conditionalLines] = line;
440
-
441
- if (doesBuildSingleTextConditionalLineMatch(line, features)) {
442
- const conditionalText = getBuildSingleTextConditionalText(
443
- conditionalLines,
444
- delemiter,
445
- features,
446
- );
447
-
448
- if (conditionalText || acc[acc.length - 1] !== "") {
449
- acc.push(conditionalText);
450
- }
451
- }
452
-
453
- return acc;
454
- }
455
- if (line && typeof line === "object") {
456
- for (const key in line) {
457
- const lineItem = line[key];
458
- if (features.includes(key)) {
459
- const nextLines = Array.isArray(lineItem) &&
460
- !isBuildSingleTextConditionalLine(lineItem)
461
- ? lineItem
462
- : [lineItem];
463
- acc.push(buildSingleText(nextLines, delemiter, features));
464
- }
465
- }
466
- return acc;
467
- }
468
- if (line || acc[acc.length - 1] !== "") {
469
- acc.push(line);
470
- }
471
- return acc;
472
- }, [] as string[])
473
- .join(delemiter)
474
- .trim()
475
- .replace(/^[ \t]+(?=[A-Za-z0-9])/gm, '');
420
+ return lines
421
+ .reduce((acc, line_) => {
422
+ const line = line_ || '';
423
+ if (isBuildSingleTextConditionalLineGroup(line)) {
424
+ const matchedConditionalLine = line.find((conditionalLine) =>
425
+ doesBuildSingleTextConditionalLineMatch(conditionalLine, features),
426
+ );
427
+
428
+ if (!matchedConditionalLine) {
429
+ return acc;
430
+ }
431
+
432
+ const conditionalText = getBuildSingleTextConditionalText(
433
+ matchedConditionalLine[1],
434
+ delemiter,
435
+ features,
436
+ );
437
+
438
+ if (conditionalText || acc[acc.length - 1] !== '') {
439
+ acc.push(conditionalText);
440
+ }
441
+
442
+ return acc;
443
+ }
444
+
445
+ if (isBuildSingleTextConditionalLine(line)) {
446
+ const [, conditionalLines] = line;
447
+
448
+ if (doesBuildSingleTextConditionalLineMatch(line, features)) {
449
+ const conditionalText = getBuildSingleTextConditionalText(
450
+ conditionalLines,
451
+ delemiter,
452
+ features,
453
+ );
454
+
455
+ if (conditionalText || acc[acc.length - 1] !== '') {
456
+ acc.push(conditionalText);
457
+ }
458
+ }
459
+
460
+ return acc;
461
+ }
462
+ if (line && typeof line === 'object') {
463
+ for (const key in line) {
464
+ const lineItem = line[key];
465
+ if (features.includes(key)) {
466
+ const nextLines =
467
+ Array.isArray(lineItem) &&
468
+ !isBuildSingleTextConditionalLine(lineItem)
469
+ ? lineItem
470
+ : [lineItem];
471
+ acc.push(buildSingleText(nextLines, delemiter, features));
472
+ }
473
+ }
474
+ return acc;
475
+ }
476
+ if (line || acc[acc.length - 1] !== '') {
477
+ acc.push(line);
478
+ }
479
+ return acc;
480
+ }, [] as string[])
481
+ .join(delemiter)
482
+ .trim()
483
+ .replace(/^[ \t]+(?=[A-Za-z0-9])/gm, '');
476
484
  }
477
485
 
478
486
  /**
@@ -485,14 +493,14 @@ export function buildSingleText(
485
493
  */
486
494
 
487
495
  export function joinReadable(
488
- texts: (string | null | undefined)[],
489
- separator: string = ", ",
490
- lastSeparator: string = " and ",
496
+ texts: (string | null | undefined)[],
497
+ separator: string = ', ',
498
+ lastSeparator: string = ' and ',
491
499
  ): string {
492
- const lastIx = texts.length - 1;
493
- return texts.filter(Boolean).reduce<string>((acc, text, i) => {
494
- return acc + (!acc ? "" : i === lastIx ? lastSeparator : separator) + text;
495
- }, "");
500
+ const lastIx = texts.length - 1;
501
+ return texts.filter(Boolean).reduce<string>((acc, text, i) => {
502
+ return acc + (!acc ? '' : i === lastIx ? lastSeparator : separator) + text;
503
+ }, '');
496
504
  }
497
505
 
498
506
  /**
@@ -505,22 +513,22 @@ export function joinReadable(
505
513
  */
506
514
 
507
515
  export function textWithBrackets(
508
- text: string,
509
- bracketsText?: string | string[],
510
- brackets: [string, string] = ["(", ")"],
516
+ text: string,
517
+ bracketsText?: string | string[],
518
+ brackets: [string, string] = ['(', ')'],
511
519
  ) {
512
- let bText;
513
- if (Array.isArray(bracketsText)) {
514
- bText = bracketsText.filter(Boolean).join(" ").trim();
515
- } else {
516
- bText = bracketsText?.trim();
517
- }
518
- if (!bText) {
519
- return text;
520
- } else if (!text) {
521
- return bText;
522
- }
523
- return `${text} ${brackets[0].trimStart()}${bText}${brackets[1].trimEnd()}`;
520
+ let bText;
521
+ if (Array.isArray(bracketsText)) {
522
+ bText = bracketsText.filter(Boolean).join(' ').trim();
523
+ } else {
524
+ bText = bracketsText?.trim();
525
+ }
526
+ if (!bText) {
527
+ return text;
528
+ } else if (!text) {
529
+ return bText;
530
+ }
531
+ return `${text} ${brackets[0].trimStart()}${bText}${brackets[1].trimEnd()}`;
524
532
  }
525
533
 
526
534
  /**
@@ -532,11 +540,11 @@ export function textWithBrackets(
532
540
  */
533
541
 
534
542
  export function removeGeneratedTextGarbage(str: string) {
535
- if (!str || typeof str !== "string") {
536
- return "";
537
- }
538
- // Remove all line breaks and spaces
539
- return str.replace(/[\n\r\s]+/g, " ").trim();
543
+ if (!str || typeof str !== 'string') {
544
+ return '';
545
+ }
546
+ // Remove all line breaks and spaces
547
+ return str.replace(/[\n\r\s]+/g, ' ').trim();
540
548
  }
541
549
 
542
550
  /**
@@ -546,10 +554,10 @@ export function removeGeneratedTextGarbage(str: string) {
546
554
  */
547
555
 
548
556
  export function escapeCSVValue(value: string): string {
549
- if (/[",\n]/.test(value)) {
550
- return `"${value.replace(/"/g, '""')}"`;
551
- }
552
- return value;
557
+ if (/[",\n]/.test(value)) {
558
+ return `"${value.replace(/"/g, '""')}"`;
559
+ }
560
+ return value;
553
561
  }
554
562
 
555
563
  /**
@@ -557,14 +565,14 @@ export function escapeCSVValue(value: string): string {
557
565
  */
558
566
 
559
567
  export function truncateFileName(fileName: string, maxLen = 34) {
560
- if (fileName.length <= maxLen) {
561
- return fileName;
562
- }
568
+ if (fileName.length <= maxLen) {
569
+ return fileName;
570
+ }
563
571
 
564
- const extIndex = fileName.lastIndexOf(".");
565
- const ext = extIndex > 0 ? fileName.slice(extIndex) : "";
566
- const headLen = Math.max(1, maxLen - ext.length - 3);
567
- return fileName.slice(0, headLen) + "..." + ext;
572
+ const extIndex = fileName.lastIndexOf('.');
573
+ const ext = extIndex > 0 ? fileName.slice(extIndex) : '';
574
+ const headLen = Math.max(1, maxLen - ext.length - 3);
575
+ return fileName.slice(0, headLen) + '...' + ext;
568
576
  }
569
577
 
570
578
  /**
@@ -573,23 +581,24 @@ export function truncateFileName(fileName: string, maxLen = 34) {
573
581
  */
574
582
 
575
583
  export function formatPhoneNumber(phone?: string | null) {
576
- const match = phone?.match(/(\d{3})(\d{3})(\d{4})$/);
577
- if (match) {
578
- const [, area, first, second] = match;
579
- const countryCode = phone!.substring(
580
- 0,
581
- phone!.length - area.length - first.length - second.length,
582
- ).trim();
583
- const normalizedCountryCode = countryCode
584
- ? countryCode.startsWith("+") ? countryCode : `+${countryCode}`
585
- : "";
586
- // NOTE: This does not account for non North American (+1) phone numbers
587
- return `${normalizedCountryCode}${
588
- normalizedCountryCode ? " " : ""
589
- }(${area}) ${first}-${second}`;
590
- }
591
-
592
- return phone;
584
+ const match = phone?.match(/(\d{3})(\d{3})(\d{4})$/);
585
+ if (match) {
586
+ const [, area, first, second] = match;
587
+ const countryCode = phone!
588
+ .substring(0, phone!.length - area.length - first.length - second.length)
589
+ .trim();
590
+ const normalizedCountryCode = countryCode
591
+ ? countryCode.startsWith('+')
592
+ ? countryCode
593
+ : `+${countryCode}`
594
+ : '';
595
+ // NOTE: This does not account for non North American (+1) phone numbers
596
+ return `${normalizedCountryCode}${
597
+ normalizedCountryCode ? ' ' : ''
598
+ }(${area}) ${first}-${second}`;
599
+ }
600
+
601
+ return phone;
593
602
  }
594
603
 
595
604
  /**
@@ -601,49 +610,50 @@ export function formatPhoneNumber(phone?: string | null) {
601
610
  */
602
611
 
603
612
  export function splitTextIntoChunks(
604
- text: string,
605
- chunkSize: number,
606
- linebreakDistance: number = 50,
613
+ text: string,
614
+ chunkSize: number,
615
+ linebreakDistance: number = 50,
607
616
  ): string[] {
608
- if (!text || chunkSize <= 0 || text.length < chunkSize) {
609
- return [text || ""];
610
- }
611
-
612
- const chunks: string[] = [];
613
- let start = 0;
614
-
615
- while (start < text.length) {
616
- let end = Math.min(start + chunkSize, text.length);
617
-
618
- if (end < text.length) {
619
- // Find the nearest line break around the target chunk boundary
620
- const beforeBreak = text.lastIndexOf("\n", end);
621
-
622
- let chosenBreak = -1;
623
- if (
624
- beforeBreak !== -1 && end - beforeBreak <= linebreakDistance &&
625
- beforeBreak > start
626
- ) {
627
- chosenBreak = beforeBreak + 1;
628
- }
629
-
630
- if (chosenBreak !== -1) {
631
- end = chosenBreak;
632
- } else {
633
- // Fall back to last whitespace near the end
634
- const lastSpace = text.lastIndexOf(" ", end);
635
- if (lastSpace > start && end - lastSpace < 100) {
636
- end = lastSpace;
637
- }
638
- }
639
- }
640
-
641
- const chunk = text.slice(start, end).trim();
642
- if (chunk) chunks.push(chunk);
643
- start = end;
644
- }
645
-
646
- return chunks;
617
+ if (!text || chunkSize <= 0 || text.length < chunkSize) {
618
+ return [text || ''];
619
+ }
620
+
621
+ const chunks: string[] = [];
622
+ let start = 0;
623
+
624
+ while (start < text.length) {
625
+ let end = Math.min(start + chunkSize, text.length);
626
+
627
+ if (end < text.length) {
628
+ // Find the nearest line break around the target chunk boundary
629
+ const beforeBreak = text.lastIndexOf('\n', end);
630
+
631
+ let chosenBreak = -1;
632
+ if (
633
+ beforeBreak !== -1 &&
634
+ end - beforeBreak <= linebreakDistance &&
635
+ beforeBreak > start
636
+ ) {
637
+ chosenBreak = beforeBreak + 1;
638
+ }
639
+
640
+ if (chosenBreak !== -1) {
641
+ end = chosenBreak;
642
+ } else {
643
+ // Fall back to last whitespace near the end
644
+ const lastSpace = text.lastIndexOf(' ', end);
645
+ if (lastSpace > start && end - lastSpace < 100) {
646
+ end = lastSpace;
647
+ }
648
+ }
649
+ }
650
+
651
+ const chunk = text.slice(start, end).trim();
652
+ if (chunk) chunks.push(chunk);
653
+ start = end;
654
+ }
655
+
656
+ return chunks;
647
657
  }
648
658
 
649
659
  /**
@@ -651,10 +661,10 @@ export function splitTextIntoChunks(
651
661
  */
652
662
 
653
663
  export function formatReferenceNumber(idStr: string) {
654
- if (idStr && /^\d+$/.test(idStr)) {
655
- return "#" + idStr;
656
- }
657
- return idStr;
664
+ if (idStr && /^\d+$/.test(idStr)) {
665
+ return '#' + idStr;
666
+ }
667
+ return idStr;
658
668
  }
659
669
 
660
670
  /**
@@ -664,18 +674,18 @@ export function formatReferenceNumber(idStr: string) {
664
674
  */
665
675
 
666
676
  export function getNthString(num: number): string {
667
- const mod10 = num % 10;
668
- const mod100 = num % 100;
677
+ const mod10 = num % 10;
678
+ const mod100 = num % 100;
669
679
 
670
- if (mod10 === 1 && mod100 !== 11) {
671
- return `${num}st`;
672
- } else if (mod10 === 2 && mod100 !== 12) {
673
- return `${num}nd`;
674
- } else if (mod10 === 3 && mod100 !== 13) {
675
- return `${num}rd`;
676
- } else {
677
- return `${num}th`;
678
- }
680
+ if (mod10 === 1 && mod100 !== 11) {
681
+ return `${num}st`;
682
+ } else if (mod10 === 2 && mod100 !== 12) {
683
+ return `${num}nd`;
684
+ } else if (mod10 === 3 && mod100 !== 13) {
685
+ return `${num}rd`;
686
+ } else {
687
+ return `${num}th`;
688
+ }
679
689
  }
680
690
 
681
691
  /**
@@ -687,47 +697,51 @@ export function getNthString(num: number): string {
687
697
  */
688
698
 
689
699
  export function makeAddressText(
690
- address: Partial<AddressObj>,
691
- format: "REGION_ONLY" | "SINGLE_LINE" | "NORMAL" = "NORMAL",
692
- useFullCountryName: boolean = false,
693
- delimiter: string = ", ",
700
+ address: Partial<AddressObj>,
701
+ format: 'REGION_ONLY' | 'SINGLE_LINE' | 'NORMAL' = 'NORMAL',
702
+ useFullCountryName: boolean = false,
703
+ delimiter: string = ', ',
694
704
  ) {
695
- if (!address) {
696
- return null;
697
- }
698
-
699
- const countryName =
700
- useFullCountryName && i18n.has(`country.from_code.${address.country}`)
701
- ? i18n.t(`country.from_code.${address.country}`)
702
- : address.country;
703
-
704
- if (format === "REGION_ONLY") {
705
- return [
706
- address.city,
707
- address.state,
708
- countryName,
709
- ].filter(Boolean).join(delimiter);
710
- } else if (format === "SINGLE_LINE") {
711
- return [
712
- address.line1,
713
- address.line2,
714
- address.city,
715
- address.state,
716
- address.postalCode,
717
- countryName,
718
- ].filter(Boolean).join(delimiter);
719
- }
720
-
721
- // NORMAL format
722
- return [
723
- address.line1,
724
- address.line2,
725
- [
726
- [address.city, address.state].filter(Boolean).join(", "),
727
- address.postalCode,
728
- ].filter(Boolean).join(" "),
729
- countryName,
730
- ].filter(Boolean).join("\n");
705
+ if (!address) {
706
+ return null;
707
+ }
708
+
709
+ const countryName =
710
+ useFullCountryName && i18n.has(`country.from_code.${address.country}`)
711
+ ? i18n.t(`country.from_code.${address.country}`)
712
+ : address.country;
713
+
714
+ if (format === 'REGION_ONLY') {
715
+ return [address.city, address.state, countryName]
716
+ .filter(Boolean)
717
+ .join(delimiter);
718
+ } else if (format === 'SINGLE_LINE') {
719
+ return [
720
+ address.line1,
721
+ address.line2,
722
+ address.city,
723
+ address.state,
724
+ address.postalCode,
725
+ countryName,
726
+ ]
727
+ .filter(Boolean)
728
+ .join(delimiter);
729
+ }
730
+
731
+ // NORMAL format
732
+ return [
733
+ address.line1,
734
+ address.line2,
735
+ [
736
+ [address.city, address.state].filter(Boolean).join(', '),
737
+ address.postalCode,
738
+ ]
739
+ .filter(Boolean)
740
+ .join(' '),
741
+ countryName,
742
+ ]
743
+ .filter(Boolean)
744
+ .join('\n');
731
745
  }
732
746
 
733
747
  /**
@@ -735,12 +749,31 @@ export function makeAddressText(
735
749
  * @returns Formatted display name
736
750
  */
737
751
 
738
- export function getDisplayName(firstName?: string | null, lastName?: string | null) {
739
- const fullName = buildSingleText([firstName, lastName], ' ');
740
- const displayName = guessFirstName(fullName, 8) || '?';
752
+ export function getDisplayName(
753
+ firstName?: string | null,
754
+ lastName?: string | null,
755
+ ) {
756
+ const fullName = buildSingleText([firstName, lastName], ' ');
757
+ const displayName = guessFirstName(fullName, 8) || '?';
758
+
759
+ return {
760
+ fullName,
761
+ displayName,
762
+ };
763
+ }
764
+
765
+ /**
766
+ * Hash a string with FNV-1a (32-bit) into a short stable hex token.
767
+ * @returns 8-character hexadecimal hash string
768
+ */
769
+
770
+ export function hashStringFNV1a(value: string) {
771
+ let hash = 0x811c9dc5;
772
+
773
+ for (let i = 0; i < value.length; i++) {
774
+ hash ^= value.charCodeAt(i);
775
+ hash = Math.imul(hash, 0x01000193);
776
+ }
741
777
 
742
- return {
743
- fullName,
744
- displayName
745
- };
778
+ return (hash >>> 0).toString(16).padStart(8, '0');
746
779
  }