@litert/[email protected]

该文章根据 CC-BY-4.0 协议发表,转载请遵循该协议。
本文地址:https://fenying.net/en/project/litert/encodings/v2.3.0/

The buffer-based encoding utility method for node.js.

Following types of encodings are supported:

Name Description Binary-Safe
base64 The standard BASE64 encoding. Yes
base64url The URL-safe BASE64 encoding. Yes
base62x The BASE62x encoding. Yes
base32 The standard BASE32 encoding. Yes
hex The hexadecimal encoding. Yes
urlencode The purely URL-safe encoding. Yes
strict_uri The extended URL-safe encoding. No

Encoding urlencode

This is a real urlencode implement, it will escape all bytes as %xx format, excepting A-Z, a-z and 0-9. This is a binary-safe encoding.

Binary-safe means it could work with binary data perfectly, without gibberish. And it’s all the same below.

Encoding uri

This is a simple reference of method encodeURIComponent, so it works as method encodeURIComponent does. And it’s not a binary-safe encoding.

Encoding strict_uri

This is based on uri, but all special chars including "-", ".", "_", "!", "*", "(", ")", "~", "'" will be escaped. However, it’s still not a binary-safe encoding.

NOTE: The data of strict_uri encoding, could be simply decoded by function decodeURIComponent.

Encoding base64url

This is based on base64, while charactors "=", "+", "/" will be replaced with URL-safe charactors. This is a binary-safe encoding.

Encoding base62x

This is a variation of base64. And it is a binary-safe encoding.

Installation

1npm install @litert/encodings@^2.3.0

v2.3.0 CHANGELOG

  • config(deps): updated dependencies.
  • fix(encoding): fixed decoding of the urlencode.
  • build(test): added test cases.
  • build(project): upgraded the minimum version of Node.js to v14.