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

image-promise

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-promise - npm Package Compare versions

Comparing version 6.0.2 to 6.1.0

index.js

11

index.d.ts

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

export default function (image: string | HTMLImageElement, attributes?: object): Promise<HTMLImageElement>;
export default function (images: ArrayLike<string> | ArrayLike<HTMLImageElement>, attributes?: object): Promise<HTMLImageElement[]>;
declare type Input = string | HTMLImageElement;
declare type Output = HTMLImageElement;
declare type Attributes = Record<string, string>;
declare type ImagePromise = Promise<HTMLImageElement> & {
image: HTMLImageElement;
};
declare function loadImages(input: Input, attributes?: Attributes): ImagePromise;
declare function loadImages(input: ArrayLike<Input>, attributes?: Attributes): Promise<Output[]>;
export default loadImages;

72

package.json
{
"name": "image-promise",
"version": "6.0.2",
"version": "6.1.0",
"description": "Load one or more images, return a promise. Only 0.4KB, for the browser, no dependencies.",
"license": "MIT",
"repository": "bfred-it/image-promise",
"author": "Federico Brigante <github@bfred.it> (bfred.it)",
"keywords": [
"browser",
"cache",
"image",
"imagesloaded",
"img",
"lazyload",
"load",
"onload",
"preload",
"lazyload",
"promise",
"then",
"cache",
"imagesloaded",
"vanilla"
],
"repository": "fregante/image-promise",
"license": "MIT",
"author": "Federico Brigante <opensource@bfred.it> (bfred.it)",
"files": [
"dist/image-promise.common-js.js",
"dist/image-promise.es-modules.js",
"index.js",
"index.d.ts"
],
"module": "index.js",
"types": "./index.d.ts",
"main": "dist/image-promise.common-js.js",
"scripts": {
"build:js": "bfred-npm-bundler image-promise loadImage",
"build": "npm-run-all --silent jsfix build:*",
"jsfix": "xo --ignore 'tests/**/*' --fix",
"watch:build": "onchange 'index.js' --initial -- npm run build -- --continue-on-error",
"watch": "npm-run-all --parallel --silent watch:*",
"prepublish": "npm run build",
"version": "npm run build; git add dist",
"test": "npm run build",
"intern:chrome": "intern-runner config=tests/chrome",
"intern:browserstack": "intern-runner config=tests/intern"
"build": "tsc",
"prepublishOnly": "tsc",
"test": "xo && tsc --noEmit",
"watch": "tsc --watch"
},
"devDependencies": {
"bfred-npm-bundler": "^8.1.0",
"intern": "^3.4.2",
"npm-run-all": "^4.0.2",
"onchange": "^3.2.1",
"xo": "^0.17.1"
},
"xo": {
"env": [
"envs": [
"browser"
]
],
"extensions": [
"ts"
],
"overrides": [
{
"files": "**/*.ts",
"extends": "xo-typescript",
"rules": {
"@typescript-eslint/promise-function-async": "off"
}
}
],
"rules": {
"prefer-promise-reject-errors": "off"
}
},
"bugs": {
"url": "https://github.com/bfred-it/image-promise/issues"
},
"homepage": "https://github.com/bfred-it/image-promise#readme"
"devDependencies": {
"@sindresorhus/tsconfig": "^0.4.0",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"eslint-config-xo-typescript": "^0.15.0",
"type-fest": "^0.8.1",
"typescript": "^3.5.3",
"xo": "*"
}
}

@@ -1,44 +0,43 @@

# image-promise [![gzipped size][badge-gzip]](#no-link) [![Travis build status][badge-travis]][link-travis] [![npm version][badge-version]][link-npm] [![npm downloads][badge-downloads]][link-npm]
# image-promise [![][badge-gzip]](#link-npm)
[badge-gzip]: https://badges.herokuapp.com/size/github/bfred-it/image-promise/master/dist/image-promise.min.js?gzip=true&label=gzipped%20size
[badge-travis]: https://api.travis-ci.org/bfred-it/image-promise.svg
[badge-version]: https://img.shields.io/npm/v/image-promise.svg
[badge-downloads]: https://img.shields.io/npm/dt/image-promise.svg
[link-travis]: https://travis-ci.org/bfred-it/image-promise
[badge-gzip]: https://img.shields.io/bundlephobia/minzip/image-promise.svg?label=gzipped
[link-npm]: https://www.npmjs.com/package/image-promise
> Load one or more images, return a promise. Only 0.4KB, for the browser, no dependencies.
> Load one or more images, return a promise. Only 0.5KB, for the browser, no dependencies.
It can be used in two ways:
- given a URL, generate an `<img>` and wait for it to load:
- pass a URL: it will generate an `<img>` and wait for it to load:
```js
loadImage('img.jpg').then(/*it's loaded!*/)
loadImage('img.jpg').then(/* It's loaded! */)
```
- given an `<img>`, wait for it to load:
- pass an `<img>`: it will wait for it to load:
```js
const img = document.querySelector('img.my-image');
loadImage(img).then(/*it's loaded!*/)
loadImage(img).then(/* It's loaded! */)
```
```
- pass an array of URLs and/or `<img>`s, wait for them to load:
```js
const img = document.querySelector('img.my-image');
loadImage([img, 'loading.gif']).then(/* Both are loaded! */)
```
## Install
Pick your favorite:
You can just download the [standalone bundle](https://packd.fregante.now.sh/image-promise@latest?name=loadImage) (it might take a minute to download)
```html
<script src="dist/image-promise.min.js"></script>
```
Or use `npm`:
```sh
npm install --save image-promise
npm install image-promise
```
```js
var loadImage = require('image-promise');
```
```js
// This module is only offered as a ES Module
import loadImage from 'image-promise';

@@ -54,4 +53,4 @@ ```

```js
var image = 'cat.jpg';
// var image = $('img')[0]; // it can also be an <img> element
const image = 'cat.jpg';
// const image = $('img')[0]; // it can also be an <img> element

@@ -72,5 +71,5 @@ loadImage(image)

```js
var images = ['cat.jpg', 'dog.jpg'];
// var images = $('img'); // it can also be a jQuery object
// var images = document.querySelectorAll('img'); // or a NodeList
const images = ['cat.jpg', 'dog.jpg'];
// const images = $('img'); // it can also be a jQuery object
// const images = document.querySelectorAll('img'); // or a NodeList

@@ -96,3 +95,3 @@ loadImage(images)

```js
var image = 'http://catpics.com/cat.jpg';
const image = 'https://catpics.com/cat.jpg';

@@ -117,2 +116,2 @@ loadImage(image, { crossorigin: 'anonymous' })

MIT © [Federico Brigante](http://twitter.com/bfred_it)
MIT © [Federico Brigante](https://bfred.it)
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