diff options
| author | Leyla Jähnig <[email protected]> | 2022-08-25 19:33:08 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-25 19:33:08 +0200 |
| commit | da78c885ff792d147cae5aec5206676a202ae35f (patch) | |
| tree | c474693c363dbd1290fa5950e80808106c2a70cf | |
| parent | af34753a503db586eff509ce2a498f668c99ed47 (diff) | |
| download | faker-da78c885ff792d147cae5aec5206676a202ae35f.tar.xz faker-da78c885ff792d147cae5aec5206676a202ae35f.zip | |
refactor(helpers): deprecate repeatString (#1299)
| -rw-r--r-- | src/modules/helpers/index.ts | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 6f94fe63..fac7e3e2 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1,5 +1,6 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; +import { deprecated } from '../../internal/deprecated'; import { luhnCheckValue } from './luhn-check'; /** @@ -160,13 +161,17 @@ export class Helpers { * faker.helpers.repeatString('Hello world! ') // '' * faker.helpers.repeatString('Hello world! ', 1) // 'Hello world! ' * faker.helpers.repeatString('Hello world! ', 2) // 'Hello world! Hello world! ' + * + * @deprecated Use [String.prototype.repeat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat) instead. */ repeatString(string = '', num = 0): string { - let text = ''; - for (let i = 0; i < num; i++) { - text += string.toString(); - } - return text; + deprecated({ + deprecated: 'faker.helpers.repeatString()', + proposed: 'String.prototype.repeat()', + since: '7.5', + until: '8.0', + }); + return string.repeat(num); } /** @@ -208,7 +213,7 @@ export class Helpers { repetitions = this.faker.datatype.number({ min: min, max: max }); string = string.slice(0, token.index) + - this.repeatString(token[1], repetitions) + + token[1].repeat(repetitions) + string.slice(token.index + token[0].length); token = string.match(RANGE_REP_REG); } @@ -218,7 +223,7 @@ export class Helpers { repetitions = parseInt(token[2]); string = string.slice(0, token.index) + - this.repeatString(token[1], repetitions) + + token[1].repeat(repetitions) + string.slice(token.index + token[0].length); token = string.match(REP_REG); } |
