Skip to content

Commit

Permalink
Remove support for optional hash as it didn't work correctly (#34)
Browse files Browse the repository at this point in the history
* Remove support for optional hash as it didn't work correctly.
* Bump version
  • Loading branch information
stewartlord authored May 1, 2017
1 parent 359c665 commit 7961557
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 42 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, Stewart Lord
Copyright (c) 2017, Stewart Lord
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"pnglib.js",
"identicon.js"
],
"version": "2.1.1",
"version": "2.2.0",
"homepage": "https://github.com/stewartlord/identicon.js",
"authors": [
"stewartlord"
],
"description": "GitHub-style identicons in JS with no server-side processing.",
"description": "GitHub-style identicons as PNGs or SVGs in JS.",
"moduleType": [
"globals"
],
Expand Down
17 changes: 0 additions & 17 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,6 @@ <h4>Raw (Smaller)</h4>
</script>
</div>
</div>

<div class="row">
<div class="col-md-12">
<h4>Time-based</h4>
<p>Omit the hash to generate an identicon based on the current time.</p>
<pre>
var data = new Identicon().toString();
document.write('&lt;img src="data:image/png;base64,' + data + '"&gt;');</pre>
<script type="text/javascript">

var data = new Identicon().toString();
document.write(
'<br><img src="data:image/png;base64,' + data + '"><br><br>'
);
</script>
</div>
</div>
</div>
</body>
</html>
27 changes: 6 additions & 21 deletions identicon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Identicon.js 2.1.1
* Identicon.js 2.2.0
* http://github.com/stewartlord/identicon.js
*
* PNGLib required for PNG output
Expand All @@ -19,9 +19,12 @@
}

var Identicon = function(hash, options){
if (typeof(hash) !== 'string' || hash.length < 15) {
throw 'A hash of at least 15 characters is required.';
}

this.defaults = {
background: [240, 240, 240, 255],
hash: this.createHashFromString((new Date()).toISOString()),
margin: 0.08,
size: 64,
format: 'png'
Expand All @@ -33,7 +36,7 @@
if (typeof(arguments[1]) === 'number') { this.options.size = arguments[1]; }
if (arguments[2]) { this.options.margin = arguments[2]; }

this.hash = hash || this.defaults.hash;
this.hash = hash
this.background = this.options.background || this.defaults.background;
this.margin = this.options.margin || this.defaults.margin;
this.size = this.options.size || this.defaults.size;
Expand Down Expand Up @@ -128,24 +131,6 @@
}
},

// Creates a consistent-length hash from a string
createHashFromString: function(str){
var hash = '0', salt = 'identicon', i, chr, len;

if (!str) {
return hash;
}

str += salt + str; // Better randomization for short inputs.

for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash.toString();
},

isSvg: function(){
return this.format.match(/svg/i)
}
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": "identicon.js",
"version": "2.1.1",
"version": "2.2.0",
"description": "GitHub-style identicons as PNGs or SVGs in JS.",
"main": "identicon.js",
"repository": {
Expand Down

0 comments on commit 7961557

Please sign in to comment.