New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

utf8-decoder

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utf8-decoder

<!-- automd:badges color=yellow -->

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-70%
Maintainers
0
Weekly downloads
 
Created
Source

utf8-decoder

npm version npm downloads

A simple UTF-8 decoder, keeping align with native TextDecoder as much as possible.

Most part of the code is modified from V8's Utf8DfaDecoder, which is a modified version of Flexible and Economical UTF-8 Decoder.

  • Handle malformed UTF-8 better than most solutions.
  • Produce same output as the Node's TextDecoder.
  • Keep default char unicode as-is instead of throwing error.
  • Process surrogate pairs correctly for Emojis.
  • Designed with performance in mind. Provide comparable performance to native TextDecoder.

You can try over the test case for other UTF-8 decoders to see the difference, especially the malformed cases.

Usage

Install package:

# ✨ Auto-detect
npx nypm install utf8-decoder

# npm
npm install utf8-decoder

# yarn
yarn add utf8-decoder

# pnpm
pnpm install utf8-decoder

# bun
bun install utf8-decoder

Import:

ESM (Node.js, Bun)

import { decode } from "utf8-decoder";

CommonJS (Legacy Node.js)

const { decode } = require("utf8-decoder");

CDN (Deno, Bun and Browsers)

import { decode } from "https://esm.sh/utf8-decoder";

Development

local development
  • Clone this repository
  • Install latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

Reference

Unicode/UTF-8 is a complex topic, here are some references for further reading:

I recommend reading the chapter 3 of the Unicode Standard for a better understanding of the encoding and the invalid sequences and error handling.

This project is highly inspired by the following projects:

License

Published under the MIT license. Made by community 💛


🤖 auto updated with automd

FAQs

Package last updated on 27 Jun 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc