Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions site/src/lib/tools/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,20 @@ describe("SEO links match the locale-specific indexability policy", () => {
expect(localized.map((x) => x.slug)).toEqual(old.map((x) => x.slug));
});
});


describe("small 2026-11-15 search discovery trial", () => {
it("indexes exactly two additional proven interactive tools in en and ja", async () => {
const { INDEX_DISCOVERY_TRIAL_SLUGS, CORE_TOOLS_BY_DEMAND, isIndexableIn, indexableLocalesFor } = await import("./registry");
expect([...INDEX_DISCOVERY_TRIAL_SLUGS]).toEqual(["image-resizer", "csv-json-converter"]);
for (const slug of INDEX_DISCOVERY_TRIAL_SLUGS) {
expect(CORE_TOOLS_BY_DEMAND).not.toContain(slug);
expect(indexableLocalesFor(slug)).toEqual(["en", "ja"]);
expect(isIndexableIn("en", slug)).toBe(true);
expect(isIndexableIn("ja", slug)).toBe(true);
expect(isIndexableIn("es", slug)).toBe(false);
expect(isIndexableIn("th", slug)).toBe(false);
}
expect(isIndexableIn("en", "json-formatter")).toBe(false);
});
});
20 changes: 19 additions & 1 deletion site/src/lib/tools/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,25 @@ export const CORE_TOOLS_BY_DEMAND = [
"speed-converter", "loan-calculator", "age-calculator", "conception-date-calculator",
] as const;

export const INDEXED_SLUGS = new Set<string>(CORE_TOOLS_BY_DEMAND);
/**
* 2026-11-15: small, reversible discovery experiment — two genuinely
* interactive, privacy-preserving utilities already linked from homepage
* journeys. Only en/ja are eligible, using the existing canonical/hreflang
* policy. Do not restore all 223 tools or all 17 locales at once.
*
* Evaluation: compare GSC page impressions/clicks/index coverage for these
* exact four URLs over 28 days, alongside core-tool controls. If a trial page
* lacks clear search utility or index coverage deteriorates, revert it.
*/
export const INDEX_DISCOVERY_TRIAL_SLUGS = [
"image-resizer",
"csv-json-converter",
] as const;

export const INDEXED_SLUGS = new Set<string>([
...CORE_TOOLS_BY_DEMAND,
...INDEX_DISCOVERY_TRIAL_SLUGS,
]);

