diff --git a/lib/builtin_query_functions.ts b/lib/builtin_query_functions.ts index fa462142..b82bba90 100644 --- a/lib/builtin_query_functions.ts +++ b/lib/builtin_query_functions.ts @@ -2,8 +2,15 @@ import type { FunctionMap } from "../plug-api/types.ts"; import { niceDate, niceTime } from "./dates.ts"; export const builtinFunctions: FunctionMap = { - today() { - return niceDate(new Date()); + // String functions + contains(str: unknown, substr: unknown) { + if (typeof str !== "string") { + throw new Error("contains(): str is not a string"); + } + if (typeof substr !== "string") { + throw new Error("contains(): substr is not a string"); + } + return str.includes(substr); }, replace( str: unknown, @@ -72,6 +79,9 @@ export const builtinFunctions: FunctionMap = { escapeDirective: (directiveText: unknown) => { return `{{${directiveText}}}`; }, + today() { + return niceDate(new Date()); + }, time: () => niceTime(new Date()), tomorrow: () => { const tomorrow = new Date(); diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index bf268b2f..1e227f8a 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -6,7 +6,7 @@ release. ## Edge _These features are not yet properly released, you need to use [the edge builds](https://community.silverbullet.md/t/living-on-the-edge-builds/27) to try them._ -* Nothing yet since 0.7.4, be patient! +* Added [[Functions#contains(str, substr)]] function ## 0.7.5 * [[Plugs/Share]] using the {[Share: Page Or Selection]} command (bound to Ctrl-s/Cmd-s by default): allowing you to quickly share the current page (or selection) to the clipboard as: diff --git a/website/Functions.md b/website/Functions.md index c21c2d10..7b0ef7fa 100644 --- a/website/Functions.md +++ b/website/Functions.md @@ -46,6 +46,9 @@ Replace text in a string. `match` can either be a literal string or a regular ex This function supports an infinite number of replacements, so you can keep adding more, e.g. `replace(str, match1, replacement1, match2, replacement2, match3, replacement3)` +## contains(str, substr) +Returns whether `str` contains `substr` as a substring. + ## json(obj) Convert the argument to a JSON string (for debugging purposes).