npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lib/utf-8

v0.1.0

Published

This is a well-tested UTF-8 encoder / decoder with some distinctive features:

Downloads

36

Readme

@lib/utf-8

This is a well-tested UTF-8 encoder / decoder with some distinctive features:

  • Very small when minified.
  • Forgiving with invalid inputs.
    • Any JavaScript string will remain identical after encoding and decoding, even if the string itself is invalid UTF-16. See WTF-8 encoding.
    • Overlong UTF-8 sequences of up to 6 bytes are allowed.
  • Detects unrecoverably corrupt UTF-8 input.
    • Runs of unexpected continuation bytes, or a start byte followed by insufficient continuation bytes, become replacement character fffd.
  • Handles astral plane characters like emoji.
  • Supports reading from and writing into existing buffers using given offsets.
  • Written in TypeScript.

Installation

From npm and Node.js:

npm install --save @lib/utf-8
var utf8 = require('@lib/utf-8');

From CDN in HTML:

<script src="https://cdn.jsdelivr.net/npm/@lib/[email protected]/bundle.js"></script>

Using RequireX:

import * as utf8 from '@lib/utf-8';

Usage

// Prints: 194, 189
console.log(utf8.encodeUTF8('½').join(', '));

// Prints: ½
console.log(utf8.decodeUTF8([194, 189]));

API

encodeUTF8(src, dst?, dstPos?, srcPos?, srcEnd?)

UTF-8 encode a string to an array of bytes. This transform cannot fail and is reversible for any input string, regardless of strange or invalid characters (handled using WTF-8).

  • src String to encode.
  • dst Destination array or buffer for storing the result.
  • dstPos Initial offset to destination, default is 0.
  • srcPos Initial offset to source data, default is 0.
  • srcEnd Source data end offset, default is its length.

Returns end offset past data stored if a destination was given, otherwise a numeric array containing the encoded result. Note that output length cannot exceed 3 * input length.

decodeUTF8(src, dst?, srcPos?, srcEnd?)

UTF-8 decode an array of bytes into a string. Invalid surrogate pairs are left as-is to support WTF-8. All other invalid codes become replacement characters (fffd).

  • src Array to encode.
  • dst Output string prefix, default is empty.
  • srcPos Initial offset to source data, default is 0.
  • srcEnd Source data end offset, default is its length.

Returns decoded string.

License

The MIT License

Copyright (c) 2019- RequireX authors.