/**
* INDEXED_LOCALES(en/ja)以外で、ページ単位で index を残すもの。
Expand Down
71 changes: 7 additions & 64 deletions site/src/tools/csv-json-converter/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,7 @@
import { useMemo, useState } from "react";
import { useTranslations } from "next-intl";

// RFC 4180 compliant CSV parser (handles quoted fields with commas, escaped quotes, line breaks).
function parseCsv(text: string, delimiter: string): string[][] {
const rows: string[][] = [];
let row: string[] = [];
let field = "";
let inQuotes = false;
let i = 0;
while (i < text.length) {
const ch = text[i];
if (inQuotes) {
if (ch === '"') {
if (text[i + 1] === '"') {
field += '"';
i += 2;
continue;
}
inQuotes = false;
i++;
continue;
}
field += ch;
i++;
} else {
if (ch === '"') {
inQuotes = true;
i++;
} else if (ch === delimiter) {
row.push(field);
field = "";
i++;
} else if (ch === "\n" || ch === "\r") {
row.push(field);
rows.push(row);
row = [];
field = "";
if (ch === "\r" && text[i + 1] === "\n") i += 2;
else i++;
} else {
field += ch;
i++;
}
}
}
if (field || row.length) {
row.push(field);
rows.push(row);
}
return rows.filter((r) => r.length > 1 || (r.length === 1 && r[0] !== ""));
}

function escapeCsvField(value: unknown, delimiter: string): string {
const s = value === null || value === undefined ? "" : String(value);
if (s.includes(delimiter) || s.includes('"') || s.includes("\n") || s.includes("\r")) {
return '"' + s.replace(/"/g, '""') + '"';
}
return s;
}
import { parseCsv, escapeCsvField, assertUniqueHeaders, assertRowWidth } from "./csv-utils";

export default function CsvJsonConverter() {
const t = useTranslations("tools.csv-json-converter");
Expand All @@ -78,13 +22,12 @@ export default function CsvJsonConverter() {
if (rows.length === 0) return { ok: true as const, value: "[]" };
if (headerRow) {
const headers = rows[0]!;
const data = rows.slice(1).map((r) => {
const obj: Record<string, string> = {};
for (let i = 0; i < headers.length; i++) {
const key = headers[i]!;
obj[key] = r[i] ?? "";
}
return obj;
assertUniqueHeaders(headers);
const data = rows.slice(1).map((r, index) => {
assertRowWidth(r, headers.length, index + 2);
// Object.fromEntries preserves a literal "__proto__" column as data,
// rather than silently dropping it through the Object prototype setter.
return Object.fromEntries(headers.map((key, i) => [key, r[i]] as const)) as Record<string, string>;
});
return { ok: true as const, value: JSON.stringify(data, null, 2) };
}
Expand Down
46 changes: 46 additions & 0 deletions site/src/tools/csv-json-converter/csv-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import { assertRowWidth, assertUniqueHeaders, escapeCsvField, parseCsv } from "./csv-utils";

describe("CSV import integrity", () => {
it("parses the default sample and CRLF rows", () => {
expect(parseCsv("name,age\r\nAlice,30\r\nBob,25\r\n", ",")).toEqual([
["name", "age"], ["Alice", "30"], ["Bob", "25"],
]);
});

it("supports RFC 4180 quoted commas, doubled quotes and multiline fields", () => {
expect(parseCsv('name,note\r\n"Doe, Jane","line 1\r\nline 2"\r\n"Sam","say ""hello"""', ",")).toEqual([
["name", "note"], ["Doe, Jane", "line 1\r\nline 2"], ["Sam", 'say "hello"'],
]);
});

it("supports the advertised alternative delimiters", () => {
expect(parseCsv("a;b\n1;2", ";")).toEqual([["a", "b"], ["1", "2"]]);
expect(parseCsv("a\tb\n1\t2", "\t")).toEqual([["a", "b"], ["1", "2"]]);
expect(parseCsv("a|b\n1|2", "|")).toEqual([["a", "b"], ["1", "2"]]);
expect(() => parseCsv("a:b", ":")).toThrow(/Unsupported/);
});

it("rejects CSV that would otherwise silently become incorrect JSON", () => {
expect(() => parseCsv('a,b\n"unfinished', ",")).toThrow(/Unclosed/);
expect(() => parseCsv('a,b\nx"y",z', ",")).toThrow(/Unexpected quote/);
expect(() => parseCsv('a,b\n"x"oops,z', ",")).toThrow(/after a closing/);
});

it("rejects empty or repeated headers before data can be overwritten", () => {
expect(() => assertUniqueHeaders(["name", "name"])).toThrow(/Duplicate/);
expect(() => assertUniqueHeaders(["name", " "])).toThrow(/empty/);
expect(() => assertUniqueHeaders(["__proto__", "name"])).not.toThrow();
});

it("rejects ragged rows before losing or inventing data", () => {
expect(() => assertRowWidth(["Alice", "30"], 2, 2)).not.toThrow();
expect(() => assertRowWidth(["Bob", "25", "extra"], 2, 3)).toThrow(/CSV row 3 has 3 fields; expected 2/);
expect(() => assertRowWidth(["Carol"], 2, 4)).toThrow(/CSV row 4 has 1 fields; expected 2/);
});

it("exports quoted cells safely as CSV text", () => {
expect(escapeCsvField('say "hi", now', ",")).toBe('"say ""hi"", now"');
expect(escapeCsvField("line1\nline2", ",")).toBe('"line1\nline2"');
});
});
102 changes: 102 additions & 0 deletions site/src/tools/csv-json-converter/csv-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* Strict CSV field parser for the browser-only conversion tool.
* The common RFC 4180 quoting rules are enforced instead of returning
* plausible-looking but corrupted JSON on malformed CSV input.
*
* The delimiter selector also supports TSV, semicolon and pipe.
*/
export function parseCsv(text: string, delimiter: string): string[][] {
if (![",", ";", "\t", "|"].includes(delimiter)) {
throw new Error("Unsupported CSV delimiter");
}
const rows: string[][] = [];
let row: string[] = [];
let field = "";
let state: "start" | "unquoted" | "quoted" | "afterQuote" = "start";

const pushField = () => {
row.push(field);
field = "";
state = "start";
};
const pushRow = () => {
pushField();
rows.push(row);
row = [];
};

for (let i = 0; i < text.length; i++) {
const char = text[i];
if (state === "quoted") {
if (char === '"') {
if (text[i + 1] === '"') {
field += '"';
i++;
} else {
state = "afterQuote";
}
} else {
field += char;
}
continue;
}

if (char === delimiter) {
pushField();
continue;
}
if (char === "\n" || char === "\r") {
pushRow();
if (char === "\r" && text[i + 1] === "\n") i++;
continue;
}

if (char === '"') {
if (state !== "start") {
throw new Error("Unexpected quote inside an unquoted CSV field");
}
state = "quoted";
continue;
}
if (state === "afterQuote") {
throw new Error("Unexpected character after a closing CSV quote");
}
field += char;
state = "unquoted";
}

if (state === "quoted") {
throw new Error("Unclosed quoted CSV field");
}
if (field !== "" || row.length > 0 || state === "afterQuote") pushRow();

// Preserve existing behavior for empty physical lines. In particular,
// do not invent an extra data row for a trailing line break.
return rows.filter((r) => r.length > 1 || (r.length === 1 && r[0] !== ""));
}

