@jsb188/app 1.1.10 → 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.
- package/package.json +54 -45
- package/src/constants/agent.ts +58 -25
- package/src/constants/app.ts +18 -14
- package/src/constants/billing.ts +92 -92
- package/src/constants/emoji.ts +9144 -8936
- package/src/constants/other.ts +1 -5
- package/src/constants/user.ts +16 -25
- package/src/constants/wsActions.ts +35 -0
- package/src/i18n/account.ts +129 -107
- package/src/i18n/agent.ts +63 -43
- package/src/i18n/agentDoc.ts +110 -0
- package/src/i18n/app.ts +101 -91
- package/src/i18n/auth.ts +119 -102
- package/src/i18n/billing.ts +73 -78
- package/src/i18n/campaign.ts +217 -0
- package/src/i18n/country.ts +248 -248
- package/src/i18n/datetime.ts +26 -26
- package/src/i18n/error.ts +428 -182
- package/src/i18n/field_docs.ts +28 -0
- package/src/i18n/form.ts +464 -344
- package/src/i18n/index.ts +25 -18
- package/src/i18n/log.ts +53 -213
- package/src/i18n/memory.ts +39 -0
- package/src/i18n/message.ts +3 -4
- package/src/i18n/note.ts +17 -0
- package/src/i18n/org.ts +115 -109
- package/src/i18n/sheet.ts +376 -4
- package/src/i18n/workflow.ts +70 -23
- package/src/main.ts +66 -62
- package/src/platform.ts +25 -24
- package/src/types/ai.d.ts +33 -23
- package/src/types/app.d.ts +95 -37
- package/src/types/auth.d.ts +66 -40
- package/src/types/console.d.ts +3 -0
- package/src/types/form.d.ts +65 -61
- package/src/types/other.d.ts +6 -6
- package/src/types.d.ts +12 -14
- package/src/utils/account.ts +64 -58
- package/src/utils/api.ts +280 -77
- package/src/utils/authSession.ts +24 -0
- package/src/utils/billing.ts +110 -103
- package/src/utils/color.ts +202 -0
- package/src/utils/cron.ts +49 -18
- package/src/utils/datetime.ts +255 -103
- package/src/utils/emoji.ts +107 -84
- package/src/utils/expression.ts +867 -0
- package/src/utils/interval.ts +80 -0
- package/src/utils/logic.ts +209 -36
- package/src/utils/managedSession.ts +34 -0
- package/src/utils/managedSessionBff.test.ts +60 -0
- package/src/utils/managedSessionBff.ts +117 -0
- package/src/utils/number.ts +60 -32
- package/src/utils/object.ts +198 -30
- package/src/utils/promise.ts +27 -0
- package/src/utils/queryReset.ts +179 -0
- package/src/utils/recurringTask.ts +60 -0
- package/src/utils/schema.ts +293 -0
- package/src/utils/string.test.ts +220 -208
- package/src/utils/string.ts +471 -438
- package/src/utils/timeZone.ts +309 -851
- package/src/utils/url_client.ts +73 -69
- package/tsconfig.json +10 -10
- package/src/i18n/product.ts +0 -76
package/src/utils/string.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import i18n from
|
|
2
|
-
import type { AddressObj } from
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
str: string,
|
|
18
|
+
len: number = 100,
|
|
19
|
+
ellipsis: string = '...',
|
|
20
20
|
): string {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
if (!str || str.length < len) {
|
|
22
|
+
return str;
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const trimmed = str.substring(0, len);
|
|
26
|
+
const spaceIndex = trimmed.lastIndexOf(' ');
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (spaceIndex < 0) {
|
|
29
|
+
return trimmed.substring(0, len) + ellipsis;
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (spaceIx >= 0) {
|
|
47
|
+
shortened = shortened.substring(0, spaceIx + 1);
|
|
48
|
+
}
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if (len < shortened.length) {
|
|
51
|
+
shortened = shortened.substring(0, len);
|
|
52
|
+
}
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
if (articleReplacedEnd.length < 5) {
|
|
60
|
+
return shortened.trim();
|
|
61
|
+
}
|
|
64
62
|
|
|
65
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
139
|
-
|
|
133
|
+
str: string,
|
|
134
|
+
doNotConvertInternational: boolean = false,
|
|
140
135
|
) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
195
|
+
namesList: (string | null | undefined)[] = [],
|
|
201
196
|
): string[] {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
208
|
-
|
|
202
|
+
const uniqueNames: string[] = [];
|
|
203
|
+
const seen = new Set<string>();
|
|
209
204
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
str: string,
|
|
264
|
+
len: number,
|
|
265
|
+
replaceDoubleLineBreaks?: boolean,
|
|
271
266
|
) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
if (!str?.trim()) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
306
307
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
321
|
-
|
|
321
|
+
string[],
|
|
322
|
+
BuildSingleTextLine | BuildSingleTextLine[],
|
|
322
323
|
];
|
|
323
324
|
type BuildSingleTextConditionalLineGroup = BuildSingleTextConditionalLine[];
|
|
324
325
|
interface BuildSingleTextFeatureMap {
|
|
325
|
-
|
|
326
|
+
[key: string]: BuildSingleTextLine | BuildSingleTextLine[];
|
|
326
327
|
}
|
|
327
328
|
|
|
328
329
|
export type BuildSingleTextLine =
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
340
|
+
line: BuildSingleTextLine | BuildSingleTextLine[],
|
|
340
341
|
): line is BuildSingleTextConditionalLine {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
355
|
+
line: BuildSingleTextLine | BuildSingleTextLine[],
|
|
353
356
|
): line is BuildSingleTextConditionalLineGroup {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
365
|
-
|
|
369
|
+
requirement: string,
|
|
370
|
+
features: string[],
|
|
366
371
|
) {
|
|
367
|
-
|
|
368
|
-
|
|
372
|
+
const isNegatedRequirement = requirement.startsWith('!');
|
|
373
|
+
const feature = isNegatedRequirement ? requirement.slice(1) : requirement;
|
|
369
374
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
375
|
+
if (!feature) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
373
378
|
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
384
|
-
|
|
388
|
+
conditionalLine: BuildSingleTextConditionalLine,
|
|
389
|
+
features: string[],
|
|
385
390
|
) {
|
|
386
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
401
|
+
conditionalLines: BuildSingleTextLine | BuildSingleTextLine[],
|
|
402
|
+
delemiter: string,
|
|
403
|
+
features: string[],
|
|
397
404
|
) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
lines: BuildSingleTextLine[],
|
|
417
|
+
delemiter: string = '\n',
|
|
418
|
+
features: string[] = [],
|
|
412
419
|
) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
496
|
+
texts: (string | null | undefined)[],
|
|
497
|
+
separator: string = ', ',
|
|
498
|
+
lastSeparator: string = ' and ',
|
|
491
499
|
): string {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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
|
-
|
|
509
|
-
|
|
510
|
-
|
|
516
|
+
text: string,
|
|
517
|
+
bracketsText?: string | string[],
|
|
518
|
+
brackets: [string, string] = ['(', ')'],
|
|
511
519
|
) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
-
|
|
561
|
-
|
|
562
|
-
|
|
568
|
+
if (fileName.length <= maxLen) {
|
|
569
|
+
return fileName;
|
|
570
|
+
}
|
|
563
571
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
-
|
|
605
|
-
|
|
606
|
-
|
|
613
|
+
text: string,
|
|
614
|
+
chunkSize: number,
|
|
615
|
+
linebreakDistance: number = 50,
|
|
607
616
|
): string[] {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
-
|
|
668
|
-
|
|
677
|
+
const mod10 = num % 10;
|
|
678
|
+
const mod100 = num % 100;
|
|
669
679
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
700
|
+
address: Partial<AddressObj>,
|
|
701
|
+
format: 'REGION_ONLY' | 'SINGLE_LINE' | 'NORMAL' = 'NORMAL',
|
|
702
|
+
useFullCountryName: boolean = false,
|
|
703
|
+
delimiter: string = ', ',
|
|
694
704
|
) {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
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(
|
|
739
|
-
|
|
740
|
-
|
|
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
|
-
|
|
743
|
-
fullName,
|
|
744
|
-
displayName
|
|
745
|
-
};
|
|
778
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
746
779
|
}
|