You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Module with various helper methods providing basic (seed-dependent) operations useful for implementing faker methods.
9
75
*/
@@ -247,6 +313,235 @@ export class HelpersModule {
247
313
returnstring;
248
314
}
249
315
316
+
/**
317
+
* Generates a string matching the given regex like expressions.
318
+
*
319
+
* This function doesn't provide full support of actual `RegExp`.
320
+
* Features such as grouping, anchors and character classes are not supported.
321
+
* If you are looking for a library that randomly generates strings based on
322
+
* `RegExp`s, see [randexp.js](https://github.com/fent/randexp.js)
323
+
*
324
+
* Supported patterns:
325
+
* - `x{times}` => Repeat the `x` exactly `times` times.
326
+
* - `x{min,max}` => Repeat the `x` `min` to `max` times.
327
+
* - `[x-y]` => Randomly get a character between `x` and `y` (inclusive).
328
+
* - `[x-y]{times}` => Randomly get a character between `x` and `y` (inclusive) and repeat it `times` times.
329
+
* - `[x-y]{min,max}` => Randomly get a character between `x` and `y` (inclusive) and repeat it `min` to `max` times.
330
+
* - `[^...]` => Randomly get an ASCII number or letter character that is not in the given range. (e.g. `[^0-9]` will get a random non-numeric character).
331
+
* - `[-...]` => Include dashes in the range. Must be placed after the negate character `^` and before any character sets if used (e.g. `[^-0-9]` will not get any numeric characters or dashes).
332
+
* - `/[x-y]/i` => Randomly gets an uppercase or lowercase character between `x` and `y` (inclusive).
333
+
* - `x?` => Randomly decide to include or not include `x`.
334
+
* - `[x-y]?` => Randomly decide to include or not include characters between `x` and `y` (inclusive).
335
+
* - `x*` => Repeat `x` 0 or more times.
336
+
* - `[x-y]*` => Repeat characters between `x` and `y` (inclusive) 0 or more times.
337
+
* - `x+` => Repeat `x` 1 or more times.
338
+
* - `[x-y]+` => Repeat characters between `x` and `y` (inclusive) 1 or more times.
339
+
* - `.` => returns a wildcard ASCII character that can be any number, character or symbol. Can be combined with quantifiers as well.
340
+
*
341
+
* @param pattern The template string/RegExp to to generate a matching string for.
342
+
*
343
+
* @throws If min value is more than max value in quantifier. e.g. `#{10,5}`
344
+
* @throws If invalid quantifier symbol is passed in.
0 commit comments