-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from diasdavid/revamp
Revamp
- Loading branch information
Showing
8 changed files
with
138 additions
and
206 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,51 @@ | ||
var sha1 = require('git-sha1'); | ||
|
||
exports = module.exports = Id; | ||
|
||
var maxHex = 'ffffffffffff'; | ||
var maxDec = parseInt(maxHex, 16); | ||
|
||
function Id(_id) { | ||
var dec; | ||
var hex; | ||
|
||
if (typeof _id === 'number') { | ||
dec = _id; | ||
var tmp = ('00000000000000' + _id.toString(16)); | ||
hex = tmp.substring(tmp.length - 12, tmp.length); | ||
var sha1 = require('git-sha1') | ||
|
||
exports = module.exports = Id | ||
|
||
var maxHex = 'ffffffffffff' | ||
// var maxDec = parseInt(maxHex, 16) | ||
|
||
function Id (_id) { | ||
var dec | ||
var hex | ||
|
||
if (typeof _id === 'number') { | ||
dec = _id | ||
var tmp = ('00000000000000' + _id.toString(16)) | ||
hex = tmp.substring(tmp.length - 12, tmp.length) | ||
} | ||
if (typeof _id === 'string') { | ||
dec = parseInt(_id, 16) | ||
hex = _id | ||
} | ||
if (typeof _id === 'undefined') { | ||
hex = sha1((~~(Math.random() * 1e9)).toString(36) + Date.now()) | ||
.substring(0, 12) | ||
dec = parseInt(hex, 16) | ||
} | ||
|
||
this.toHex = function () { | ||
return hex | ||
} | ||
|
||
this.toDec = function () { | ||
return dec | ||
} | ||
|
||
this.next = function () { | ||
if (hex === maxHex) { | ||
return '000000000000' | ||
} else { | ||
var a = ('000000000000' + ((dec + 1).toString(16))) | ||
return a.substring(a.length - 12, a.length) | ||
} | ||
if (typeof _id === 'string') { | ||
dec = parseInt(_id, 16); | ||
hex = _id; | ||
} | ||
if (typeof _id === 'undefined') { | ||
hex = sha1((~~(Math.random() * 1e9)).toString(36) + Date.now()) | ||
.substring(0, 12); | ||
dec = parseInt(hex, 16); | ||
} | ||
|
||
this.toHex = function() { | ||
return hex; | ||
}; | ||
} | ||
|
||
this.toDec = function() { | ||
return dec; | ||
}; | ||
|
||
this.next = function() { | ||
if (hex === maxHex) { | ||
return '000000000000'; | ||
} else { | ||
var a = ('000000000000' + ((dec + 1).toString(16))); | ||
return a.substring(a.length - 12, a.length); | ||
} | ||
}; | ||
|
||
return this; | ||
return this | ||
} | ||
|
||
// | ||
// bigger Id than available to make the message spin the ring | ||
// | ||
exports.spin = function() { | ||
return (maxDec + 1).toString(16); | ||
}; | ||
|
||
// | ||
// returns the Id in a hex value, which correspondes to the hash of the content | ||
// | ||
exports.hash = function(content) { | ||
return sha1(content).substring(0, 12); | ||
}; | ||
// returns the Id in a hex value, which corresponds to the hash of the content | ||
exports.hash = function (content) { | ||
return sha1(content).substring(0, 12) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.