Comparing version 0.0.17 to 1.0.17
33
index.js
@@ -1,2 +0,4 @@ | ||
module.exports = function bencode (input) { | ||
module.exports = bencode | ||
function bencode (input) { | ||
var encoder = get_encoder(input) | ||
@@ -7,13 +9,36 @@ return encoder(input) | ||
var types = { | ||
'string': bencode_string | ||
'[object String]': bencode_string, | ||
'[object Object]': bencode_dict, | ||
'[object Array]': bencode_list, | ||
'[object Number]': bencode_integer | ||
} | ||
function get_encoder (input) { | ||
var type = typeof input | ||
var type = Object.prototype.toString.call(input) | ||
return types[type] | ||
} | ||
function bencode_list (array) { | ||
var list = 'l' | ||
var parts = array.map(bencode) | ||
return list.concat(parts.join(''), 'e') | ||
} | ||
function bencode_dict (object) { | ||
var dict = 'd' | ||
var keys = Object.keys(object) | ||
keys.sort() | ||
keys.forEach(function (key) { | ||
dict += bencode(key) | ||
dict += bencode(object[key]) | ||
}) | ||
dict += 'e' | ||
return dict | ||
} | ||
function bencode_string (string) { | ||
return string.length + ':' + string | ||
} | ||
function bencode_integer (integer) { | ||
return 'i' + integer + 'e' | ||
} |
{ | ||
"name": "zbencode", | ||
"version": "0.0.17", | ||
"version": "1.0.17", | ||
"description": "Bencoding for bittorrent", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,11 +6,12 @@ var tap = require('tap') | ||
// test('fibwibblers and xyrscawlers', function (t) { | ||
// t.plan(2) | ||
tap.equal(bencode(17), 'i17e') | ||
tap.equal(bencode(0), 'i0e') | ||
tap.equal(bencode(-17), 'i-17e') | ||
// var x = someModule() | ||
// t.equal(x.foo(2), 22) | ||
tap.equal(bencode([17]), 'li17ee') | ||
tap.equal(bencode(['piss', 'shit']), 'l4:piss4:shite') | ||
// x.beep(function (err, res) { | ||
// t.equal(res, 'boop') | ||
// }) | ||
// }) | ||
tap.equal(bencode({'piss': 'shit'}), 'd4:piss4:shite') | ||
tap.equal(bencode({'piss': [17, 'shit']}), 'd4:pissli17e4:shitee') | ||
tap.equal(bencode({'cow': 'moo', 'spam': 'eggs'}), 'd3:cow3:moo4:spam4:eggse') | ||
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2148
5
48
1
1
11