@lrnwebcomponents/utils
Advanced tools
Comparing version 4.0.8 to 4.0.29
{ | ||
"name": "@lrnwebcomponents/utils", | ||
"version": "4.0.8", | ||
"version": "4.0.29", | ||
"description": "Helper functions to clean up web component data handling.", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
}, | ||
"gitHead": "546e19dc98d156fe786ad6410a8229e3a4167deb" | ||
"gitHead": "1c2b9fb55d09a8c07c955a663f507f8e17efa3fc" | ||
} |
24
utils.js
@@ -6,2 +6,26 @@ /** | ||
/** | ||
* Convert a base64 encoded string to type Blob | ||
* @param {String} b64Data - base64 encoded string | ||
* @param {String} contentType - type to mark as the encoding of the blob | ||
* @param {Number} sliceSize - size of chunks | ||
* @returns {Blob} class blob for file operations | ||
*/ | ||
export function b64toBlob(b64Data, contentType='', sliceSize=512) { | ||
const byteCharacters = atob(b64Data); | ||
const byteArrays = []; | ||
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { | ||
const slice = byteCharacters.slice(offset, offset + sliceSize); | ||
const byteNumbers = new Array(slice.length); | ||
for (let i = 0; i < slice.length; i++) { | ||
byteNumbers[i] = slice.charCodeAt(i); | ||
} | ||
const byteArray = new Uint8Array(byteNumbers); | ||
byteArrays.push(byteArray); | ||
} | ||
const blob = new Blob(byteArrays, {type: contentType}); | ||
return blob; | ||
} | ||
/** | ||
* Mix of solutions from https://stackoverflow.com/questions/8493195/how-can-i-parse-a-csv-string-with-javascript-which-contains-comma-in-data | ||
@@ -8,0 +32,0 @@ */ |
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
108721
2910