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

waitasecond

Package Overview
Dependencies
Maintainers
1
Versions
124
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 1.7.0 to 1.8.0

2

dist/functions/forAllImagesInElement.d.ts

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

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

@@ -1,94 +0,38 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
/*
TODO: !!! Rename forImagesReady, forMediaReady
TODO: !!! Timeout by chaining
TODO: !!! rejectWhenNotLoaded by chaining
TODO: !!! Corrupted images into samples
TODO: !!! Also with media and pictures
TODO: !!! Universal for every loadable think
TODO: Verbose mode for console.info
*/
// tslint:disable:no-console
export function forAllImagesInElement(element) {
return Promise.all(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();
}
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
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:
_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();
}
}
imgElement.addEventListener('load', function () {
// console.info(`Image ${i} resolved`);
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);
});
}))];
case 1:
_a.sent();
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*/];
}
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).`));
});
});
})).then(() => {
/* Note: Returning void */
});
}
exports.forAllImagesInElement = forAllImagesInElement;

@@ -1,6 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function forAnimationFrame() {
return new Promise(function (resolve) {
requestAnimationFrame(function (now) {
export function forAnimationFrame() {
return new Promise((resolve) => {
requestAnimationFrame((now) => {
// TODO: !!! What exactly is now?
resolve(now);

@@ -10,2 +9,1 @@ });

}
exports.forAnimationFrame = forAnimationFrame;

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function forDocumentLoad() {
return new Promise(function (resolve) {
window.addEventListener('load', function () {
export function forDocumentLoad() {
return new Promise((resolve) => {
window.addEventListener('load', () => {
resolve();

@@ -10,2 +8,1 @@ });

}
exports.forDocumentLoad = forDocumentLoad;

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function forDOMContentLoaded() {
return new Promise(function (resolve) {
document.addEventListener('DOMContentLoaded', function () {
export function forDOMContentLoaded() {
return new Promise((resolve) => {
document.addEventListener('DOMContentLoaded', () => {
resolve();

@@ -10,2 +8,1 @@ });

}
exports.forDOMContentLoaded = forDOMContentLoaded;

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function forEver() {
return new Promise(function () {
export function forEver() {
return new Promise(() => {
// Note: Never ever resolved
});
}
exports.forEver = forEver;

@@ -1,7 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var forTime_1 = require("./forTime");
function forImmediate() {
return forTime_1.forTime(0);
import { forTime } from './forTime.js';
export function forImmediate() {
// Note: Not using setImmediate because it is non-standard feature only in browser window
// @see https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate
return forTime(0);
}
exports.forImmediate = forImmediate;

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function forTime(miliseconds) {
return new Promise(function (resolve) {
setTimeout(function () {
export function forTime(miliseconds) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();

@@ -10,2 +8,1 @@ }, miliseconds);

}
exports.forTime = forTime;

@@ -1,63 +0,11 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var forTime_1 = require("./forTime");
function forTimeout(timeout, value) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.race([
value,
(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, forTime_1.forTime(timeout)];
case 1:
_a.sent();
throw new Error("Timeout " + timeout + "ms is up.");
}
});
}); })(),
])];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
import { forTime } from './forTime.js';
export async function forTimeout(timeout, value) {
return await Promise.race([
value,
(async () => {
await forTime(timeout);
throw new Error(`Timeout ${timeout}ms is up.`);
})(),
]);
}
exports.forTimeout = forTimeout;
/*

@@ -64,0 +12,0 @@ Note: Possible alternative way:

@@ -1,39 +0,2 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var forTime_1 = require("./forTime");
import { forTime } from './forTime.js';
/**

@@ -44,19 +7,7 @@ * This waiter function will sync some action to some precise time

*/
function forTimeSynced(period, shift) {
if (shift === void 0) { shift = 0; }
return __awaiter(this, void 0, void 0, function () {
var currentTime, wait;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
currentTime = new Date().getTime();
wait = period - ((currentTime - shift) % period);
return [4 /*yield*/, forTime_1.forTime(wait)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
export async function forTimeSynced(period, shift = 0) {
const currentTime = new Date().getTime();
const wait = period - ((currentTime - shift) % period);
await forTime(wait);
}
exports.forTimeSynced = forTimeSynced;
// TODO: !!! Human readable forTimeSynced (it is somewhere already implemented)

@@ -1,79 +0,14 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
import { forTime } from './forTime.js';
// TODO: !!! Options style in func params everywhere
export async function forValueDefined(getValue, waiter = async () => {
await forTime(10);
}, limit = 1000) {
for (let i = 0; i < limit; i++) {
const value = await getValue();
if (value !== undefined && value !== null) {
return value;
}
await waiter();
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var forTime_1 = require("./forTime");
function forValueDefined(getValue, waiter, limit) {
var _this = this;
if (waiter === void 0) { waiter = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, forTime_1.forTime(10)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); }; }
if (limit === void 0) { limit = 1000; }
return __awaiter(this, void 0, void 0, function () {
var i, value;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < limit)) return [3 /*break*/, 5];
return [4 /*yield*/, getValue()];
case 2:
value = _a.sent();
if (value !== undefined && value !== null) {
return [2 /*return*/, value];
}
return [4 /*yield*/, waiter()];
case 3:
_a.sent();
_a.label = 4;
case 4:
i++;
return [3 /*break*/, 1];
case 5: throw new Error("Limit " + limit + " overflowed in waitForDefined.");
}
});
});
throw new Error(`Limit ${limit} overflowed in waitForDefined.`);
}
exports.forValueDefined = forValueDefined;

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

import { forAllImagesInElement } from './functions/forAllImagesInElement';
import { forAnimationFrame } from './functions/forAnimationFrame';
import { forDocumentLoad } from './functions/forDocumentLoad';
import { forDOMContentLoaded } from './functions/forDOMContentLoaded';
import { forEver } from './functions/forEver';
import { forImmediate } from './functions/forImmediate';
import { forTime } from './functions/forTime';
import { forTimeout } from './functions/forTimeout';
import { forTimeSynced } from './functions/forTimeSynced';
import { forValueDefined } from './functions/forValueDefined';
import { forAllImagesInElement } from './functions/forAllImagesInElement.js';
import { forAnimationFrame } from './functions/forAnimationFrame.js';
import { forDocumentLoad } from './functions/forDocumentLoad.js';
import { forDOMContentLoaded } from './functions/forDOMContentLoaded.js';
import { forEver } from './functions/forEver.js';
import { forImmediate } from './functions/forImmediate.js';
import { forTime } from './functions/forTime.js';
import { forTimeout } from './functions/forTimeout.js';
import { forTimeSynced } from './functions/forTimeSynced.js';
import { forValueDefined } from './functions/forValueDefined.js';
export { forTime, forEver, forTimeout, forImmediate, forTimeSynced, forValueDefined, forDocumentLoad, forAnimationFrame, forDOMContentLoaded, forAllImagesInElement, };

@@ -1,24 +0,13 @@

"use strict";
// GENERATED WITH generate-main-exports
// Warning: Do not edit by hand, all changes will be lost on next execution!
Object.defineProperty(exports, "__esModule", { value: true });
var forAllImagesInElement_1 = require("./functions/forAllImagesInElement");
exports.forAllImagesInElement = forAllImagesInElement_1.forAllImagesInElement;
var forAnimationFrame_1 = require("./functions/forAnimationFrame");
exports.forAnimationFrame = forAnimationFrame_1.forAnimationFrame;
var forDocumentLoad_1 = require("./functions/forDocumentLoad");
exports.forDocumentLoad = forDocumentLoad_1.forDocumentLoad;
var forDOMContentLoaded_1 = require("./functions/forDOMContentLoaded");
exports.forDOMContentLoaded = forDOMContentLoaded_1.forDOMContentLoaded;
var forEver_1 = require("./functions/forEver");
exports.forEver = forEver_1.forEver;
var forImmediate_1 = require("./functions/forImmediate");
exports.forImmediate = forImmediate_1.forImmediate;
var forTime_1 = require("./functions/forTime");
exports.forTime = forTime_1.forTime;
var forTimeout_1 = require("./functions/forTimeout");
exports.forTimeout = forTimeout_1.forTimeout;
var forTimeSynced_1 = require("./functions/forTimeSynced");
exports.forTimeSynced = forTimeSynced_1.forTimeSynced;
var forValueDefined_1 = require("./functions/forValueDefined");
exports.forValueDefined = forValueDefined_1.forValueDefined;
import { forAllImagesInElement } from './functions/forAllImagesInElement.js';
import { forAnimationFrame } from './functions/forAnimationFrame.js';
import { forDocumentLoad } from './functions/forDocumentLoad.js';
import { forDOMContentLoaded } from './functions/forDOMContentLoaded.js';
import { forEver } from './functions/forEver.js';
import { forImmediate } from './functions/forImmediate.js';
import { forTime } from './functions/forTime.js';
import { forTimeout } from './functions/forTimeout.js';
import { forTimeSynced } from './functions/forTimeSynced.js';
import { forValueDefined } from './functions/forValueDefined.js';
export { forTime, forEver, forTimeout, forImmediate, forTimeSynced, forValueDefined, forDocumentLoad, forAnimationFrame, forDOMContentLoaded, forAllImagesInElement, };
{
"name": "waitasecond",
"version": "1.7.0",
"version": "1.8.0",
"description": "Simple tool library for the waiting using Promises.",

@@ -15,3 +15,7 @@ "main": "dist/main.js",

"scripts": {
"start": "npm run build-watch",
"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",

@@ -21,12 +25,9 @@ "build-watch": "tsc --watch",

"pretty-imports": "npx organize-imports-cli tsconfig.json",
"prettier-watch": "onchange \"{src,test,.vscode}/**/*.{ts,json}\" -- prettier --config .prettierrc --write {{changed}}",
"prettier-commit": "git diff --exit-code && npm run pretty-imports && npm run prettier && git add src && git commit --allow-empty -m \"Prettier\"",
"documentation": "typedoc --excludePrivate --hideGenerator --mode file --theme minimal --out docs --name \"Waitasecond\" ./src",
"documentation": "typedoc",
"documentation-commit": "git diff --exit-code && npm run documentation && git add docs && git commit --allow-empty -m \"Documentation\"",
"test": "jest --config jestconfig.json",
"test-watch": "jest --config jestconfig.json --watchAll",
"lint": "tslint -p tsconfig.json",
"generate-main-exports": "ts-node ./scripts/generate-main-exports/generate-main-exports.ts",
"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 test && npm run lint && npm run generate-main-exports-commit && npm run build && npm run prettier-commit && npm run documentation-commit",
"preversion": "npm run lint && npm test && npm run generate-main-exports-commit && npm run build && npm run prettier-commit && npm run documentation-commit",
"postversion": "git push && git push --tags && npm publish"

@@ -42,16 +43,27 @@ },

"devDependencies": {
"@types/cypress-image-snapshot": "^3.1.6",
"@types/express": "^4.17.13",
"@types/jest": "^24.0.13",
"@types/serve-index": "^1.9.1",
"codecov": "^3.5.0",
"glob-promise": "^3.4.0",
"cypress": "^8.3.1",
"cypress-image-snapshot": "^4.0.1",
"express": "^4.17.1",
"express-throttle-bandwidth": "^1.0.1",
"glob-promise": "^4.2.0",
"jest": "^24.8.0",
"onchange": "^3.3.0",
"open": "^8.2.1",
"organize-imports-cli": "^0.8.0",
"prettier": "github:prettier/prettier",
"serve-index": "^1.9.1",
"serve-static": "^1.14.1",
"ts-jest": "^24.0.2",
"ts-node": "^9.0.0",
"ts-node-dev": "^1.1.8",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.1"
"typedoc": "^0.21.9",
"typescript": "^4.0.3"
}
}

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

# Wait a second library
# ⏰ Waitasecond
A very simple tool library for the waiting using Promises.
Waitasecond 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
Install from [NPM](https://www.npmjs.com/package/configchecker)
Install from [NPM](https://www.npmjs.com/package/waitasecond)

@@ -13,28 +13,109 @@ ```bash

