@dashkite/bake
v0.0.6
Published
Universal JavaScript Encoding Transformations Toolkit
Readme
bake
Universal JavaScript Encoding Transformations Toolkit
"bake" (pronounced "bah-keh") is the romaji representation of a Japanese word meaning "change" or "tranform". This name is also a playful reference to mojibake, describing character encoding failures that result in unintended transformations.
Installation
npm i @dashkite/bakeUsage
bake is designed around standard JavaScript interfaces, so you can use it freely in the browser or Node.js environments. And while DashKite writes with CoffeeScript, and that's what you'll see in examples, bake is published as transpiled JavaScript.
import { convert } from "@dashkite/bake"
string = "I choose to see the beauty."
message = convert from: "utf8", to: "base64", string
# mesage is as follows
# SSBjaG9vc2UgdG8gc2VlIHRoZSBiZWF1dHkuAPI
convert
convert (specification, data) -> transformedDataconvert accepts a specification and some data to work with. It will read the from and to properties of the specification and output transformedData for you, if it knows how.
The specification is an obect with the properties:
from: The starting format ofdatato: The desired format oftransformedData
Available Formats
- base16 / hex
- base36
- base64
- base64url / safe-base64
- bytes
- json
- utf8
- uri
Format Notes
base64url/safe-base64is based on RFC 4648's "base64url" mapping.base36is less common than base64 and base16, but it's a useful format. Likebase64, this format has the advantage of compact expression, butbase36is always URL-safe and uses only lower-case, making it attractive for identifiers.bytesrefers to an instance ofUint8Arrayjsonrefers to JSON string encoding as applied to UTF8 strings. Do not use this to generally stringify data structures.urirefers toencodeURIas appied to UTF8 strings.
