diff options
| author | Leyla Jähnig <[email protected]> | 2022-11-25 16:59:10 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-25 16:59:10 +0100 |
| commit | 7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743 (patch) | |
| tree | 323754ca575c56ccf688539cfcca66d54c903602 /src/modules/helpers | |
| parent | 0af0fff4a410d7531368c709327ba0798a47091a (diff) | |
| download | faker-7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743.tar.xz faker-7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743.zip | |
feat(number): move methods to new module (#1122)
Co-authored-by: ST-DDT <[email protected]>
Co-authored-by: Eric Cheng <[email protected]>
Co-authored-by: Leyla Jähnig <[email protected]>
Co-authored-by: Shinigami92 <[email protected]>
Diffstat (limited to 'src/modules/helpers')
| -rw-r--r-- | src/modules/helpers/index.ts | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 406f7f19..6caa8eff 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -56,9 +56,9 @@ export class HelpersModule { let str = ''; for (let i = 0; i < string.length; i++) { if (string.charAt(i) === symbol) { - str += this.faker.datatype.number(9); + str += this.faker.number.int(9); } else if (string.charAt(i) === '!') { - str += this.faker.datatype.number({ min: 2, max: 9 }); + str += this.faker.number.int({ min: 2, max: 9 }); } else { str += string.charAt(i); } @@ -117,13 +117,13 @@ export class HelpersModule { for (let i = 0; i < string.length; i++) { if (string.charAt(i) === '#') { - str += this.faker.datatype.number(9); + str += this.faker.number.int(9); } else if (string.charAt(i) === '?') { str += this.arrayElement(alpha); } else if (string.charAt(i) === '*') { str += this.faker.datatype.boolean() ? this.arrayElement(alpha) - : this.faker.datatype.number(9); + : this.faker.number.int(9); } else { str += string.charAt(i); } @@ -197,7 +197,7 @@ export class HelpersModule { max = min; min = tmp; } - repetitions = this.faker.datatype.number({ min: min, max: max }); + repetitions = this.faker.number.int({ min, max }); string = string.slice(0, token.index) + token[1].repeat(repetitions) + @@ -229,7 +229,7 @@ export class HelpersModule { } string = string.slice(0, token.index) + - this.faker.datatype.number({ min: min, max: max }).toString() + + this.faker.number.int({ min, max }).toString() + string.slice(token.index + token[0].length); token = string.match(RANGE_REG); } @@ -289,7 +289,7 @@ export class HelpersModule { } for (let i = list.length - 1; i > 0; --i) { - const j = this.faker.datatype.number(i); + const j = this.faker.number.int(i); [list[i], list[j]] = [list[j], list[i]]; } @@ -341,7 +341,7 @@ export class HelpersModule { * * @example * faker.helpers.mustache('I found {{count}} instances of "{{word}}".', { - * count: () => `${faker.datatype.number()}`, + * count: () => `${faker.number.int()}`, * word: "this word", * }) // 'I found 57591 instances of "this word".' * @@ -438,9 +438,7 @@ export class HelpersModule { array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T> ): T { const index = - array.length > 1 - ? this.faker.datatype.number({ max: array.length - 1 }) - : 0; + array.length > 1 ? this.faker.number.int({ max: array.length - 1 }) : 0; return array[index]; } @@ -470,7 +468,7 @@ export class HelpersModule { count = array.length === 0 ? 0 - : this.faker.datatype.number({ min: 1, max: array.length }); + : this.faker.number.int({ min: 1, max: array.length }); } else if (count > array.length) { count = array.length; } else if (count < 0) { @@ -485,7 +483,7 @@ export class HelpersModule { while (i-- > min) { index = Math.floor( - (i + 1) * this.faker.datatype.float({ min: 0, max: 0.99 }) + (i + 1) * this.faker.number.float({ min: 0, max: 0.99 }) ); temp = arrayCopy[index]; arrayCopy[index] = arrayCopy[i]; @@ -644,7 +642,7 @@ export class HelpersModule { if (typeof numberOrRange === 'number') { return numberOrRange; } - return this.faker.datatype.number(numberOrRange); + return this.faker.number.int(numberOrRange); } /** |
