-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.ts
33 lines (31 loc) · 1.23 KB
/
delete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Placeholder, PlaceholderCategory, PlaceholderType } from "../../types";
import { deletePersistentVariable } from "./utils";
/**
* Directive to delete a persistent variable. If the variable does not exist, nothing will happen. The placeholder will always be replaced with an empty string.
*
* Syntax: `{{delete x}}`, where `x` is the name of the variable to delete.
*/
const DeletePersistentVariablePlaceholder: Placeholder = {
name: "delete",
regex: /{{delete [a-zA-Z0-9_]+}}/g,
apply: async (str: string) => {
const matches = str.match(/{{delete ([a-zA-Z0-9_]+)}}/);
if (matches) {
const key = matches[1];
await deletePersistentVariable(key);
}
return { result: "" };
},
constant: false,
fn: async (id: string) =>
(await DeletePersistentVariablePlaceholder.apply(`{{delete ${id}}}`))
.result,
example: "{{delete storedText}}",
description:
"Deletes a persistent variable. If the variable does not exist, nothing will happen. Replaced with an empty string.",
hintRepresentation: "{{delete x}",
fullRepresentation: "Delete Persistent Variable",
type: PlaceholderType.StaticDirective,
categories: [PlaceholderCategory.Memory],
};
export default DeletePersistentVariablePlaceholder;