npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kiyotd/wait-define

v1.0.0

Published

An asynchronous function that waits until a property of an object is defined.

Downloads

9

Readme

wait-define

オブジェクトのプロパティが定義されるまで待つ非同期関数です。

An asynchronous function that waits until a property of an object is defined.

Installation

npm i @kiyotd/wait-define

Examples

window.hello が定義されるまで待つ場合

If you wait until window.hello is defined

main.ts

import { waitDefine } from '@kiyotd/wait-define';

document.addEventListener('DOMContentLoaded', () => {

  console.log('waiting for window.hello ...');

  // window.hello が定義されるまで待つ, 監視間隔は 500ms, タイムアウトは 2000ms
  waitDefine('hello', window, 500, 2000)
    .then(() => {
      console.log('window.hello is defined!');
    })
    .catch((error) => {
      console.error('An error occurred:', error);
    });

  // window.hello を定義する
  setTimeout(() => {
    // @ts-ignore
    window.hello = 'world';
  }, 2500);
});

上記の例では、2500ms 後に window.hello が定義されるので、タイムアウトによりエラーが発生します。

In the above example, window.hello is defined after 2500ms, so the timeout causes an error.

Arguments

| Name | Type | Description | |----------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | propertyName | string | 定義を待つプロパティ名The property name to wait for definition | | obj | any | プロパティの定義を待つオブジェクトObject waiting for property definition | | interval_ms | number | 定義を確認する間隔(ミリ秒)。デフォルトは100ミリ秒。Interval (in milliseconds) to check definitions. Default is 100 milliseconds. | | timeout_ms | number | 待機を終了し、エラーをスローするまでの時間(ミリ秒)。指定しない場合、定義が確認されるまで無限に待ちます。Time (in milliseconds) to exit wait and throw an error. If not specified, waits indefinitely until the definition is confirmed. |

Returns

プロパティが定義されたら解決されるPromiseを返します。

Returns a Promise that resolves when the property is defined.

License

MIT