{"name":"waitasecond","version":"1.7.0","author":{"name":"Pavol Hejný"},"license":"MIT","_id":"waitasecond@1.7.0","homepage":"https://github.com/hejny/waitasecond#readme","bugs":{"url":"https://github.com/hejny/waitasecond/issues"},"dist":{"shasum":"081058903dbe00acdb63b19f05cbf4bb1100a837","tarball":"http://registry-npm.ywwl.com/waitasecond/download/waitasecond-1.7.0.tgz","fileCount":27,"integrity":"sha512-cAyULLER5TnNvp0Ngz2SfglqMvwRKZW3reM9ij+mkpQ73rDVfYkVfJLvFCnUlSHmUpwHmYi7nzYFgaS01oz0kQ==","signatures":[{"sig":"MEUCIQC7cR1ZeoGhMvF9ELeFvZsJ2/qKiJvpmFboBz6iaTGqdAIgKMJJ0yZjKGelr/lKDEpUcb4biix2GzTG5IQ+jBWhrco=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":27739,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg9scbCRA9TVsSAnZWagAANZoP/2gXHiOI9jaSRlf8RuUE\n5uiI2up8x9/YXWpuSDCDeTgMtXRU/6HHSfkD2nhHotHWK/gvUk12OlHbCGhH\nkWYnj0nd4ZgcOsv5nr43KwZtAgIUApiaBAYQCykmdjC3ONR3uhofROswWJq8\ncBgAs1uqX9UseUMhzXZ57relLfdlu+ZU+bgw5AQbTPMVd+Dvxf/66Q9pbrqR\n0RTNywKXn/hDaKdTr2yCDrESSItY59bjq3Q89dvQ0NcteDKgZD0lKXFQ6tER\nECxQQvdmJSlahMJUpvWsdSppBQhg/8n8Ma1tecoAjKSY7a+ZQIqnP1UgKU3Q\nuwTHXIWDMBrgGdOmQJc9z4T9qdVmMe79GQwMy4Jq8C5bnGvs3uMpqaZRq+OY\nDJrjNcSik8PgJLgje8qA4qu5qbHkhEB/W6LeTZKiM+xD4+fMDQMYgFmELHcs\nM08SEvb0YikHf2hN3tCSvUdbBcE3r41WJogIVRvk9Xs7pdBdS43K6RaF7yJi\nUbKqVRWmu8zZPcLTOEbyxoH7VI7gAj6FCwu8Ci0Uv9ZzRAyRYFpIc+U9+OS2\n8kp0wOoOgvdOlkmeAnp/jPf5AW5Ugd43MeR45YKxS/o/bmkIarME/ZNUIPrX\nsht2jzyCCwerK12QWlwO0JwSSkl4F+DH1/0LuIhz8d7oGVXxUCa3H2PUY0z/\n3NzP\r\n=1g6X\r\n-----END PGP SIGNATURE-----\r\n","size":5980,"noattachment":false,"key":"/waitasecond/-/waitasecond-1.7.0.tgz"},"main":"dist/main.js","gitHead":"0bba7f977a4b650505437ec5c6c489ac2c72e02b","scripts":{"lint":"tslint -p tsconfig.json","test":"jest --config jestconfig.json","build":"tsc","start":"npm run build-watch","prettier":"prettier --config .prettierrc --write \"{src,test,.vscode}/**/*.{ts,json}\"","preversion":"npm test && npm run lint && npm run generate-main-exports-commit && npm run build && npm run prettier-commit && npm run documentation-commit","test-watch":"jest --config jestconfig.json --watchAll","build-watch":"tsc --watch","postversion":"git push && git push --tags && npm publish","documentation":"typedoc --excludePrivate --hideGenerator --mode file --theme minimal --out docs --name \"Waitasecond\" ./src","prettier-watch":"onchange \"{src,test,.vscode}/**/*.{ts,json}\" -- prettier --config .prettierrc --write {{changed}}","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\"","documentation-commit":"git diff --exit-code && npm run documentation && git add docs && git commit --allow-empty -m \"Documentation\"","generate-main-exports":"ts-node ./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\""},"typings":"dist/main.d.ts","_npmUser":{"name":"hejny","email":"me@pavolhejny.com"},"directions":{"functions":"dist/functions"},"repository":{"url":"git+ssh://git@github.com/hejny/waitasecond.git","type":"git"},"_npmVersion":"6.14.8","description":"Simple tool library for the waiting using Promises.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24.8.0","tslint":"^5.17.0","codecov":"^3.5.0","ts-jest":"^24.0.2","ts-node":"^9.0.0","typedoc":"^0.14.2","onchange":"^3.3.0","prettier":"github:prettier/prettier","typescript":"^3.5.1","@types/jest":"^24.0.13","glob-promise":"^3.4.0","organize-imports-cli":"^0.8.0","tslint-config-prettier":"^1.18.0"},"_npmOperationalInternal":{"tmp":"tmp/waitasecond_1.7.0_1626785563754_0.5238960286546828","host":"s3://npm-registry-packages"},"readme":"# ⏰ Waitasecond\n\n<!--Badges-->\n<!--⚠️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.-->\n\n\n[![License of Waitasecond](https://img.shields.io/github/license/hejny/waitasecond.svg?style=flat)](https://github.com/hejny/waitasecond/blob/main/LICENSE)\n[![NPM Version of Waitasecond](https://badge.fury.io/js/waitasecond.svg)](https://www.npmjs.com/package/waitasecond)\n[![Quality of package Waitasecond](https://packagequality.com/shield/waitasecond.svg)](https://packagequality.com/#?package=waitasecond)\n[![Known Vulnerabilities](https://snyk.io/test/github/hejny/waitasecond/badge.svg)](https://snyk.io/test/github/hejny/waitasecond)\n[![Issues](https://img.shields.io/github/issues/hejny/waitasecond.svg?style=flat)](https://github.com/hejny/waitasecond/issues)\n[![Cypress.io](https://img.shields.io/badge/tested%20with-Cypress-04C38E.svg)](https://www.cypress.io/)\n[![Socket](https://socket.dev/api/badge/npm/package/waitasecond)](https://socket.dev/npm/package/waitasecond)\n\n<!--/Badges-->\n\n\nWaitasecond is a javascript library that makes managing **async code and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** simple and elegant. It provides an await-like API that can be used in the browser, worker, and node environment, making it a powerful tool for any project. Additionally, the library is fully typed, allowing developers to have complete confidence in the reliability of their code. With Waitasecond, developers can easily and reliably handle any asynchronous task with ease.\n\n\n<!--Wallpaper-->\n<!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src//workflows/315-ai-generated-wallpaper/4-aiGeneratedWallpaperUseInReadme.ts so every manual change will be overwritten.-->\n[![Wallpaper of ⏰ Waitasecond](assets/ai/wallpaper/gallery/43a3e1f3-bde0-4747-bf6b-04158e54f112-0_0.png)](https://www.midjourney.com/app/jobs/43a3e1f3-bde0-4747-bf6b-04158e54f112)\n<!--/Wallpaper-->\n\n## 🔥 Install\n\nInstall from [NPM](https://www.npmjs.com/package/waitasecond)\n\n```bash\nnpm i waitasecond\n```\n\n## 🕛 Await forTime _([setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) equivalent)_\n\nIn 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.\nBut there are some **relicts from [callback hell](http://callbackhell.com/)** like **setTimeout, requestAnimationFrame,...**. Waitasecond has motivation to turn this into elegant syntax:\n\n```typescript\nimport { forTime } from 'waitasecond';\n\nconsole.log(`⏳ This is logged immediately.`);\nawait forTime(500);\nconsole.log(`⌛ And this after 500 milliseconds.`);\nawait forTime(666);\nconsole.log(`😈 Wow, I have escaped from callback hell`);\n```\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forTime)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forTime.ts)\n\n## 🕧 Await forImmediate _([setImmediate](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) equivalent)_\n\n```typescript\nimport { forImmediate } from 'waitasecond';\n\nasync function doSomething() {\n    console.log(`🍏 foo`);\n    await forImmediate();\n    console.log(`🍎 bar`);\n}\n\ndoSomething();\ndoSomething();\n\n// 🍏 foo\n// 🍏 foo\n// 🍎 bar\n// 🍎 bar\n\nawait doSomething();\nawait doSomething();\n\n// 🍏 foo\n// 🍎 bar\n// 🍏 foo\n// 🍎 bar\n```\n\n_Note: Despite window.setImmediate is a non-standard feature and it is not working in node, function **forImmediate is working in all environments**_\n_Note: If you want to use an equivalent of [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval), see [RxJS interval](https://rxjs.dev/api/index/function/interval)._\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forImmediate)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forImmediate.ts)\n\n## 🕐 Await forAnimationFrame _([requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) equivalent)_\n\nWith forAnimationFrame you can write nice looking **render**/update/whatever **loops**.\n\n```typescript\nimport { forAnimationFrame } from 'waitasecond';\n\nwhile (\n    true /* ← Normally, this would be 💩 code, but with forAnimationFrame it is a nicer syntax version of requestAnimationFrame*/\n) {\n    const now = await forAnimationFrame();\n\n    updateScene(now);\n    renderScene(now);\n}\n```\n\n_Note: This is working only in a browser environment._\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forAnimationFrame)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forAnimationFrame.ts)\n\n## 🕜 Await forEver\n\nforEver 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).\n\n```typescript\nimport { forEver } from 'waitasecond';\n\nawait forEver();\nconsole.log(`🧟 This will never ever happen.`);\n```\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forEver)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forEver.ts)\n\n## 🕑 Await forTimeSynced\n\n**forTimeSynced** is an ideal way how to do periodical ticking in an unstable environment.\nFor example, if you want to run a process every 10 minutes on a server, but PM2 is restarting a server unexpectedly.\n\n```typescript\nimport { forTimeSynced } from 'waitasecond';\n\nwhile (true) {\n    await forTimeSynced(10 /* Minutes */ * 60 * 1000);\n    console.log(\n        `⌛ This will be logged every 10 minutes according to computer time. So it fires for example on 12:00, 12:10, 12:20,...`,\n    );\n}\n```\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forTimeSynced)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forTimeSynced.ts)\n\n## 🕝 Await forValueDefined\n\n```typescript\nimport { forValueDefined } from 'waitasecond';\n\nconst firstName = forValueDefined(() => data.firstName);\n```\n\n_Note: This is not definitely the ideal way how to wait for things. But it can be helpful if you want to \"observe\" some mutating object which do not support it natively._\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forValueDefined)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forValueDefined.ts)\n\n## 🕒 Await forImage\n\n```typescript\nimport { forImage } from 'waitasecond';\n\nawait forImage(document.querySelector('.logo'));\nconsole.log(`🖼️ Now I can be sure that the logo is loaded.`);\n\n// ...\nawait renderToPdf(document.body);\n// ...\n```\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forImage)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forImage.ts)\n\n## 🕒 Await forAllImagesInElement\n\n```typescript\nimport { forAllImagesInElement } from 'waitasecond';\n\nawait forAllImagesInElement(document.body);\nconsole.log(`🖼️ Now I can be sure that all images in body are loaded.`);\n\n// ...\nawait renderToPdf(document.body);\n// ...\n```\n\n[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forAllImagesInElement)\n[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forAllImagesInElement.ts)\n\n<!--Contributing-->\n<!--⚠️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.-->\n\n## 🖋️ Contributing\n\nI 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).\n\nYou can also ⭐ star the waitasecond package, [follow me on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).\n\n<!--/Contributing-->\n\n<!--Partners-->\n<!--⚠️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.-->\n\n## ✨ Partners\n\n\n<a href=\"https://collboard.com/\" title=\"Collboard\"><img src=\"https://collboard.fra1.cdn.digitaloceanspaces.com/assets/18.12.1/logo-small.png#gh-light-mode-only\" alt=\"Collboard\" height=\"60\"/></a>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n<a href=\"https://webgpt.cz/?partner=ph&utm_medium=referral&utm_source=github-readme&utm_campaign=partner-ph\" title=\"WebGPT\"><img src=\"https://webgpt.cz/_next/static/media/webgpt-black.8d958d25.png#gh-light-mode-only\" alt=\"WebGPT\" height=\"60\"/></a>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n<a href=\"https://github.com/webgptorg/promptbook\" title=\"Promptbook\"><img src=\"https://raw.githubusercontent.com/webgptorg/promptbook/main/other/design/logo.png#gh-light-mode-only\" alt=\"Promptbook\" height=\"60\"/></a>\n\n\n[Become a partner](https://www.pavolhejny.com/contact/)\n\n<!--/Partners-->\n","publish_time":1626785563872,"maintainers":[{"name":"hejny","email":"pavol@hejny.org"}],"_cnpm_publish_time":1626785563872,"dist-tags":{"latest":"1.11.164"}}