From d0b3bb3d771325a2cf6271345f1634ccec51abd1 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 6 Jul 2023 00:35:58 +0200 Subject: [PATCH 01/11] Add ISBN method to commerce module --- src/modules/commerce/index.ts | 147 ++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 89f4771134b..6e9403e8aae 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -1,6 +1,76 @@ import type { Faker } from '../../faker'; import { deprecated } from '../../internal/deprecated'; +// Source for official prefixes: https://www.isbn-international.org/range_file_generation +const ISBN_LENGTH_RULES: { [key: string]: Array<[number, number]> } = { + '0': [ + [1999999, 2], + [2279999, 3], + [2289999, 4], + [3689999, 3], + [3699999, 4], + [6389999, 3], + [6397999, 4], + [6399999, 7], + [6449999, 3], + [6459999, 7], + [6479999, 3], + [6489999, 7], + [6549999, 3], + [6559999, 4], + [6999999, 3], + [8499999, 4], + [8999999, 5], + [9499999, 6], + [9999999, 7], + ], + '1': [ + [99999, 3], + [299999, 2], + [349999, 3], + [399999, 4], + [499999, 3], + [699999, 2], + [999999, 4], + [3979999, 3], + [5499999, 4], + [6499999, 5], + [6799999, 4], + [6859999, 5], + [7139999, 4], + [7169999, 3], + [7319999, 4], + [7399999, 7], + [7749999, 5], + [7753999, 7], + [7763999, 5], + [7764999, 7], + [7769999, 5], + [7782999, 7], + [7899999, 5], + [7999999, 4], + [8004999, 5], + [8049999, 5], + [8379999, 5], + [8384999, 7], + [8671999, 5], + [8675999, 4], + [8697999, 5], + [9159999, 6], + [9165059, 7], + [9168699, 6], + [9169079, 7], + [9195999, 6], + [9196549, 7], + [9729999, 6], + [9877999, 4], + [9911499, 6], + [9911999, 7], + [9989899, 6], + [9999999, 7], + ], +}; + /** * Module to generate commerce and product related entries. * @@ -266,4 +336,81 @@ export class CommerceModule { this.faker.definitions.commerce.product_description ); } + + /** + * Returns a random [ISBN](https://en.wikipedia.org/wiki/ISBN) identifier. + * + * @param options The variant to return or an options object. Defaults to `{}`. + * @param options.variant The variant to return. Can be either `10` (10-digit format) + * or `13` (13-digit format). Defaults to `13`. + * @param options.separator The separator to use in the format. Defaults to `'-'`. + * + * @example + * faker.commerce.isbn() // '978-0-692-82459-7' + * faker.commerce.isbn(10) // '1-155-36404-X' + * faker.commerce.isbn(13) // '978-1-60808-867-6' + * faker.commerce.isbn({ separator: ' ' }) // '978 0 452 81498 1' + * faker.commerce.isbn({ variant: 10, separator: ' ' }) // '0 940319 49 7' + * faker.commerce.isbn({ variant: 13, separator: ' ' }) // '978 1 6618 9122 0' + * + * @since 8.0.0 + */ + isbn( + options: + | 10 + | 13 + | { + /** + * The variant of the identifier to return. + * Can be either `10` (10-digit format) + * or `13` (13-digit format). + * + * @default 13 + */ + variant?: 10 | 13; + + /** + * The separator to use in the format. + * + * @default '-' + */ + separator?: string; + } = {} + ): string { + if (typeof options === 'number') { + options = { variant: options }; + } + + const { variant = 13, separator = '-' } = options; + + const prefix = '978'; + const group: string = this.faker.number.int({ min: 0, max: 1 }).toString(); + const element: string = this.faker.string.numeric(8); + + const registrantLength: number = ISBN_LENGTH_RULES[group].find( + ([key]): boolean => parseInt(element.slice(0, -1)) <= key + )[1]; + + const registrant: string = element.slice(0, registrantLength); + const publication: string = element.slice(registrantLength); + + const data: string[] = [prefix, group, registrant, publication]; + if (variant === 10) { + data.shift(); + } + + const isbn: string = data.join(''); + + let checksum = 0; + for (let i = 0; i < variant - 1; i++) { + const weight: number = variant === 10 ? i + 1 : i % 2 ? 3 : 1; + checksum += weight * parseInt(isbn[i]); + } + + checksum = variant === 10 ? checksum % 11 : (10 - (checksum % 10)) % 10; + + data.push(checksum === 10 ? 'X' : checksum.toString()); + + return data.join(separator); + } } From e6d8bdb0fef6c02419be5f1d17689729e5464be7 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 6 Jul 2023 00:36:04 +0200 Subject: [PATCH 02/11] Add unit tests for ISBN method --- test/commerce.spec.ts | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/commerce.spec.ts b/test/commerce.spec.ts index 743aa58b38d..bd65b9be294 100644 --- a/test/commerce.spec.ts +++ b/test/commerce.spec.ts @@ -158,6 +158,55 @@ describe('commerce', () => { ); }); }); + + describe(`isbn()`, () => { + it('should return ISBN-13 with hyphen separators when not passing arguments', () => { + const isbn = faker.commerce.isbn(); + + expect(isbn).toBeTruthy(); + expect(isbn).toBeTypeOf('string'); + expect( + isbn, + 'The expected match should be ISBN-13 with hyphens' + ).toMatch(/^978-[01]-[\d-]{9}-\d$/); + }); + + it('should return ISBN-10 with hyphen separators when passing variant 10 as argument', () => { + const isbn = faker.commerce.isbn(10); + + expect( + isbn, + 'The expected match should be ISBN-10 with hyphens' + ).toMatch(/^[01]-[\d-]{9}-[\dX]$/); + }); + + it('should return ISBN-13 with hyphen separators when passing variant 13 as argument', () => { + const isbn = faker.commerce.isbn(13); + + expect( + isbn, + 'The expected match should be ISBN-13 with hyphens' + ).toMatch(/^978-[01]-[\d-]{9}-\d$/); + }); + + it('should return ISBN-10 with space separators when passing variant 10 and space separators as argument', () => { + const isbn = faker.commerce.isbn({ variant: 10, separator: ' ' }); + + expect( + isbn, + 'The expected match should be ISBN-10 with space separators' + ).toMatch(/^[01] [\d ]{9} [\dX]$/); + }); + + it('should return ISBN-13 with space separators when passing space separators as argument', () => { + const isbn = faker.commerce.isbn({ separator: ' ' }); + + expect( + isbn, + 'The expected match should be ISBN-13 with space separators' + ).toMatch(/^978 [01] [\d ]{9} \d$/); + }); + }); } ); }); From f0c96b761b790a576d358c5e959bc29eacbe0037 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 6 Jul 2023 00:55:44 +0200 Subject: [PATCH 03/11] Improve variable names --- src/modules/commerce/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 6e9403e8aae..7b60851ebc5 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -2,7 +2,9 @@ import type { Faker } from '../../faker'; import { deprecated } from '../../internal/deprecated'; // Source for official prefixes: https://www.isbn-international.org/range_file_generation -const ISBN_LENGTH_RULES: { [key: string]: Array<[number, number]> } = { +const ISBN_LENGTH_RULES: { + [group: string]: Array<[rangeMaximum: number, length: number]>; +} = { '0': [ [1999999, 2], [2279999, 3], @@ -388,7 +390,8 @@ export class CommerceModule { const element: string = this.faker.string.numeric(8); const registrantLength: number = ISBN_LENGTH_RULES[group].find( - ([key]): boolean => parseInt(element.slice(0, -1)) <= key + ([rangeMaximum]): boolean => + parseInt(element.slice(0, -1)) <= rangeMaximum )[1]; const registrant: string = element.slice(0, registrantLength); From 20a8d6b6d7b19ecdcb5187b4c0a3bafbca75bfcd Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 6 Jul 2023 18:54:28 +0200 Subject: [PATCH 04/11] Add tests for ISBN method --- test/__snapshots__/commerce.spec.ts.snap | 48 ++++++++++++++++++++++++ test/commerce.spec.ts | 11 ++++++ 2 files changed, 59 insertions(+) diff --git a/test/__snapshots__/commerce.spec.ts.snap b/test/__snapshots__/commerce.spec.ts.snap index 1dde678565e..7844fb4d8ef 100644 --- a/test/__snapshots__/commerce.spec.ts.snap +++ b/test/__snapshots__/commerce.spec.ts.snap @@ -2,6 +2,22 @@ exports[`commerce > 42 > department 1`] = `"Tools"`; +exports[`commerce > 42 > isbn > noArgs 1`] = `"978-0-7917-7551-6"`; + +exports[`commerce > 42 > isbn > with space separator 1`] = `"978 0 7917 7551 6"`; + +exports[`commerce > 42 > isbn > with space separators 1`] = `"978 0 7917 7551 6"`; + +exports[`commerce > 42 > isbn > with variant 10 1`] = `"0-7917-7551-8"`; + +exports[`commerce > 42 > isbn > with variant 10 and space separator 1`] = `"0 7917 7551 8"`; + +exports[`commerce > 42 > isbn > with variant 10 and space separators 1`] = `"0 7917 7551 8"`; + +exports[`commerce > 42 > isbn > with variant 13 1`] = `"978-0-7917-7551-6"`; + +exports[`commerce > 42 > isbn 1`] = `"978-0-7917-7551-6"`; + exports[`commerce > 42 > price > noArgs 1`] = `"375.00"`; exports[`commerce > 42 > price > with max 1`] = `"375.00"`; @@ -36,6 +52,22 @@ exports[`commerce > 42 > productName 1`] = `"Fantastic Soft Sausages"`; exports[`commerce > 1211 > department 1`] = `"Automotive"`; +exports[`commerce > 1211 > isbn > noArgs 1`] = `"978-1-4872-1906-2"`; + +exports[`commerce > 1211 > isbn > with space separator 1`] = `"978 1 4872 1906 2"`; + +exports[`commerce > 1211 > isbn > with space separators 1`] = `"978 1 4872 1906 2"`; + +exports[`commerce > 1211 > isbn > with variant 10 1`] = `"1-4872-1906-7"`; + +exports[`commerce > 1211 > isbn > with variant 10 and space separator 1`] = `"1 4872 1906 7"`; + +exports[`commerce > 1211 > isbn > with variant 10 and space separators 1`] = `"1 4872 1906 7"`; + +exports[`commerce > 1211 > isbn > with variant 13 1`] = `"978-1-4872-1906-2"`; + +exports[`commerce > 1211 > isbn 1`] = `"978-1-4872-1906-2"`; + exports[`commerce > 1211 > price > noArgs 1`] = `"929.00"`; exports[`commerce > 1211 > price > with max 1`] = `"929.00"`; @@ -70,6 +102,22 @@ exports[`commerce > 1211 > productName 1`] = `"Unbranded Cotton Salad"`; exports[`commerce > 1337 > department 1`] = `"Computers"`; +exports[`commerce > 1337 > isbn > noArgs 1`] = `"978-0-512-25403-0"`; + +exports[`commerce > 1337 > isbn > with space separator 1`] = `"978 0 512 25403 0"`; + +exports[`commerce > 1337 > isbn > with space separators 1`] = `"978 0 512 25403 0"`; + +exports[`commerce > 1337 > isbn > with variant 10 1`] = `"0-512-25403-6"`; + +exports[`commerce > 1337 > isbn > with variant 10 and space separator 1`] = `"0 512 25403 6"`; + +exports[`commerce > 1337 > isbn > with variant 10 and space separators 1`] = `"0 512 25403 6"`; + +exports[`commerce > 1337 > isbn > with variant 13 1`] = `"978-0-512-25403-0"`; + +exports[`commerce > 1337 > isbn 1`] = `"978-0-512-25403-0"`; + exports[`commerce > 1337 > price > noArgs 1`] = `"263.00"`; exports[`commerce > 1337 > price > with max 1`] = `"263.00"`; diff --git a/test/commerce.spec.ts b/test/commerce.spec.ts index bd65b9be294..ee2ed5fa008 100644 --- a/test/commerce.spec.ts +++ b/test/commerce.spec.ts @@ -38,6 +38,17 @@ describe('commerce', () => { symbol: '$', }); }); + + t.describe('isbn', (t) => { + t.it('noArgs') + .it('with variant 10', 10) + .it('with variant 13', 13) + .it('with variant 10 and space separators', { + variant: 10, + separator: ' ', + }) + .it('with space separators', { separator: ' ' }); + }); }); describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( From 3e75ef1c70b36887c0be5fcd0bcd2b203141fdc1 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 6 Jul 2023 19:14:17 +0200 Subject: [PATCH 05/11] Update snap file --- test/__snapshots__/commerce.spec.ts.snap | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/__snapshots__/commerce.spec.ts.snap b/test/__snapshots__/commerce.spec.ts.snap index 7844fb4d8ef..00b8f08e58a 100644 --- a/test/__snapshots__/commerce.spec.ts.snap +++ b/test/__snapshots__/commerce.spec.ts.snap @@ -4,20 +4,14 @@ exports[`commerce > 42 > department 1`] = `"Tools"`; exports[`commerce > 42 > isbn > noArgs 1`] = `"978-0-7917-7551-6"`; -exports[`commerce > 42 > isbn > with space separator 1`] = `"978 0 7917 7551 6"`; - exports[`commerce > 42 > isbn > with space separators 1`] = `"978 0 7917 7551 6"`; exports[`commerce > 42 > isbn > with variant 10 1`] = `"0-7917-7551-8"`; -exports[`commerce > 42 > isbn > with variant 10 and space separator 1`] = `"0 7917 7551 8"`; - exports[`commerce > 42 > isbn > with variant 10 and space separators 1`] = `"0 7917 7551 8"`; exports[`commerce > 42 > isbn > with variant 13 1`] = `"978-0-7917-7551-6"`; -exports[`commerce > 42 > isbn 1`] = `"978-0-7917-7551-6"`; - exports[`commerce > 42 > price > noArgs 1`] = `"375.00"`; exports[`commerce > 42 > price > with max 1`] = `"375.00"`; @@ -54,20 +48,14 @@ exports[`commerce > 1211 > department 1`] = `"Automotive"`; exports[`commerce > 1211 > isbn > noArgs 1`] = `"978-1-4872-1906-2"`; -exports[`commerce > 1211 > isbn > with space separator 1`] = `"978 1 4872 1906 2"`; - exports[`commerce > 1211 > isbn > with space separators 1`] = `"978 1 4872 1906 2"`; exports[`commerce > 1211 > isbn > with variant 10 1`] = `"1-4872-1906-7"`; -exports[`commerce > 1211 > isbn > with variant 10 and space separator 1`] = `"1 4872 1906 7"`; - exports[`commerce > 1211 > isbn > with variant 10 and space separators 1`] = `"1 4872 1906 7"`; exports[`commerce > 1211 > isbn > with variant 13 1`] = `"978-1-4872-1906-2"`; -exports[`commerce > 1211 > isbn 1`] = `"978-1-4872-1906-2"`; - exports[`commerce > 1211 > price > noArgs 1`] = `"929.00"`; exports[`commerce > 1211 > price > with max 1`] = `"929.00"`; @@ -104,20 +92,14 @@ exports[`commerce > 1337 > department 1`] = `"Computers"`; exports[`commerce > 1337 > isbn > noArgs 1`] = `"978-0-512-25403-0"`; -exports[`commerce > 1337 > isbn > with space separator 1`] = `"978 0 512 25403 0"`; - exports[`commerce > 1337 > isbn > with space separators 1`] = `"978 0 512 25403 0"`; exports[`commerce > 1337 > isbn > with variant 10 1`] = `"0-512-25403-6"`; -exports[`commerce > 1337 > isbn > with variant 10 and space separator 1`] = `"0 512 25403 6"`; - exports[`commerce > 1337 > isbn > with variant 10 and space separators 1`] = `"0 512 25403 6"`; exports[`commerce > 1337 > isbn > with variant 13 1`] = `"978-0-512-25403-0"`; -exports[`commerce > 1337 > isbn 1`] = `"978-0-512-25403-0"`; - exports[`commerce > 1337 > price > noArgs 1`] = `"263.00"`; exports[`commerce > 1337 > price > with max 1`] = `"263.00"`; From d48b747de66cfe1ec9522e098fcbacd4f1a175f3 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 9 Jul 2023 12:38:59 +0200 Subject: [PATCH 06/11] Use `helpers.objectKey` instead of `number.int` --- src/modules/commerce/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 7b60851ebc5..b4b1816c150 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -386,7 +386,9 @@ export class CommerceModule { const { variant = 13, separator = '-' } = options; const prefix = '978'; - const group: string = this.faker.number.int({ min: 0, max: 1 }).toString(); + const group: string = this.faker.helpers + .objectKey(ISBN_LENGTH_RULES) + .toString(); const element: string = this.faker.string.numeric(8); const registrantLength: number = ISBN_LENGTH_RULES[group].find( From 2b3ab5e7f38d49042375a427c57ca13f05c51e88 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 9 Jul 2023 12:39:25 +0200 Subject: [PATCH 07/11] Remove obvious explicit type definition --- src/modules/commerce/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index b4b1816c150..fe3c184f04c 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -408,7 +408,7 @@ export class CommerceModule { let checksum = 0; for (let i = 0; i < variant - 1; i++) { - const weight: number = variant === 10 ? i + 1 : i % 2 ? 3 : 1; + const weight = variant === 10 ? i + 1 : i % 2 ? 3 : 1; checksum += weight * parseInt(isbn[i]); } From f605d3aeea40aee52bf8cedddafc720f6402948a Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 9 Jul 2023 12:41:38 +0200 Subject: [PATCH 08/11] Validate ISBN with validator.js --- test/commerce.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/commerce.spec.ts b/test/commerce.spec.ts index ee2ed5fa008..b8422b65a5a 100644 --- a/test/commerce.spec.ts +++ b/test/commerce.spec.ts @@ -1,3 +1,4 @@ +import validator from 'validator'; import { describe, expect, it } from 'vitest'; import { faker } from '../src'; import { seededTests } from './support/seededRuns'; @@ -180,6 +181,7 @@ describe('commerce', () => { isbn, 'The expected match should be ISBN-13 with hyphens' ).toMatch(/^978-[01]-[\d-]{9}-\d$/); + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13)); }); it('should return ISBN-10 with hyphen separators when passing variant 10 as argument', () => { @@ -189,6 +191,7 @@ describe('commerce', () => { isbn, 'The expected match should be ISBN-10 with hyphens' ).toMatch(/^[01]-[\d-]{9}-[\dX]$/); + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 10)); }); it('should return ISBN-13 with hyphen separators when passing variant 13 as argument', () => { @@ -198,6 +201,7 @@ describe('commerce', () => { isbn, 'The expected match should be ISBN-13 with hyphens' ).toMatch(/^978-[01]-[\d-]{9}-\d$/); + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13)); }); it('should return ISBN-10 with space separators when passing variant 10 and space separators as argument', () => { @@ -207,6 +211,7 @@ describe('commerce', () => { isbn, 'The expected match should be ISBN-10 with space separators' ).toMatch(/^[01] [\d ]{9} [\dX]$/); + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 10)); }); it('should return ISBN-13 with space separators when passing space separators as argument', () => { @@ -216,6 +221,7 @@ describe('commerce', () => { isbn, 'The expected match should be ISBN-13 with space separators' ).toMatch(/^978 [01] [\d ]{9} \d$/); + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13)); }); }); } From 84f30baa7b978c9e64ce667d49b21f8e0a3a5a04 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 20 Jul 2023 19:32:19 +0200 Subject: [PATCH 09/11] Remove explicit type defintions --- src/modules/commerce/index.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index fe3c184f04c..bcc561611da 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -386,25 +386,22 @@ export class CommerceModule { const { variant = 13, separator = '-' } = options; const prefix = '978'; - const group: string = this.faker.helpers - .objectKey(ISBN_LENGTH_RULES) - .toString(); - const element: string = this.faker.string.numeric(8); + const group = this.faker.helpers.objectKey(ISBN_LENGTH_RULES).toString(); + const element = this.faker.string.numeric(8); - const registrantLength: number = ISBN_LENGTH_RULES[group].find( - ([rangeMaximum]): boolean => - parseInt(element.slice(0, -1)) <= rangeMaximum + const registrantLength = ISBN_LENGTH_RULES[group].find( + ([rangeMaximum]) => parseInt(element.slice(0, -1)) <= rangeMaximum )[1]; - const registrant: string = element.slice(0, registrantLength); - const publication: string = element.slice(registrantLength); + const registrant = element.slice(0, registrantLength); + const publication = element.slice(registrantLength); - const data: string[] = [prefix, group, registrant, publication]; + const data = [prefix, group, registrant, publication]; if (variant === 10) { data.shift(); } - const isbn: string = data.join(''); + const isbn = data.join(''); let checksum = 0; for (let i = 0; i < variant - 1; i++) { From 02a55ab571ed88808ba2e28eddc006b921e2f1c7 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 20 Jul 2023 19:33:47 +0200 Subject: [PATCH 10/11] Simplify group rule selection --- src/modules/commerce/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index bcc561611da..318e6a45c27 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -2,9 +2,10 @@ import type { Faker } from '../../faker'; import { deprecated } from '../../internal/deprecated'; // Source for official prefixes: https://www.isbn-international.org/range_file_generation -const ISBN_LENGTH_RULES: { - [group: string]: Array<[rangeMaximum: number, length: number]>; -} = { +const ISBN_LENGTH_RULES: Record< + string, + Array<[rangeMaximum: number, length: number]> +> = { '0': [ [1999999, 2], [2279999, 3], @@ -386,11 +387,13 @@ export class CommerceModule { const { variant = 13, separator = '-' } = options; const prefix = '978'; - const group = this.faker.helpers.objectKey(ISBN_LENGTH_RULES).toString(); + const [group, groupRules] = + this.faker.helpers.objectEntry(ISBN_LENGTH_RULES); const element = this.faker.string.numeric(8); + const elementValue = parseInt(element.slice(0, -1)); - const registrantLength = ISBN_LENGTH_RULES[group].find( - ([rangeMaximum]) => parseInt(element.slice(0, -1)) <= rangeMaximum + const registrantLength = groupRules.find( + ([rangeMaximum]) => elementValue <= rangeMaximum )[1]; const registrant = element.slice(0, registrantLength); From 2a6552f5da57c5ae6e8180527b5cc4afbe84a257 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Thu, 20 Jul 2023 22:49:46 +0200 Subject: [PATCH 11/11] Update `@since` Co-authored-by: ST-DDT --- src/modules/commerce/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 96c46a3f4c4..2464af03020 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -348,7 +348,7 @@ export class CommerceModule { * faker.commerce.isbn({ variant: 10, separator: ' ' }) // '0 940319 49 7' * faker.commerce.isbn({ variant: 13, separator: ' ' }) // '978 1 6618 9122 0' * - * @since 8.0.0 + * @since 8.1.0 */ isbn( options: