Functions are used in Bases to manipulate data from Properties in filters and formulas. See the bases syntax reference to learn more about how you can use functions.
Aside from Global functions, most functions depend on the type of value you want to modify:
Global
Global functions are used without a type.
date()
date(date: string): date
date(string): dateparses the provided string and returns a date object.- The
datestring should be in the formatYYYY-MM-DD HH:mm:ss.
file()
file(path: string | file | url): file
- Returns a file object for the given file or path.
- Example:
file(link("[[filename]]"))orfile("path to file").
if()
if(condition: any, trueResult: any, falseResult?: any): any
conditionis the condition to be evaluated.trueResultis the output if condition is true.falseResultis the optional output if the condition is false. If it is not given, then it is assumed to benull.- Returns the
trueResultifconditionis true, or is a truthy value, orfalseResultotherwise. - Example:
if(isModified, "Modified", "Unmodified")
image()
image(path: string | file | url): image
- Returns an image object which will render the image in the view.
- Example:
image(image-property)orimage("https://obsidian.md/images/obsidian-logo-gradient.svg")
icon()
icon(name: string): icon
- Returns a value that will render as an icon in a view. The icon name must match a supported Lucide icon.
- Example:
icon("arrow-right").
max()
max(value1: number, value2: number…): number
- Returns the largest of all the provided numbers.
min()
min(value1: number, value2: number…): number
- Returns the smallest of all the provided numbers.
link()
link(path: string | file, display?: value): Link
- Parses a string
pathand returns a Link object that renders as a link to the path given. - Optionally provide the
displayparameter to change what text the link says.
list()
list(element: any): List
- If the provided element is a list, return it unmodified.
- Otherwise, wraps the provided
elementin a list, creating a list with a single element. - This function can be helpful when a property contains a mixture of strings or lists across the vault.
- Example:
list("value")returns["value"].
now()
now(): date
now()returns a date object representing the current moment.
number()
number(input: any): number
- Attempt to return the provided value as a number.
- Date objects will be returned as milliseconds since the unix epoch.
- Booleans will return a 1 or 0.
- Strings will be parsed into a number and return an error if the result is invalid.
- Example,
number("3.4")returns3.4.
duration()
duration(value: string): duration
- Parse a string as a duration. See the date arithmetic section for the
valuestring format. - Durations do not need to be explicitly parsed when performing date arithmetic (for example,
now() + '1d'), but the do when performing arithmetic on durations (for example,now() + (duration('1d') * 2)). - When performing arithmetic on durations with scalars, the duration must be on the left. For example
duration('5h') * 2, instead of2 * duration('5h').
today()
today(): date
today()returns a date object representing the current date. The time portion is set to zero.
date()
date(input: string | date): date
- Returns a date object representing the parsed input timestamp or date object.
Any
Functions you can use with any value. This includes strings (e.g. "hello"), numbers (e.g. 42), lists (e.g. [1,2,3]), objects, and more.
toString()
any.toString(): string
- Returns the string representation of any value.
- Example:
123.toString()returns"123".
isTruthy()
any.isTruthy(): boolean
- Return the value coerced into a boolean.
- Example:
1.isTruthy()returnstrue.
Date
Functions you can use with a date and time such as date("2025-05-27"). Date comparisons can be done using date arithmetic.
Fields
The following fields are available for dates:
| Field | Type | Description |
|---|---|---|
date.year | number | The year of the date |
date.month | number | The month of the date (1–12) |
date.day | number | The day of the month |
date.hour | number | The hour (0–23) |
date.minute | number | The minute (0–59) |
date.second | number | The second (0–59) |
date.millisecond | number | The millisecond (0–999) |
date()
date.date(): date
- Returns a date object with the time removed.
- Example:
now().date().format("YYYY-MM-DD HH:mm:ss"returns a string such as “2025-12-31 00:00:00”
format()
date.format(format: string): string
formatis the format string (e.g.,"YYYY-MM-DD").- Returns the date formatted as specified by a Moment.js format string.
- Example:
date.format("YYYY-MM-DD")returns"2025-05-27".
time()
date.time(): string
- Returns the time.
- Example:
now().time()returns a string such as “23:59:59”
relative()
date.relative(): string
- Returns a readable comparison of the date to the current datetime.
- Example:
file.mtime.relative()returns a value such as3 days ago.
isEmpty()
date.isEmpty(): boolean
- Returns false.
String
Functions you can use with a sequence of characters such as "hello".
Fields
| Field | Type | Description |
|---|---|---|
string.length | number | The number of characters in the string |
contains()
string.contains(value: string): boolean
valueis the substring to search for.- Returns true if the string contains
value. - Example:
"hello".contains("ell")returnstrue.
containsAll()
string.containsAll(…values: string): boolean
valuesare one or more substrings to search for.- Returns true if the string contains all of the
values. - Example:
"hello".containsAll("h", "e")returnstrue.
containsAny()
string.containsAny(…values: string): boolean
valuesare one or more substrings to search for.- Returns true if the string contains at least one of the
values. - Example:
"hello".containsAny("x", "y", "e")returnstrue.
endsWith()
string.endsWith(query: string): boolean
queryis the string to check at the end.- Returns true if this string ends with
query. - Example:
"hello".endsWith("lo")returnstrue.
isEmpty()
string.isEmpty(): boolean
- Returns true if the string has no characters, or is not present.
- Example:
"Hello world".isEmpty()returnsfalse. - Example:
"".isEmpty()returnstrue.
replace()
string.replace(pattern: string | Regexp, replacement: string): string
patternis the value to search for in the target string.replacementis the value to replace found patterns with.- If
patternis a string, all occurrences of the pattern will be replaced. - If
patternis a Regexp, thegflag determines if only the first or if all occurrences are replaced. - Example:
"a,b,c,d".replace(/,/, "-")returns"a-b,c,d", where as"a,b,c,d".replace(/,/g, "-")returns"a-b-c-d".
lower()
string.lower(): string
- Returns the string converted to lower case.
reverse()
string.reverse(): string
- Reverses the string.
- Example:
"hello".reverse()returns"olleh".
slice()
string.slice(start: number, end?: number): string
startis the inclusive start index.endis the optional exclusive end index.- Returns a substring from
start(inclusive) toend(exclusive). - Example:
"hello".slice(1, 4)returns"ell". - If
endis omitted, slices to the end of the string.
split()
string.split(separator: string | Regexp, n?: number): list
separatoris the delimiter for splitting the string.nis an optional number. If provided, the result will have the firstnelements.- Returns an list of substrings.
- Example:
"a,b,c,d".split(",", 3)or"a,b,c,d".split(/,/, 3)returns["a", "b", "c"].
startsWith()
string.startsWith(query: string): boolean
queryis the string to check at the beginning.- Returns true if this string starts with
query. - Example:
"hello".startsWith("he")returnstrue.
title()
string.title(): string
- Converts the string to title case (first letter of each word capitalized).
- Example:
"hello world".title()returns"Hello World".
trim()
string.trim(): string
- Removes whitespace from both ends of the string.
- Example:
" hi ".trim()returns"hi".
Number
Functions you can use with numeric values such as 42, 3.14.
abs()
number.abs(): number
- Returns the absolute value of the number.
- Example:
(-5).abs()returns5.
ceil()
number.ceil(): number
- Rounds the number up to the nearest integer.
- Example:
(2.1).ceil()returns3.
floor()
number.floor(): number
- Rounds the number down to the nearest integer.
- Example:
(2.9).floor()returns2.
round()
number.round(digits: number): number
- Rounds the number to the nearest integer.
- Optionally, provided a
digitsparameter to round to that number of decimal digits. - Example:
(2.5).round()returns3, and(2.3333).round(2)returns2.33.
toFixed()
number.toFixed(precision: number): string
precisionis the number of decimal places.- Returns a string with the number in fixed-point notation.
- Example:
(3.14159).toFixed(2)returns"3.14".
isEmpty()
number.isEmpty(): boolean
- Returns true if the number is not present.
- Example:
5.isEmpty()returnsfalse.
List
Functions you can use with an ordered list of elements such as [1, 2, 3].
Fields
| Field | Type | Description |
|---|---|---|
list.length | number | The number of elements in the list |
contains()
list.contains(value: any): boolean
valueis the element to search for.- Returns true if the list contains
value. - Example:
[1,2,3].contains(2)returnstrue.
containsAll()
list.containsAll(…values: any): boolean
valuesare one or more elements to search for.- Returns true if the list contains all of the
values. - Example:
[1,2,3].containsAll(2,3)returnstrue.
containsAny()
list.containsAny(…values: any): boolean
valuesare one or more elements to search for.- Returns true if the list contains at least one of the
values. - Example:
[1,2,3].containsAny(3,4)returnstrue.
isEmpty()
list.isEmpty(): boolean
- Returns true if the list has no elements.
- Example:
[1,2,3].isEmpty()returnsfalse.
join()
list.join(separator: string): string
separatoris the string to insert between elements.- Joins all list elements into a single string.
- Example:
[1,2,3].join(",")returns"1,2,3".
reverse()
list.reverse(): list
- Reverses the list in place.
- Example:
[1,2,3].reverse()returns[3,2,1].
sort()
list.sort(): list
- Sorts list elements from smallest to largest.
- Example:
[3, 1, 2].sort()returns[1, 2, 3]. - Example:
["c", "a", "b"].sort()returns["a", "b", "c"].
flat()
list.flat(): list
- Flattens nested list into a single list.
- Example:
[1,[2,3]].flat()returns[1,2,3].
unique()
list.unique(): list
- Removes duplicate elements.
- Example:
[1,2,2,3].unique()returns[1,2,3].
slice()
list.slice(start: number, end?: number): list
startis the inclusive start index.endis the optional exclusive end index.- Returns a shallow copy of a portion of the list from
start(inclusive) toend(exclusive). - Example:
[1,2,3,4].slice(1,3)returns[2,3]. - If
endis omitted, slices to the end of the list.
map()
list.map(value: Any): list
- Transform each element of this list by calling a conversion function, which uses the variables
indexandvalue, and returns the new value to be placed in the list. valueis the value of an item in the list.indexis the index of the current value.- Example:
[1,2,3,4].map(value + 1)returns[2,3,4,5].
filter()
list.filter(value: Boolean): list
- Filter the elements of this list by calling a filter function, which uses the variables
indexandvalue, and returns a boolean value for whether the element should be kept. valueis the value of an item in the list.indexis the index of the current value.- Example:
[1,2,3,4].filter(value > 2)returns[3,4].
Link
Functions you can use on a link. Links can be created from a file (file.asLink()) or a path (link("path")).
linksTo()
link.linksTo(file): boolean
- Returns whether the file represented by the
linkhas a link tofile.
asFile()
link.asFile(): file
- Returns a file object if the link refers to a valid local file.
- Example:
link("[[filename]]").asFile()
File
Functions you can use with file in the vault.
asLink()
file.asLink(display?: string): Link
displayoptional display text for the link.- Returns a Link object that renders as a functioning link.
- Example:
file.asLink()
hasLink()
file.hasLink(otherFile: file | string): boolean
otherFileis another file object or string path to check.- Returns true if
filelinks tootherFile. - Example:
file.hasLink(otherFile)returnstrueif there’s a link fromfiletootherFile.
hasProperty()
file.hasProperty(name: string): boolean
- Returns true if the note has the given file property.
hasTag()
file.hasTag(…values: string): boolean
valuesare one or more tag names.- Returns true if the file has any of the tags in
values. - Example:
file.hasTag("tag1", "tag2")returnstrueif the file has either tag.
inFolder()
file.inFolder(folder: string): boolean
folderis the folder name to check.- Returns true if the file is in the specified folder.
- Example:
file.inFolder("notes")returnstrue.
Object
Functions you can use with a collection of key-value pairs such as {"a": 1, "b": 2}.
isEmpty()
object.isEmpty(): boolean
- Returns true if the object has no own properties.
- Example:
{}.isEmpty()returnstrue.
keys()
object.keys(): list
- Returns a list containing the keys of the object.
values()
object.values(): list
- Returns a list containing the values of the object.
Regular expression
Functions you can use with a regular expression pattern. Example: /abc/.
matches()
regexp.matches(value: string): boolean
valueis the string to test.- Returns true if the regular expression matches
value. - Example:
/abc/.matches("abcde")returnstrue.