mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 07:23:51 +01:00
Add more template tag plugins (#3)
This commit is contained in:
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