
Security News
November CVEs Fell 25% YoY, Driven by Slowdowns at Major CNAs
November CVE publications fell 25% YoY even as 2025 totals rose, showing how a few major CNAs can swing “global” counts and skew perceived risk.
@47ng/codec
Advanced tools
Universal conversion of Uint8Array from/into UTF-8, base64url and hex in the browser and Node.js
@47ng/codecUniversal conversion of Uint8Array from/into UTF-8, base64url and hex in the browser and Node.js
Available codecs:
utf8 - UTF-8b64 - Base 64 URL (RFC-4648, Section 5)hex - Hexadecimal, lowercaseWatch out !
utf8uses a different convention than the other codecs (encode and decode are swapped), to reflect howTextEncoderandTextDecoderbehave.
$ yarn add @47ng/codec
# or
$ npm i @47ng/codec
TextEncoder / TextDecoderimport { b64, hex, utf8 } from '@47ng/codec'
b64.encode(utf8.encode('Hello, World !')) // SGVsbG8sIFdvcmxkICE=
hex.encode(b64.decode('SGVsbG8sIFdvcmxkICE=')) // 48656c6c6f2c20576f726c642021
utf8.decode(hex.decode('48656c6c6f2c20576f726c642021')) // Hello, World !
b64.decode('SGVsbG8sIFdvcmxkICE=') // <Buffer 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 20 21>
utf8.encode: Convert an UTF-8 string into an array of bytes (Uint8Array)utf8.decode: Convert an array of bytes into an UTF-8 stringExamples:
import { utf8 } from '@47ng/codec'
const uint8Array = utf8.encode('Hello, World!')
// Uint8Array [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]
const backToText = utf8.decode(uint8Array)
// 'Hello, World!'
b64.encode: Convert an array of bytes into a base64url stringb64.decode: Convert a base64 string into an array of bytesb64.urlSafe: Convert a standard base64 string to base64urlb64.urlUnsafe: Convert a base64url string to standard base64 dictionaryNote: For decoding, any dictionary is supported, and trailing padding (
=) is optional.
Examples:
import { b64, utf8 } from '@47ng/codec'
const uint8Array = b64.decode('8J-Ri_CfjI0')
// Uint8Array [240, 159, 145, 139, 240, 159, 140, 141]
// Encoding always emits padding
const backToBase64 = b64.encode(uint8Array)
// '8J-Ri_CfjI0='
const asText = utf8.decode(uint8Array)
// '👋🌍'
hex.encode: Convert an array of bytes into a hex stringhex.decode: Convert a hex string into an array of bytesNote: Decoding accepts any case (lowercase, uppercase, mixed).
Examples:
import { hex } from '@47ng/codec'
const uint8Array = hex.decode('48656C6C6F2C20576f726c642021')
// Uint8Array [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]
// Encoding is always lowercase
const backToBase64 = hex.encode(uint8Array)
// '48656c6c6f2c20576f726c642021'
The library exports convenience methods for converting from one string representation to another:
import {
hexToBase64url,
base64ToHex,
utf8ToBase64,
base64toUTF8,
utf8ToHex,
hexToUTF8
} from '@47ng/codec'
base64ToHex('SGVsbG8sIFdvcmxkICE=')
// 48656c6c6f2c20576f726c642021
hexToBase64url('48656c6c6f2c20576f726c642021')
// SGVsbG8sIFdvcmxkICE=
utf8ToBase64('Hello, World !')
// SGVsbG8sIFdvcmxkICE=
base64toUTF8('SGVsbG8sIFdvcmxkICE=')
// Hello, World !
utf8ToHex('Hello, World !')
// 48656c6c6f2c20576f726c642021
hexToUTF8('48656c6c6f2c20576f726c642021')
// Hello, World !
It also exports encoder / decoder objects with strong TypeScript types, to help you build your own encoders & decoders:
import { encoders, decoders, Encoding } from '@47ng/codec'
// type Encoding = 'base64' | 'utf8' | 'hex'
function convert(
input: string,
inputEncoding: Encoding,
outputEncoding: Encoding
): string {
const decoder = decoders[inputEncoding]
const encoder = encoders[outputEncoding]
return encoder(decoder(input))
}
convert('Hello, World!', 'utf8', 'base64')
// SGVsbG8sIFdvcmxkICE
convert('Hello, World!', 'utf8', 'hex')
// 48656c6c6f2c20576f726c642021
You can detect the encoding of a string:
import { detectEncoding } from '@47ng/codec'
detectEncoding('baadf00dcafebabe') // hex
// Both variants of base64 are detected
detectEncoding('SGVs+G8s/FdvcmxkICE=') // base64
detectEncoding('SGVs-G8s_FdvcmxkICE=') // base64
detectEncoding('not hex not base64') // utf8
MIT - Made with ❤️ by François Best.
Using this package at work ? Sponsor me to help with support and maintenance.
FAQs
Universal conversion of Uint8Array from/into UTF-8, base64url and hex in the browser and Node.js
The npm package @47ng/codec receives a total of 21,898 weekly downloads. As such, @47ng/codec popularity was classified as popular.
We found that @47ng/codec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
November CVE publications fell 25% YoY even as 2025 totals rose, showing how a few major CNAs can swing “global” counts and skew perceived risk.

Security News
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.

Research
/Security News
We spotted a wave of auto-generated “elf-*” npm packages published every two minutes from new accounts, with simple malware variants and early takedowns underway.