Socket
Socket
Sign inDemoInstall

waitasecond

Package Overview
Dependencies
1
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.8.10 to 1.8.11

.gitattributes

3

dist/functions/forAllImagesInElement.d.ts
export declare function forAllImagesInElement(element: HTMLElement): Promise<void>;
/**
* TODO: !!! forAllImagesInElement should be able to recieve an <img> element
*/

17

dist/functions/forAllImagesInElement.js

@@ -16,7 +16,11 @@ "use strict";

function forAllImagesInElement(element) {
return Promise.all(Array.from(element.querySelectorAll('img')).map(function (imgElement, i) {
return Promise.all(Array.from(element.querySelectorAll('img')).map(function (imgElement /*, i*/) {
return new Promise(function (resolve, reject) {
if (imgElement.complete) {
if (imgElement.naturalHeight === 0) {
console.info("Image " + i + " rejected due to 0 naturalHeight");
/*
console.info(
`Image ${i} rejected due to 0 naturalHeight`,
);
*/
// TODO: !!! Check this also in load

@@ -26,3 +30,3 @@ reject(imgElement);

else {
console.info("Image " + i + " is already completed");
// console.info(`Image ${i} is already completed`);
resolve();

@@ -32,7 +36,7 @@ }

imgElement.addEventListener('load', function () {
console.info("Image " + i + " resolved");
// console.info(`Image ${i} resolved`);
resolve();
});
imgElement.addEventListener('error', function () {
console.info("Image " + i + " rejected");
// console.info(`Image ${i} rejected`);
// TODO: !!! imgElement into ImageError

@@ -47,1 +51,4 @@ reject(new Error("Some images can`t be loaded. If you want to supress this error keep rejectWhenNotLoaded=false (default value)."));

exports.forAllImagesInElement = forAllImagesInElement;
/**
* TODO: !!! forAllImagesInElement should be able to recieve an <img> element
*/
{
"name": "waitasecond",
"version": "1.8.10",
"description": "Simple tool library for the waiting using Promises.",
"sideEffects": false,
"main": "./dist/main.js",
"types": "./dist/main.d.ts",
"exports": {
".": "./dist/main.js",
"./forAllImagesInElement": "./dist/functions/forAllImagesInElement.js",
"./forAnimationFrame": "./dist/functions/forAnimationFrame.js",
"./forDocumentLoad": "./dist/functions/forDocumentLoad.js",
"./forDOMContentLoaded": "./dist/functions/forDOMContentLoaded.js",
"./forEver": "./dist/functions/forEver.js",
"./forImmediate": "./dist/functions/forImmediate.js",
"./forTime": "./dist/functions/forTime.js",
"./forTimeout": "./dist/functions/forTimeout.js",
"./forTimeSynced": "./dist/functions/forTimeSynced.js",
"./forValueDefined": "./dist/functions/forValueDefined.js"
},
"typesVersions": {
"*": {
"./forAllImagesInElement": [
"./dist/functions/forAllImagesInElement.d.ts"
],
"./forAnimationFrame": [
"./dist/functions/forAnimationFrame.d.ts"
],
"./forDocumentLoad": [
"./dist/functions/forDocumentLoad.d.ts"
],
"./forDOMContentLoaded": [
"./dist/functions/forDOMContentLoaded.d.ts"
],
"./forEver": [
"./dist/functions/forEver.d.ts"
],
"./forImmediate": [
"./dist/functions/forImmediate.d.ts"
],
"./forTime": [
"./dist/functions/forTime.d.ts"
],
"./forTimeout": [
"./dist/functions/forTimeout.d.ts"
],
"./forTimeSynced": [
"./dist/functions/forTimeSynced.d.ts"
],
"./forValueDefined": [
"./dist/functions/forValueDefined.d.ts"
]
}
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:hejny/waitasecond.git"
},
"author": "Pavol Hejný",
"license": "MIT",
"scripts": {
"test": "npm run test-unit && npm run test-integration",
"test-unit": "jest --config jestconfig.json",
"test-integration": "./node_modules/.bin/cypress run",
"test-integration-interactive": "./node_modules/.bin/cypress open",
"samples-server": "ts-node-dev --project ./samples/samplesServer/tsconfig.json ./samples/samplesServer/samplesServer.ts",
"build": "tsc",
"build-watch": "tsc --watch",
"prettier": "prettier --config .prettierrc --write \"{src,test,.vscode}/**/*.{ts,json}\"",
"pretty-imports": "npx organize-imports-cli tsconfig.json",
"prettier-commit": "git diff --exit-code && npm run pretty-imports && npm run prettier && git add src && git commit --allow-empty -m \"Prettier\"",
"generate-documentation": "typedoc",
"generate-documentation-commit": "git diff --exit-code && npm run generate-documentation && git add docs && git commit --allow-empty -m \"Documentation\"",
"lint": "tslint -p tsconfig.json",
"generate-main-exports": "ts-node --project ./scripts/generate-main-exports/tsconfig.json ./scripts/generate-main-exports/generate-main-exports.ts",
"generate-main-exports-commit": "git diff --exit-code && npm run generate-main-exports && npm run prettier && git add src && git commit --allow-empty -m \"Updating exports\"",
"preversion": "npm run lint && npm test && npm run generate-main-exports-commit && npm run build && npm run prettier-commit",
"postversion": "npm run generate-documentation-commit && git push && git push --tags && npm publish"
},
"dependencies": {
"ts-essentials": "^8.1.0"
},
"devDependencies": {
"@types/cypress-image-snapshot": "^3.1.6",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.1",
"@types/serve-index": "^1.9.1",
"codecov": "^3.8.3",
"cypress": "^8.4.0",
"cypress-image-snapshot": "^4.0.1",
"express": "^4.17.1",
"express-throttle-bandwidth": "^1.0.1",
"glob-promise": "^4.2.0",
"jest": "^27.2.0",
"onchange": "^7.1.0",
"open": "^8.2.1",
"organize-imports-cli": "^0.8.0",
"prettier": "^2.4.0",
"serve-index": "^1.9.1",
"serve-static": "^1.14.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typedoc": "^0.22.3",
"typescript": "^4.4.3"
"name": "waitasecond",
"version": "1.8.11",
"description": "Wait a second is an extremely simple and elegant tool for using working with async code and Promises. It is usable by browser, worker, and node environment and fully typed.",
"sideEffects": false,
"main": "./dist/main.js",
"types": "./dist/main.d.ts",
"exports": {
".": "./dist/main.js",
"./forAllImagesInElement": "./dist/functions/forAllImagesInElement.js",
"./forAnimationFrame": "./dist/functions/forAnimationFrame.js",
"./forDocumentLoad": "./dist/functions/forDocumentLoad.js",
"./forDOMContentLoaded": "./dist/functions/forDOMContentLoaded.js",
"./forEver": "./dist/functions/forEver.js",
"./forImmediate": "./dist/functions/forImmediate.js",
"./forTime": "./dist/functions/forTime.js",
"./forTimeout": "./dist/functions/forTimeout.js",
"./forTimeSynced": "./dist/functions/forTimeSynced.js",
"./forValueDefined": "./dist/functions/forValueDefined.js"
},
"typesVersions": {
"*": {
"./forAllImagesInElement": [
"./dist/functions/forAllImagesInElement.d.ts"
],
"./forAnimationFrame": [
"./dist/functions/forAnimationFrame.d.ts"
],
"./forDocumentLoad": [
"./dist/functions/forDocumentLoad.d.ts"
],
"./forDOMContentLoaded": [
"./dist/functions/forDOMContentLoaded.d.ts"
],
"./forEver": [
"./dist/functions/forEver.d.ts"
],
"./forImmediate": [
"./dist/functions/forImmediate.d.ts"
],
"./forTime": [
"./dist/functions/forTime.d.ts"
],
"./forTimeout": [
"./dist/functions/forTimeout.d.ts"
],
"./forTimeSynced": [
"./dist/functions/forTimeSynced.d.ts"
],
"./forValueDefined": [
"./dist/functions/forValueDefined.d.ts"
]
}
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:hejny/waitasecond.git"
},
"author": "Pavol Hejný",
"license": "SEE LICENSE IN LICENSE",
"scripts": {
"test": "npm run test-unit && npm run test-integration",
"test-unit": "jest --config jestconfig.json",
"test-integration": "./node_modules/.bin/cypress run",
"test-integration-interactive": "./node_modules/.bin/cypress open",
"samples-server": "ts-node-dev --project ./samples/samplesServer/tsconfig.json ./samples/samplesServer/samplesServer.ts",
"build": "tsc",
"build-watch": "tsc --watch",
"prettier": "prettier --config .prettierrc --write \"{src,test,.vscode}/**/*.{ts,json}\"",
"pretty-imports": "npx organize-imports-cli tsconfig.json",
"prettier-commit": "git diff --exit-code && npm run pretty-imports && npm run prettier && git add src && git commit --allow-empty -m \"Prettier\"",
"generate-documentation": "typedoc",
"generate-documentation-commit": "git diff --exit-code && npm run generate-documentation && git add docs && git commit --allow-empty -m \"Documentation\"",
"lint": "tslint -p tsconfig.json",
"generate-main-exports": "ts-node --project ./scripts/generate-main-exports/tsconfig.json ./scripts/generate-main-exports/generate-main-exports.ts",
"generate-main-exports-commit": "git diff --exit-code && npm run generate-main-exports && npm run prettier && git add src && git commit --allow-empty -m \"Updating exports\"",
"preversion": "npm run lint && npm test && npm run generate-main-exports-commit && npm run build && npm run prettier-commit",
"postversion": "npm run generate-documentation-commit && git push && git push --tags && npm publish"
},
"dependencies": {
"ts-essentials": "8.1.0"
},
"devDependencies": {
"@types/cypress-image-snapshot": "3.1.6",
"@types/express": "4.17.13",
"@types/jest": "27.0.1",
"@types/serve-index": "1.9.1",
"codecov": "3.8.3",
"cypress": "8.4.0",
"cypress-image-snapshot": "4.0.1",
"express": "4.17.1",
"express-throttle-bandwidth": "1.0.1",
"glob-promise": "4.2.0",
"jest": "27.2.0",
"onchange": "7.1.0",
"open": "8.2.1",
"organize-imports-cli": "0.8.0",
"prettier": "2.4.0",
"serve-index": "1.9.1",
"serve-static": "1.14.1",
"ts-jest": "27.0.5",
"ts-node": "10.2.1",
"ts-node-dev": "1.1.8",
"tslint": "5.20.1",
"tslint-config-prettier": "1.18.0",
"typedoc": "0.22.11",
"typescript": "4.4.3"
}
}
# ⏰ Waitasecond
<!--Badges-->
<!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src/workflows/800-badges/badges.ts so every manual change will be overwritten.-->
[![License of ⏰ Waitasecond](https://img.shields.io/github/license/hejny/waitasecond.svg?style=flat)](https://github.com/hejny/waitasecond/blob/main/LICENSE)
[![NPM Version of ⏰ Waitasecond](https://badge.fury.io/js/waitasecond.svg)](https://www.npmjs.com/package/waitasecond)
[![Quality of package ⏰ Waitasecond](https://packagequality.com/shield/waitasecond.svg)](https://packagequality.com/#?package=waitasecond)
[![Known Vulnerabilities](https://snyk.io/test/github/hejny/waitasecond/badge.svg)](https://snyk.io/test/github/hejny/waitasecond)
[![Issues](https://img.shields.io/github/issues/hejny/waitasecond.svg?style=flat)](https://github.com/hejny/waitasecond/issues)
[![Cypress.io](https://img.shields.io/badge/tested%20with-Cypress-04C38E.svg)](https://www.cypress.io/)
<!--/Badges-->
Wait a second is an extremely simple and elegant tool for using **working with async code and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**. It is usable by browser, worker, and node environment and fully typed.
# 🔥 Install
## 🔥 Install

@@ -13,3 +26,3 @@ Install from [NPM](https://www.npmjs.com/package/waitasecond)

## 🕛 Await forTime _([setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) equivalent)_
### 🕛 Await forTime _([setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) equivalent)_

@@ -32,3 +45,3 @@ In JavaScript, there is an elegant way how to write asynchronous code with **async/await** syntax construct. Every internal function and library is heading forward to be compatible with Promises and deprecating its old callback type.

## 🕧 Await forImmediate _([setImmediate](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) equivalent)_
### 🕧 Await forImmediate _([setImmediate](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) equivalent)_

@@ -39,5 +52,5 @@ ```typescript

async function doSomething() {
console.log(`🍏 foo`);
await forImmediate();
console.log(`🍎 bar`);
console.log(`🍏 foo`);
await forImmediate();
console.log(`🍎 bar`);
}

@@ -68,3 +81,3 @@

## 🕐 Await forAnimationFrame _([requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) equivalent)_
### 🕐 Await forAnimationFrame _([requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) equivalent)_

@@ -77,8 +90,8 @@ With forAnimationFrame you can write nice looking **render**/update/whatever **loops**.

while (
true /* ← Normally, this would be 💩 code, but with forAnimationFrame it is a nicer syntax version of requestAnimationFrame*/
true /* ← Normally, this would be 💩 code, but with forAnimationFrame it is a nicer syntax version of requestAnimationFrame*/
) {
const now = await forAnimationFrame();
const now = await forAnimationFrame();
updateScene(now);
renderScene(now);
updateScene(now);
renderScene(now);
}

@@ -92,3 +105,3 @@ ```

## 🕜 Await forEver
### 🕜 Await forEver

@@ -107,3 +120,3 @@ forEver function returns a promise which never resolves or rejects. It is an elegant way to test what happened if some part of asynchronous code stuck (for example, fetch call).

## 🕑 Await forTimeSynced
### 🕑 Await forTimeSynced

@@ -117,6 +130,6 @@ **forTimeSynced** is an ideal way how to do periodical ticking in an unstable environment.

while (true) {
await forTimeSynced(10 /* Minutes */ * 60 * 1000);
console.log(
`⌛ This will be logged every 10 minutes according to computer time. So it fires for example on 12:00, 12:10, 12:20,...`,
);
await forTimeSynced(10 /* Minutes */ * 60 * 1000);
console.log(
`⌛ This will be logged every 10 minutes according to computer time. So it fires for example on 12:00, 12:10, 12:20,...`,
);
}

@@ -157,4 +170,49 @@ ```

# 🖋️ Contributing
I am opened to your pull requests, feedback, suggestions, and donations. Contact to me is on my [personal page](https://www.pavolhejny.com)
<!--Contributing-->
<!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src/workflows/810-contributing/contributing.ts so every manual change will be overwritten.-->
## 🖋️ Contributing
I am open to pull requests, feedback, and suggestions. Or if you like this utility, you can [☕ buy me a coffee](https://www.buymeacoffee.com/hejny) or [donate via cryptocurrencies](https://github.com/hejny/hejny/blob/main/documents/crypto.md).
You can also ⭐ star the waitasecond package, [follow me on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).
<!--/Contributing-->
<!--Partners-->
<!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src/workflows/820-partners/partners.ts so every manual change will be overwritten.-->
## ✨ Partners
<a href="https://collboard.com/">
<img src="https://collboard.fra1.cdn.digitaloceanspaces.com/assets/18.12.1/logo-small.png" alt="Collboard logo" width="50" />
</a>
&nbsp;&nbsp;&nbsp;
<a href="https://czech.events/">
<img src="https://czech.events/design/logos/czech.events.transparent-logo.png" alt="Czech.events logo" width="50" />
</a>
&nbsp;&nbsp;&nbsp;
<a href="https://sigmastamp.ml/">
<img src="https://www.sigmastamp.ml/sigmastamp-logo.white.svg" alt="SigmaStamp logo" width="50" />
</a>
[Become a partner](https://www.pavolhejny.com/contact/)
<!--/Partners-->

@@ -16,33 +16,37 @@ /*

return Promise.all<void>(
Array.from(element.querySelectorAll('img')).map((imgElement, i) => {
return new Promise((resolve, reject) => {
if (imgElement.complete) {
if (imgElement.naturalHeight === 0) {
Array.from(element.querySelectorAll('img')).map(
(imgElement /*, i*/) => {
return new Promise((resolve, reject) => {
if (imgElement.complete) {
if (imgElement.naturalHeight === 0) {
/*
console.info(
`Image ${i} rejected due to 0 naturalHeight`,
);
*/
// TODO: !!! Check this also in load
reject(imgElement);
} else {
console.info(`Image ${i} is already completed`);
resolve();
// TODO: !!! Check this also in load
reject(imgElement);
} else {
// console.info(`Image ${i} is already completed`);
resolve();
}
}
}
imgElement.addEventListener('load', () => {
console.info(`Image ${i} resolved`);
resolve();
imgElement.addEventListener('load', () => {
// console.info(`Image ${i} resolved`);
resolve();
});
imgElement.addEventListener('error', () => {
// console.info(`Image ${i} rejected`);
// TODO: !!! imgElement into ImageError
reject(
new Error(
`Some images can\`t be loaded. If you want to supress this error keep rejectWhenNotLoaded=false (default value).`,
),
);
});
});
imgElement.addEventListener('error', () => {
console.info(`Image ${i} rejected`);
// TODO: !!! imgElement into ImageError
reject(
new Error(
`Some images can\`t be loaded. If you want to supress this error keep rejectWhenNotLoaded=false (default value).`,
),
);
});
});
}),
},
),
).then(() => {

@@ -52,1 +56,5 @@ /* Note: Returning void */

}
/**
* TODO: !!! forAllImagesInElement should be able to recieve an <img> element
*/

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc