@darkwolf/base58
Advanced tools
Comparing version 1.0.5 to 1.0.6
46
index.js
@@ -6,13 +6,9 @@ const { validator, errors } = require('./utils') | ||
constructor(alphabet) { | ||
new Validator(alphabet) | ||
.isNotExists() | ||
.or | ||
if (validator.isExists(alphabet)) new Validator(alphabet) | ||
.isString() | ||
.throw(errors.INVALID_ALPHABET | ||
.throw(() => errors.INVALID_ALPHABET | ||
.setType('invalid-argument-type') | ||
.setMessage('"alphabet" argument must be a string')) | ||
if (validator.isExists(alphabet)) new Validator(alphabet) | ||
.isAlphabet() | ||
.throw(errors.INVALID_ALPHABET | ||
.throw(() => errors.INVALID_ALPHABET | ||
.setType('invalid-argument-value') | ||
@@ -34,11 +30,11 @@ .setMessage('"alphabet" argument has the wrong format')) | ||
.isExists() | ||
.throw(errors.INVALID_ALPHABET | ||
.throw(() => errors.INVALID_ALPHABET | ||
.setType('argument-required') | ||
.setMessage('"alphabet" argument is required')) | ||
.isString() | ||
.throw(errors.INVALID_ALPHABET | ||
.throw(() => errors.INVALID_ALPHABET | ||
.setType('invalid-argument-type') | ||
.setMessage('"alphabet" argument must be a string')) | ||
.isAlphabet() | ||
.throw(errors.INVALID_ALPHABET | ||
.throw(() => errors.INVALID_ALPHABET | ||
.setType('invalid-argument-value') | ||
@@ -56,9 +52,12 @@ .setMessage('"alphabet" argument has the wrong format')) | ||
.setMessage('"input" argument is required')) | ||
.isString() | ||
.or | ||
.isBuffer() | ||
.throw(errors.INVALID_INPUT | ||
let buffer | ||
if (validator.isString(input)) { | ||
buffer = Buffer.from(input) | ||
} else if (validator.isBuffer(input)) { | ||
buffer = input | ||
} else { | ||
throw errors.INVALID_INPUT | ||
.setType('invalid-argument-type') | ||
.setMessage('"input" argument must be a string or a buffer')) | ||
const buffer = validator.isBuffer(input) ? input : Buffer.from(input) | ||
.setMessage('"input" argument must be a string or a buffer') | ||
} | ||
return buffer.reduce((bytes, carry, i) => { | ||
@@ -86,9 +85,12 @@ if (!(carry || bytes.length ^ i)) bytes.push(1) | ||
.setMessage('"input" argument is required')) | ||
.isString() | ||
.or | ||
.isBuffer() | ||
.throw(errors.INVALID_INPUT | ||
let string | ||
if (validator.isString(input)) { | ||
string = input | ||
} else if (validator.isBuffer(input)) { | ||
string = input.toString() | ||
} else { | ||
throw errors.INVALID_INPUT | ||
.setType('invalid-argument-type') | ||
.setMessage('"input" argument must be a string or a buffer')) | ||
const string = validator.isString(input) ? input : input.toString() | ||
.setMessage('"input" argument must be a string or a buffer') | ||
} | ||
return String.fromCharCode(...string.split('').map(o => this.alphabet.indexOf(o)).reduce((bytes, carry, i) => { | ||
@@ -95,0 +97,0 @@ if (!(carry || bytes.length ^ i)) bytes.push(0) |
{ | ||
"name": "@darkwolf/base58", | ||
"version": "1.0.5", | ||
"description": "Base58 Encoder/Decoder", | ||
"version": "1.0.6", | ||
"description": "Base58 Encoder/Decoder Utility", | ||
"main": "index.js", | ||
@@ -27,5 +27,5 @@ "scripts": { | ||
"dependencies": { | ||
"@darkwolf/code-error": "^2.0.7", | ||
"@darkwolf/validator": "^2.0.2" | ||
"@darkwolf/code-error": "^2.0.8", | ||
"@darkwolf/validator": "^2.0.3" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Base58 | ||
# Base58 Encoder/Decoder Utility | ||
## Install | ||
@@ -3,0 +3,0 @@ ```sh |
@@ -9,3 +9,3 @@ const CodeError = require('@darkwolf/code-error') | ||
if (args.length === 3) { | ||
if (args.length > 2) { | ||
const [code, type, message] = args | ||
@@ -12,0 +12,0 @@ options.code = code |
@@ -16,17 +16,8 @@ const { Validator } = require('@darkwolf/Validator') | ||
_isNotAlphabet(...args) { | ||
return !this._isAlphabet(...args) | ||
} | ||
isAlphabet(...args) { | ||
if (args.length) return this._isAlphabet(...args) | ||
return this._valid(this._isAlphabet(this.value)) | ||
return this._valid(() => this._isAlphabet(this.value)) | ||
} | ||
isNotAlphabet(...args) { | ||
if (args.length) return this._isNotAlphabet(...args) | ||
return this._valid(this._isNotAlphabet(this.value)) | ||
} | ||
} | ||
module.exports = new Base58Validator() |
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
7236
150
Updated@darkwolf/code-error@^2.0.8
Updated@darkwolf/validator@^2.0.3