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,196 +1,196 @@
import type { Context } from '@yaakapp/api';
import { describe, expect, it } from 'vite-plus/test';
import { plugin } from '../src';
import type { Context } from "@yaakapp/api";
import { describe, expect, it } from "vite-plus/test";
import { plugin } from "../src";
describe('regex.match', () => {
const matchFunction = plugin.templateFunctions?.find((f) => f.name === 'regex.match');
describe("regex.match", () => {
const matchFunction = plugin.templateFunctions?.find((f) => f.name === "regex.match");
it('should exist', () => {
it("should exist", () => {
expect(matchFunction).toBeDefined();
});
it('should extract first capture group', async () => {
it("should extract first capture group", async () => {
const result = await matchFunction?.onRender({} as Context, {
values: {
regex: 'Hello (\\w+)',
input: 'Hello World',
regex: "Hello (\\w+)",
input: "Hello World",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('World');
expect(result).toBe("World");
});
it('should extract named capture group', async () => {
it("should extract named capture group", async () => {
const result = await matchFunction?.onRender({} as Context, {
values: {
regex: 'Hello (?<name>\\w+)',
input: 'Hello World',
regex: "Hello (?<name>\\w+)",
input: "Hello World",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('World');
expect(result).toBe("World");
});
it('should return full match when no capture groups', async () => {
it("should return full match when no capture groups", async () => {
const result = await matchFunction?.onRender({} as Context, {
values: {
regex: 'Hello \\w+',
input: 'Hello World',
regex: "Hello \\w+",
input: "Hello World",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('Hello World');
expect(result).toBe("Hello World");
});
it('should return empty string when no match', async () => {
it("should return empty string when no match", async () => {
const result = await matchFunction?.onRender({} as Context, {
values: {
regex: 'Goodbye',
input: 'Hello World',
regex: "Goodbye",
input: "Hello World",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('');
expect(result).toBe("");
});
it('should return empty string when regex is empty', async () => {
it("should return empty string when regex is empty", async () => {
const result = await matchFunction?.onRender({} as Context, {
values: {
regex: '',
input: 'Hello World',
regex: "",
input: "Hello World",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('');
expect(result).toBe("");
});
it('should return empty string when input is empty', async () => {
it("should return empty string when input is empty", async () => {
const result = await matchFunction?.onRender({} as Context, {
values: {
regex: 'Hello',
input: '',
regex: "Hello",
input: "",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('');
expect(result).toBe("");
});
});
describe('regex.replace', () => {
const replaceFunction = plugin.templateFunctions?.find((f) => f.name === 'regex.replace');
describe("regex.replace", () => {
const replaceFunction = plugin.templateFunctions?.find((f) => f.name === "regex.replace");
it('should exist', () => {
it("should exist", () => {
expect(replaceFunction).toBeDefined();
});
it('should replace one occurrence by default', async () => {
it("should replace one occurrence by default", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: 'o',
input: 'Hello World',
replacement: 'a',
regex: "o",
input: "Hello World",
replacement: "a",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('Hella World');
expect(result).toBe("Hella World");
});
it('should replace with capture groups', async () => {
it("should replace with capture groups", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: '(\\w+) (\\w+)',
input: 'Hello World',
replacement: '$2 $1',
regex: "(\\w+) (\\w+)",
input: "Hello World",
replacement: "$2 $1",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('World Hello');
expect(result).toBe("World Hello");
});
it('should replace with full match reference', async () => {
it("should replace with full match reference", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: 'World',
input: 'Hello World',
replacement: '[$&]',
regex: "World",
input: "Hello World",
replacement: "[$&]",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('Hello [World]');
expect(result).toBe("Hello [World]");
});
it('should respect flags parameter', async () => {
it("should respect flags parameter", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: 'hello',
input: 'Hello World',
replacement: 'Hi',
flags: 'i',
regex: "hello",
input: "Hello World",
replacement: "Hi",
flags: "i",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('Hi World');
expect(result).toBe("Hi World");
});
it('should handle empty replacement', async () => {
it("should handle empty replacement", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: 'World',
input: 'Hello World',
replacement: '',
regex: "World",
input: "Hello World",
replacement: "",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('Hello ');
expect(result).toBe("Hello ");
});
it('should return original input when no match', async () => {
it("should return original input when no match", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: 'Goodbye',
input: 'Hello World',
replacement: 'Hi',
regex: "Goodbye",
input: "Hello World",
replacement: "Hi",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('Hello World');
expect(result).toBe("Hello World");
});
it('should return empty string when regex is empty', async () => {
it("should return empty string when regex is empty", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: '',
input: 'Hello World',
replacement: 'Hi',
regex: "",
input: "Hello World",
replacement: "Hi",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('');
expect(result).toBe("");
});
it('should return empty string when input is empty', async () => {
it("should return empty string when input is empty", async () => {
const result = await replaceFunction?.onRender({} as Context, {
values: {
regex: 'Hello',
input: '',
replacement: 'Hi',
regex: "Hello",
input: "",
replacement: "Hi",
},
purpose: 'send',
purpose: "send",
});
expect(result).toBe('');
expect(result).toBe("");
});
it('should throw on invalid regex', async () => {
it("should throw on invalid regex", async () => {
const fn = replaceFunction?.onRender({} as Context, {
values: {
regex: '[',
input: 'Hello World',
replacement: 'Hi',
regex: "[",
input: "Hello World",
replacement: "Hi",
},
purpose: 'send',
purpose: "send",
});
await expect(fn).rejects.toThrow(
'Invalid regular expression: /[/: Unterminated character class',
"Invalid regular expression: /[/: Unterminated character class",
);
});
});