@poppinss/utils
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -15,3 +15,6 @@ /// <reference types="node" /> | ||
*/ | ||
decode(encoded: string | Buffer, encoding?: BufferEncoding): string; | ||
decode(encode: string, encoding: BufferEncoding, strict: true): string | null; | ||
decode(encode: string, encoding: undefined, strict: true): string | null; | ||
decode(encode: string, encoding?: BufferEncoding, strict?: false): string; | ||
decode(encode: Buffer, encoding?: BufferEncoding): string; | ||
/** | ||
@@ -25,5 +28,8 @@ * Base64 encode Buffer or string to be URL safe. (RFC 4648) | ||
*/ | ||
urlDecode(encoded: string | Buffer, encoding?: BufferEncoding): string; | ||
urlDecode(encode: string, encoding: BufferEncoding, strict: true): string | null; | ||
urlDecode(encode: string, encoding: undefined, strict: true): string | null; | ||
urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string; | ||
urlDecode(encode: Buffer, encoding?: BufferEncoding): string; | ||
} | ||
export declare const base64: Base64; | ||
export {}; |
@@ -22,9 +22,11 @@ "use strict"; | ||
} | ||
/** | ||
* Base64 decode a previously encoded string or Buffer. | ||
*/ | ||
decode(encoded, encoding = 'utf-8') { | ||
return Buffer.isBuffer(encoded) | ||
? encoded.toString(encoding) | ||
: Buffer.from(encoded, 'base64').toString(encoding); | ||
decode(encoded, encoding = 'utf-8', strict = false) { | ||
if (Buffer.isBuffer(encoded)) { | ||
return encoded.toString(encoding); | ||
} | ||
const decoded = Buffer.from(encoded, 'base64').toString(encoding); | ||
if (strict && this.encode(decoded, encoding) !== encoded) { | ||
return null; | ||
} | ||
return decoded; | ||
} | ||
@@ -35,9 +37,13 @@ urlEncode(data, encoding) { | ||
} | ||
/** | ||
* Base64 URL decode a previously encoded string or Buffer. (RFC 4648) | ||
*/ | ||
urlDecode(encoded, encoding = 'utf-8') { | ||
return this.decode(encoded, encoding); | ||
urlDecode(encoded, encoding = 'utf-8', strict = false) { | ||
if (Buffer.isBuffer(encoded)) { | ||
return encoded.toString(encoding); | ||
} | ||
const decoded = Buffer.from(encoded, 'base64').toString(encoding); | ||
if (strict && this.urlEncode(decoded, encoding) !== encoded) { | ||
return null; | ||
} | ||
return decoded; | ||
} | ||
} | ||
exports.base64 = new Base64(); |
{ | ||
"name": "@poppinss/utils", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Handy utilities for repetitive work", | ||
@@ -33,4 +33,4 @@ "main": "build/index.js", | ||
"@adonisjs/mrm-preset": "^2.3.0", | ||
"@poppinss/dev-utils": "^1.0.4", | ||
"@types/node": "^13.11.0", | ||
"@poppinss/dev-utils": "^1.0.5", | ||
"@types/node": "^13.11.1", | ||
"commitizen": "^4.0.4", | ||
@@ -41,7 +41,7 @@ "cz-conventional-changelog": "^3.1.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-adonis": "^1.0.8", | ||
"husky": "^4.2.3", | ||
"eslint-plugin-adonis": "^1.0.9", | ||
"husky": "^4.2.5", | ||
"japa": "^3.0.1", | ||
"lodash-cli": "^4.17.5", | ||
"mrm": "^2.2.0", | ||
"mrm": "^2.2.1", | ||
"np": "^5.2.1", | ||
@@ -48,0 +48,0 @@ "ts-node": "^8.8.2", |
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
50733
28
620