Skip to content

Commit

Permalink
feat: datatype.hexadecimal signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
ejcheng committed Aug 7, 2022
1 parent 034b759 commit 7befc35
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/modules/datatype/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Faker } from '../..';
import { FakerError } from '../../errors/faker-error';
import { deprecated } from '../../internal/deprecated';

/**
* Module to generate various primitive values and data types.
Expand Down Expand Up @@ -187,13 +188,32 @@ export class Datatype {
/**
* Returns a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) number.
*
* @param length Length of the generated number. Defaults to `1`.
* @param length Deprecated, do not use.
* @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 `''`.
*
* @example
* faker.datatype.hexadecimal() // '0xb'
* faker.datatype.hexadecimal(10) // '0xaE13F044fb'
*/
hexadecimal(length = 1): string {
hexadecimal(
length?: number,
options?: { length?: number; prefix?: string }
): string {
if (length) {
deprecated({
deprecated: 'faker.datatype.hexadecimal(length)',
proposed: 'faker.datatype.hexadecimal({ length })',
since: '7.3',
until: '8.0',
});
} else {
length = options?.length ?? 1;
}

const prefix = options?.prefix ?? '';

let wholeString = '';

for (let i = 0; i < length; i++) {
Expand Down Expand Up @@ -223,7 +243,7 @@ export class Datatype {
]);
}

return `0x${wholeString}`;
return `${prefix}${wholeString}`;
}

/**
Expand Down

0 comments on commit 7befc35

Please sign in to comment.