Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/semibran/img-load
:sunrise_over_mountains::sparkles: tiny promise-based <img> loader for the browser
https://github.com/semibran/img-load
async browser image-loader promise
Last synced: 14 days ago
JSON representation
:sunrise_over_mountains::sparkles: tiny promise-based <img> loader for the browser
- Host: GitHub
- URL: https://github.com/semibran/img-load
- Owner: semibran
- License: mit
- Created: 2017-06-05T22:53:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-21T23:52:27.000Z (over 6 years ago)
- Last Synced: 2024-10-20T13:24:21.759Z (26 days ago)
- Topics: async, browser, image-loader, promise
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# img-load
> tiny promise-based `` loader for the browser```js
loadImage("images/foo.png")
.then(image => document.body.appendChild(image))
```## usage
[![npm badge]][npm package]### `loadImage(path)`
Returns a [`Promise`][using promises] which resolves to the image indicated by `path`.Consider using `loadImage` within an [async function] to further simplify usage.
```js
import loadImage from "img-load"async function main() {
let foo = await loadImage("images/foo.png")
let bar = await loadImage("images/bar.png")
// use `foo.png` and `bar.png`
}main()
```[npm package]: https://www.npmjs.com/package/img-load
[npm badge]: https://nodei.co/npm/img-load.png?mini
[using promises]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises
[async function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/async_function