/** Duplicate / blank columns must fail, not silently overwrite values. */
export function assertUniqueHeaders(headers: string[]): void {
const seen = new Set<string>();
for (const name of headers) {
if (!name.trim()) throw new Error("CSV header must not be empty");
if (seen.has(name)) throw new Error("Duplicate CSV header: " + name);
seen.add(name);
}
}

/** Do not discard surplus cells or invent missing values when headers are used. */
export function assertRowWidth(row: string[], expected: number, line: number): void {
if (row.length !== expected) {
throw new Error("CSV row " + line + " has " + row.length + " fields; expected " + expected);
}
}

/** Escape a cell before placing it in a delimited text export. */
export function escapeCsvField(value: unknown, delimiter: string): string {
const s = value === null || value === undefined ? "" : String(value);
if (s.includes(delimiter) || s.includes('"') || s.includes("\n") || s.includes("\r")) {
return '"' + s.replace(/"/g, '""') + '"';
}
return s;
}
5 changes: 4 additions & 1 deletion site/src/tools/csv-json-converter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const meta: ToolMeta = {
slug: "csv-json-converter",
category: "text",
applicationCategory: "DeveloperApplication",
updatedAt: "2026-05-08",
updatedAt: "2026-11-15",
related: ["json-formatter", "markdown-to-html", "text-replace"],
primaryKeyword: { en: "CSV to JSON converter", ja: "CSV JSON 変換" },
hasHowTo: true,
hasFaq: true,
sources: [
{ label: "RFC 4180 — Common Format and MIME Type for CSV Files", url: "https://www.rfc-editor.org/rfc/rfc4180" },
],
};

export default meta;
6 changes: 5 additions & 1 deletion site/src/tools/image-resizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ const meta: ToolMeta = {
slug: "image-resizer",
category: "image",
applicationCategory: "MultimediaApplication",
updatedAt: "2026-08-22",
updatedAt: "2026-11-15",
related: ["qr-code-generator", "base64-encoder", "color-converter"],
primaryKeyword: { en: "image resizer", ja: "画像リサイズ" },
hasHowTo: true,
hasFaq: true,
sources: [
{ label: "MDN — Canvas drawImage()", url: "https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage" },
{ label: "MDN — Canvas toBlob()", url: "https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob" },
],
};

export default meta;
Loading