dat-encoding
Advanced tools
Comparing version 3.0.2 to 4.0.0
@@ -5,3 +5,4 @@ 'use strict' | ||
exports.encode = function (buf, opts) { | ||
function encode (buf) { | ||
if (typeof buf === 'string') return encode(decode(buf)) | ||
if (buf.length !== 32) throw new Error('Invalid buffer') | ||
@@ -11,3 +12,4 @@ return Buffer.from(buf).toString('hex') | ||
exports.decode = function (str) { | ||
function decode (str) { | ||
if (Buffer.isBuffer(str)) return decode(encode(str)) | ||
var match = /(?:[a-z]+:\/\/(?:dat\.land\/)?)?([^/]{64})/.exec(str) | ||
@@ -17,1 +19,4 @@ if (!match) throw new Error('Invalid key') | ||
} | ||
exports.encode = exports.toBuf = encode | ||
exports.decode = exports.toStr = decode |
{ | ||
"name": "dat-encoding", | ||
"version": "3.0.2", | ||
"version": "4.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "juliangruber/dat-encoding", |
@@ -21,12 +21,18 @@ | ||
### .encode(buf[, opts]) | ||
### .encode(buf) | ||
### .toStr(buf) | ||
Encode `buf` into a hex string. Throws if `buf` isn't 32 bytes of length. | ||
If `buf` is already a string, checks if it's valid and returns it. | ||
### .decode(str) | ||
### .toBuf(str) | ||
Decode `str` into its binary representation. Also supports `dat://` and `dat.com/` links. Throws if the raw link isn't 64 bytes of base64. | ||
If `str` is already a buffer, checks if it's valid and returns it. | ||
## License | ||
MIT |
@@ -7,5 +7,5 @@ var test = require('tape') | ||
t.equal(enc.encode(Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), '6161616161616161616161616161616161616161616161616161616161616161') | ||
t.equal(enc.encode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), '6161616161616161616161616161616161616161616161616161616161616161') | ||
t.throws(function () { enc.encode('tooshort') }) | ||
t.equal(enc.encode(Buffer('0100000000000000ffffffff0000000000008004010000004012800201000000', 'hex')), '0100000000000000ffffffff0000000000008004010000004012800201000000') | ||
t.equal(enc.encode, enc.toBuf) | ||
t.end() | ||
@@ -45,2 +45,4 @@ }) | ||
t.equal(enc.decode, enc.toStr) | ||
t.end() | ||
@@ -47,0 +49,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4346
70
38