Skip to content

Commit

Permalink
Add generator and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanMaRuiz committed Aug 26, 2020
1 parent 21bd260 commit ec2b985
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 33 deletions.
28 changes: 2 additions & 26 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
* ISBN util to validate and generate a valid random ISBN-10 or ISBN-13.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -32,7 +32,3 @@ generate('10');
//=> 'isbn-10: 8448122313'
```
### Why this tool?
// TBD
7 changes: 6 additions & 1 deletion __test__/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ');
});
2 changes: 1 addition & 1 deletion src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ec2b985

Please sign in to comment.