Add more template tag plugins (#3)

This commit is contained in:
Gregory Schier
2024-10-02 06:56:07 -07:00
committed by GitHub
parent 9df586cb59
commit 54689d19ef
29 changed files with 412 additions and 7160 deletions

View File

@@ -0,0 +1,9 @@
{
"name": "@yaakapp/template-function-hash",
"private": true,
"version": "0.0.1",
"scripts": {
"build": "yaakcli build ./src/index.ts",
"dev": "yaakcli dev ./src/index.js"
}
}

View File

@@ -0,0 +1,24 @@
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
import { createHash } from 'node:crypto';
const algorithms = ['md5', 'sha1', 'sha256', 'sha512'];
export const plugin: PluginDefinition = {
templateFunctions: algorithms.map(algorithm => ({
name: `hash.${algorithm}`,
args: [
{
name: 'input',
label: 'Input',
placeholder: 'input text',
type: 'text',
},
],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
if (!args.values.input) return '';
return createHash(algorithm)
.update(args.values.input, 'utf-8')
.digest('hex');
},
})),
};