@anteros/core 0.0.4 → 0.0.6
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 +1 -1
- package/utils/func.ts +9 -3
package/package.json
CHANGED
package/utils/func.ts
CHANGED
|
@@ -409,8 +409,10 @@ export type GenerateRandomOptions = {
|
|
|
409
409
|
useNumbers?: boolean;
|
|
410
410
|
includeSymbols?: string;
|
|
411
411
|
excludeSymbols?: string;
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
/** Préfixe (string fixe ou fonction qui reçoit la valeur générée). Ex: `(v) => 'BP-' + v` */
|
|
413
|
+
startWith?: string | ((value: string) => string);
|
|
414
|
+
/** Suffixe (string fixe ou fonction qui reçoit la valeur générée). Ex: `(v) => v + '-X'` */
|
|
415
|
+
endWith?: string | ((value: string) => string);
|
|
414
416
|
toLowerCase?: boolean;
|
|
415
417
|
toUpperCase?: boolean;
|
|
416
418
|
toNumber?: boolean;
|
|
@@ -463,7 +465,11 @@ async function generateRandom(options: GenerateRandomOptions, ctx: {
|
|
|
463
465
|
result += charset[randomIndex];
|
|
464
466
|
}
|
|
465
467
|
|
|
466
|
-
|
|
468
|
+
// startWith/endWith sont ajoutés autour du random (length ne contrôle que la partie aléatoire)
|
|
469
|
+
// Si c'est une fonction, elle reçoit la valeur aléatoire pour la personnaliser
|
|
470
|
+
const start = typeof startWith === 'function' ? startWith(result) : startWith;
|
|
471
|
+
const end = typeof endWith === 'function' ? endWith(result) : endWith;
|
|
472
|
+
result = start + result + end;
|
|
467
473
|
|
|
468
474
|
if (toLowerCase) {
|
|
469
475
|
result = result.toLowerCase();
|