Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 21b9e5a

Browse files
committed
Url encode/decode functions
1 parent 6d6012f commit 21b9e5a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • plugins/template-function-encode/src

plugins/template-function-encode/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,25 @@ export const plugin: PluginDefinition = {
1818
return Buffer.from(args.values.value ?? '', 'base64').toString('utf-8');
1919
},
2020
},
21+
{
22+
name: 'url.encode',
23+
description: 'Encode a value for use in a URL (percent-encoding)',
24+
args: [{ label: 'Plain Text', type: 'text', name: 'value', multiLine: true }],
25+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
26+
return encodeURIComponent(args.values.value ?? '');
27+
},
28+
},
29+
{
30+
name: 'url.decode',
31+
description: 'Decode a percent-encoded URL value',
32+
args: [{ label: 'Encoded Value', type: 'text', name: 'value', multiLine: true }],
33+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
34+
try {
35+
return decodeURIComponent(args.values.value ?? '');
36+
} catch {
37+
return '';
38+
}
39+
},
40+
},
2141
],
2242
};

0 commit comments

Comments
 (0)