Socket
Socket
Sign inDemoInstall

waitasecond

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

waitasecond - npm Package Compare versions

Comparing version 0.3.1 to 0.5.0

dist/index.d.ts

2

dist/functions/forAllImagesInElement.d.ts

@@ -1,1 +0,1 @@

export declare function forAllImagesInElement(element: HTMLElement): Promise<void>;
export declare function forAllImagesInElement(element: HTMLElement, rejectWhenNotLoaded?: boolean, timeout?: number): Promise<void>;

@@ -38,29 +38,54 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
function forAllImagesInElement(element) {
function forAllImagesInElement(element, rejectWhenNotLoaded, timeout) {
if (rejectWhenNotLoaded === void 0) { rejectWhenNotLoaded = false; }
if (timeout === void 0) { timeout = 1500; }
return __awaiter(this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(Array.from(element.querySelectorAll('img')).map(function (imgElement) {
return new Promise(function (resolve, reject) {
if (imgElement.complete) {
if (imgElement.naturalHeight === 0) {
reject(imgElement);
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, Promise.all(
// TODO: How to handle console.info
Array.from(element.querySelectorAll('img')).map(function (imgElement) {
return new Promise(function (resolve, reject) {
if (imgElement.complete) {
if (imgElement.naturalHeight === 0) {
// console.info(`Image ${i} rejected due to 0 naturalHeight`);
reject(imgElement);
}
else {
// console.info(`Image ${i} resolved`);
resolve();
}
}
else {
imgElement.addEventListener('load', function () {
// console.info(`Image ${i} resolved`);
resolve();
}
return;
}
;
imgElement.addEventListener('load', function () {
resolve();
});
imgElement.addEventListener('error', function () {
// console.info(`Image ${i} rejected`);
reject(imgElement);
});
setTimeout(function () {
// console.info(`Image ${i} rejected due to timeout`);
reject(imgElement);
}, timeout);
});
imgElement.addEventListener('error', function () {
reject(imgElement);
});
});
}))];
}))];
case 1:
_a.sent();
return [2 /*return*/];
return [3 /*break*/, 3];
case 2:
error_1 = _a.sent();
if (rejectWhenNotLoaded) {
throw new Error("Some images can`t be loaded. If you want to supress this error keep rejectWhenNotLoaded=false (default value).");
}
else {
return [2 /*return*/];
}
return [3 /*break*/, 3];
case 3:
// This return will be reached only when there will be all promises resolved and there will be no error
return [2 /*return*/];
}

@@ -67,0 +92,0 @@ });

export declare function forAnimationFrame(): Promise<number>;

@@ -0,0 +0,0 @@ "use strict";

export declare function forDocumentLoad(): Promise<void>;

@@ -0,0 +0,0 @@ "use strict";

export declare function forImmediate(): Promise<void>;

@@ -0,0 +0,0 @@ "use strict";

export declare function forTime(miliseconds: number): Promise<void>;

@@ -0,0 +0,0 @@ "use strict";

export declare function forValueDefined<T>(getValue: () => T | undefined, waiter?: () => Promise<void>, limit?: number): Promise<T>;

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { forAllImagesInElement } from './functions/forAllImagesInElement';

@@ -0,0 +0,0 @@ "use strict";

{
"name": "waitasecond",
"version": "0.3.1",
"version": "0.5.0",
"description": "Simple tool library for the waiting using Promises.",

@@ -5,0 +5,0 @@ "main": "dist/main.js",

@@ -18,3 +18,3 @@ # Wait a second library

```typescript
import { } from 'waitASecond';
import { } from 'waitasecond';

@@ -36,8 +36,2 @@ // TODO:

```
or *minor* or *major*. Scripts defined in package.json will test, lint, build, create documentation and push the whole project for you.
# Authors
- [Pavol Hejný](https://github.com/hejny)
- [David Pohan](https://github.com/pohy)
on *minor* or *major*. Scripts defined in package.json will test, lint, build, create documentation and push the whole project for you.

Sorry, the diff of this file is not supported yet

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