New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fetch-inject

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-inject - npm Package Compare versions

Comparing version

to
1.10.0

CHANGELOG.md

2

dist/fetch-inject.es.js

@@ -25,3 +25,3 @@ /**

* @module fetchInject
* @license ISC
* @license BTC
* @param {(USVString[]|Request[])} inputs Resources you wish to fetch.

@@ -28,0 +28,0 @@ * @param {Promise} [promise] A promise to await before attempting injection.

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.9.1 | © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz | @license BTC */
const head=function(e,t,n,o,r,c,i){c=t.createElement(n),i=t.getElementsByTagName(n)[0],c.appendChild(t.createTextNode(o.text)),c.onload=r(o),i?i.parentNode.insertBefore(c,i):t.head.appendChild(c)},fetchInject=function(e,t){if(!e||!Array.isArray(e))return Promise.reject(new TypeError("`inputs` must be an array"));if(t&&!(t instanceof Promise))return Promise.reject(new TypeError("`promise` must be a promise"));const n=[],o=t?[].concat(t):[],r=[];return e.forEach(e=>o.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{n.push({text:e[0],blob:e[1]})})))),Promise.all(o).then(()=>{n.forEach(e=>{r.push({then:t=>{e.blob.type.includes("text/css")?head(window,document,"style",e,t):head(window,document,"script",e,t)}})});return Promise.all(r)})};export default fetchInject;
/*! Fetch Inject v1.9.1 | © 2018, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz | @license BTC */
const head=function(e,t,n,r,o,a,s){a=t.createElement(n),s=t.getElementsByTagName(n)[0],a.appendChild(t.createTextNode(r.text)),a.onload=o(r),s?s.parentNode.insertBefore(a,s):t.head.appendChild(a)},fetchInject=function(e,t){if(!e||!Array.isArray(e))return Promise.reject(new TypeError("`inputs` must be an array"));if(t&&!(t instanceof Promise))return Promise.reject(new TypeError("`promise` must be a promise"));const n=[],r=t?[].concat(t):[],o=[];return e.forEach(e=>r.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{n.push({text:e[0],blob:e[1]})})))),Promise.all(r).then(()=>(n.forEach(e=>{o.push({then:t=>{e.blob.type.includes("text/css")?head(window,document,"style",e,t):head(window,document,"script",e,t)}})}),Promise.all(o)))};export default fetchInject;
var fetchInject = (function () {
'use strict';
'use strict';
/**
* BTC License
*
* © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* BTC License
*
* © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
const head = (function(i,s,o,g,r,a,m){a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.appendChild(s.createTextNode(g.text));a.onload=r(g);m?m.parentNode.insertBefore(a,m):s.head.appendChild(a);}); // eslint-disable-line
const head = (function(i,s,o,g,r,a,m){a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.appendChild(s.createTextNode(g.text));a.onload=r(g);m?m.parentNode.insertBefore(a,m):s.head.appendChild(a);}); // eslint-disable-line
/**
* Fetch Inject module.
*
* @module fetchInject
* @license ISC
* @param {(USVString[]|Request[])} inputs Resources you wish to fetch.
* @param {Promise} [promise] A promise to await before attempting injection.
* @throws {Promise<TypeError>} Rejects with error on invalid arguments.
* @throws {Promise<Error>} Whatever `fetch` decides to throw.
* @throws {SyntaxError} Via DOM upon attempting to parse unexpected tokens.
* @returns {Promise<Object[]>} A promise which resolves to an `Array` of
* Objects containing `Response` `Body` properties used by the module.
*/
const fetchInject = function (inputs, promise) {
if (!(inputs && Array.isArray(inputs))) return Promise.reject(new TypeError('`inputs` must be an array'))
if (promise && !(promise instanceof Promise)) return Promise.reject(new TypeError('`promise` must be a promise'))
/**
* Fetch Inject module.
*
* @module fetchInject
* @license BTC
* @param {(USVString[]|Request[])} inputs Resources you wish to fetch.
* @param {Promise} [promise] A promise to await before attempting injection.
* @throws {Promise<TypeError>} Rejects with error on invalid arguments.
* @throws {Promise<Error>} Whatever `fetch` decides to throw.
* @throws {SyntaxError} Via DOM upon attempting to parse unexpected tokens.
* @returns {Promise<Object[]>} A promise which resolves to an `Array` of
* Objects containing `Response` `Body` properties used by the module.
*/
const fetchInject = function (inputs, promise) {
if (!(inputs && Array.isArray(inputs))) return Promise.reject(new TypeError('`inputs` must be an array'))
if (promise && !(promise instanceof Promise)) return Promise.reject(new TypeError('`promise` must be a promise'))
const resources = [];
const deferreds = promise ? [].concat(promise) : [];
const thenables = [];
const resources = [];
const deferreds = promise ? [].concat(promise) : [];
const thenables = [];
inputs.forEach(input => deferreds.push(
window.fetch(input).then(res => {
return [res.clone().text(), res.blob()]
}).then(promises => {
return Promise.all(promises).then(resolved => {
resources.push({ text: resolved[0], blob: resolved[1] });
inputs.forEach(input => deferreds.push(
window.fetch(input).then(res => {
return [res.clone().text(), res.blob()]
}).then(promises => {
return Promise.all(promises).then(resolved => {
resources.push({ text: resolved[0], blob: resolved[1] });
})
})
));
return Promise.all(deferreds).then(() => {
resources.forEach(resource => {
thenables.push({ then: resolve => {
resource.blob.type.includes('text/css')
? head(window, document, 'style', resource, resolve)
: head(window, document, 'script', resource, resolve);
}});
});
return Promise.all(thenables)
})
));
};
return Promise.all(deferreds).then(() => {
resources.forEach(resource => {
thenables.push({ then: resolve => {
resource.blob.type.includes('text/css')
? head(window, document, 'style', resource, resolve)
: head(window, document, 'script', resource, resolve);
}});
});
return Promise.all(thenables)
})
};
return fetchInject;
return fetchInject;
}());

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.9.1 | © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz | @license BTC */
var fetchInject=function(){"use strict";const e=function(e,t,n,r,o,i,c){i=t.createElement(n),c=t.getElementsByTagName(n)[0],i.appendChild(t.createTextNode(r.text)),i.onload=o(r),c?c.parentNode.insertBefore(i,c):t.head.appendChild(i)};return function(t,n){if(!t||!Array.isArray(t))return Promise.reject(new TypeError("`inputs` must be an array"));if(n&&!(n instanceof Promise))return Promise.reject(new TypeError("`promise` must be a promise"));const r=[],o=n?[].concat(n):[],i=[];return t.forEach(e=>o.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{r.push({text:e[0],blob:e[1]})})))),Promise.all(o).then(()=>{r.forEach(t=>{i.push({then:n=>{t.blob.type.includes("text/css")?e(window,document,"style",t,n):e(window,document,"script",t,n)}})});return Promise.all(i)})}}();
/*! Fetch Inject v1.9.1 | © 2018, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz | @license BTC */
var fetchInject=function(){"use strict";const e=function(e,t,r,n,o,s,i){s=t.createElement(r),i=t.getElementsByTagName(r)[0],s.appendChild(t.createTextNode(n.text)),s.onload=o(n),i?i.parentNode.insertBefore(s,i):t.head.appendChild(s)};return function(t,r){if(!t||!Array.isArray(t))return Promise.reject(new TypeError("`inputs` must be an array"));if(r&&!(r instanceof Promise))return Promise.reject(new TypeError("`promise` must be a promise"));const n=[],o=r?[].concat(r):[],s=[];return t.forEach(e=>o.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{n.push({text:e[0],blob:e[1]})})))),Promise.all(o).then(()=>(n.forEach(t=>{s.push({then:r=>{t.blob.type.includes("text/css")?e(window,document,"style",t,r):e(window,document,"script",t,r)}})}),Promise.all(s)))}}();
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.fetchInject = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.fetchInject = factory());
}(this, (function () { 'use strict';
/**
* BTC License
*
* © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* BTC License
*
* © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
const head = (function(i,s,o,g,r,a,m){a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.appendChild(s.createTextNode(g.text));a.onload=r(g);m?m.parentNode.insertBefore(a,m):s.head.appendChild(a);}); // eslint-disable-line
const head = (function(i,s,o,g,r,a,m){a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.appendChild(s.createTextNode(g.text));a.onload=r(g);m?m.parentNode.insertBefore(a,m):s.head.appendChild(a);}); // eslint-disable-line
/**
* Fetch Inject module.
*
* @module fetchInject
* @license ISC
* @param {(USVString[]|Request[])} inputs Resources you wish to fetch.
* @param {Promise} [promise] A promise to await before attempting injection.
* @throws {Promise<TypeError>} Rejects with error on invalid arguments.
* @throws {Promise<Error>} Whatever `fetch` decides to throw.
* @throws {SyntaxError} Via DOM upon attempting to parse unexpected tokens.
* @returns {Promise<Object[]>} A promise which resolves to an `Array` of
* Objects containing `Response` `Body` properties used by the module.
*/
const fetchInject = function (inputs, promise) {
if (!(inputs && Array.isArray(inputs))) return Promise.reject(new TypeError('`inputs` must be an array'))
if (promise && !(promise instanceof Promise)) return Promise.reject(new TypeError('`promise` must be a promise'))
/**
* Fetch Inject module.
*
* @module fetchInject
* @license BTC
* @param {(USVString[]|Request[])} inputs Resources you wish to fetch.
* @param {Promise} [promise] A promise to await before attempting injection.
* @throws {Promise<TypeError>} Rejects with error on invalid arguments.
* @throws {Promise<Error>} Whatever `fetch` decides to throw.
* @throws {SyntaxError} Via DOM upon attempting to parse unexpected tokens.
* @returns {Promise<Object[]>} A promise which resolves to an `Array` of
* Objects containing `Response` `Body` properties used by the module.
*/
const fetchInject = function (inputs, promise) {
if (!(inputs && Array.isArray(inputs))) return Promise.reject(new TypeError('`inputs` must be an array'))
if (promise && !(promise instanceof Promise)) return Promise.reject(new TypeError('`promise` must be a promise'))
const resources = [];
const deferreds = promise ? [].concat(promise) : [];
const thenables = [];
const resources = [];
const deferreds = promise ? [].concat(promise) : [];
const thenables = [];
inputs.forEach(input => deferreds.push(
window.fetch(input).then(res => {
return [res.clone().text(), res.blob()]
}).then(promises => {
return Promise.all(promises).then(resolved => {
resources.push({ text: resolved[0], blob: resolved[1] });
inputs.forEach(input => deferreds.push(
window.fetch(input).then(res => {
return [res.clone().text(), res.blob()]
}).then(promises => {
return Promise.all(promises).then(resolved => {
resources.push({ text: resolved[0], blob: resolved[1] });
})
})
));
return Promise.all(deferreds).then(() => {
resources.forEach(resource => {
thenables.push({ then: resolve => {
resource.blob.type.includes('text/css')
? head(window, document, 'style', resource, resolve)
: head(window, document, 'script', resource, resolve);
}});
});
return Promise.all(thenables)
})
));
};
return Promise.all(deferreds).then(() => {
resources.forEach(resource => {
thenables.push({ then: resolve => {
resource.blob.type.includes('text/css')
? head(window, document, 'style', resource, resolve)
: head(window, document, 'script', resource, resolve);
}});
});
return Promise.all(thenables)
})
};
return fetchInject;
return fetchInject;
})));

@@ -1,2 +0,2 @@

/*! Fetch Inject v1.9.1 | © 2017, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz | @license BTC */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.fetchInject=t()}(this,function(){"use strict";const e=function(e,t,n,o,r,i,c){i=t.createElement(n),c=t.getElementsByTagName(n)[0],i.appendChild(t.createTextNode(o.text)),i.onload=r(o),c?c.parentNode.insertBefore(i,c):t.head.appendChild(i)};return function(t,n){if(!t||!Array.isArray(t))return Promise.reject(new TypeError("`inputs` must be an array"));if(n&&!(n instanceof Promise))return Promise.reject(new TypeError("`promise` must be a promise"));const o=[],r=n?[].concat(n):[],i=[];return t.forEach(e=>r.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{o.push({text:e[0],blob:e[1]})})))),Promise.all(r).then(()=>{o.forEach(t=>{i.push({then:n=>{t.blob.type.includes("text/css")?e(window,document,"style",t,n):e(window,document,"script",t,n)}})});return Promise.all(i)})}});
/*! Fetch Inject v1.9.1 | © 2018, 13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz | @license BTC */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.fetchInject=t()}(this,function(){"use strict";const e=function(e,t,n,o,r,i,s){i=t.createElement(n),s=t.getElementsByTagName(n)[0],i.appendChild(t.createTextNode(o.text)),i.onload=r(o),s?s.parentNode.insertBefore(i,s):t.head.appendChild(i)};return function(t,n){if(!t||!Array.isArray(t))return Promise.reject(new TypeError("`inputs` must be an array"));if(n&&!(n instanceof Promise))return Promise.reject(new TypeError("`promise` must be a promise"));const o=[],r=n?[].concat(n):[],i=[];return t.forEach(e=>r.push(window.fetch(e).then(e=>[e.clone().text(),e.blob()]).then(e=>Promise.all(e).then(e=>{o.push({text:e[0],blob:e[1]})})))),Promise.all(r).then(()=>(o.forEach(t=>{i.push({then:n=>{t.blob.type.includes("text/css")?e(window,document,"style",t,n):e(window,document,"script",t,n)}})}),Promise.all(i)))}});
{
"name": "fetch-inject",
"version": "1.9.1",
"version": "1.10.0",
"description": "Dynamically inline assets into the DOM using Fetch Injection.",
"author": "Josh Habdas <josh@habd.as> (https://habd.as/)",
"author": "Josh Habdas <jhabdas@protonmail.com> (https://habd.as/)",
"module": "dist/fetch-inject.es.js",
"main": "dist/fetch-inject.umd.js",
"keywords": [
"dom",
"fetch",
"inject",
"import",
"inject",
"promise",
"script",
"css",
"pwa"
"script"
],

@@ -22,33 +19,21 @@ "repository": "jhabdas/fetch-inject",

"clean": "rimraf dist",
"commit": "git-cz",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "standard",
"release": "semantic-release pre && npm run build && npm publish && semantic-release post"
"release": "standard-version"
},
"standard-version": {
"scripts": {
"prerelease": "npm run lint"
}
},
"devDependencies": {
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.0.0",
"ghooks": "^2.0.0",
"rimraf": "^2.6.1",
"rollup": "^0.42.0",
"rollup-plugin-license": "^0.4.0",
"rimraf": "^2.6.2",
"rollup": "^0.60.4",
"rollup-plugin-license": "^0.6.0",
"rollup-plugin-uglify": "^2.0.1",
"semantic-release": "^6.3.2",
"standard": "^10.0.2",
"uglify-es": "^3.0.12"
"standard": "^11.0.1",
"standard-version": "^4.4.0",
"uglify-es": "^3.3.9"
},
"standard": {
"ignore": [
"/dist"
]
},
"config": {
"ghooks": {
"pre-push": "npm run lint"
},
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"license": "BTC"
}
}

