Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base64it

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base64it - npm Package Compare versions

Comparing version 0.9.1 to 1.0.0

.jshintrc

63

lib/base64it.js
"use strict";
/*global window*/
var strictEncode = null;
var strictDecode = null;
var nativeEncode = require("./base64Native").encode;
var nativeDecode = require("./base64Native").decode;
var stripPadding = require("./utils").stripPadding;
var breakIntoPieces = require("./utils").breakIntoPieces;
if (typeof window !== "undefined" && typeof window.btoa === "function") { // When running in a browser.
function applyOptions(encoded, options) {
options = options || {};
if (options.stripPadding) {
encoded = stripPadding(encoded);
}
if (options.lineLength) {
encoded = breakIntoPieces(encoded, options.lineLength);
}
if (options.urlSafe) {
encoded = encoded.replace(/\+/g, "-").replace(/\//g, "_");
}
return encoded;
}
strictEncode = function (unencoded) {
return window.btoa(unencoded);
};
function encodeWithOptions(unencoded, options) {
var encoded = nativeEncode(unencoded);
return applyOptions(encoded, options);
}
strictDecode = function (encoded) {
return window.atob(encoded);
};
} else { // When running in Node.
strictEncode = function (unencoded) {
return new Buffer(unencoded).toString("base64");
};
strictDecode = function (encoded) {
return new Buffer(encoded, "base64");
};
function urlSafeDecode(encoded) {
return nativeDecode(encoded.replace(/-/g, "+").replace(/_/g, "/"));
}
module.exports = {
strictEncode: strictEncode,
strictDecode: strictDecode,
encode: encodeWithOptions,
decode: urlSafeDecode,
urlSafeEncode: function (unencoded) {
return strictEncode(unencoded).replace("+", "-").replace("/", "_");
strictEncode: function (unencoded, options) {
options = options || {};
options.urlSafe = false;
return encodeWithOptions(unencoded, options);
},
strictDecode: nativeDecode,
urlSafeDecode: function (encoded) {
return strictDecode(encoded.replace("-", "+").replace("_", "/"));
}
urlSafeEncode: function (unencoded, options) {
options = options || {};
options.urlSafe = true;
return encodeWithOptions(unencoded, options);
},
urlSafeDecode: urlSafeDecode
};
{
"name": "base64it",
"version": "0.9.1",
"description": "A simple base64 encoder/decoder that works with HTML5 and Node. Supports strict mode and URL safe.",
"version": "1.0.0",
"description": "A simple base64 encoder/decoder that works with HTML5 and Node. Supports strict mode and URL safe encoding/decoding.",
"homepage": "https://github.com/YuzuJS/base64it",

@@ -20,2 +20,10 @@ "main": "lib/base64it.js",

],
"devDependencies": {
"jshint": ">= 0.7.1",
"coffee-script": ">= 1.3.3",
"mocha": ">= 1.1.0",
"chai": ">= 1.0.4",
"sinon": ">= 1.3.4",
"sinon-chai": ">= 2.1.0"
},
"license": {

@@ -25,2 +33,6 @@ "type": "MIT",

},
"scripts": {
"lint": "jshint ./lib",
"test": "mocha"
},
"repository": {

@@ -27,0 +39,0 @@ "type": "git",

@@ -1,5 +0,5 @@

base64it
Base64It [![Build Status](https://travis-ci.org/YuzuJS/base64it.svg)](https://travis-ci.org/YuzuJS/base64it)
========
A simple base64 encoder/decoder that works with HTML5 and Node. Supports strict mode and URL safe.
A simple base64 encoder/decoder that works with HTML5 and Node. Supports strict mode and URL safe encoding/decoding.

@@ -12,3 +12,57 @@ ### Get the package

### License
Released under MIT license
##Encoding
base64it supports the following encoding standards:
1. Standard 'base64' (i.e. strict) (see [RFC 4648 § 4](http://tools.ietf.org/html/rfc4648#section-4>))
2. Standard 'base64url' with URL and Filename Safe Alphabet (see [RFC 4648 § 5](http://tools.ietf.org/html/rfc4648#section-5>))
### Examples
To encode, just call base64.encode.
```javascript
var base64 = require("base64it");
var encoded = base64.encode("Hello world")
console.log(encoded); // SGVsbG8gd29ybGQ=
```
To convert it back, just call base64.decode.
```javascript
var decoded = base64.decode(encoded)
console.log(decoded); // Hello world
```
### Live Demo
You can also see Base64It in action, live, on the Interwebs! Check out this fiddle. <http://jsfiddle.net/donavon/aqv815ec/>
## API
##### base64.encode(unencoded:string, options?:Options):string
Encodes a string into a base64 encoded string.
Where:
**unencoded** is the string you want to encode.
**options** is a set of encoding Options as follows (optional)
* **stripPadding**:Boolean - determines whether the resulting string will have any padding characters (i.e. "=") removed (default = false)
* **lineLength**:Number - if set, the resulting string will be broken into multiple lines seperated by \r\n. This is normally set to either 64 or 76. (default = one continuous line)
* **urlSafe**:Boolean - if set, the resulting string will be URL Safe (i.e. "+" and "/" chars willbe converted to "-" and "_" respectively). (default = false)
##### base64.strictEncode(unencoded:string, options?:Options):string
This is simply sugar around `base64.encode` with the `urlSafe` options seto to `false`.
##### base64.urlSafeEncode(unencoded:string, options?:Options):string
This is simply sugar around `base64.encode` with the `urlSafe` options seto to `true`.
##### base64.strictDecode(encoded:string):string
This will decode a base64 encoded string. Padding characters are optional.
##### base64.urlSafeDecode(encoded:string):string
This will decode a URL safe base64 encoded string. Padding characters are optional.
## License
For use under [MIT license](http://github.com/YuzuJS/base64it/raw/master/LICENSE)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc