Giter Club home page Giter Club logo

url-safe-base64's Introduction

url-safe-base64

url safe base64 en- and decoding

NPM version

TOC

Example

import {
  encode, decode, trim,
  isBase64, isUrlSafeBase64
} from 'url-safe-base64'
const safe = encode('A/B+C==')
// > 'A-B_C=='
trim(safe)
// > 'A-B_C'
const base64 = decode(safe)
// > 'A/B+C=='
isBase64(base64)
// > true
isBase64(safe)
// > false
isUrlSafeBase64(base64)
// > false
isUrlSafeBase64(safe)
// > true

API

encode(base64)

encode base64 string url safe

Parameters

parameter type description
base64 String base64 encoded string

Returns String, url-safe-base64 encoded

decode(safe)

decode url-safe-base64 string to base64

Parameters

parameter type description
safe String - url-safe-base64 string

Returns String, base64 encoded

trim(string)

trim padding - window.atob might handle trimmed strings, e.g. in Chrome@57, Firefox@52

Parameters

parameter type description
string String - base64 or url-safe-base64 string

Returns String, string with padding chars removed

isBase64(string)

checks if string is base64 encoded

Returns Boolean, true if base64 encoded

isUrlSafeBase64(string)

checks if string is url-safe-base64 encoded

Returns Boolean, true if url-safe-base64 encoded

Installation

$ npm install --save url-safe-base64

Tests

$ npm test

LICENSE

UNLICENSE https://unlicense.org/

url-safe-base64's People

Contributors

commenthol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

url-safe-base64's Issues

isBase64() and isUrlSafeBase64() not properly testing

It seems I can give isBase64() and isUrlSafeBase64() any string of letters and numbers and they still return true, even when the string is neither Base64 nor URL-safe Base64.

isBase64('abc123');
// true

isUrlSafeBase64('abc123');
// true

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.