API Overview
UntilJS provides a simple, Promise-based API for waiting on value changes.
Installation
bash
pnpm add untiljsbash
npm install untiljsbash
yarn add untiljsQuick Reference
Functions
| Function | Description |
|---|---|
| until() | Main function to create an Until instance |
| createStore() | Create a reactive store for use with until |
Types
| Type | Description |
|---|---|
| WatchSource | Types of values that can be watched |
| Subscribable | Interface for subscribable objects |
| UntilToMatchOptions | Options for wait methods |
Methods
| Method | Description |
|---|---|
| toBe(value, options?) | Wait until value equals target |
| toMatch(condition, options?) | Wait until condition returns true |
| toBeTruthy(options?) | Wait until value is truthy |
| toBeNull(options?) | Wait until value is null |
| toBeUndefined(options?) | Wait until value is undefined |
| toBeNaN(options?) | Wait until value is NaN |
| changed(options?) | Wait until value changes |
| changedTimes(n, options?) | Wait until value changes n times |
| toContains(value, options?) | Wait until array contains value |
| not.* | Inverse of any method above |
Basic Usage
typescript
import until from 'untiljs'
// Basic usage
let value = 0
setTimeout(() => { value = 5 }, 1000)
await until(() => value).toBe(5)Return Value
All methods return a Promise that resolves to:
- The current value when the condition is met
- The current value on timeout (if
throwOnTimeoutis false) - Rejects on timeout (if
throwOnTimeoutis true)
typescript
const result = await until(() => value).toBe(5)
console.log(result) // 5