package
Return a value or an evaluated function (with arguments).
npm install evaluate-valueGitHub-flavored package documentation.
Across all versions, last 30 days.
917,914 in 30 days
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
5.0 kB
Includes dependencies.
Return a value or an evaluated function (with arguments).
npm install evaluate-valueimport evaluateValue from 'evaluate-value';
evaluateValue(true); //-> true
evaluateValue(() => true); //-> true
evaluateValue((arg1, arg2) => arg1 + arg2, 2, 2); //-> 4An EvaluateValueArgs type is exposed for convenient wrapping:
import { type EvaluateValueArgs } from 'evaluate-value';
interface Options {
prop: (arg: string) => boolean;
}
const DEFAULT_OPTIONS: Options = {
prop: arg => arg === 'something',
};
/**
* Fallback to the default value for a specific option if there's no custom value.
*/
const defaultFallback = <K extends keyof typeof DEFAULT_OPTIONS>(
options: Options | undefined,
name: