Giter Site home page Giter Site logo

hexagon / base64 Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 2.0 1.33 MB

Base64 and base64url to string or arraybuffer, and back. Works in Node, Deno or browser.

Home Page: http://base64.56k.guru/

License: MIT License

JavaScript 12.24% TypeScript 87.76%
base64 base64url arraybuffer string typescript javascript node deno esmodule esm umd commonjs

base64's Introduction

@hexagon/base64

Probably the only JavaScript base64 library you'll ever need!

@hexagon/base64

Encode, decode and validate base64/base64url to string/arraybuffer and vice-versa. Works in Node, Deno and browser.

Node.js CI Deno CI npm version NPM Downloads jsdelivr Codacy Badge MIT License

  • Supports regular base64 and base64url
  • Convert to/from string or arraybuffer
  • Validate / identify base64 and base64url
  • Works in Node.js >=4.0 (both require and import).
  • Works in Deno >=1.16.
  • Works in browsers as standalone, UMD or ES-module.
  • Includes TypeScript typings.
// Encode string as regular base64
const example1enc = base64.fromString("Hellö Wörld, how are you doing today?!");
console.log(example1enc);
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==

// Decode string as regular base64
const example1dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==");
console.log(example1dec);
// > Hellö Wörld, how are you doing today?!

Full documentation available at base64.56k.guru

Quick Installation

Node.js: npm install @hexagon/base64 --save

Deno (x): import base64 from "https://deno.land/x/[email protected]/src/base64.js";

Deno (jsr.io): import base64 from "jsr:@hexagon/[email protected]";

For browser/cdn usage, refer to the documentation.

Quick API

  • fromArrayBuffer(buffer, urlMode) - Encodes ArrayBuffer into base64 or base64url if urlMode(optional) is true

  • toArrayBuffer(str, urlMode) - Decodes base64url string (or base64url string if urlMode is true) to ArrayBuffer

  • fromString(str, urlMode) - Encodes String into base64 string(base64url string if urlMode is true)

  • toString(str, urlMode) - Decodes base64 or base64url string to String

  • validate(str, urlMode) - Returns true if String str is valid base64/base64 dependending on urlMode

Contributing

See Contribution Guide

Donations

If you found this library helpful and wish to support its development, consider making a donation through Hexagon's GitHub Sponsors page. Your generosity ensures the library's continued development and maintenance.

Contributors

The underlying code is loosely based on github.com/niklasvh/base64-arraybuffer

License

MIT

base64's People

Contributors

hexagon avatar xcelr8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

xcelr8 cjsewell

base64's Issues

types not exported correctly

Types are not being picked up in my project, heres a minimal reproduction:

https://stackblitz.com/edit/vitejs-vite-ayep6m?file=src%2Fmain.ts

CleanShot 2024-06-22 at 16 27 33@2x

I think this has todo with the following settings in tsconfig

"moduleResolution": "Bundler",
"module": "ESNext",

I could resolve this by patching @hexagon/base64 package.json to the following:

   "exports": {
     ".": {
-      "import": "./src/base64.js",
+      "import": {"default":"./src/base64.js", "types":"./types/base64.d.ts"},
       "require": "./dist/base64.cjs",
       "browser": "./dist/base64.min.js"
     }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.