Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
fast-text-encoding
Advanced tools
The fast-text-encoding npm package is a polyfill for the TextEncoder and TextDecoder APIs, which are part of the Encoding Living Standard. These APIs provide a straightforward way to encode and decode text using various character encodings, primarily UTF-8. This package is particularly useful in environments where the native TextEncoder and TextDecoder are not available, such as older browsers or specific Node.js versions.
Text Encoding
This feature allows you to encode a JavaScript string into a Uint8Array of bytes using UTF-8 encoding. It's useful for preparing text data for transmission or storage in binary formats.
const textEncoder = new TextEncoder();
const encoded = textEncoder.encode('Hello, World!');
console.log(encoded);
Text Decoding
This feature enables you to decode a Uint8Array of bytes into a JavaScript string using UTF-8 or other supported encodings. It's commonly used for reading text data received in binary format.
const textDecoder = new TextDecoder();
const decoded = textDecoder.decode(new Uint8Array([72, 101, 108, 108, 111]));
console.log(decoded);
The text-encoding package is another polyfill for the TextEncoder and TextDecoder APIs, similar to fast-text-encoding. It supports a wider range of encodings beyond UTF-8, making it more versatile for applications that need to work with different character sets. However, it might be larger in size and potentially slower than fast-text-encoding, which focuses on speed and efficiency for UTF-8 encoding.
While not a direct polyfill for TextEncoder and TextDecoder, the buffer package in Node.js provides similar functionalities for encoding and decoding text in various character encodings. It's more integrated into the Node.js ecosystem and offers a broader set of features for manipulating binary data, but it might be more complex to use for simple text encoding/decoding tasks compared to fast-text-encoding.
This is a fast polyfill for TextEncoder
and TextDecoder
, which let you encode and decode JavaScript strings into UTF-8 bytes.
It is fast partially as it does not support any encodings aside UTF-8 (and note that natively, only TextDecoder
supports alternative encodings anyway).
Include the minified inside a script
tag or as an ES6 Module for its side-effects.
It will create TextEncoder
and TextDecoder
if the symbols are missing on window
.
<script src="node_modules/fast-text-encoding/text.min.js"></script>
<script type="module">
import './node_modules/fast-text-encoding/text.min.js';
// confidently do something with TextEncoder \o/
</script>
Note: Always include text.min.js
, as it's compiled to ES5 for older environments.
Install via NPM or Yarn (name "fast-text-encoding"), and then import purely for side effects:
// don't need to save this anywhere, just require before use
require('fast-text-encoding');
const buffer = new TextEncoder().encode('Turn me into UTF-8!');
// buffer is now a Uint8Array of [84, 117, 114, 110, ...]
However, note that Buffer.from('Turn me into UTF-8!')
is Node's native version of the text encoding functionality.
You can probably massage Buffer
into acting like TextEncoder
and TextDecoder
.
Built for IE11, Edge and Node environments. Not required for Chrome, Firefox etc, which have native implementations.
Compile code with Closure Compiler.
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name text.min.js
// ==/ClosureCompiler==
// code here
FAQs
Fast polyfill for TextEncoder and TextDecoder, only supports utf-8
The npm package fast-text-encoding receives a total of 4,483,096 weekly downloads. As such, fast-text-encoding popularity was classified as popular.
We found that fast-text-encoding 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.