Skip to content

Commit

Permalink
validate if hex is correct and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Trukes committed Nov 5, 2020
1 parent 7d49496 commit 39b9d31
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Install into your project
npm install avatarholder --save
```

Require avatarholder library

```
let avatarholder = require('avatarholder');
```

And start to generating your avatars...

```
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,17 @@ exports.getFont = (canvasWidth) => {
}

exports.getColor = () => {
let randomColor = '#' + Math.floor(Math.random()*16777215).toString(16);
return randomColor;
let hex = '#' + Math.floor(Math.random()*16777215).toString(16);

// validate if is a color
if (hex.indexOf('#') === 0) {
hexTest = hex.slice(1);
}
if (hexTest.length !== 6 && hexTest.length !== 3) {
return this.getColor();
}

return hex;
}

exports.getInitials = (text) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "avatarholder",
"version": "1.0.5",
"version": "1.0.6",
"description": "Library to generate automatic avatars",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 39b9d31

Please sign in to comment.