x-address-codec
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -115,3 +115,3 @@ 'use strict'; | ||
possibleVersions.some(function (version, i) { | ||
var foundVersion = possibleVersions.some(function (version, i) { | ||
var asArray = Array.isArray(version) ? version : [version]; | ||
@@ -128,3 +128,3 @@ if (seqEqual(versionBytes, asArray)) { | ||
if (!ret.bytes) { | ||
if (!foundVersion) { | ||
throw new Error('version_invalid'); | ||
@@ -131,0 +131,0 @@ } |
@@ -13,12 +13,24 @@ 'use strict'; | ||
function addMethods(codecMethods, api) { | ||
function addVersion(name, args) { | ||
function addVersion(name, opts) { | ||
function add(operation) { | ||
api[operation + name] = function (string) { | ||
return api[operation](string, args); | ||
var encode = operation === 'encode'; | ||
var func = api[operation + name] = function (arg, arg2) { | ||
var params = opts; | ||
if (arg2 && encode) { | ||
params = { version: opts.versions[opts.versionTypes.indexOf(arg2)] }; | ||
} | ||
return api[operation](arg, params); | ||
}; | ||
return func; | ||
} | ||
add('decode'); | ||
if (!args.versions) { | ||
add('encode'); | ||
} | ||
var decode = add('decode'); | ||
add('encode'); | ||
api['validate' + name] = function (arg) { | ||
try { | ||
decode(arg); | ||
} catch (e) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
} | ||
@@ -25,0 +37,0 @@ for (var k in codecMethods) { |
{ | ||
"name": "x-address-codec", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "crypto currency address codec", | ||
@@ -38,3 +38,3 @@ "files": [ | ||
"compile-with-source-maps": "babel -i runtime -s -t -d dist/npm/ src/", | ||
"prepublish": "npm run compile", | ||
"prepublish": "npm test && npm run lint && npm run compile", | ||
"test": "istanbul test _mocha", | ||
@@ -41,0 +41,0 @@ "coveralls": "cat ./coverage/lcov.info | coveralls", |
15503
272