Added `contains` function
parent
06a827bf7e
commit
42dd7f3678
|
@ -2,8 +2,15 @@ import type { FunctionMap } from "../plug-api/types.ts";
|
||||||
import { niceDate, niceTime } from "./dates.ts";
|
import { niceDate, niceTime } from "./dates.ts";
|
||||||
|
|
||||||
export const builtinFunctions: FunctionMap = {
|
export const builtinFunctions: FunctionMap = {
|
||||||
today() {
|
// String functions
|
||||||
return niceDate(new Date());
|
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(
|
replace(
|
||||||
str: unknown,
|
str: unknown,
|
||||||
|
@ -72,6 +79,9 @@ export const builtinFunctions: FunctionMap = {
|
||||||
escapeDirective: (directiveText: unknown) => {
|
escapeDirective: (directiveText: unknown) => {
|
||||||
return `{{${directiveText}}}`;
|
return `{{${directiveText}}}`;
|
||||||
},
|
},
|
||||||
|
today() {
|
||||||
|
return niceDate(new Date());
|
||||||
|
},
|
||||||
time: () => niceTime(new Date()),
|
time: () => niceTime(new Date()),
|
||||||
tomorrow: () => {
|
tomorrow: () => {
|
||||||
const tomorrow = new Date();
|
const tomorrow = new Date();
|
||||||
|
|
|
@ -6,7 +6,7 @@ release.
|
||||||
## Edge
|
## 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._
|
_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
|
## 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:
|
* [[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:
|
||||||
|
|
|
@ -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)`
|
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)
|
## json(obj)
|
||||||
Convert the argument to a JSON string (for debugging purposes).
|
Convert the argument to a JSON string (for debugging purposes).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue