topkat-utils 1.0.48 → 1.0.49
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/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/utils.ts +4 -5
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/utils.ts
CHANGED
|
@@ -841,10 +841,7 @@ function getId(obj: any = {}): string {
|
|
|
841
841
|
else if (isType(obj, 'objectId')) return obj.toString();
|
|
842
842
|
}
|
|
843
843
|
|
|
844
|
-
|
|
845
|
-
* @returns {array} return values of all callbacks
|
|
846
|
-
*/
|
|
847
|
-
function forI(nbIterations: number, callback: (number: number, previousValue, arrayOfPreviousValues: any[]) => void | any) {
|
|
844
|
+
function forI<T extends any[] | any>(nbIterations: number, callback: (number: number, previousValue, arrayOfPreviousValues: any[]) => T): T[] {
|
|
848
845
|
const results = []
|
|
849
846
|
for (let i = 0; i < nbIterations; i++) {
|
|
850
847
|
const prevValue = results[results.length - 1]
|
|
@@ -853,7 +850,7 @@ function forI(nbIterations: number, callback: (number: number, previousValue, ar
|
|
|
853
850
|
return results
|
|
854
851
|
}
|
|
855
852
|
|
|
856
|
-
async function forIasync(nbIterations: number, callback: (number) =>
|
|
853
|
+
async function forIasync<T extends any[] | any>(nbIterations: number, callback: (number) => T): Promise<T[]> {
|
|
857
854
|
const results = []
|
|
858
855
|
for (let i = 0; i < nbIterations; i++) {
|
|
859
856
|
results.push(await callback(i))
|
|
@@ -1328,6 +1325,7 @@ function validatorReturnErrArray(...paramsToValidate: ValidatorObject[]): [strin
|
|
|
1328
1325
|
'bigint',
|
|
1329
1326
|
'year',
|
|
1330
1327
|
'any',
|
|
1328
|
+
'email',
|
|
1331
1329
|
//...Object.keys(configFn().customTypes)
|
|
1332
1330
|
];
|
|
1333
1331
|
|
|
@@ -1347,6 +1345,7 @@ function validatorReturnErrArray(...paramsToValidate: ValidatorObject[]): [strin
|
|
|
1347
1345
|
object: val => !Array.isArray(val) && val !== null && typeof val === type,
|
|
1348
1346
|
buffer: val => Buffer.isBuffer(val),
|
|
1349
1347
|
year: val => /^\d\d\d\d$/.test(val),
|
|
1348
|
+
email: val => /^[^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,}$/.test(val),
|
|
1350
1349
|
any: () => true,
|
|
1351
1350
|
};
|
|
1352
1351
|
|