# Usage
## πŸ•› Await forTime _([setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) equivalent)_
In JavaScript there is very elegant syntax to write asynchronous code with **async/await**. Every internal function and library is heading forward to be compatible with Promises and deprecating its old callback type.
But there are some **relicts from [callback hell](http://callbackhell.com/)** like **setTimeout, requestAnimationFrame,...**. Waitasecond has motivation to turn this into elegant syntax:
```typescript
import {} from 'waitasecond';
import { forTime } from 'waitasecond';
// TODO:
console.log(`⏳ This is logged immediatelly.`);
await forTime(500);
console.log(`βŒ› And this after 500 miliseconds.`);
await forTime(666);
console.log(`😈 Wow, I have escaped from callback hell`);
```
# Contributing
## πŸ•§ Await forImmediate _([setImmediate](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) equivalent)_
I am opened to your pull requests, feedback, suggestions and donations :) . Contact to me is on my [personal page](https://www.pavolhejny.com)
```typescript
import { forImmediate } from 'waitasecond';
Please install theese plugins:
async function doSomething() {
console.log(`🍏 foo`);
await forImmediate();
console.log(`🍎 bar`);
}
- [Terminals Manager](https://marketplace.visualstudio.com/items?itemName=fabiospampinato.vscode-terminals)
- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
- [ESlint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
doSomething();
doSomething();
## Publishing a new version
// 🍏 foo
// 🍏 foo
// 🍎 bar
// 🍎 bar
Just do
await doSomething();
await doSomething();
```bash
npm version patch
// 🍏 foo
// 🍎 bar
// 🍏 foo
// 🍎 bar
```
on _minor_ or _major_. Scripts defined in package.json will test, lint, build, create documentation and push the whole project for you.
_Note: Despite window.setImmediate is non-standard feature and it is not working in node, function **forImmediate is working in all environments**_
_Note: If you want to use equivalent of [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval), see [https://rxjs.dev/api/index/function/interval)._
## πŸ• Await forAnimationFrame _([requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) equivalent)_
With forAnimationFrame you can write nice looking **render**/update/whatever **loops**.
```typescript
import { forAnimationFrame } from 'waitasecond';
while (
true /* ← Normally this would be πŸ’© code but with forAnimationFrame it is nicer syntax version of requestAnimationFrame*/
) {
const now = await forAnimationFrame();
updateScene(now);
renderScene(now);
}
```
_Note: This is working only in browser environment._
## πŸ•œ Await forEver
Never resolves or rejects. It is elegant way to test what happen if some part of async code stucks (for example some fetch call).
```typescript
import { forEver } from 'waitasecond';
await forEver();
console.log(`🧟 This will never ever happen.`);
```
## πŸ•‘ Await forTimeSynced
```typescript
import { forTimeSynced } from 'waitasecond';
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 forValueDefined
```typescript
import { forValueDefined } from 'waitasecond';
// TODO: !!!
```
## πŸ•’ Await forAllImagesInElement
```typescript
import { forAllImagesInElement } from 'waitasecond';
// TODO: !!!
```
# πŸ–‹οΈ Contributing
I am opened to your pull requests, feedback, suggestions and donations :) . Contact to me is on my [personal page](https://www.pavolhejny.com)
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