Skip to content

Commit

Permalink
chore: upgrade aegir
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Dec 18, 2020
1 parent 6f431d2 commit 3a2ab7a
Show file tree
Hide file tree
Showing 9 changed files with 4,091 additions and 6,556 deletions.
2 changes: 1 addition & 1 deletion compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @param {Uint8Array} a
* @param {Uint8Array} b
* @returns {Number}
* @returns {number}
*/
function compare (a, b) {
for (let i = 0; i < a.byteLength; i++) {
Expand Down
2 changes: 1 addition & 1 deletion concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Returns a new Uint8Array created by concatenating the passed ArrayLikes
*
* @param {Array<ArrayLike<number>>} arrays
* @param {Number} [length]
* @param {number} [length]
* @returns {Uint8Array}
*/
function concat (arrays, length) {
Expand Down
23 changes: 10 additions & 13 deletions from-string.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
'use strict'

const { names } = require('multibase/src/constants')
const { encoding: getCodec } = require('multibase')
const { TextEncoder } = require('web-encoding')
const utf8Encoder = new TextEncoder()

/**
* Interperets each character in a string as a byte and
* @typedef {import('multibase/src/types').BaseName} BaseName
*/

/**
* Interprets each character in a string as a byte and
* returns a Uint8Array of those bytes.
*
* @param {String} string The string to turn into an array
* @param {string} string - The string to turn into an array
* @returns {Uint8Array}
*/
function asciiStringToUint8Array (string) {
Expand All @@ -28,10 +32,9 @@ function asciiStringToUint8Array (string) {
*
* Also `ascii` which is similar to node's 'binary' encoding.
*
* @param {String} string
* @param {String} [encoding=utf8] utf8, base16, base64, base64urlpad, etc
* @param {string} string
* @param {BaseName | 'utf8' | 'utf-8' | 'ascii'} [encoding=utf8] - utf8, base16, base64, base64urlpad, etc
* @returns {Uint8Array}
* @see {@link https://www.npmjs.com/package/multibase|multibase} for supported encodings other than `utf8`
*/
function fromString (string, encoding = 'utf8') {
if (encoding === 'utf8' || encoding === 'utf-8') {
Expand All @@ -42,13 +45,7 @@ function fromString (string, encoding = 'utf8') {
return asciiStringToUint8Array(string)
}

const codec = names[encoding]

if (!codec) {
throw new Error('Unknown base')
}

return codec.decode(string)
return getCodec(encoding).decode(string)
}

module.exports = fromString
Loading

0 comments on commit 3a2ab7a

Please sign in to comment.