Run oxfmt across repo, add format script and docs

Add .oxfmtignore to skip generated bindings and wasm-pack output.
Add npm format script, update DEVELOPMENT.md for Vite+ toolchain,
and format all non-generated files with oxfmt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-03-13 10:15:49 -07:00
parent 45262edfbd
commit b4a1c418bb
664 changed files with 13638 additions and 13492 deletions

View File

@@ -1,9 +1,9 @@
{
"name": "@yaak/template-function-json",
"displayName": "JSON Template Functions",
"description": "Template functions for working with JSON data",
"private": true,
"version": "0.1.0",
"private": true,
"description": "Template functions for working with JSON data",
"main": "build/index.js",
"types": "src/index.ts",
"scripts": {

View File

@@ -1,45 +1,45 @@
import type { XPathResult } from '@yaak/template-function-xml';
import type { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
import { JSONPath } from 'jsonpath-plus';
import type { XPathResult } from "@yaak/template-function-xml";
import type { CallTemplateFunctionArgs, Context, PluginDefinition } from "@yaakapp/api";
import { JSONPath } from "jsonpath-plus";
const RETURN_FIRST = 'first';
const RETURN_ALL = 'all';
const RETURN_JOIN = 'join';
const RETURN_FIRST = "first";
const RETURN_ALL = "all";
const RETURN_JOIN = "join";
export const plugin: PluginDefinition = {
templateFunctions: [
{
name: 'json.jsonpath',
description: 'Filter JSON-formatted text using JSONPath syntax',
previewArgs: ['query'],
name: "json.jsonpath",
description: "Filter JSON-formatted text using JSONPath syntax",
previewArgs: ["query"],
args: [
{
type: 'editor',
name: 'input',
label: 'Input',
language: 'json',
type: "editor",
name: "input",
label: "Input",
language: "json",
placeholder: '{ "foo": "bar" }',
},
{
type: 'h_stack',
type: "h_stack",
inputs: [
{
type: 'select',
name: 'result',
label: 'Return Format',
type: "select",
name: "result",
label: "Return Format",
defaultValue: RETURN_FIRST,
options: [
{ label: 'First result', value: RETURN_FIRST },
{ label: 'All results', value: RETURN_ALL },
{ label: 'Join with separator', value: RETURN_JOIN },
{ label: "First result", value: RETURN_FIRST },
{ label: "All results", value: RETURN_ALL },
{ label: "Join with separator", value: RETURN_JOIN },
],
},
{
name: 'join',
type: 'text',
label: 'Separator',
name: "join",
type: "text",
label: "Separator",
optional: true,
defaultValue: ', ',
defaultValue: ", ",
dynamic(_ctx, args) {
return { hidden: args.values.result !== RETURN_JOIN };
},
@@ -47,15 +47,15 @@ export const plugin: PluginDefinition = {
],
},
{
type: 'checkbox',
name: 'formatted',
label: 'Pretty Print',
description: 'Format the output as JSON',
type: "checkbox",
name: "formatted",
label: "Pretty Print",
description: "Format the output as JSON",
dynamic(_ctx, args) {
return { hidden: args.values.result === RETURN_JOIN };
},
},
{ type: 'text', name: 'query', label: 'Query', placeholder: '$..foo' },
{ type: "text", name: "query", label: "Query", placeholder: "$..foo" },
],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
try {
@@ -72,36 +72,36 @@ export const plugin: PluginDefinition = {
},
},
{
name: 'json.escape',
description: 'Escape a JSON string, useful when using the output in JSON values',
name: "json.escape",
description: "Escape a JSON string, useful when using the output in JSON values",
args: [
{
type: 'text',
name: 'input',
label: 'Input',
type: "text",
name: "input",
label: "Input",
multiLine: true,
placeholder: 'Hello "World"',
},
],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
const input = String(args.values.input ?? '');
return input.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
const input = String(args.values.input ?? "");
return input.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
},
},
{
name: 'json.minify',
description: 'Remove unnecessary whitespace from a valid JSON string.',
name: "json.minify",
description: "Remove unnecessary whitespace from a valid JSON string.",
args: [
{
type: 'editor',
language: 'json',
name: 'input',
label: 'Input',
type: "editor",
language: "json",
name: "input",
label: "Input",
placeholder: '{ "foo": "bar" }',
},
],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
const input = String(args.values.input ?? '');
const input = String(args.values.input ?? "");
try {
return JSON.stringify(JSON.parse(input));
} catch {
@@ -112,7 +112,7 @@ export const plugin: PluginDefinition = {
],
};
export type JSONPathResult = 'first' | 'join' | 'all';
export type JSONPathResult = "first" | "join" | "all";
export function filterJSONPath(
body: string,
@@ -125,15 +125,15 @@ export function filterJSONPath(
let items = JSONPath({ path, json: parsed });
if (items == null) {
return '';
return "";
}
if (!Array.isArray(items)) {
// Already good
} else if (result === 'first') {
items = items[0] ?? '';
} else if (result === 'join') {
items = items.map((i) => objToStr(i, false)).join(join ?? '');
} else if (result === "first") {
items = items[0] ?? "";
} else if (result === "join") {
items = items.map((i) => objToStr(i, false)).join(join ?? "");
}
return objToStr(items, formatted);
@@ -141,8 +141,8 @@ export function filterJSONPath(
function objToStr(o: unknown, formatted = false): string {
if (
Object.prototype.toString.call(o) === '[object Array]' ||
Object.prototype.toString.call(o) === '[object Object]'
Object.prototype.toString.call(o) === "[object Array]" ||
Object.prototype.toString.call(o) === "[object Object]"
) {
return formatted ? JSON.stringify(o, null, 2) : JSON.stringify(o);
}