@@ -12,6 +12,6 @@ <h1 align="center">Fetch Inject</h1>

<a href="https://cdn.jsdelivr.net/npm/fetch-inject">
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/npm/fetch-inject@latest/dist/fetch-inject.min.js?compression=gzip&style=flat-square" alt="Size of IIFE bundle with gzip compression">
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/npm/fetch-inject@latest/dist/fetch-inject.min.js?compression=brotli&style=flat-square" alt="Size of IIFE bundle with brotli compression">
</a>
<a href="https://travis-ci.org/jhabdas/fetch-inject">
<img src="https://img.shields.io/travis/jhabdas/fetch-inject.svg?style=flat-square" alt="Build Status">
<a href="https://www.jsdelivr.com/package/npm/fetch-inject">
<img src="https://data.jsdelivr.com/v1/package/npm/fetch-inject/badge" alt="Hits per month from jsDelivr CDN">
</a>

@@ -40,3 +40,3 @@ <a href="https://www.npmjs.com/package/fetch-inject">

[![Fetch Inject Unprimed Cache](https://github.com/jhabdas/fetch-inject/blob/master/docs/fetch-inject-unprimed-cache.png?raw=true)](https://wordcamp.habd.as/)
![Fetch Inject Unprimed Cache](https://github.com/jhabdas/fetch-inject/blob/master/docs/fetch-inject-unprimed-cache.png?raw=true)

@@ -274,3 +274,3 @@ Click the image for a live demo of the application used to produce the above waterfall.

Then, before the close of the document `body`, provide the traditional experience to avoid blocking the parser until content is visible:
Then, before the close of the document `body` (if JS) or in the `head` (if CSS), provide the traditional experience:

@@ -322,2 +322,4 @@ ```js

© 2017, <a href="bitcoin:13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz">13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz</a>
© 2017, <a href="bitcoin:13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz?label=Comfusion&message=Donation%20for%Fetch%20Inject">13AMDq9isKtQTxMQG4w7Yo7cEhqKAqQ4Lz</a>
[![Fetch Inject](https://static.hackcabin.com/images/qr/btc-license.png)](https://hackernoon.com/introducing-the-btc-license-28650887eb11)