MCPcopy
hub / github.com/faker-js/faker / replaceSymbols

Method replaceSymbols

src/modules/helpers/index.ts:310–356  ·  view source on GitHub ↗

* Parses the given string symbol by symbol and replaces the placeholder appropriately. * * - `#` will be replaced with a digit (`0` - `9`). * - `?` will be replaced with an upper letter ('A' - 'Z') * - and `*` will be replaced with either a digit or letter. * * @param string The te

(string: string = '')

Source from the content-addressed store, hash-verified

308 * @since 3.0.0
309 */
310 replaceSymbols(string: string = ''): string {
311 const alpha = [
312 'A',
313 'B',
314 'C',
315 'D',
316 'E',
317 'F',
318 'G',
319 'H',
320 'I',
321 'J',
322 'K',
323 'L',
324 'M',
325 'N',
326 'O',
327 'P',
328 'Q',
329 'R',
330 'S',
331 'T',
332 'U',
333 'V',
334 'W',
335 'X',
336 'Y',
337 'Z',
338 ];
339 let result = '';
340
341 for (let i = 0; i < string.length; i++) {
342 if (string.charAt(i) === '#') {
343 result += this.faker.number.int(9);
344 } else if (string.charAt(i) === '?') {
345 result += this.arrayElement(alpha);
346 } else if (string.charAt(i) === '*') {
347 result += this.faker.datatype.boolean()
348 ? this.arrayElement(alpha)
349 : this.faker.number.int(9);
350 } else {
351 result += string.charAt(i);
352 }
353 }
354
355 return result;
356 }
357
358 /**
359 * Replaces the symbols and patterns in a credit card schema including Luhn checksum.

Callers 2

helpers.spec.tsFile · 0.80
zipCodeMethod · 0.80

Calls 3

arrayElementMethod · 0.95
intMethod · 0.80
booleanMethod · 0.80

Tested by

no test coverage detected