@hexagon/base64
Advanced tools
Comparing version 2.0.1 to 2.0.2
/** | ||
* Convenience function for converting a base64 encoded string to an ArrayBuffer instance | ||
* @public | ||
* | ||
* @param {string} data - Base64 representation of data | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be expected | ||
* @returns {ArrayBuffer} - Decoded | ||
data | ||
*/ | ||
declare function toArrayBuffer(data: string, urlMode?: boolean): ArrayBuffer; | ||
/** | ||
* Convenience | ||
function for creating a base64 encoded string from an ArrayBuffer instance | ||
* @public | ||
* | ||
* @param {ArrayBuffer} arrBuf - ArrayBuffer to be encoded | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be returned | ||
* @returns {string} - Base64 representation of data | ||
*/ | ||
declare function fromArrayBuffer(arrBuf: ArrayBuffer, urlMode?: boolean): string; | ||
/** | ||
* Convenience function for converting base64 to string | ||
* @public | ||
* | ||
* @param {string} str - Base64 encoded string to be decoded | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be expected | ||
* @returns {string} - Decoded string | ||
*/ | ||
declare function toString(str: string, urlMode?: boolean): string; | ||
/** | ||
* Convenience function for converting a javascript string to base64 | ||
* @public | ||
* | ||
* @param {string} str - String to be converted to base64 | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be returned | ||
* @returns {string} - Base64 encoded | ||
string | ||
*/ | ||
declare function fromString(str: string, urlMode?: boolean): string; | ||
/** | ||
* Function to validate base64 | ||
* @public | ||
* @param {string} encoded - Base64 or Base64url encoded data | ||
* @param {boolean} [urlMode] - If set to true, base64url will be expected | ||
* @returns {boolean} - Valid base64/base64url? | ||
*/ | ||
declare function validate(encoded: string, urlMode?: boolean): boolean; | ||
/** | ||
* @namespace base64 | ||
*/ | ||
declare const base64: { | ||
/** | ||
* Convenience function for converting a base64 encoded string to an ArrayBuffer instance | ||
* @public | ||
* | ||
* @param {string} data - Base64 representation of data | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be expected | ||
* @returns {ArrayBuffer} - Decoded | ||
data | ||
*/ | ||
toArrayBuffer: (data: string, urlMode?: boolean) => ArrayBuffer; | ||
/** | ||
* Convenience | ||
function for creating a base64 encoded string from an ArrayBuffer instance | ||
* @public | ||
* | ||
* @param {ArrayBuffer} arrBuf - ArrayBuffer to be encoded | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be returned | ||
* @returns {string} - Base64 representation of data | ||
*/ | ||
fromArrayBuffer: (arrBuf: ArrayBuffer, urlMode?: boolean) => string; | ||
/** | ||
* Convenience function for converting base64 to string | ||
* @public | ||
* | ||
* @param {string} str - Base64 encoded string to be decoded | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be expected | ||
* @returns {string} - Decoded string | ||
*/ | ||
toString: (str: string, urlMode?: boolean) => string; | ||
/** | ||
* Convenience function for converting a javascript string to base64 | ||
* @public | ||
* | ||
* @param {string} str - String to be converted to base64 | ||
* @param {boolean} [urlMode] - If set to true, URL mode string will be returned | ||
* @returns {string} - Base64 encoded | ||
string | ||
*/ | ||
fromString: (str: string, urlMode?: boolean) => string; | ||
/** | ||
* Function to validate base64 | ||
* @public | ||
* @param {string} encoded - Base64 or Base64url encoded data | ||
* @param {boolean} [urlMode] - If set to true, base64url will be expected | ||
* @returns {boolean} - Valid base64/base64url? | ||
*/ | ||
validate: (encoded: string, urlMode?: boolean) => boolean; | ||
toString: typeof toString; | ||
fromString: typeof fromString; | ||
toArrayBuffer: typeof toArrayBuffer; | ||
fromArrayBuffer: typeof fromArrayBuffer; | ||
validate: typeof validate; | ||
}; | ||
export { base64 }; | ||
export { base64, fromArrayBuffer, fromString, toArrayBuffer, toString, validate }; |
@@ -1,1 +0,1 @@ | ||
var u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",h=r=>{let t=typeof Uint8Array>"u"?[]:new Uint8Array(256),o=u.length;for(let n=0;n<o;n++)t[r.charCodeAt(n)]=n;return t},U=h(u),p=h(b),m=/^[-A-Za-z0-9\-_]*$/,w=/^[-A-Za-z0-9+/]*={0,3}$/,y={toArrayBuffer:(r,t)=>{let o=r.length,n=r.length*.75,e,f=0,s,i,c,g;r[r.length-1]==="="&&(n--,r[r.length-2]==="="&&n--);let A=new ArrayBuffer(n),l=new Uint8Array(A),a=t?p:U;for(e=0;e<o;e+=4)s=a[r.charCodeAt(e)],i=a[r.charCodeAt(e+1)],c=a[r.charCodeAt(e+2)],g=a[r.charCodeAt(e+3)],l[f++]=s<<2|i>>4,l[f++]=(i&15)<<4|c>>2,l[f++]=(c&3)<<6|g&63;return A},fromArrayBuffer:(r,t)=>{let o=new Uint8Array(r),n,e="",f=o.length,s=t?b:u;for(n=0;n<f;n+=3)e+=s[o[n]>>2],e+=s[(o[n]&3)<<4|o[n+1]>>4],e+=s[(o[n+1]&15)<<2|o[n+2]>>6],e+=s[o[n+2]&63];let i=f%3;return i===2?e=e.substring(0,e.length-1)+(t?"":"="):i===1&&(e=e.substring(0,e.length-2)+(t?"":"==")),e},toString:(r,t)=>new TextDecoder().decode(y.toArrayBuffer(r,t)),fromString:(r,t)=>y.fromArrayBuffer(new TextEncoder().encode(r),t),validate:(r,t)=>{if(!(typeof r=="string"||r instanceof String))return!1;try{return t?m.test(r):w.test(r)}catch{return!1}}};export{y as base64}; | ||
var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",y=n=>{let t=typeof Uint8Array>"u"?[]:new Uint8Array(256),o=a.length;for(let e=0;e<o;e++)t[n.charCodeAt(e)]=e;return t},p=y(a),m=y(b),w=/^[-A-Za-z0-9\-_]*$/,d=/^[-A-Za-z0-9+/]*={0,3}$/;function h(n,t){let o=n.length,e=n.length*.75,r,i=0,s,c,u,g;n[n.length-1]==="="&&(e--,n[n.length-2]==="="&&e--);let A=new ArrayBuffer(e),l=new Uint8Array(A),f=t?m:p;for(r=0;r<o;r+=4)s=f[n.charCodeAt(r)],c=f[n.charCodeAt(r+1)],u=f[n.charCodeAt(r+2)],g=f[n.charCodeAt(r+3)],l[i++]=s<<2|c>>4,l[i++]=(c&15)<<4|u>>2,l[i++]=(u&3)<<6|g&63;return A}function U(n,t){let o=new Uint8Array(n),e,r="",i=o.length,s=t?b:a;for(e=0;e<i;e+=3)r+=s[o[e]>>2],r+=s[(o[e]&3)<<4|o[e+1]>>4],r+=s[(o[e+1]&15)<<2|o[e+2]>>6],r+=s[o[e+2]&63];let c=i%3;return c===2?r=r.substring(0,r.length-1)+(t?"":"="):c===1&&(r=r.substring(0,r.length-2)+(t?"":"==")),r}function k(n,t){return new TextDecoder().decode(h(n,t))}function B(n,t){return U(new TextEncoder().encode(n),t)}function C(n,t){if(!(typeof n=="string"||n instanceof String))return!1;try{return t?w.test(n):d.test(n)}catch{return!1}}var x={toString:k,fromString:B,toArrayBuffer:h,fromArrayBuffer:U,validate:C};export{x as base64,U as fromArrayBuffer,B as fromString,h as toArrayBuffer,k as toString,C as validate}; |
@@ -1,1 +0,1 @@ | ||
var base64=(()=>{var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var B=(r,n)=>{for(var o in n)g(r,o,{get:n[o],enumerable:!0})},d=(r,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of U(n))!w.call(r,e)&&e!==o&&g(r,e,{get:()=>n[e],enumerable:!(t=m(n,e))||t.enumerable});return r};var k=r=>d(g({},"__esModule",{value:!0}),r);var L={};B(L,{default:()=>z});var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",p=r=>{let n=typeof Uint8Array>"u"?[]:new Uint8Array(256),o=A.length;for(let t=0;t<o;t++)n[r.charCodeAt(t)]=t;return n},C=p(A),x=p(h),S=/^[-A-Za-z0-9\-_]*$/,T=/^[-A-Za-z0-9+/]*={0,3}$/,c={toArrayBuffer:(r,n)=>{let o=r.length,t=r.length*.75,e,f=0,s,i,l,y;r[r.length-1]==="="&&(t--,r[r.length-2]==="="&&t--);let b=new ArrayBuffer(t),u=new Uint8Array(b),a=n?x:C;for(e=0;e<o;e+=4)s=a[r.charCodeAt(e)],i=a[r.charCodeAt(e+1)],l=a[r.charCodeAt(e+2)],y=a[r.charCodeAt(e+3)],u[f++]=s<<2|i>>4,u[f++]=(i&15)<<4|l>>2,u[f++]=(l&3)<<6|y&63;return b},fromArrayBuffer:(r,n)=>{let o=new Uint8Array(r),t,e="",f=o.length,s=n?h:A;for(t=0;t<f;t+=3)e+=s[o[t]>>2],e+=s[(o[t]&3)<<4|o[t+1]>>4],e+=s[(o[t+1]&15)<<2|o[t+2]>>6],e+=s[o[t+2]&63];let i=f%3;return i===2?e=e.substring(0,e.length-1)+(n?"":"="):i===1&&(e=e.substring(0,e.length-2)+(n?"":"==")),e},toString:(r,n)=>new TextDecoder().decode(c.toArrayBuffer(r,n)),fromString:(r,n)=>c.fromArrayBuffer(new TextEncoder().encode(r),n),validate:(r,n)=>{if(!(typeof r=="string"||r instanceof String))return!1;try{return n?S.test(r):T.test(r)}catch{return!1}}};var z=c;return k(L);})(); | ||
var base64=(()=>{var a=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var x=(n,e)=>{for(var o in e)a(n,o,{get:e[o],enumerable:!0})},S=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of B(e))!C.call(n,r)&&r!==o&&a(n,r,{get:()=>e[r],enumerable:!(t=k(e,r))||t.enumerable});return n};var T=n=>S(a({},"__esModule",{value:!0}),n);var D={};x(D,{base64:()=>v,fromArrayBuffer:()=>b,fromString:()=>w,toArrayBuffer:()=>A,toString:()=>m,validate:()=>d});var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",U="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",p=n=>{let e=typeof Uint8Array>"u"?[]:new Uint8Array(256),o=g.length;for(let t=0;t<o;t++)e[n.charCodeAt(t)]=t;return e},z=p(g),L=p(U),P=/^[-A-Za-z0-9\-_]*$/,Z=/^[-A-Za-z0-9+/]*={0,3}$/;function A(n,e){let o=n.length,t=n.length*.75,r,i=0,s,c,u,y;n[n.length-1]==="="&&(t--,n[n.length-2]==="="&&t--);let h=new ArrayBuffer(t),l=new Uint8Array(h),f=e?L:z;for(r=0;r<o;r+=4)s=f[n.charCodeAt(r)],c=f[n.charCodeAt(r+1)],u=f[n.charCodeAt(r+2)],y=f[n.charCodeAt(r+3)],l[i++]=s<<2|c>>4,l[i++]=(c&15)<<4|u>>2,l[i++]=(u&3)<<6|y&63;return h}function b(n,e){let o=new Uint8Array(n),t,r="",i=o.length,s=e?U:g;for(t=0;t<i;t+=3)r+=s[o[t]>>2],r+=s[(o[t]&3)<<4|o[t+1]>>4],r+=s[(o[t+1]&15)<<2|o[t+2]>>6],r+=s[o[t+2]&63];let c=i%3;return c===2?r=r.substring(0,r.length-1)+(e?"":"="):c===1&&(r=r.substring(0,r.length-2)+(e?"":"==")),r}function m(n,e){return new TextDecoder().decode(A(n,e))}function w(n,e){return b(new TextEncoder().encode(n),e)}function d(n,e){if(!(typeof n=="string"||n instanceof String))return!1;try{return e?P.test(n):Z.test(n)}catch{return!1}}var v={toString:m,fromString:w,toArrayBuffer:A,fromArrayBuffer:b,validate:d};return T(D);})(); |
@@ -52,3 +52,3 @@ { | ||
"name": "@hexagon/base64", | ||
"version": "2.0.1" | ||
"version": "2.0.2" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14981
79