Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-preloader

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-preloader - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

51

lib/async-preloader.js

@@ -287,6 +287,15 @@ (function (global, factory) {

_context6.next = 5;
return response.blob();
return response[item.body || "blob"]();
case 5:
data = _context6.sent;
if (!(item.body === "arrayBuffer")) {
_context6.next = 8;
break;
}
return _context6.abrupt("return", data);
case 8:
image = new Image();

@@ -296,3 +305,3 @@

_context6.next = 10;
_context6.next = 12;
return new Promise(function (resolve, reject) {

@@ -305,6 +314,6 @@ image.addEventListener("load", function () {

case 10:
case 12:
return _context6.abrupt("return", _context6.sent);
case 11:
case 13:
case "end":

@@ -338,6 +347,15 @@ return _context6.stop();

_context7.next = 5;
return response.blob();
return response[item.body || "blob"]();
case 5:
data = _context7.sent;
if (!(item.body === "arrayBuffer")) {
_context7.next = 8;
break;
}
return _context7.abrupt("return", data);
case 8:
video = document.createElement("video");

@@ -347,3 +365,3 @@

_context7.next = 10;
_context7.next = 12;
return new Promise(function (resolve, reject) {

@@ -356,6 +374,6 @@ video.addEventListener("canplaythrough", function () {

case 10:
case 12:
return _context7.abrupt("return", _context7.sent);
case 11:
case 13:
case "end":

@@ -389,6 +407,15 @@ return _context7.stop();

_context8.next = 5;
return response.blob();
return response[item.body || "blob"]();
case 5:
data = _context8.sent;
if (!(item.body === "arrayBuffer")) {
_context8.next = 8;
break;
}
return _context8.abrupt("return", data);
case 8:
audio = document.createElement("audio");

@@ -400,3 +427,3 @@

_context8.next = 12;
_context8.next = 14;
return new Promise(function (resolve, reject) {

@@ -409,6 +436,6 @@ audio.addEventListener("canplaythrough", function () {

case 12:
case 14:
return _context8.abrupt("return", _context8.sent);
case 13:
case 15:
case "end":

@@ -415,0 +442,0 @@ return _context8.stop();

@@ -281,6 +281,15 @@ import FontFaceObserver from 'fontfaceobserver';

_context6.next = 5;
return response.blob();
return response[item.body || "blob"]();
case 5:
data = _context6.sent;
if (!(item.body === "arrayBuffer")) {
_context6.next = 8;
break;
}
return _context6.abrupt("return", data);
case 8:
image = new Image();

@@ -290,3 +299,3 @@

_context6.next = 10;
_context6.next = 12;
return new Promise(function (resolve, reject) {

@@ -299,6 +308,6 @@ image.addEventListener("load", function () {

case 10:
case 12:
return _context6.abrupt("return", _context6.sent);
case 11:
case 13:
case "end":

@@ -332,6 +341,15 @@ return _context6.stop();

_context7.next = 5;
return response.blob();
return response[item.body || "blob"]();
case 5:
data = _context7.sent;
if (!(item.body === "arrayBuffer")) {
_context7.next = 8;
break;
}
return _context7.abrupt("return", data);
case 8:
video = document.createElement("video");

@@ -341,3 +359,3 @@

_context7.next = 10;
_context7.next = 12;
return new Promise(function (resolve, reject) {

@@ -350,6 +368,6 @@ video.addEventListener("canplaythrough", function () {

case 10:
case 12:
return _context7.abrupt("return", _context7.sent);
case 11:
case 13:
case "end":

@@ -383,6 +401,15 @@ return _context7.stop();

_context8.next = 5;
return response.blob();
return response[item.body || "blob"]();
case 5:
data = _context8.sent;
if (!(item.body === "arrayBuffer")) {
_context8.next = 8;
break;
}
return _context8.abrupt("return", data);
case 8:
audio = document.createElement("audio");

@@ -394,3 +421,3 @@

_context8.next = 12;
_context8.next = 14;
return new Promise(function (resolve, reject) {

@@ -403,6 +430,6 @@ audio.addEventListener("canplaythrough", function () {

case 12:
case 14:
return _context8.abrupt("return", _context8.sent);
case 13:
case 15:
case "end":

@@ -409,0 +436,0 @@ return _context8.stop();

{
"name": "async-preloader",
"version": "1.1.1",
"version": "2.0.0",
"description": "Assets preloader using ES2017 async/await and fetch.",

@@ -5,0 +5,0 @@ "main": "lib/async-preloader.js",

@@ -26,2 +26,4 @@ # async-preloader

loader?: string;
options?: object;
body?: "arrayBuffer" | "blob" | "formData" | "json" | "text"
}

@@ -34,3 +36,5 @@ ```

|**src**|Input for the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)|
|**loader**|Optional string from one of the [LOADERS Map](https://github.com/dmnsgn/async-preloader/blob/master/src/index.js#L20). It needs to be specified for Font and Audio (webm|off). Otherwise the loader is inferred from the file extension or default to `Response.text()` if there is no extension.|
|**loader**|Optional _string_ from one of the [LOADERS Map](https://github.com/dmnsgn/async-preloader/blob/master/src/index.js#L20). It needs to be specified for Font and Audio (webm|off). Otherwise the loader is inferred from the file extension or default to `Response.text()` if there is no extension.|
|**options**|Optional _object_ to pass to the [fetch method](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch).|
|**body**|Optional _string_ to define the [Body method](https://developer.mozilla.org/en-US/docs/Web/API/Body) to handle the Response. Default to `blob()` for Image, Video and Audio.|

@@ -124,6 +128,6 @@ ### AsyncPreloader.items

const pItem = AsyncPreloader.loadJson("assets/json.json");
const pItem = AsyncPreloader.loadJson({ "src": "assets/json.json" });
pItem
.then(item => useLoadedItemFromManifest(item))
.then(item => useLoadedItem(item))
.catch(error => console.error("Error loading item", error));

@@ -155,5 +159,21 @@ ```

### Get an `ArrayBuffer` instead of a blob
You can specify how the response is handle by using the `body` key in a `LoadItem`.
Typical use case: use with the WebAudio API to decode the data with `baseAudioContext.decodeAudioData()`:
```js
import AsyncPreloader from "async-preloader";
const pItem = AsyncPreloader.loadAudio({ src: "assets/audio.mp3", body: "arrayBuffer" });
pItem
.then(item => audioContext.decodeAudioData(item))
.catch(error => console.error("Error decoding audio", error));
```
## License
MIT © [Damien Seguin](https://github.com/dmnsgn)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc