aboutsummaryrefslogtreecommitdiff
path: root/src/modules/string
diff options
context:
space:
mode:
authorKcops11 <[email protected]>2023-02-11 05:36:03 -0600
committerGitHub <[email protected]>2023-02-11 11:36:03 +0000
commita51521d2704c3ca8be0e0ba044d17143ba71f453 (patch)
treeba22d1c2dfe80fa28154f141b0cf0a97f546f6e4 /src/modules/string
parentfd960941a5434464736b236e73df9813bc22c86c (diff)
downloadfaker-a51521d2704c3ca8be0e0ba044d17143ba71f453.tar.xz
faker-a51521d2704c3ca8be0e0ba044d17143ba71f453.zip
docs: improving readability of UUID string (#1622)
Co-authored-by: ST-DDT <[email protected]>
Diffstat (limited to 'src/modules/string')
-rw-r--r--src/modules/string/index.ts11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts
index 6240184c..188c91eb 100644
--- a/src/modules/string/index.ts
+++ b/src/modules/string/index.ts
@@ -678,14 +678,9 @@ export class StringModule {
* @since 8.0.0
*/
uuid(): string {
- const RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
- const replacePlaceholders = (placeholder: string) => {
- const random = this.faker.number.int(15);
- const value = placeholder === 'x' ? random : (random & 0x3) | 0x8;
- return value.toString(16);
- };
-
- return RFC4122_TEMPLATE.replace(/[xy]/g, replacePlaceholders);
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
+ .replace(/x/g, () => this.faker.number.hex({ min: 0x0, max: 0xf }))
+ .replace(/y/g, () => this.faker.number.hex({ min: 0x8, max: 0xb }));
}
/**