Code Monkey home page Code Monkey logo

base64.js's Introduction

Base64.js

简介

虽然JavaScript中可以使用原生的btoa和atob函数进行Base64的编解码。但是不支持中文字符,并且不支持url-safe的Base64编解码。当编码后的结果要是通过get请求传输时(比如跨域提交时),结果中包含有'/'字符将导致出错。

本项目借鉴了loonhxl的 jbase64 项目,并做了一些修改。

  • 支持一般Base64的编码和解码
  • 支持符合RFC_4648标准中"URL and Filename Safe Alphabet"的URL安全Base64编解码
  • 支持中文字符的编解码(Unicode编码)

使用

直接引入

<script type="text/javascript" src="base64.js"></script>

通过RequireJs

require(['base64'], function (BASE64) {
});

通过CommonJs

var BASE64 = require('base64');

示例

BASE64.encode(inputStr);//普通Base64编码
BASE64.decode(inputStr);//普通Base64解码
BASE64.urlsafe_encode(inputStr);//url-safe Base64编码
BASE64.urlsafe_decode(inputStr);//url-safe Base64解码

base64.js's People

Contributors

slice30k avatar

Watchers

James Cloos avatar

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.