Move everything into subdir for repo merge

This commit is contained in:
Gregory Schier
2025-05-29 07:16:39 -07:00
parent 385a369699
commit 723e8d2874
90 changed files with 919 additions and 0 deletions

View File

@@ -1,13 +0,0 @@
{
"name": "@yaakapp/template-function-xml",
"private": true,
"version": "0.0.1",
"scripts": {
"build": "yaakcli build ./src/index.ts",
"dev": "yaakcli dev ./src/index.js"
},
"dependencies": {
"@xmldom/xmldom": "^0.8.10",
"xpath": "^0.0.34"
}
}

View File

@@ -1,29 +0,0 @@
import { DOMParser } from '@xmldom/xmldom';
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
import xpath from 'xpath';
export const plugin: PluginDefinition = {
templateFunctions: [{
name: 'xml.xpath',
description: 'Filter XML-formatted text using XPath syntax',
args: [
{ type: 'text', name: 'input', label: 'Input', multiLine: true, placeholder: '<foo></foo>' },
{ type: 'text', name: 'query', label: 'Query', placeholder: '//foo' },
],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
try {
const doc = new DOMParser().parseFromString(String(args.values.input), 'text/xml');
let result = xpath.select(String(args.values.query), doc, false);
if (Array.isArray(result)) {
return String(result.map(c => String(c.firstChild))[0] ?? '');
} else if (result instanceof Node) {
return String(result.firstChild);
} else {
return String(result);
}
} catch (e) {
return null;
}
},
}],
};