From 379ba79ba3b9735ed039d87f32fc14fa9920d4ed Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 28 Aug 2022 09:59:51 -0400 Subject: fix(datatype): unintentional hex breaking change (#1306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Leyla Jähnig --- src/modules/color/index.ts | 5 ++++- src/modules/database/index.ts | 6 +++++- src/modules/datatype/index.ts | 14 +++++++------- src/modules/finance/index.ts | 1 - src/modules/git/index.ts | 12 ++++++++++-- 5 files changed, 26 insertions(+), 12 deletions(-) (limited to 'src/modules') diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index d64b7750..faa898d4 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -297,7 +297,10 @@ export class Color { let color: string | number[]; let cssFunction: CSSFunction = 'rgb'; if (format === 'hex') { - color = this.faker.datatype.hexadecimal({ length: includeAlpha ? 8 : 6 }); + color = this.faker.datatype.hexadecimal({ + length: includeAlpha ? 8 : 6, + prefix: '', + }); color = formatHexColor(color, options); return color; } diff --git a/src/modules/database/index.ts b/src/modules/database/index.ts index 5887ab09..69e07315 100644 --- a/src/modules/database/index.ts +++ b/src/modules/database/index.ts @@ -69,6 +69,10 @@ export class Database { * faker.database.mongodbObjectId() // 'e175cac316a79afdd0ad3afb' */ mongodbObjectId(): string { - return this.faker.datatype.hexadecimal({ length: 24, case: 'lower' }); + return this.faker.datatype.hexadecimal({ + length: 24, + case: 'lower', + prefix: '', + }); } } diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index 671e8c6c..57399450 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -190,17 +190,17 @@ export class Datatype { * * @param options The optional options object. * @param options.length Length of the generated number. Defaults to `1`. - * @param options.prefix Prefix for the generated number. Defaults to `''`. + * @param options.prefix Prefix for the generated number. Defaults to `'0x'`. * @param options.case Case of the generated number. Defaults to `'mixed'`. * * @example - * faker.datatype.hexadecimal() // 'B' - * faker.datatype.hexadecimal({ length: 10 }) // 'aE13d044cB' + * faker.datatype.hexadecimal() // '0xB' + * faker.datatype.hexadecimal({ length: 10 }) // '0xaE13d044cB' * faker.datatype.hexadecimal({ prefix: '0x' }) // '0xE' * faker.datatype.hexadecimal({ case: 'lower' }) // 'f' - * faker.datatype.hexadecimal({ length: 10, prefix: '0x' }) // '0xf12a974eB1' - * faker.datatype.hexadecimal({ length: 10, case: 'upper' }) // 'E3F38014FB' - * faker.datatype.hexadecimal({ prefix: '0x', case: 'lower' }) // '0xd' + * faker.datatype.hexadecimal({ length: 10, prefix: '#' }) // '#f12a974eB1' + * faker.datatype.hexadecimal({ length: 10, case: 'upper' }) // '0xE3F38014FB' + * faker.datatype.hexadecimal({ prefix: '', case: 'lower' }) // 'd' * faker.datatype.hexadecimal({ length: 10, prefix: '0x', case: 'mixed' }) // '0xAdE330a4D1' */ hexadecimal( @@ -220,7 +220,7 @@ export class Datatype { }; } - const { length = 1, prefix = '', case: letterCase = 'mixed' } = options; + const { length = 1, prefix = '0x', case: letterCase = 'mixed' } = options; let wholeString = ''; diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index f1b089e3..c6f79976 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -323,7 +323,6 @@ export class Finance { ethereumAddress(): string { const address = this.faker.datatype.hexadecimal({ length: 40, - prefix: '0x', case: 'lower', }); return address; diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index 21596273..be8d02f1 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -92,7 +92,11 @@ export class Git { * faker.git.commitSha() // '2c6e3880fd94ddb7ef72d34e683cdc0c47bec6e6' */ commitSha(): string { - return this.faker.datatype.hexadecimal({ length: 40, case: 'lower' }); + return this.faker.datatype.hexadecimal({ + length: 40, + case: 'lower', + prefix: '', + }); } /** @@ -102,6 +106,10 @@ export class Git { * faker.git.shortSha() // '6155732' */ shortSha(): string { - return this.faker.datatype.hexadecimal({ length: 7, case: 'lower' }); + return this.faker.datatype.hexadecimal({ + length: 7, + case: 'lower', + prefix: '', + }); } } -- cgit v1.2.3