Initial Commit
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
/// <reference path="../typings/index.d.ts" />
|
||||
export interface Base64Url {
|
||||
(input: string | Buffer, encoding?: string): string;
|
||||
encode(input: string | Buffer, encoding?: string): string;
|
||||
decode(base64url: string, encoding?: string): string;
|
||||
toBase64(base64url: string | Buffer): string;
|
||||
fromBase64(base64: string): string;
|
||||
toBuffer(base64url: string): Buffer;
|
||||
}
|
||||
declare let base64url: Base64Url;
|
||||
export default base64url;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
var pad_string_1 = require("./pad-string");
|
||||
function encode(input, encoding) {
|
||||
if (encoding === void 0) { encoding = "utf8"; }
|
||||
if (Buffer.isBuffer(input)) {
|
||||
return fromBase64(input.toString("base64"));
|
||||
}
|
||||
return fromBase64(new Buffer(input, encoding).toString("base64"));
|
||||
}
|
||||
;
|
||||
function decode(base64url, encoding) {
|
||||
if (encoding === void 0) { encoding = "utf8"; }
|
||||
return new Buffer(toBase64(base64url), "base64").toString(encoding);
|
||||
}
|
||||
function toBase64(base64url) {
|
||||
base64url = base64url.toString();
|
||||
return pad_string_1.default(base64url)
|
||||
.replace(/\-/g, "+")
|
||||
.replace(/_/g, "/");
|
||||
}
|
||||
function fromBase64(base64) {
|
||||
return base64
|
||||
.replace(/=/g, "")
|
||||
.replace(/\+/g, "-")
|
||||
.replace(/\//g, "_");
|
||||
}
|
||||
function toBuffer(base64url) {
|
||||
return new Buffer(toBase64(base64url), "base64");
|
||||
}
|
||||
var base64url = encode;
|
||||
base64url.encode = encode;
|
||||
base64url.decode = decode;
|
||||
base64url.toBase64 = toBase64;
|
||||
base64url.fromBase64 = fromBase64;
|
||||
base64url.toBuffer = toBuffer;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = base64url;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export default function padString(input: string): string;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
function padString(input) {
|
||||
var segmentLength = 4;
|
||||
var stringLength = input.length;
|
||||
var diff = stringLength % segmentLength;
|
||||
if (!diff) {
|
||||
return input;
|
||||
}
|
||||
var position = stringLength;
|
||||
var padLength = segmentLength - diff;
|
||||
var paddedStringLength = stringLength + padLength;
|
||||
var buffer = new Buffer(paddedStringLength);
|
||||
buffer.write(input);
|
||||
while (padLength--) {
|
||||
buffer.write("=", position++);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = padString;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
module.exports = require('./dist/base64url').default;
|
||||
module.exports.default = module.exports;
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "base64url@^2.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "base64url",
|
||||
"name": "base64url",
|
||||
"rawSpec": "^2.0.0",
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/Users/linnemann/Documents/dev/nodejs/microservices_boilerplate/service002/node_modules/jws"
|
||||
]
|
||||
],
|
||||
"_from": "base64url@>=2.0.0 <3.0.0",
|
||||
"_id": "base64url@2.0.0",
|
||||
"_inCache": true,
|
||||
"_location": "/base64url",
|
||||
"_nodeVersion": "6.2.2",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/base64url-2.0.0.tgz_1468467204479_0.18601951375603676"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "brianloveswords",
|
||||
"email": "brianloveswords@gmail.com"
|
||||
},
|
||||
"_npmVersion": "3.9.5",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "base64url@^2.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "base64url",
|
||||
"name": "base64url",
|
||||
"rawSpec": "^2.0.0",
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ecdsa-sig-formatter",
|
||||
"/jwa",
|
||||
"/jws"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz",
|
||||
"_shasum": "eac16e03ea1438eff9423d69baa36262ed1f70bb",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "base64url@^2.0.0",
|
||||
"_where": "/Users/linnemann/Documents/dev/nodejs/microservices_boilerplate/service002/node_modules/jws",
|
||||
"author": {
|
||||
"name": "Brian J Brennan"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/brianloveswords/base64url/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "For encoding to/from base64urls",
|
||||
"devDependencies": {
|
||||
"tap": "6.1.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "eac16e03ea1438eff9423d69baa36262ed1f70bb",
|
||||
"tarball": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
"typings/",
|
||||
"index.js"
|
||||
],
|
||||
"gitHead": "59b00b9bfa6ca96fb1458f0ebee269dc8f5a14c7",
|
||||
"homepage": "https://github.com/brianloveswords/base64url#readme",
|
||||
"keywords": [
|
||||
"base64",
|
||||
"base64url"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "brianloveswords",
|
||||
"email": "brian@nyhacker.org"
|
||||
}
|
||||
],
|
||||
"name": "base64url",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/brianloveswords/base64url.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "rm -f dist/*",
|
||||
"prepublish": "npm run test",
|
||||
"test": "npm run clean && npm run build && tap test/*.test.js"
|
||||
},
|
||||
"typings": "dist/base64url.d.ts",
|
||||
"version": "2.0.0"
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
# base64url [](http://travis-ci.org/brianloveswords/base64url)
|
||||
|
||||
Converting to, and from, [base64url](http://en.wikipedia.org/wiki/Base64#RFC_4648)
|
||||
|
||||
# Install
|
||||
|
||||
```bash
|
||||
$ npm install base64url
|
||||
```
|
||||
|
||||
After installing with `npm` you can require this library from JavaScript or TypeScript:
|
||||
|
||||
JavaScript
|
||||
```js
|
||||
const base64url = require('base64url');
|
||||
```
|
||||
|
||||
TypeScript:
|
||||
```typescript
|
||||
import base64url from "base64url";
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
## CLI
|
||||
|
||||
The CLI has been removed. For the time being, please install `base64url@1.0.6` if you need the CLI.
|
||||
|
||||
## Library
|
||||
|
||||
### base64url(input: string | Buffer, encoding: string = "utf8"): string
|
||||
|
||||
### base64url.encode(input: string | Buffer, encoding: string = "utf8"): string
|
||||
|
||||
base64url encode `input`. Input should be a `string` or a `Buffer`.
|
||||
|
||||
|
||||
Example
|
||||
|
||||
```js
|
||||
> base64url("ladies and gentlemen we are floating in space")
|
||||
'bGFkaWVzIGFuZCBnZW50bGVtYW4sIHdlIGFyZSBmbG9hdGluZyBpbiBzcGFjZQ'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### base64url.decode(input: string, encoding: string = "utf8"): string
|
||||
|
||||
Convert a base64url encoded string into a raw string. The `encoding` argument can be used if the input is a string that's not utf8.
|
||||
|
||||
```js
|
||||
> base64url.decode("cmlkZTogZHJlYW1zIGJ1cm4gZG93bg")
|
||||
'ride: dreams burn down'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### base64url.fromBase64(input: string): string
|
||||
|
||||
Convert a base64 encoded string to a base64url encoded string.
|
||||
|
||||
Example
|
||||
|
||||
```js
|
||||
> base64url.fromBase64('qL8R4QIcQ/ZsRqOAbeRfcZhilN/MksRtDaErMA==')
|
||||
'qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
### base64url.toBase64(input: string): string
|
||||
|
||||
Convert a base64url encoded string to a base64 encoded string.
|
||||
|
||||
```js
|
||||
> base64url.toBase64('qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA')
|
||||
'qL8R4QIcQ/ZsRqOAbeRfcZhilN/MksRtDaErMA=='
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
### base64url.toBuffer(input: string): Buffer
|
||||
|
||||
Convert a base64url encoded string to a Buffer containing the decoded bytes.
|
||||
|
||||
```js
|
||||
> base64url.toBuffer('c3Bpcml0dWFsaXplZA')
|
||||
<Buffer 73 70 69 72 69 74 75 61 6c 69 7a 65 64>
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
|
||||
```
|
||||
Copyright (c) 2013–2016 Brian J. Brennan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
```
|
||||
+2578
File diff suppressed because it is too large
Load Diff
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"resolution": "main",
|
||||
"tree": {
|
||||
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/77b1b1709315b03b9b1b67c589d599bebeeef2ee/node/node.d.ts",
|
||||
"raw": "registry:dt/node#6.0.0+20160709114037",
|
||||
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/77b1b1709315b03b9b1b67c589d599bebeeef2ee/node/node.d.ts"
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
/// <reference path="globals/node/index.d.ts" />
|
||||
Reference in New Issue
Block a user