UNPKG

rvx

Version:

A signal based rendering library

116 lines (104 loc) 3.82 kB
/*! MIT License Copyright (c) 2025 Max J. Polster Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import { Signal, Expression } from './rvx.js'; /** * Create a derived signal for debouncing user input updates. * * + If the source signal is updated, scheduled updates from the input are aborted. * + If the input signal is updated, a source update is scheduled with the specified delay and any previously scheduled update is aborted. * + Updates are processed until the current lifecycle is disposed. * * @param source The source signal. * @param delay The delay in milliseconds. * @returns The derived input signal. * * @example * ```tsx * import { debounce } from "rvx/convert"; * * <TextInput value={someSignal.pipe(debounce, 300)} /> * ``` */ declare function debounce<T>(source: Signal<T>, delay: number): Signal<T>; /**w * Map expression values to strings except `null` or `undefined`. * * See {@link map}. * * @example * ```tsx * import { optionalString } from "rvx"; * * <div some-value={optionalString(false)} />; // <div some-value="false" /> * <div some-value={optionalString(null)} />; // <div /> * <div some-value={optionalString(undefined)} />; // <div /> * ``` */ declare function optionalString<T>(input: Expression<T>): Expression<string | Exclude<T, Exclude<T, null | undefined>>>; /** * Map an expression to join array elements using the specified separator. * * See {@link map}. * * @param separator The separator to use. Default is a space. * * @example * ```tsx * import { separated } from "rvx"; * * <div aria-owns={separated(["a", "b", ...])} /> * ``` */ declare function separated(input: Expression<unknown[]>, separator?: string): Expression<string>; declare function separated<T>(input: Expression<T>, separator?: string): Expression<T extends any[] ? (Exclude<T, any[]> | string) : T>; /** * Map expression values to strings. * * See {@link map}. * * @example * ```tsx * import { string } from "rvx/convert"; * * <div some-value={string(true)} />; // <div some-value="true" /> * <div some-value={string(false)} />; // <div some-value="false" /> * <div some-value={string(null)} />; // <div some-value="null" /> * ``` */ declare function string(input: Expression<unknown>): Expression<string>; /** * Create a derived signal for trimming user input. * * + The source signal contains the trimmed value. * + The input signal contains the un-trimmed value. * + Updates are processed until the current lifecycle is disposed. * * @param source The source signal. * @returns The derived input signal. * * @example * ```tsx * import { trim } from "rvx/convert"; * * <TextInput value={someSignal.pipe(trim)} /> * ``` */ declare function trim(source: Signal<string>): Signal<string>; export { debounce, optionalString, separated, string, trim };