Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
async-preloader
Advanced tools
Assets preloader using ES2017 async/await and fetch.
$ npm install --save async-preloader
interface LoadItem {
id?: string;
src: string;
loader?: string;
}
Key | Description |
---|---|
id | Optional id to retrieve the file using AsyncPreloader.items.get(id) |
src | Input for the Fetch API |
loader | Optional string from one of the LOADERS Map. It needs to be specified for Font and Audio (webm |
items
(Array): Array of LoadItem
s
(Promise): A Promise that resolves with the loaded items.
import AsyncPreloader from "async-preloader";
const pItems = AsyncPreloader.loadItems([
{ "id": "myDefaultFile", "src": "assets/default" },
{ "id": "myTextFile", "src": "assets/text.txt" },
{ "id": "myJsonFile", "src": "assets/json.json" },
{ "id": "myImageFile", "src": "assets/image.jpg" },
{ "id": "myVideoFile", "src": "assets/video.mp4" },
{ "id": "myAudioFile", "src": "assets/audio.mp3" },
{ "id": "myXmlFile", "src": "assets/xml.xml" },
{ "id": "mySvgFile", "src": "assets/xml.svg" },
{ "id": "myHtmlFile", "src": "assets/xml.html" },
{ "id": "myFont", "src": "Open Sans Regular", "loader": "Font" }
]);
pItems
.then(items => {
const element = AsyncPreloader.items.get("myVideoFile");
document.body.appendChild(element);
})
.catch(error => console.error("Error loading items", error));
Note: Font loader is using FontFaceObserver
You can also load a manifest file. It works in a similar fashion as createjs's PreloadJS.
src
(String): Input for the Fetch API. It will load the file using the JsonLoader
and look for an "items"
key containing an array of LoadItem
s.
(Promise): A Promise that resolves with the loaded items.
import AsyncPreloader from "async-preloader";
const pItems = AsyncPreloader.loadItems('assets/manifest.json');
pItems
.then(items => useLoadedItemsFromManifest(items)) // or AsyncPreloader.items.get(pathOrId)
.catch(error => console.error("Error loading items", error));
It is also possible to use the LOADERS individually.
item
(LoadItem): a LoadItem
.
(Promise): A Promise that resolves with the loaded item.
import AsyncPreloader from "async-preloader";
const pItem = AsyncPreloader.loadJson('assets/json.json');
pItem
.then(item => useLoadedItemFromManifest(item))
.catch(error => console.error("Error loading item", error));
MIT © Damien Seguin
FAQs
Assets preloader using async/await and fetch for usage both in the browser and Node.js.
The npm package async-preloader receives a total of 0 weekly downloads. As such, async-preloader popularity was classified as not popular.
We found that async-preloader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.