Giter Site home page Giter Site logo

fetch-images's Introduction

Fetch images function

Function for preloading images.

Your request fetchImages with the array of links of images or HTMLImageElement. fetchImages is resolve, if all images are downloaded successfully. If one of the image will be broken, fetchImages rejects.

Usage

import fetchImages from "fetch-images";

let img = new Image();

const images = [
  "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Edvard_Munch_-_The_dance_of_life_%281899-1900%29.jpg/1920px-Edvard_Munch_-_The_dance_of_life_%281899-1900%29.jpg",
  img
];

const failImages = [
  "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/The_Scream.jpg/800px-The_Scream.jpg",
  'blah'
];

fetchImages(images)
  .then(values => {
    values.map(value => console.log(value));
  })
.catch(err => console.log(err));

fetchImages(...images)
  .then(values => {
    values.map(value => console.log(value));
  })
.catch(err => console.log(err));

fetchImages(failImages)
  .then(values => {
    values.map(value => console.lol(value));
  })
.catch(err => console.log(err));

img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/The_Scream.jpg/800px-The_Scream.jpg";

fetch-images's People

Contributors

homm avatar zmoki avatar

Watchers

 avatar

Forkers

homm

fetch-images's Issues

fetchImages should accept many arguments

The task was (to be precise, in Russian):

Функция принимает в качестве аргументов любое кол-во в любой комбинации:
— строки. URL до картинок, которые нужно загрузить.
— объекты HTMLImageElement, в которые загружены картинки,
либо загружаются картинки, либо даже еще не начали загружать картинки
(только что созданные с помощью new Image(), у которых src будет установлен
после вызова функции).

This means: the function should accept any number of arguments, every of which can be a string or HTMLImageElement. Not the array of arguments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.