base32-encode
Advanced tools
Comparing version 1.0.0 to 1.1.0
12
index.js
@@ -5,4 +5,5 @@ var RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567' | ||
module.exports = function base32Encode (buffer, variant) { | ||
var alphabet, padding | ||
module.exports = function base32Encode (buffer, variant, options) { | ||
options = options || {} | ||
var alphabet, defaultPadding | ||
@@ -13,11 +14,11 @@ switch (variant) { | ||
alphabet = RFC4648 | ||
padding = true | ||
defaultPadding = true | ||
break | ||
case 'RFC4648-HEX': | ||
alphabet = RFC4648_HEX | ||
padding = true | ||
defaultPadding = true | ||
break | ||
case 'Crockford': | ||
alphabet = CROCKFORD | ||
padding = false | ||
defaultPadding = false | ||
break | ||
@@ -28,2 +29,3 @@ default: | ||
var padding = (options.padding !== undefined ? options.padding : defaultPadding) | ||
var length = buffer.byteLength | ||
@@ -30,0 +32,0 @@ var view = new Uint8Array(buffer) |
{ | ||
"name": "base32-encode", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "LinusU/base32-encode", |
@@ -23,2 +23,5 @@ # Base32 Encode | ||
console.log(base32Encode(buffer, 'RFC4648', { padding: false })) | ||
//=> ORSXG5A | ||
console.log(base32Encode(buffer, 'RFC4648-HEX')) | ||
@@ -30,6 +33,8 @@ //=> EHIN6T0= | ||
### base32Encode(buffer, variant) | ||
### base32Encode(buffer, variant, options) | ||
- `buffer` <ArrayBuffer> | ||
- `variant` <String> | ||
- `options` <Object> | ||
- `padding` <Boolean> | ||
@@ -44,4 +49,6 @@ Encode the data in `buffer`. `variant` should be one of the supported variants | ||
Options may have a `padding` property which provides a way to forcefully enable or disable padding. The default behavior is to follow the default of the selected variant. | ||
## See also | ||
- [base32-decode](https://github.com/LinusU/base32-decode) - Base32 decoder |
@@ -68,4 +68,10 @@ var assert = require('assert') | ||
// base32 encode with no options | ||
testCases.forEach(function (testCase) { | ||
assert.equal(base32Encode(hexToArrayBuffer(testCase[1]), testCase[0]), testCase[2]) | ||
}) | ||
// base32 encode with disabled padding option | ||
testCases.forEach(function (testCase) { | ||
assert.equal(base32Encode(hexToArrayBuffer(testCase[1]), testCase[0], { padding: false }), testCase[2].replace(/=/g, '')) | ||
}) |
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
8331
6
120
52