Comparing version 3.5.2 to 3.6.0
@@ -12,7 +12,7 @@ /** | ||
*/ | ||
declare const version = "3.5.2"; | ||
declare const version = "3.6.0"; | ||
/** | ||
* @deprecated use lowercase `version`. | ||
*/ | ||
declare const VERSION = "3.5.2"; | ||
declare const VERSION = "3.6.0"; | ||
/** | ||
@@ -78,2 +78,7 @@ * polyfill version of `btoa` | ||
/** | ||
* check if a value is a valid Base64 string | ||
* @param {String} src a value to check | ||
*/ | ||
declare const isValid: (src: any) => boolean; | ||
/** | ||
* extend String.prototype with relevant methods | ||
@@ -105,2 +110,3 @@ */ | ||
decode: (src: string) => string; | ||
isValid: (src: any) => boolean; | ||
fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string; | ||
@@ -126,2 +132,3 @@ toUint8Array: (a: string) => Uint8Array; | ||
export { decode }; | ||
export { isValid }; | ||
export { fromUint8Array }; | ||
@@ -128,0 +135,0 @@ export { toUint8Array }; |
@@ -43,3 +43,3 @@ | ||
*/ | ||
const version = '3.5.2'; | ||
const version = '3.6.0'; | ||
/** | ||
@@ -242,2 +242,12 @@ * @deprecated use lowercase `version`. | ||
const decode = (src) => _decode(_unURI(src)); | ||
/** | ||
* check if a value is a valid Base64 string | ||
* @param {String} src a value to check | ||
*/ | ||
const isValid = (src) => { | ||
if (typeof src !== 'string') | ||
return false; | ||
const s = src.replace(/\s+/g, '').replace(/=+$/, ''); | ||
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s); | ||
}; | ||
// | ||
@@ -291,2 +301,3 @@ const _noEnum = (v) => { | ||
decode: decode, | ||
isValid: isValid, | ||
fromUint8Array: fromUint8Array, | ||
@@ -293,0 +304,0 @@ toUint8Array: toUint8Array, |
{ | ||
"name": "js-base64", | ||
"version": "3.5.2", | ||
"version": "3.6.0", | ||
"description": "Yet another Base64 transcoder in pure-JS", | ||
@@ -5,0 +5,0 @@ "main": "base64.js", |
@@ -32,3 +32,3 @@ [![build status](https://secure.travis-ci.org/dankogai/js-base64.png)](http://travis-ci.org/dankogai/js-base64) | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.5.2/base64.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.min.js"></script> | ||
``` | ||
@@ -56,3 +56,3 @@ | ||
// note jsdelivr.net does not automatically minify .mjs | ||
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.5.2/base64.mjs'; | ||
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.mjs'; | ||
</script> | ||
@@ -64,3 +64,3 @@ ``` | ||
// or if you prefer no Base64 namespace | ||
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.5.2/base64.mjs'; | ||
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.mjs'; | ||
</script> | ||
@@ -112,2 +112,13 @@ ``` | ||
```javascript | ||
Base64.isValid(0); // false: 0 is not string | ||
Base64.isValid(''); // true: a valid Base64-encoded empty byte | ||
Base64.isValid('ZA=='); // true: a valid Base64-encoded 'd' | ||
Base64.isValid('Z A='); // true: whitespaces are okay | ||
Base64.isValid('ZA'); // true: padding ='s can be omitted | ||
Base64.isValid('++'); // true: can be non URL-safe | ||
Base64.isValid('--'); // true: or URL-safe | ||
Base64.isValid('+-'); // false: can't mix both | ||
``` | ||
### Built-in Extensions | ||
@@ -114,0 +125,0 @@ |
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
32579
743
173