Skip to content

Commit

Permalink
feat: export supported string encodings (#18)
Browse files Browse the repository at this point in the history
To make consuming the types of this module easier, export the list
of supported to/from string encodings
  • Loading branch information
achingbrain authored Apr 15, 2021
1 parent 18f8cb1 commit 4b971ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { encoding: getCodec } = require('multibase')
const utf8Encoder = new TextEncoder()

/**
* @typedef {import('multibase/src/types').BaseName} BaseName
* @typedef {import('multibase/src/types').BaseName | 'utf8' | 'utf-8' | 'ascii' | undefined} SupportedEncodings
*/

/**
Expand All @@ -31,7 +31,7 @@ function asciiStringToUint8Array (string) {
* Also `ascii` which is similar to node's 'binary' encoding.
*
* @param {string} string
* @param {BaseName | 'utf8' | 'utf-8' | 'ascii'} [encoding=utf8] - utf8, base16, base64, base64urlpad, etc
* @param {SupportedEncodings} [encoding=utf8] - utf8, base16, base64, base64urlpad, etc
* @returns {Uint8Array}
*/
function fromString (string, encoding = 'utf8') {
Expand Down
4 changes: 2 additions & 2 deletions to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { encoding: getCodec } = require('multibase')
const utf8Decoder = new TextDecoder('utf8')

/**
* @typedef {import('multibase/src/types').BaseName} BaseName
* @typedef {import('multibase/src/types').BaseName | 'utf8' | 'utf-8' | 'ascii' | undefined} SupportedEncodings
*/

/**
Expand All @@ -30,7 +30,7 @@ function uint8ArrayToAsciiString (array) {
* Also `ascii` which is similar to node's 'binary' encoding.
*
* @param {Uint8Array} array - The array to turn into a string
* @param {BaseName | 'utf8' | 'utf-8' | 'ascii'} [encoding=utf8] - The encoding to use
* @param {SupportedEncodings} [encoding=utf8] - The encoding to use
* @returns {string}
*/
function toString (array, encoding = 'utf8') {
Expand Down

0 comments on commit 4b971ec

Please sign in to comment.