mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
Add more template tag plugins (#3)
This commit is contained in:
9
plugins/template-function-hash/package.json
Executable file
9
plugins/template-function-hash/package.json
Executable 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"
|
||||
}
|
||||
}
|
||||
24
plugins/template-function-hash/src/index.ts
Executable file
24
plugins/template-function-hash/src/index.ts
Executable 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');
|
||||
},
|
||||
})),
|
||||
};
|
||||
Reference in New Issue
Block a user