universal-base64
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -1,2 +0,2 @@ | ||
export declare const decode: any; | ||
export declare const encode: any; | ||
export declare function encode(str: string): string; | ||
export declare function decode(str: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decode = window.atob.bind(window); | ||
exports.encode = window.btoa.bind(window); | ||
function percentToByte(p) { | ||
return String.fromCharCode(parseInt(p.slice(1), 16)); | ||
} | ||
function encode(str) { | ||
return btoa(encodeURIComponent(str).replace(/%[0-9A-F]{2}/g, percentToByte)); | ||
} | ||
exports.encode = encode; | ||
function byteToPercent(b) { | ||
return `%${`00${b.charCodeAt(0).toString(16)}`.slice(-2)}`; | ||
} | ||
function decode(str) { | ||
return decodeURIComponent(Array.from(atob(str), byteToPercent).join("")); | ||
} | ||
exports.decode = decode; | ||
//# sourceMappingURL=browser.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const browser_1 = require("./browser"); | ||
describe('node', () => { | ||
it('should base64 encode', () => { | ||
expect(browser_1.encode('test')).toEqual('dGVzdA=='); | ||
describe("node", () => { | ||
it("should base64 encode", () => { | ||
expect(browser_1.encode("hello")).toEqual("aGVsbG8="); | ||
}); | ||
it('should base64 decode', () => { | ||
expect(browser_1.decode('dGVzdA==')).toEqual('test'); | ||
it("should encode non latin characters", () => { | ||
expect(browser_1.encode("你好")).toEqual("5L2g5aW9"); | ||
}); | ||
it("should base64 decode", () => { | ||
expect(browser_1.decode("aGVsbG8=")).toEqual("hello"); | ||
}); | ||
it("should decode non latin characters", () => { | ||
expect(browser_1.decode("5L2g5aW9")).toEqual("你好"); | ||
}); | ||
}); | ||
//# sourceMappingURL=browser.spec.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function decode(str) { | ||
return Buffer.from(str, 'base64').toString('latin1'); | ||
return Buffer.from(str, "base64").toString("utf8"); | ||
} | ||
exports.decode = decode; | ||
function encode(str) { | ||
return Buffer.from(str, 'latin1').toString('base64'); | ||
return Buffer.from(str, "utf8").toString("base64"); | ||
} | ||
exports.encode = encode; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("./index"); | ||
describe('node', () => { | ||
it('should base64 encode', () => { | ||
expect(index_1.encode('test')).toEqual('dGVzdA=='); | ||
describe("node", () => { | ||
it("should base64 encode", () => { | ||
expect(index_1.encode("hello")).toEqual("aGVsbG8="); | ||
}); | ||
it('should base64 decode', () => { | ||
expect(index_1.decode('dGVzdA==')).toEqual('test'); | ||
it("should encode non latin characters", () => { | ||
expect(index_1.encode("你好")).toEqual("5L2g5aW9"); | ||
}); | ||
it("should base64 decode", () => { | ||
expect(index_1.decode("aGVsbG8=")).toEqual("hello"); | ||
}); | ||
it("should decode non latin characters", () => { | ||
expect(index_1.decode("5L2g5aW9")).toEqual("你好"); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.spec.js.map |
{ | ||
"name": "universal-base64", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Small universal base64 functions for node.js and browsers", | ||
@@ -12,10 +12,17 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"prettier": "prettier --write", | ||
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json", | ||
"build": "rm -rf dist/ && tsc", | ||
"format": "npm run prettier -- README.md \"src/**/*.{js,ts}\"", | ||
"build": "rimraf dist && tsc", | ||
"specs": "jest --coverage", | ||
"test": "npm run lint && npm run build && npm run specs && npm run bundle && npm run bundle:size", | ||
"bundle": "browserify . -o browser.js", | ||
"bundle:size": "wc -c < browser.js", | ||
"prepublish": "npm run build" | ||
"test": "npm run -s lint && npm run -s build && npm run -s specs && npm run -s size", | ||
"prepare": "npm run build", | ||
"size": "size-limit" | ||
}, | ||
"size-limit": [ | ||
{ | ||
"path": "./dist/browser.js", | ||
"limit": "200 B" | ||
} | ||
], | ||
"repository": { | ||
@@ -60,10 +67,29 @@ "type": "git", | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,json,css,md}": [ | ||
"npm run prettier", | ||
"git add" | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^23.3.3", | ||
"@types/node": "^10.1.2", | ||
"browserify": "^16.1.1", | ||
"jest": "^23.6.0", | ||
"@types/jest": "^24.0.13", | ||
"@types/node": "^12.0.2", | ||
"browserify": "^16.2.3", | ||
"husky": "^2.3.0", | ||
"jest": "^24.8.0", | ||
"lint-staged": "^8.1.7", | ||
"prettier": "^1.17.1", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^23.10.4", | ||
"size-limit": "^1.3.5", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "^5.9.1", | ||
"tslint-config-prettier": "^1.18.0", | ||
"tslint-config-standard": "^8.0.1", | ||
@@ -70,0 +96,0 @@ "typescript": "^3.1.1" |
@@ -7,2 +7,3 @@ # Universal Base64 | ||
[![Test coverage](https://img.shields.io/coveralls/blakeembrey/universal-base64.svg?style=flat)](https://coveralls.io/r/blakeembrey/universal-base64?branch=master) | ||
[![Bundle size](https://img.shields.io/bundlephobia/minzip/universal-base64.svg)](https://bundlephobia.com/result?p=universal-base64) | ||
@@ -22,6 +23,6 @@ > Small universal base64 functions for node.js and browsers. | ||
```js | ||
import { decode, encode } from 'universal-base64' | ||
import { decode, encode } from "universal-base64"; | ||
encode('test') //=> "dGVzdA==" | ||
decode('dGVzdA==') //=> "test" | ||
encode("test"); //=> "dGVzdA==" | ||
decode("dGVzdA=="); //=> "test" | ||
``` | ||
@@ -28,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10736
66
35
14