diff --git a/CHANGELOG.md b/CHANGELOG.md index 8797c84..8e77777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,27 +1,3 @@ -# Changelog -All notable changes to this project will be documented in this file. - -## [0.1.6] - 2020-07-22 -### Upgrade -* Upgrade dependencies - -## [0.1.5] - 2020-05-30 +## [1.0.0] - 2020-08-26 ### Added -* Add coveralls and badge to README - -## [0.1.4] - 2020-05-29 -### Added -* Fix usage example in README - -## [0.1.3] - 2020-05-29 -### Added -* Fix install command on README - -## [0.1.2] - 2020-04-26 -### Added -* CHANGELOG -* MIT LICENSE - -## [0.1.0] - 2020-04-26 -### Added -* Random generators for DNI, NIE and NIF. \ No newline at end of file +* ISBN util to validate and generate a valid random ISBN-10 or ISBN-13. diff --git a/README.md b/README.md index e9e9010..05c6491 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # ISBN Util -This module check if an isbn is valid or not and also provide method to generate a valid random isbn (10 or 13) +This module check if an ISBN is valid or not and also provide a method to generate a valid random ISBN-10 or ISBN-13 ## Install @@ -32,7 +32,3 @@ generate('10'); //=> 'isbn-10: 8448122313' ``` -### Why this tool? - -// TBD - diff --git a/__test__/generator.test.js b/__test__/generator.test.js index 9ec9a1f..e386f14 100644 --- a/__test__/generator.test.js +++ b/__test__/generator.test.js @@ -2,6 +2,11 @@ const generator = require('./../src/generator.js'); const validator = require('./../src/validator.js'); test('should return a valid isbn according with the passed param', () => { - const validIsbn = generator('10'); + const validIsbn = generator('10').split(' ')[1]; expect(validator(validIsbn)).toBe(true); }); + +test('should return a string with the correct pattern depending on the type selected', () => { + expect(generator('10')).toContain('isbn-10: '); + expect(generator('13')).toContain('isbn-13: '); +}); diff --git a/src/generator.js b/src/generator.js index 2cba4aa..a5db780 100644 --- a/src/generator.js +++ b/src/generator.js @@ -8,7 +8,7 @@ const generator = (type = isbnTypes[10]) => { const randomNumber = parseInt(Math.random() * parseInt(Math.pow(10,type))); if ( type === isbnTypes[type] ) { const tempIsbn = randomNumber.toString(); - return validator(tempIsbn) ? tempIsbn : generator(type); + return validator(tempIsbn) ? `isbn-${type}: ${tempIsbn}` : generator(type); } else { console.error('Invalid option. Pass "10" for isbn-10 and "13" for isbn-13'); process.exit(1);