Skip to content

FormulaFunction

Unofficial

A Bases formula function, such as now() or the contains() of a string.

A plugin adds its own with obsidian#Plugin.registerGlobalFunc or obsidian#Plugin.registerInstanceFunc. The built-in functions derive from a base class that is not exported, so a plugin implements every member, including FormulaFunction.applyWithContext, which is the one the evaluator calls.

Import:

import type { FormulaFunction } from '@obsidian-typings/obsidian-catalyst-latest';

Signature:

export interface FormulaFunction

Properties

PropertyTypeDescription
ctxFormulaContext | nullThe context of the evaluation in progress, set by FormulaFunction.applyWithContext and null outside it.
docString?(() => string) | stringThe description shown in the formula autocomplete, or a function returning it.
namestringThe name of the function. It is matched case-insensitively, and registering a name again replaces the previous function.
paramsFormulaFunctionParam[]The parameters of the function. For an instance function, the first parameter is the value the function is called on.

Methods

MethodReturnsDescription
apply(args?)ValueEvaluates the function.
applyWithContext(ctx, args?)ValueEvaluates the function in a formula context: sets FormulaFunction.ctx, calls FormulaFunction.apply, then resets it.
serialize(args?)stringSerializes a call to the function back to formula source.

Links to this page: