mirror of
https://github.com/deployphp/action.git
synced 2025-06-29 12:44:14 +00:00
Add node_modules
This commit is contained in:
parent
e1f786311a
commit
554eb0b122
994 changed files with 195567 additions and 0 deletions
53
node_modules/data-uri-to-buffer/dist/index.js
generated
vendored
Normal file
53
node_modules/data-uri-to-buffer/dist/index.js
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Returns a `Buffer` instance from the given data URI `uri`.
|
||||
*
|
||||
* @param {String} uri Data URI to turn into a Buffer instance
|
||||
* @returns {Buffer} Buffer instance from Data URI
|
||||
* @api public
|
||||
*/
|
||||
export function dataUriToBuffer(uri) {
|
||||
if (!/^data:/i.test(uri)) {
|
||||
throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');
|
||||
}
|
||||
// strip newlines
|
||||
uri = uri.replace(/\r?\n/g, '');
|
||||
// split the URI up into the "metadata" and the "data" portions
|
||||
const firstComma = uri.indexOf(',');
|
||||
if (firstComma === -1 || firstComma <= 4) {
|
||||
throw new TypeError('malformed data: URI');
|
||||
}
|
||||
// remove the "data:" scheme and parse the metadata
|
||||
const meta = uri.substring(5, firstComma).split(';');
|
||||
let charset = '';
|
||||
let base64 = false;
|
||||
const type = meta[0] || 'text/plain';
|
||||
let typeFull = type;
|
||||
for (let i = 1; i < meta.length; i++) {
|
||||
if (meta[i] === 'base64') {
|
||||
base64 = true;
|
||||
}
|
||||
else {
|
||||
typeFull += `;${meta[i]}`;
|
||||
if (meta[i].indexOf('charset=') === 0) {
|
||||
charset = meta[i].substring(8);
|
||||
}
|
||||
}
|
||||
}
|
||||
// defaults to US-ASCII only if type is not provided
|
||||
if (!meta[0] && !charset.length) {
|
||||
typeFull += ';charset=US-ASCII';
|
||||
charset = 'US-ASCII';
|
||||
}
|
||||
// get the encoded data portion and decode URI-encoded chars
|
||||
const encoding = base64 ? 'base64' : 'ascii';
|
||||
const data = unescape(uri.substring(firstComma + 1));
|
||||
const buffer = Buffer.from(data, encoding);
|
||||
// set `.type` and `.typeFull` properties to MIME type
|
||||
buffer.type = type;
|
||||
buffer.typeFull = typeFull;
|
||||
// set the `.charset` property
|
||||
buffer.charset = charset;
|
||||
return buffer;
|
||||
}
|
||||
export default dataUriToBuffer;
|
||||
//# sourceMappingURL=index.js.map
|
Loading…
Add table
Add a link
Reference in a new issue