Skip to content

Commit

Permalink
rewrite in js
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jun 1, 2014
1 parent 16f8e3b commit d594d74
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 54 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: node_js
node_js:
- 0.7
- 0.8
- 0.9
- "0.10"
- "0.11"
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
require('coffee-script/register');
module.exports = require('./lib/main');
module.exports = function(chars) {
if (typeof chars === 'string') {
chars = chars.split('').map(function(str){
return str.charCodeAt(0);
});
}

if (!Array.isArray(chars)) {
throw new Error('input must be a string or an array');
}

return chars.reduce(function(prev, curr){
return ((prev << 5) + prev) + curr;
}, 5381);
};
8 changes: 0 additions & 8 deletions lib/main.coffee

This file was deleted.

50 changes: 23 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
{
"name":"djb2",
"description":"djb2 hash in JS",
"version":"0.0.1",
"homepage":"http://github.com/wearefractal/djb2",
"repository":"git://github.com/wearefractal/djb2.git",
"author":"Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"main":"./index.js",

"dependencies":{
"coffee-script":"*"
},
"devDependencies":{
"mocha":"*",
"should":"*"
},
"scripts":{
"test":"mocha --compilers coffee:coffee-script"
},
"engines":{
"node":">= 0.4.0"
},
"licenses":[
{
"type":"MIT",
"url":"http://github.com/wearefractal/djb2/raw/master/LICENSE"
}
]
"name": "djb2",
"description": "djb2 hash in JS",
"version": "0.0.2",
"homepage": "http://github.com/wearefractal/djb2",
"repository": "git://github.com/wearefractal/djb2.git",
"author": "Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"main": "./index.js",
"devDependencies": {
"mocha": "^1.20.0",
"should": "^4.0.0"
},
"scripts": {
"test": "mocha"
},
"engines": {
"node": ">= 0.4.0"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/wearefractal/djb2/raw/master/LICENSE"
}
]
}
14 changes: 0 additions & 14 deletions test/main.coffee

This file was deleted.

19 changes: 19 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var djb2 = require('../');
var should = require('should');
require('mocha');

describe('djb2', function(){
describe('djb2(string)', function(){
it('should should work', function(done){
djb2("test").should.equal(2090756197);
done();
});
});

describe('djb2(arr)', function(){
it('should should work', function(done){
djb2([101,102]).should.equal(5863344);
done();
});
});
});

0 comments on commit d594d74

Please sign in to comment.