@salespark/toolkit 2.0.1 β 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +783 -572
- package/dist/index.cjs +1130 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +167 -1
- package/dist/index.d.ts +167 -1
- package/dist/index.js +1118 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,572 +1,783 @@
|
|
|
1
|
-
# SalesPark Toolkit v2 - Documentation
|
|
2
|
-
|
|
3
|
-
## @salespark/toolkit
|
|
4
|
-
|
|
5
|
-
Shared toolkit of helpers and utilities for **Node.js**, **React**, and browser environments.
|
|
6
|
-
Tree-shakeable, TypeScript-first, ESM + CJS outputs.
|
|
7
|
-
|
|
8
|
-
[](https://codecov.io/gh/FBlade/salespark-toolkit)
|
|
9
|
-
[](https://www.npmjs.com/package/@salespark/toolkit)
|
|
10
|
-

|
|
11
|
-

|
|
12
|
-

|
|
13
|
-
[](#-license)
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## π¦ Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
yarn add @salespark/toolkit
|
|
21
|
-
# or
|
|
22
|
-
npm i @salespark/toolkit
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## β¨ Features
|
|
26
|
-
|
|
27
|
-
- **Array utilities**: chunk, uniqBy, deep equality, flatten, etc.
|
|
28
|
-
- **Object utilities**: pick, omit, clean objects, etc.
|
|
29
|
-
- **String utilities**: slugify, template fill, deburr, sanitize, etc.
|
|
30
|
-
- **Number utilities**: clamp, round, safe parse, random digits, etc.
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
toBool(
|
|
359
|
-
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
//
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
**`
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
//
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
// Result:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
// Result: true
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
// Result: true
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
// Result:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
// Result:
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
// Result:
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
**`
|
|
469
|
-
|
|
470
|
-
```javascript
|
|
471
|
-
|
|
472
|
-
// Result:
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1
|
+
# SalesPark Toolkit v2 - Documentation
|
|
2
|
+
|
|
3
|
+
## @salespark/toolkit
|
|
4
|
+
|
|
5
|
+
Shared toolkit of helpers and utilities for **Node.js**, **React**, and browser environments.
|
|
6
|
+
Tree-shakeable, TypeScript-first, ESM + CJS outputs.
|
|
7
|
+
|
|
8
|
+
[](https://codecov.io/gh/FBlade/salespark-toolkit)
|
|
9
|
+
[](https://www.npmjs.com/package/@salespark/toolkit)
|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
[](#-license)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## π¦ Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @salespark/toolkit
|
|
21
|
+
# or
|
|
22
|
+
npm i @salespark/toolkit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## β¨ Features
|
|
26
|
+
|
|
27
|
+
- **Array utilities**: chunk, uniqBy, deep equality, flatten, groupBy, etc.
|
|
28
|
+
- **Object utilities**: pick, omit, clean objects, deep merge, etc.
|
|
29
|
+
- **String utilities**: slugify, template fill, deburr, sanitize, etc.
|
|
30
|
+
- **Number utilities**: clamp, round, safe parse, random digits, etc.
|
|
31
|
+
- **Function utilities**: debounce, throttle, formatCurrency, parseName, currency conversions, etc.
|
|
32
|
+
- **Boolean utilities**: safe boolean conversion with common representations
|
|
33
|
+
- **Validation utilities**: IBAN validator (ISO 13616), Portuguese tax ID validator
|
|
34
|
+
- **Security utilities**: Markdown XSS protection, content sanitization, risk assessment
|
|
35
|
+
- **Environment detection**: `isBrowser`, `isNode` runtime checks
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## π Usage
|
|
40
|
+
|
|
41
|
+
Get started in seconds with a few common utilities:
|
|
42
|
+
|
|
43
|
+
### Named Imports (Tree-shakeable)
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import {
|
|
47
|
+
debounce,
|
|
48
|
+
delay,
|
|
49
|
+
chunk,
|
|
50
|
+
slugify,
|
|
51
|
+
clamp,
|
|
52
|
+
isBrowser,
|
|
53
|
+
toBool,
|
|
54
|
+
} from "@salespark/toolkit";
|
|
55
|
+
|
|
56
|
+
// Debounce a function
|
|
57
|
+
const debouncedFn = debounce(() => {
|
|
58
|
+
/* ... */
|
|
59
|
+
}, 200);
|
|
60
|
+
|
|
61
|
+
// Delay execution
|
|
62
|
+
await delay(1000); // Wait 1 second
|
|
63
|
+
|
|
64
|
+
// Chunk an array
|
|
65
|
+
const chunks = chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]]
|
|
66
|
+
|
|
67
|
+
// Slugify a string
|
|
68
|
+
const slug = slugify("OlΓ‘ mundo!"); // "ola-mundo"
|
|
69
|
+
|
|
70
|
+
// Clamp a number
|
|
71
|
+
const safe = clamp(15, 0, 10); // 10
|
|
72
|
+
|
|
73
|
+
// Convert to boolean
|
|
74
|
+
const bool = toBool("yes"); // true
|
|
75
|
+
|
|
76
|
+
// Check environment
|
|
77
|
+
if (isBrowser) {
|
|
78
|
+
/* browser-specific code */
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Lodash-style Import (Alternative)
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import * as _ from "@salespark/toolkit";
|
|
86
|
+
|
|
87
|
+
// Debounce a function
|
|
88
|
+
const debouncedFn = _.debounce(() => {
|
|
89
|
+
/* ... */
|
|
90
|
+
}, 200);
|
|
91
|
+
|
|
92
|
+
// Chunk an array
|
|
93
|
+
const chunks = _.chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]]
|
|
94
|
+
|
|
95
|
+
// Slugify a string
|
|
96
|
+
const slug = _.slugify("OlΓ‘ mundo!"); // "ola-mundo"
|
|
97
|
+
|
|
98
|
+
// Clamp a number
|
|
99
|
+
const safe = _.clamp(15, 0, 10); // 10
|
|
100
|
+
|
|
101
|
+
// Convert to boolean
|
|
102
|
+
const bool = _.toBool("yes"); // true
|
|
103
|
+
|
|
104
|
+
// Check environment
|
|
105
|
+
if (_.isBrowser) {
|
|
106
|
+
/* browser-specific code */
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## π API Reference
|
|
111
|
+
|
|
112
|
+
### π Array Utilities
|
|
113
|
+
|
|
114
|
+
**`chunk<T>(arr: T[], size: number): T[][]`** β Splits an array into equally sized pieces.
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
chunk([1, 2, 3, 4, 5], 2);
|
|
118
|
+
// Result: [[1, 2], [3, 4], [5]]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**`uniq<T>(arr: T[]): T[]`** β Removes duplicate values from an array.
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
uniq([1, 2, 2, 3, 3, 3]);
|
|
125
|
+
// Result: [1, 2, 3]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**`uniqBy<T, K>(arr: T[], key: (v: T) => K): T[]`** β Returns unique items based on a computed key.
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
uniqBy(
|
|
132
|
+
[
|
|
133
|
+
{ id: 1, name: "John" },
|
|
134
|
+
{ id: 2, name: "Jane" },
|
|
135
|
+
{ id: 1, name: "John" },
|
|
136
|
+
],
|
|
137
|
+
(x) => x.id
|
|
138
|
+
);
|
|
139
|
+
// Result: [{id: 1, name: 'John'}, {id: 2, name: 'Jane'}]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**`areArraysEqual<T>(arr1: T[], arr2: T[]): boolean`** β Deeply compares two arrays for equality.
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
areArraysEqual([1, 2, 3], [1, 2, 3]);
|
|
146
|
+
// Result: true
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**`flatten<T>(arr: any[]): T[]`** β Flattens nested arrays into a single array (1 level deep).
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
flatten([1, [2, 3], [4, [5]]]);
|
|
153
|
+
// Result: [1, 2, 3, 4, [5]]
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**`flattenOnce<T>(array): T[]`** β Flattens array a single level deep.
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
flattenOnce([1, [2, 3], [4, 5]]);
|
|
160
|
+
// Result: [1, 2, 3, 4, 5]
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**`flattenDepth<T>(array, depth?, options?): T[]`** β Flattens array up to specified depth.
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
flattenDepth([1, [2, [3, [4]]]], 2);
|
|
167
|
+
// Result: [1, 2, 3, [4]]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**`groupBy<T, K>(arr: T[], key: ((item: T) => K) | K): Record<string, T[]>`** β Groups array items by a key or function.
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
groupBy(
|
|
174
|
+
[
|
|
175
|
+
{ type: "fruit", name: "apple" },
|
|
176
|
+
{ type: "fruit", name: "banana" },
|
|
177
|
+
{ type: "veggie", name: "carrot" },
|
|
178
|
+
],
|
|
179
|
+
"type"
|
|
180
|
+
);
|
|
181
|
+
// Result: {fruit: [{type: 'fruit', name: 'apple'}, {type: 'fruit', name: 'banana'}], veggie: [{type: 'veggie', name: 'carrot'}]}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**`sortBy<T>(arr: T[], key: ((item: T) => any) | keyof T): T[]`** β Sorts array by a key or function.
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
sortBy([{ age: 30 }, { age: 20 }, { age: 25 }], "age");
|
|
188
|
+
// Result: [{age: 20}, {age: 25}, {age: 30}]
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**`difference<T>(arr1: T[], arr2: T[]): T[]`** β Returns elements in arr1 not present in arr2.
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
difference([1, 2, 3, 4], [2, 4, 6]);
|
|
195
|
+
// Result: [1, 3]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**`intersection<T>(arr1: T[], arr2: T[]): T[]`** β Returns elements common to both arrays.
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
intersection([1, 2, 3], [2, 3, 4]);
|
|
202
|
+
// Result: [2, 3]
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**`compact<T>(arr: T[]): T[]`** β Removes falsy values from array.
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
compact([0, 1, false, 2, "", 3, null, undefined, 4]);
|
|
209
|
+
// Result: [1, 2, 3, 4]
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**`pluck<T, K>(arr: T[], key: K): Array<T[K]>`** β Extracts a property from each object in array.
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
pluck(
|
|
216
|
+
[
|
|
217
|
+
{ name: "John", age: 30 },
|
|
218
|
+
{ name: "Jane", age: 25 },
|
|
219
|
+
],
|
|
220
|
+
"name"
|
|
221
|
+
);
|
|
222
|
+
// Result: ['John', 'Jane']
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**`shuffle<T>(arr: T[]): T[]`** β Shuffles array elements randomly.
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
shuffle([1, 2, 3, 4, 5]);
|
|
229
|
+
// Result: [3, 1, 5, 2, 4] (random order)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**`isFlattenable(value: unknown): boolean`** β Checks if a value can be flattened.
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
isFlattenable([1, 2, 3]);
|
|
236
|
+
// Result: true
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**`pushAll<T>(array: T[], values: readonly T[]): T[]`** β Appends all values into array in-place.
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
const arr = [1, 2];
|
|
243
|
+
pushAll(arr, [3, 4, 5]);
|
|
244
|
+
// Result: arr is now [1, 2, 3, 4, 5]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### π¦ Object Utilities
|
|
248
|
+
|
|
249
|
+
**`pick<T, K>(obj: T, keys: K[]): Pick<T, K>`** β Picks specified properties from an object.
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
pick({ name: "John", age: 30, city: "NYC" }, ["name", "age"]);
|
|
253
|
+
// Result: {name: 'John', age: 30}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**`omit<T, K>(obj: T, keys: K[]): Omit<T, K>`** β Omits specified properties from an object.
|
|
257
|
+
|
|
258
|
+
```javascript
|
|
259
|
+
omit({ name: "John", age: 30, city: "NYC" }, ["age"]);
|
|
260
|
+
// Result: {name: 'John', city: 'NYC'}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**`objectToString(obj: unknown): string`** β Converts an object to a clean string without JSON braces.
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
objectToString({ name: "John", age: 30 });
|
|
267
|
+
// Result: "name=John_age=30"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**`cleanObject<T>(obj: T): any`** β Deep-cleans an object by removing null/undefined values.
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
cleanObject({
|
|
274
|
+
name: "John",
|
|
275
|
+
age: null,
|
|
276
|
+
city: undefined,
|
|
277
|
+
data: { valid: true, invalid: null },
|
|
278
|
+
});
|
|
279
|
+
// Result: {name: 'John', data: {valid: true}}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### π€ String Utilities
|
|
283
|
+
|
|
284
|
+
**`slugify(input: string): string`** β Converts a string to a URL-friendly slug.
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
slugify("OlΓ‘ Mundo! Como estΓ‘?");
|
|
288
|
+
// Result: "ola-mundo-como-esta"
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**`fill(template: string, values: Record<string, string|number>): string`** β Fills a template string with values.
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
fill("Hello {name}, you are {age} years old!", { name: "John", age: 30 });
|
|
295
|
+
// Result: "Hello John, you are 30 years old!"
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**`deburr(str: string): string`** β Removes diacritic marks from a string.
|
|
299
|
+
|
|
300
|
+
```javascript
|
|
301
|
+
deburr("cafΓ© rΓ©sumΓ© naΓ―ve");
|
|
302
|
+
// Result: "cafe resume naive"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**`sanitize(input: unknown, maxLength?: number): string`** β Sanitizes input by removing dangerous content.
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
sanitize("<script>alert('hack')</script>Hello World!", 20);
|
|
309
|
+
// Result: "Hello World!"
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### π’ Number Utilities
|
|
313
|
+
|
|
314
|
+
**`clamp(n: number, min: number, max: number): number`** β Restricts a number within min and max bounds.
|
|
315
|
+
|
|
316
|
+
```javascript
|
|
317
|
+
clamp(15, 0, 10);
|
|
318
|
+
// Result: 10
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**`round(n: number, decimals?: number): number`** β Rounds a number to fixed decimal places.
|
|
322
|
+
|
|
323
|
+
```javascript
|
|
324
|
+
round(3.14159, 2);
|
|
325
|
+
// Result: 3.14
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**`toInteger(value: unknown, defaultValue?: number): number`** β Safely converts a value to an integer.
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
toInteger("42.7");
|
|
332
|
+
// Result: 42
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
**`safeParseInt(value: unknown, defaultValue?: number): number`** β Alias for safe integer conversion.
|
|
336
|
+
|
|
337
|
+
```javascript
|
|
338
|
+
safeParseInt("abc", 0);
|
|
339
|
+
// Result: 0
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
**`toNumber(value: unknown, decimals?: number): number`** β Safely parses a value into a number with optional decimal precision.
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
toNumber("123,45", 2);
|
|
346
|
+
// Result: 123.45
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**`randomDigits(length?: number, options?: { charset?: string; noLeadingZero?: boolean }): string`** β Generates a random string of digits with secure randomness when available.
|
|
350
|
+
|
|
351
|
+
```javascript
|
|
352
|
+
randomDigits(6);
|
|
353
|
+
// Result: "482751" (random)
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### β
Boolean Utilities
|
|
357
|
+
|
|
358
|
+
**`toBool(value: unknown, def?: boolean): boolean`** β Converts a value to boolean, supporting common string/number representations.
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
toBool("yes");
|
|
362
|
+
// Result: true
|
|
363
|
+
|
|
364
|
+
toBool("0");
|
|
365
|
+
// Result: false
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### β‘ Function Utilities
|
|
369
|
+
|
|
370
|
+
**`debounce<T>(fn: T, wait?: number): T`** β Returns a debounced version of a function.
|
|
371
|
+
|
|
372
|
+
```javascript
|
|
373
|
+
const debouncedFn = debounce(() => console.log("Called!"), 300);
|
|
374
|
+
debouncedFn(); // Will only execute after 300ms of no further calls
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**`throttle<T>(fn: T, wait?: number): T`** β Returns a throttled version of a function.
|
|
378
|
+
|
|
379
|
+
```javascript
|
|
380
|
+
const throttledFn = throttle(() => console.log("Called!"), 1000);
|
|
381
|
+
throttledFn(); // Will execute at most once per 1000ms
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**`delay(ms: number): Promise<void>`** β Creates a promise that resolves after specified milliseconds.
|
|
385
|
+
|
|
386
|
+
```javascript
|
|
387
|
+
await delay(1000); // Wait 1 second
|
|
388
|
+
await delay(500); // Wait 500ms
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**`isNil(value: unknown): boolean`** β Checks if a value is null or undefined.
|
|
392
|
+
|
|
393
|
+
**`isNilTextOrEmpty(value: unknown): boolean`** β Strict check for `null`, `undefined`, empty string `""`, or textual values `"null"` / `"undefined"` (case-insensitive, trims spaces). Returns `true` in those cases, otherwise `false`.
|
|
394
|
+
|
|
395
|
+
```javascript
|
|
396
|
+
isNilTextOrEmpty(null); // true
|
|
397
|
+
isNilTextOrEmpty("undefined"); // true
|
|
398
|
+
isNilTextOrEmpty(" UNDEFINED "); // true
|
|
399
|
+
isNilTextOrEmpty("null"); // true
|
|
400
|
+
isNilTextOrEmpty(""); // true
|
|
401
|
+
isNilTextOrEmpty("abc"); // false
|
|
402
|
+
isNilTextOrEmpty(0); // false
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
> Deprecated: `isNullUndefinedOrEmptyEnforced` (use `isNilTextOrEmpty`).
|
|
406
|
+
|
|
407
|
+
```javascript
|
|
408
|
+
isNil(null);
|
|
409
|
+
// Result: true
|
|
410
|
+
|
|
411
|
+
isNil(undefined);
|
|
412
|
+
// Result: true
|
|
413
|
+
|
|
414
|
+
isNil(0);
|
|
415
|
+
// Result: false
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
**`isNilText(value: unknown): boolean`** β Checks if value is null/undefined or the text "null"/"undefined".
|
|
419
|
+
|
|
420
|
+
```javascript
|
|
421
|
+
isNilText("null");
|
|
422
|
+
// Result: true
|
|
423
|
+
|
|
424
|
+
isNilText("undefined");
|
|
425
|
+
// Result: true
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
**`isNilOrEmpty(value: unknown): boolean`** β Checks if value is null/undefined or an empty string.
|
|
429
|
+
|
|
430
|
+
```javascript
|
|
431
|
+
isNilOrEmpty("");
|
|
432
|
+
// Result: true
|
|
433
|
+
|
|
434
|
+
isNilOrEmpty(null);
|
|
435
|
+
// Result: true
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
**`hasNilOrEmpty(array: unknown): boolean`** β Checks if any element in array is nil or empty.
|
|
439
|
+
|
|
440
|
+
```javascript
|
|
441
|
+
hasNilOrEmpty([1, "", 3]);
|
|
442
|
+
// Result: true
|
|
443
|
+
|
|
444
|
+
hasNilOrEmpty([1, 2, 3]);
|
|
445
|
+
// Result: false
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
**`isNilEmptyOrZeroLen(value: unknown): boolean`** β Checks if value is nil, empty string, or has zero length.
|
|
449
|
+
|
|
450
|
+
```javascript
|
|
451
|
+
isNilEmptyOrZeroLen([]);
|
|
452
|
+
// Result: true
|
|
453
|
+
|
|
454
|
+
isNilEmptyOrZeroLen("");
|
|
455
|
+
// Result: true
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
**`isNilOrZeroLen(value: unknown): boolean`** β Checks if value is nil or has zero length.
|
|
459
|
+
|
|
460
|
+
```javascript
|
|
461
|
+
isNilOrZeroLen([]);
|
|
462
|
+
// Result: true
|
|
463
|
+
|
|
464
|
+
isNilOrZeroLen(null);
|
|
465
|
+
// Result: true
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**`isNilOrNaN(value: unknown): boolean`** β Checks if value is nil or NaN.
|
|
469
|
+
|
|
470
|
+
```javascript
|
|
471
|
+
isNilOrNaN(NaN);
|
|
472
|
+
// Result: true
|
|
473
|
+
|
|
474
|
+
isNilOrNaN("abc");
|
|
475
|
+
// Result: true (coerced to NaN)
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**`formatBytes(bytes: number, si?: boolean, dp?: number): string`** β Formats bytes as human-readable text.
|
|
479
|
+
|
|
480
|
+
```javascript
|
|
481
|
+
formatBytes(1024);
|
|
482
|
+
// Result: "1.0 KiB"
|
|
483
|
+
|
|
484
|
+
formatBytes(1000, true);
|
|
485
|
+
// Result: "1.0 kB"
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
**`stringSimilarity(s1: string, s2: string): number`** β Returns the similarity between two strings (0..1).
|
|
489
|
+
|
|
490
|
+
```javascript
|
|
491
|
+
stringSimilarity("hello", "hallo");
|
|
492
|
+
// Result: 0.8
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**`addThousandsSpace(value: number | string): string`** β Adds spaces between thousands in a number.
|
|
496
|
+
|
|
497
|
+
```javascript
|
|
498
|
+
addThousandsSpace(1234567);
|
|
499
|
+
// Result: "1 234 567"
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
**`formatCurrency(value: number | string | null | undefined, withoutCurrencySymbol?: boolean, currency?: string, locale?: string): string`** β Formats currency values with configurable currency and locale. Uses modern Intl.NumberFormat with automatic thousands separators, proper decimal handling, and graceful fallback for errors.
|
|
503
|
+
|
|
504
|
+
```javascript
|
|
505
|
+
// Default: EUR currency with Portuguese locale
|
|
506
|
+
formatCurrency(1234.56);
|
|
507
|
+
// Result: "1234,56 β¬"
|
|
508
|
+
|
|
509
|
+
formatCurrency(1000000.123);
|
|
510
|
+
// Result: "1 000 000,12 β¬"
|
|
511
|
+
|
|
512
|
+
formatCurrency(999.9, true);
|
|
513
|
+
// Result: "999,90" (without symbol)
|
|
514
|
+
|
|
515
|
+
// Different currencies
|
|
516
|
+
formatCurrency(1234.56, false, "USD", "en-US");
|
|
517
|
+
// Result: "$1,234.56"
|
|
518
|
+
|
|
519
|
+
formatCurrency(1234.56, false, "GBP", "en-GB");
|
|
520
|
+
// Result: "Β£1,234.56"
|
|
521
|
+
|
|
522
|
+
formatCurrency(1234.56, false, "USD", "pt-PT");
|
|
523
|
+
// Result: "1234,56 US$"
|
|
524
|
+
|
|
525
|
+
formatCurrency(null);
|
|
526
|
+
// Result: "0,00 β¬"
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
**`parseName(name: string | null | undefined): {firstName: string, lastName: string}`** β Extracts first and last name from a full name string. Handles single names, empty inputs, and multi-word names intelligently.
|
|
530
|
+
|
|
531
|
+
```javascript
|
|
532
|
+
parseName("JoΓ£o Silva");
|
|
533
|
+
// Result: { firstName: "JoΓ£o", lastName: "Silva" }
|
|
534
|
+
|
|
535
|
+
parseName("Maria JosΓ© Santos Costa");
|
|
536
|
+
// Result: { firstName: "Maria", lastName: "Costa" }
|
|
537
|
+
|
|
538
|
+
parseName("Ana");
|
|
539
|
+
// Result: { firstName: "Ana", lastName: "" }
|
|
540
|
+
|
|
541
|
+
parseName(" JosΓ© MarΓa GarcΓa ");
|
|
542
|
+
// Result: { firstName: "JosΓ©", lastName: "GarcΓa" }
|
|
543
|
+
|
|
544
|
+
parseName(null);
|
|
545
|
+
// Result: { firstName: "", lastName: "" }
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
**`symbolToCurrency(symbol: string | null | undefined): string`** β Converts currency symbols to ISO 4217 currency codes. Supports 50+ currency symbols including β¬, Β£, $, Β₯, βΉ, β½, β©, βͺ, and many others.
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
symbolToCurrency("β¬");
|
|
552
|
+
// Result: "EUR"
|
|
553
|
+
|
|
554
|
+
symbolToCurrency("$");
|
|
555
|
+
// Result: "USD"
|
|
556
|
+
|
|
557
|
+
symbolToCurrency("β©");
|
|
558
|
+
// Result: "KRW"
|
|
559
|
+
|
|
560
|
+
symbolToCurrency("R$");
|
|
561
|
+
// Result: "BRL"
|
|
562
|
+
|
|
563
|
+
symbolToCurrency("unknown");
|
|
564
|
+
// Result: "EUR" (fallback)
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
**`currencyToSymbol(currency: string | null | undefined): string`** β Converts ISO 4217 currency codes to their corresponding symbols. Supports 50+ currencies with intelligent fallbacks.
|
|
568
|
+
|
|
569
|
+
```javascript
|
|
570
|
+
currencyToSymbol("EUR");
|
|
571
|
+
// Result: "β¬"
|
|
572
|
+
|
|
573
|
+
currencyToSymbol("USD");
|
|
574
|
+
// Result: "$"
|
|
575
|
+
|
|
576
|
+
currencyToSymbol("KRW");
|
|
577
|
+
// Result: "β©"
|
|
578
|
+
|
|
579
|
+
currencyToSymbol("BRL");
|
|
580
|
+
// Result: "R$"
|
|
581
|
+
|
|
582
|
+
currencyToSymbol("UNKNOWN");
|
|
583
|
+
// Result: "β¬" (fallback)
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### π Security Utilities
|
|
587
|
+
|
|
588
|
+
**`checkMarkdownSecurity(text: string | null | undefined): SecurityCheckResult`** β Comprehensive markdown security validation with XSS protection, threat detection, and automatic sanitization.
|
|
589
|
+
|
|
590
|
+
```typescript
|
|
591
|
+
import { checkMarkdownSecurity } from "@salespark/toolkit";
|
|
592
|
+
|
|
593
|
+
// Safe content
|
|
594
|
+
checkMarkdownSecurity("# Hello World\n\nThis is **bold** text.");
|
|
595
|
+
// Result: { isValid: true, text: "...", risks: [], sanitized: false }
|
|
596
|
+
|
|
597
|
+
// Dangerous content with script
|
|
598
|
+
checkMarkdownSecurity('<script>alert("xss")</script>');
|
|
599
|
+
// Result: {
|
|
600
|
+
// isValid: false,
|
|
601
|
+
// text: "",
|
|
602
|
+
// risks: [{ type: "scriptTags", severity: "critical", description: "..." }],
|
|
603
|
+
// sanitized: true
|
|
604
|
+
// }
|
|
605
|
+
|
|
606
|
+
// Content with multiple threats
|
|
607
|
+
checkMarkdownSecurity('<iframe src="evil.com"></iframe><div onclick="bad()">test</div>');
|
|
608
|
+
// Result: Multiple risks detected, sorted by severity
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**`sanitizeMarkdown(text: string | null | undefined): string`** β Aggressive markdown sanitization removing all HTML tags, scripts, and suspicious content.
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
import { sanitizeMarkdown } from "@salespark/toolkit";
|
|
615
|
+
|
|
616
|
+
sanitizeMarkdown('<p>Hello <strong>World</strong></p>');
|
|
617
|
+
// Result: "Hello World"
|
|
618
|
+
|
|
619
|
+
sanitizeMarkdown('javascript:alert("xss")');
|
|
620
|
+
// Result: "alert(\"xss\")"
|
|
621
|
+
|
|
622
|
+
sanitizeMarkdown('<script>alert(1)</script>Safe text');
|
|
623
|
+
// Result: "Safe text"
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
**`assessSecurityRisks(risks: SecurityRisk[]): SecurityAssessment`** β Risk assessment and scoring system with actionable recommendations.
|
|
627
|
+
|
|
628
|
+
```typescript
|
|
629
|
+
import { assessSecurityRisks } from "@salespark/toolkit";
|
|
630
|
+
|
|
631
|
+
const risks = [
|
|
632
|
+
{ type: "scriptTags", severity: "critical", description: "Script injection detected" }
|
|
633
|
+
];
|
|
634
|
+
|
|
635
|
+
assessSecurityRisks(risks);
|
|
636
|
+
// Result: {
|
|
637
|
+
// score: 100,
|
|
638
|
+
// level: "critical",
|
|
639
|
+
// recommendations: [
|
|
640
|
+
// "URGENT: Critical security risks detected - do not render this content",
|
|
641
|
+
// "Always validate content from untrusted sources",
|
|
642
|
+
// "Consider implementing Content Security Policy (CSP)"
|
|
643
|
+
// ]
|
|
644
|
+
// }
|
|
645
|
+
|
|
646
|
+
// Safe content
|
|
647
|
+
assessSecurityRisks([]);
|
|
648
|
+
// Result: { score: 0, level: "safe", recommendations: ["Content appears safe to use"] }
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### β
Validation Utilities
|
|
652
|
+
|
|
653
|
+
**`isPTTaxId(value: string | number): boolean`** β Validates Portuguese Tax ID (NIF) with MOD-11 algorithm and format checking.
|
|
654
|
+
|
|
655
|
+
```typescript
|
|
656
|
+
import { isPTTaxId } from "@salespark/toolkit";
|
|
657
|
+
|
|
658
|
+
isPTTaxId("123456789"); // false (invalid check digit)
|
|
659
|
+
isPTTaxId("123 456 789"); // false (spaces stripped automatically)
|
|
660
|
+
isPTTaxId("513183504"); // true (valid NIF)
|
|
661
|
+
isPTTaxId("423456789"); // false (invalid prefix - 4 not allowed)
|
|
662
|
+
|
|
663
|
+
// Deprecated alias (use isPTTaxId instead)
|
|
664
|
+
// isValidPTTaxId("513183504"); // true
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
**`isValidIBAN(value: string): boolean`** β Validates International Bank Account Numbers (IBAN) according to ISO 13616 standard with country-specific rules.
|
|
668
|
+
|
|
669
|
+
```typescript
|
|
670
|
+
import { isValidIBAN } from "@salespark/toolkit";
|
|
671
|
+
|
|
672
|
+
isValidIBAN("NL91ABNA0417164300"); // true (valid Dutch IBAN)
|
|
673
|
+
isValidIBAN("NL91 ABNA 0417 1643 00"); // true (spaces stripped automatically)
|
|
674
|
+
isValidIBAN("GB29NWBK60161331926819"); // true (valid UK IBAN)
|
|
675
|
+
isValidIBAN("DE89370400440532013000"); // true (valid German IBAN)
|
|
676
|
+
isValidIBAN("NL91ABNA0417164301"); // false (invalid checksum)
|
|
677
|
+
isValidIBAN("XX1234567890"); // false (invalid country code)
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
### π Environment Detection
|
|
681
|
+
|
|
682
|
+
**`isBrowser: boolean`** β True if running in browser.
|
|
683
|
+
|
|
684
|
+
```javascript
|
|
685
|
+
if (isBrowser) {
|
|
686
|
+
console.log("Running in browser");
|
|
687
|
+
}
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
**`isNode: boolean`** β True if running in Node.js.
|
|
691
|
+
|
|
692
|
+
```javascript
|
|
693
|
+
if (isNode) {
|
|
694
|
+
console.log("Running in Node.js");
|
|
695
|
+
}
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
## β οΈ Deprecated Functions
|
|
699
|
+
|
|
700
|
+
The following functions are deprecated but maintained for backward compatibility:
|
|
701
|
+
|
|
702
|
+
### π Array Utilities (Deprecated)
|
|
703
|
+
|
|
704
|
+
- `areArraysDeepEqualUnordered` β Use `areArraysEqual` instead.
|
|
705
|
+
|
|
706
|
+
### β
Boolean Utilities (Deprecated)
|
|
707
|
+
|
|
708
|
+
- `parseToBool` β Use `toBool` instead.
|
|
709
|
+
|
|
710
|
+
### β‘ Function Utilities (Deprecated)
|
|
711
|
+
|
|
712
|
+
- `isNullOrUndefined` β Use `isNil` instead.
|
|
713
|
+
- `isNullOrUndefinedTextInc` β Use `isNilText` instead.
|
|
714
|
+
- `isNullUndefinedOrEmpty` β Use `isNilOrEmpty` instead.
|
|
715
|
+
- `isNullOrUndefinedInArray` β Use `hasNilOrEmpty` instead.
|
|
716
|
+
- `isNullOrUndefinedEmptyOrZero` β Use `isNilEmptyOrZeroLen` instead.
|
|
717
|
+
- `isNullUndefinedOrZero` β Use `isNilOrZeroLen` instead.
|
|
718
|
+
- `isNullOrUndefinedOrNaN` β Use `isNilOrNaN` instead.
|
|
719
|
+
- `humanFileSize` β Use `formatBytes` instead.
|
|
720
|
+
- `getStringSimilarity` β Use `stringSimilarity` instead.
|
|
721
|
+
- `addSpaceBetweenNumbers` β Use `addThousandsSpace` instead.
|
|
722
|
+
|
|
723
|
+
### β
Validation Utilities (Deprecated)
|
|
724
|
+
|
|
725
|
+
> These functions are now in the main API but their legacy aliases are deprecated:
|
|
726
|
+
|
|
727
|
+
- `isValidPTTaxId` β Use `isPTTaxId` instead.
|
|
728
|
+
|
|
729
|
+
### π’ Number Utilities (Deprecated)
|
|
730
|
+
|
|
731
|
+
- `parseToNumber` β Use `toNumber` instead.
|
|
732
|
+
- `otp` β Use `randomDigits` instead.
|
|
733
|
+
|
|
734
|
+
### π€ String Utilities (Deprecated)
|
|
735
|
+
|
|
736
|
+
- `removeDiacritics` β Use `deburr` instead.
|
|
737
|
+
- `basicSanitize` β Use `sanitize` instead.
|
|
738
|
+
|
|
739
|
+
## π·οΈ TypeScript
|
|
740
|
+
|
|
741
|
+
All functions are fully typed for best developer experience.
|
|
742
|
+
|
|
743
|
+
---
|
|
744
|
+
|
|
745
|
+
## π οΈ Support
|
|
746
|
+
|
|
747
|
+
Got stuck? Donβt panic β weβve got you covered.
|
|
748
|
+
|
|
749
|
+
### π€ AI Assistant
|
|
750
|
+
|
|
751
|
+
We built a custom **AI Assistant** trained _only_ on `@salespark/toolkit`.
|
|
752
|
+
It answers implementation and troubleshooting questions in real time:
|
|
753
|
+
|
|
754
|
+
π Ask the Toolkit GPT:
|
|
755
|
+
https://chatgpt.com/g/g-68a9bf25537081918c3b76ae8f353e70-salespark-toolkit-v2
|
|
756
|
+
|
|
757
|
+
_(Free to use with a ChatGPT account)_
|
|
758
|
+
|
|
759
|
+
---
|
|
760
|
+
|
|
761
|
+
### π Internal Usage Notice
|
|
762
|
+
|
|
763
|
+
This package is primarily designed and maintained for internal use within the SalesPark ecosystem.
|
|
764
|
+
While it can technically be used in other Node.js/Mongoose projects, no official support or guarantees are provided outside of SalesPark-managed projects.
|
|
765
|
+
|
|
766
|
+
All code follows the same engineering standards applied across the SalesPark platform, ensuring consistency, reliability, and long-term maintainability of our internal systems.
|
|
767
|
+
|
|
768
|
+
β‘ Note: This package is most efficient and works best when used together with other official SalesPark packages, where interoperability and optimizations are fully leveraged.
|
|
769
|
+
|
|
770
|
+
Disclaimer: This software is provided "as is", without warranties of any kind, express or implied. SalesPark shall not be held liable for any issues, damages, or losses arising from its use outside the intended SalesPark environment.
|
|
771
|
+
|
|
772
|
+
Organization packages: https://www.npmjs.com/org/salespark
|
|
773
|
+
|
|
774
|
+
---
|
|
775
|
+
|
|
776
|
+
## π License
|
|
777
|
+
|
|
778
|
+
MIT Β© [SalesPark](https://salespark.io)
|
|
779
|
+
|
|
780
|
+
---
|
|
781
|
+
|
|
782
|
+
_Document version: 5_
|
|
783
|
+
_Last update: 25-09-2025_
|