Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function fromString (src, encoding = 'utf8') {
switch (encoding) {
case 'utf8': {
return fromUTF8(src)
}
case 'hex': {
return new Uint8Array(fromHex(src))
}
case 'base64': {
return fromBase64(src)
}
default: {
throw new Error(`Unsupported encoding ${encoding}`)
}
}
}