未載入 Skill10643 tokens · 112447 ms
以下是完整檔案。由於目前處於 plan mode,我沒有實際建立檔案,只在回覆中提供內容。
檔名建議:`src/csv-utils.ts`(採用 Vitest 的 in-source testing,讓實作與 5 個測試同處一個檔案;需在 `vitest.config.ts` 加上 `test: { includeSource: ["src/**/*.ts"] }`,並在 build 時設 `define: { "import.meta.vitest": "undefined" }` 以剝除測試碼)。若你的專案不想改 config,把整個檔案改名為 `src/csv-utils.test.ts`,並把底部的 `if (import.meta.vitest) { const { describe, it, expect } = import.meta.vitest; ... }` 換成頂層 `import { describe, it, expect } from "vitest";` 即可,實作部分完全不用動。
```ts
/// <reference types="vitest/importMeta" />
/**
* csv-utils.ts
*
* Zero-dependency CSV parsing/escaping plus three small collection helpers.
* Runtime code uses only the JavaScript standard library.
*
* In-source Vitest tests are at the bottom of this file, guarded by
* `import.meta.vitest` so they are removed from production bundles.
*/
/* -------------------------------------------------------------------------- */
/* parseCsv */
/* -------------------------------------------------------------------------- */
export interface ParseCsvOptions {
/** Single-character field separator. Defaults to ",". */
delimiter?: string;
}
/**
* Parses RFC 4180-style CSV text into a matrix of raw string fields.
*
* Supported:
* - quoted fields containing the delimiter, CR, LF or escaped quotes ("")
* - LF, CRLF and lone-CR line endings
* - a single optional trailing newline (it does NOT produce an extra row)
*
* Notes:
* - No trimming and no type coercion: every field is returned verbatim.
* - `""` (empty input) returns `[]`.
* - A line containing only a newline yields one row with one empty field.
* - A quote inside an unquoted field is treated as a literal character.
*
* @throws {TypeError} if the delimiter is invalid.
* @throws {SyntaxError} if a quoted field is never closed.
*/
export function parseCsv(input: string, options: ParseCsvOptions = {}): string[][] {
const delimiter = options.delimiter ?? ",";
if (typeof delimiter !== "string" || delimiter.length !== 1) {
throw new TypeError(
`parseCsv: delimiter must be exactly one character, received ${JSON.stringify(delimiter)}`,
);
}
if (delimiter === '"' || delimiter === "\r" || delimiter === "\n") {
throw new TypeError(
`parseCsv: delimiter must not be a double quote or a newline character`,
);
}
const rows: string[][] = [];
let row: string[] = [];
let field = "";
/** True once at least one character (or an opening quote) belongs to the current field. */
let fieldTouched = false;
let inQuotes = false;
let index = 0;
const endField = (): void => {
row.push(field);
field = "";
fieldTouched = false;
};
const endRow = (): void => {
endField();
rows.push(row);
row = [];
};
while (index < input.length) {
const char = input[index] as string;
if (inQuotes) {
if (char === '"') {
if (input[index + 1] === '"') {
field += '"';
index += 2;
continue;
}
inQuotes = false;
index += 1;
continue;
}
field += char;
index += 1;
continue;
}
if (char === '"' && !fieldTouched) {
inQuotes = true;
fieldTouched = true;
index += 1;
continue;
}
if (char === delimiter) {
endField();
index += 1;
continue;
}
if (char === "\r") {
endRow();
index += input[index + 1] === "\n" ? 2 : 1;
continue;
}
if (char === "\n") {
endRow();
index += 1;
continue;
}
field += char;
fieldTouched = true;
index += 1;
}
if (inQuotes) {
throw new SyntaxError("parseCsv: unterminated quoted field at end of input");
}
if (fieldTouched || field.length > 0 || row.length > 0) {
endRow();
}
return rows;
}
/* -------------------------------------------------------------------------- */
/* escapeCsv */
/* -------------------------------------------------------------------------- */
export interface EscapeCsvOptions {
/** Single-character field separator the output will be joined with. Defaults to ",". */
delimiter?: string;
/** Always wrap the field in quotes, even when not strictly required. */
forceQuotes?: boolean;
}
/**
* Escapes a single value so it can be safely joined into a CSV row.
*
* Quoting happens when the text contains the delimiter, a double quote, CR/LF,
* or leading/trailing whitespace (whitespace is otherwise easy to lose in
* third-party readers). Inner double quotes are doubled.
*
* `null` and `undefined` become an empty, unquoted field.
*
* @throws {TypeError} if the delimiter is invalid.
*/
export function escapeCsv(
value: string | number | boolean | null | undefined,
options: EscapeCsvOptions = {},
): string {
const delimiter = options.delimiter ?? ",";
if (typeof delimiter !== "string" || delimiter.length !== 1) {
throw new TypeError(
`escapeCsv: delimiter must be exactly one character, received ${JSON.stringify(delimiter)}`,
);
}
if (delimiter === '"' || delimiter === "\r" || delimiter === "\n") {
throw new TypeError(
`escapeCsv: delimiter must not be a double quote or a newline character`,
);
}
if (value === null || value === undefined) {
return options.forceQuotes === true ? '""' : "";
}
const text = typeof value === "string" ? value : String(value);
const hasSpecialChar =
text.includes(delimiter) ||
text.includes('"') ||
text.includes("\n") ||
text.includes("\r");
const hasEdgeWhitespace =
text.length > 0 && (text !== text.trimStart() || text !== text.trimEnd());
if (options.forceQuotes !== true && !hasSpecialChar && !hasEdgeWhitespace) {
return text;
}
return `"${text.replaceAll('"', '""')}"`;
}
/* -------------------------------------------------------------------------- */
/* groupBy */
/* -------------------------------------------------------------------------- */
/**
* Groups items by a computed key, preserving first-seen key order and the
* original item order inside each group.
*
* A `Map` is returned (not a plain object) so keys of any type are supported
* and prototype keys such as "__proto__" are safe.
*/
export function groupBy<T, K>(
items: Iterable<T>,
keyFn: (item: T, index: number) => K,
): Map<K, T[]> {
if (typeof keyFn !== "function") {
throw new TypeError("groupBy: keyFn must be a function");
}
const groups = new Map<K, T[]>();
let index = 0;
for (const item of items) {
const key = keyFn(item, index);
const bucket = groups.get(key);
if (bucket === undefined) {
groups.set(key, [item]);
} else {
bucket.push(item);
}
index += 1;
}
return groups;
}
/* -------------------------------------------------------------------------- */
/* sumBy */
/* -------------------------------------------------------------------------- */
/**
* Sums the numbers produced by `valueFn`. Returns 0 for an empty iterable.
*
* Every produced value must be a finite number; NaN and ±Infinity throw
* instead of silently poisoning the total.
*
* @throws {TypeError} if `valueFn` returns a non-finite value.
*/
export function sumBy<T>(
items: Iterable<T>,
valueFn: (item: T, index: number) => number,
): number {
if (typeof valueFn !== "function") {
throw new TypeError("sumBy: valueFn must be a function");
}
let total = 0;
let index = 0;
for (const item of items) {
const value = valueFn(item, index);
if (typeof value !== "number" || !Number.isFinite(value)) {
throw new TypeError(
`sumBy: valueFn must return a finite number, received ${String(value)} at index ${index}`,
);
}
total += value;
index += 1;
}
return total;
}
/* -------------------------------------------------------------------------- */
/* uniqueBy */
/* -------------------------------------------------------------------------- */
/**
* Removes duplicates by a computed key, keeping the FIRST occurrence and the
* original relative order. Key equality follows Map semantics (SameValueZero),
* so NaN keys deduplicate correctly.
*/
export function uniqueBy<T, K>(
items: Iterable<T>,
keyFn: (item: T, index: number) => K,
): T[] {
if (typeof keyFn !== "function") {
throw new TypeError("uniqueBy: keyFn must be a function");
}
const seen = new Set<K>();
const result: T[] = [];
let index = 0;
for (const item of items) {
const key = keyFn(item, index);
if (!seen.has(key)) {
seen.add(key);
result.push(item);
}
index += 1;
}
return result;
}
/* -------------------------------------------------------------------------- */
/* In-source Vitest tests: one test per exported function */
/* -------------------------------------------------------------------------- */
if (import.meta.vitest) {
const { describe, it, expect } = import.meta.vitest;
describe("csv-utils", () => {
it("parseCsv handles quotes, escaped quotes, CRLF and a custom delimiter", () => {
const csv = 'name,note\r\n"Ada, L.","said ""hi"""\nBob,\n';
expect(parseCsv(csv)).toEqual([
["name", "note"],
["Ada, L.", 'said "hi"'],
["Bob", ""],
]);
expect(parseCsv("")).toEqual([]);
expect(parseCsv("a\nb")).toEqual([["a"], ["b"]]);
expect(parseCsv("x;y;", { delimiter: ";" })).toEqual([["x", "y", ""]]);
expect(parseCsv('"multi\nline"')).toEqual([["multi\nline"]]);
expect(() => parseCsv('"never closed')).toThrow(SyntaxError);
expect(() => parseCsv("a,b", { delimiter: ";;" })).toThrow(TypeError);
});
it("escapeCsv quotes only when needed and round-trips through parseCsv", () => {
expect(escapeCsv("plain")).toBe("plain");
expect(escapeCsv("a,b")).toBe('"a,b"');
expect(escapeCsv('he said "no"')).toBe('"he said ""no"""');
expect(escapeCsv(" padded ")).toBe('" padded "');
expect(escapeCsv("line\nbreak")).toBe('"line\nbreak"');
expect(escapeCsv(null)).toBe("");
expect(escapeCsv(undefined)).toBe("");
expect(escapeCsv(42)).toBe("42");
expect(escapeCsv("safe", { forceQuotes: true })).toBe('"safe"');
expect(escapeCsv("a;b", { delimiter: ";" })).toBe('"a;b"');
expect(escapeCsv("a;b")).toBe("a;b");
const row = ["a,b", 'q"q', "line\nbreak", " pad ", ""];
const encoded = row.map((value) => escapeCsv(value)).join(",");
expect(parseCsv(encoded)).toEqual([row]);
});
it("groupBy keeps first-seen key order and item order within groups", () => {
const items = [
{ type: "fruit", name: "apple" },
{ type: "veg", name: "leek" },
{ type: "fruit", name: "pear" },
];
const grouped = groupBy(items, (item) => item.type);
expect([...grouped.keys()]).toEqual(["fruit", "veg"]);
expect(grouped.get("fruit")).toEqual([items[0], items[2]]);
expect(grouped.get("veg")).toEqual([items[1]]);
expect(grouped.get("missing")).toBeUndefined();
expect(groupBy([] as string[], (value) => value).size).toBe(0);
const byParity = groupBy(["a", "b", "c"], (_value, index) =>
index % 2 === 0 ? "even" : "odd",
);
expect(byParity.get("even")).toEqual(["a", "c"]);
expect(byParity.get("odd")).toEqual(["b"]);
});
it("sumBy adds finite numbers and rejects non-finite results", () => {
expect(sumBy([{ n: 1 }, { n: 2 }, { n: 3.5 }], (item) => item.n)).toBe(6.5);
expect(sumBy([] as number[], (value) => value)).toBe(0);
expect(sumBy(new Set([1, 2, 3]), (value) => value)).toBe(6);
expect(sumBy([{ n: 5 }, { n: -5 }], (item) => item.n)).toBe(0);
expect(sumBy(["a", "bb"], (value, index) => value.length * index)).toBe(2);
expect(() => sumBy([1], () => Number.NaN)).toThrow(TypeError);
expect(() => sumBy([1], () => Number.POSITIVE_INFINITY)).toThrow(TypeError);
});
it("uniqueBy keeps the first occurrence of each key in original order", () => {
const rows = [
{ id: 1, label: "first" },
{ id: 2, label: "second" },
{ id: 1, label: "duplicate" },
];
expect(uniqueBy(rows, (row) => row.id)).toEqual([rows[0], rows[1]]);
expect(uniqueBy(["a", "A", "b", "B"], (s) => s.toLowerCase())).toEqual(["a", "b"]);
expect(uniqueBy([] as number[], (value) => value)).toEqual([]);
expect(uniqueBy([Number.NaN, Number.NaN, 1], (value) => value)).toEqual([
Number.NaN,
1,
]);
expect(uniqueBy(["x", "y", "z"], (_value, index) => index % 2)).toEqual(["x", "y"]);
});
});
}
```
執行方式:`npx vitest run src/csv-utils.ts`(in-source 模式需先設定 `includeSource`)。
幾點需要你確認、我無法自行判斷的事:
- 我沒有讀取你的專案,因此不知道現有的 tsconfig `target`/`lib` 設定。程式中用到 `String.prototype.replaceAll`(ES2021)、`trimStart`/`trimEnd`(ES2019)與 `Object`/`Map`/`Set` 迭代;若你的 target 低於 ES2021,把 `replaceAll('"', '""')` 換成 `split('"').join('""')` 即可。
- 我未實際執行測試(plan mode 下沒有執行工具),所以上述測試是依實作邏輯推導而非驗證過的結果;請跑一次確認。
已載入 Skill +10092 tokens · 109083 ms
已依 `full-output-enforcement` 的規範產出:完整檔案、五個匯出函式、五個對應 Vitest 測試,無省略號/TODO/placeholder,無任何外部執行期相依(僅 Vitest 本身作為測試執行器)。
---
## `src/csv-utils.ts`
```ts
/// <reference types="vitest/importMeta" />
/**
* csv-utils.ts
*
* Zero-dependency CSV / collection helpers with in-source Vitest tests.
* Runtime dependencies: none. Test-only dependency: vitest (dev).
*/
/* ------------------------------------------------------------------ */
/* Types */
/* ------------------------------------------------------------------ */
export interface ParseCsvOptions {
/** Single-character field separator. Defaults to ",". */
delimiter?: string;
}
export interface EscapeCsvOptions {
/** Single-character field separator. Defaults to ",". */
delimiter?: string;
/** Always wrap the result in quotes, even when not strictly required. */
quoteAll?: boolean;
}
/* ------------------------------------------------------------------ */
/* Internal helpers (not part of the public API) */
/* ------------------------------------------------------------------ */
function assertSingleCharDelimiter(delimiter: string): void {
if (delimiter.length !== 1) {
throw new TypeError(
`Delimiter must be exactly one character, received ${JSON.stringify(delimiter)}.`,
);
}
if (delimiter === '"' || delimiter === '\r' || delimiter === '\n') {
throw new TypeError(
`Delimiter must not be a quote or line-break character, received ${JSON.stringify(delimiter)}.`,
);
}
}
/* ------------------------------------------------------------------ */
/* 1. parseCsv */
/* ------------------------------------------------------------------ */
/**
* Parses an RFC 4180-style CSV string into a matrix of raw string fields.
*
* Supported behaviour:
* - Quoted fields may contain the delimiter, CR, LF, and doubled quotes ("").
* - Row separators may be LF or CRLF (a lone CR is also treated as a break).
* - A trailing line break does not produce a spurious empty final row.
* - An empty input string yields an empty array.
*
* @throws {SyntaxError} when a quoted field is never closed.
* @throws {TypeError} when the delimiter is invalid.
*/
export function parseCsv(input: string, options: ParseCsvOptions = {}): string[][] {
const delimiter = options.delimiter ?? ',';
assertSingleCharDelimiter(delimiter);
const rows: string[][] = [];
let row: string[] = [];
let field = '';
let inQuotes = false;
let fieldStarted = false;
let index = 0;
while (index < input.length) {
const char = input[index];
if (inQuotes) {
if (char === '"') {
if (input[index + 1] === '"') {
field += '"';
index += 2;
continue;
}
inQuotes = false;
index += 1;
continue;
}
field += char;
index += 1;
continue;
}
if (char === '"') {
inQuotes = true;
fieldStarted = true;
index += 1;
continue;
}
if (char === delimiter) {
row.push(field);
field = '';
fieldStarted = false;
index += 1;
continue;
}
if (char === '\r' || char === '\n') {
if (char === '\r' && input[index + 1] === '\n') {
index += 1;
}
row.push(field);
rows.push(row);
row = [];
field = '';
fieldStarted = false;
index += 1;
continue;
}
field += char;
fieldStarted = true;
index += 1;
}
if (inQuotes) {
throw new SyntaxError('Unterminated quoted field in CSV input.');
}
if (fieldStarted || row.length > 0) {
row.push(field);
rows.push(row);
}
return rows;
}
/* ------------------------------------------------------------------ */
/* 2. escapeCsv */
/* ------------------------------------------------------------------ */
/**
* Escapes a single value for safe inclusion in a CSV row.
*
* Quoting is applied when the stringified value contains the delimiter,
* a double quote, CR, LF, or has leading/trailing whitespace. Embedded
* quotes are doubled. `null` and `undefined` become an empty string.
*
* @throws {TypeError} when the delimiter is invalid.
*/
export function escapeCsv(value: unknown, options: EscapeCsvOptions = {}): string {
const delimiter = options.delimiter ?? ',';
assertSingleCharDelimiter(delimiter);
const text = value === null || value === undefined ? '' : String(value);
const needsQuotes =
options.quoteAll === true ||
text.includes(delimiter) ||
text.includes('"') ||
text.includes('\n') ||
text.includes('\r') ||
/^\s/.test(text) ||
/\s$/.test(text);
if (!needsQuotes) {
return text;
}
return `"${text.replace(/"/g, '""')}"`;
}
/* ------------------------------------------------------------------ */
/* 3. groupBy */
/* ------------------------------------------------------------------ */
/**
* Groups items into a Map keyed by the value returned from `keySelector`.
* Insertion order of both keys and grouped items is preserved.
*/
export function groupBy<T, K>(
items: Iterable<T>,
keySelector: (item: T, index: number) => K,
): Map<K, T[]> {
const groups = new Map<K, T[]>();
let index = 0;
for (const item of items) {
const key = keySelector(item, index);
const bucket = groups.get(key);
if (bucket === undefined) {
groups.set(key, [item]);
} else {
bucket.push(item);
}
index += 1;
}
return groups;
}
/* ------------------------------------------------------------------ */
/* 4. sumBy */
/* ------------------------------------------------------------------ */
/**
* Sums the numbers produced by `valueSelector`. Returns 0 for an empty
* iterable.
*
* @throws {TypeError} when the selector yields a non-finite number
* (NaN, Infinity, -Infinity) or a non-number.
*/
export function sumBy<T>(
items: Iterable<T>,
valueSelector: (item: T, index: number) => number,
): number {
let total = 0;
let index = 0;
for (const item of items) {
const value = valueSelector(item, index);
if (typeof value !== 'number' || !Number.isFinite(value)) {
throw new TypeError(
`sumBy expected a finite number at index ${index}, received ${String(value)}.`,
);
}
total += value;
index += 1;
}
return total;
}
/* ------------------------------------------------------------------ */
/* 5. uniqueBy */
/* ------------------------------------------------------------------ */
/**
* Returns a new array containing the first item for each distinct key,
* preserving the original ordering. Key equality uses SameValueZero,
* so `NaN` matches `NaN`.
*/
export function uniqueBy<T, K>(
items: Iterable<T>,
keySelector: (item: T, index: number) => K,
): T[] {
const seen = new Set<K>();
const result: T[] = [];
let index = 0;
for (const item of items) {
const key = keySelector(item, index);
if (!seen.has(key)) {
seen.add(key);
result.push(item);
}
index += 1;
}
return result;
}
/* ------------------------------------------------------------------ */
/* In-source Vitest tests — one test per exported function */
/* ------------------------------------------------------------------ */
if (import.meta.vitest) {
const { describe, it, expect } = import.meta.vitest;
describe('parseCsv', () => {
it('parses quoted fields, embedded delimiters, quotes, newlines and CRLF', () => {
const csv =
'name,notes,qty\r\n' +
'"Smith, John","He said ""hi""",3\n' +
'Empty,"line\nbreak",0\n';
expect(parseCsv(csv)).toEqual([
['name', 'notes', 'qty'],
['Smith, John', 'He said "hi"', '3'],
['Empty', 'line\nbreak', '0'],
]);
expect(parseCsv('')).toEqual([]);
expect(parseCsv('a,')).toEqual([['a', '']]);
expect(parseCsv('""')).toEqual([['']]);
expect(parseCsv('a;b;c', { delimiter: ';' })).toEqual([['a', 'b', 'c']]);
expect(() => parseCsv('"never closed')).toThrow(SyntaxError);
expect(() => parseCsv('a,b', { delimiter: ',,' })).toThrow(TypeError);
});
});
describe('escapeCsv', () => {
it('quotes only when required and round-trips through parseCsv', () => {
expect(escapeCsv('plain')).toBe('plain');
expect(escapeCsv('a,b')).toBe('"a,b"');
expect(escapeCsv('say "hi"')).toBe('"say ""hi"""');
expect(escapeCsv('line\nbreak')).toBe('"line\nbreak"');
expect(escapeCsv('line\r\nbreak')).toBe('"line\r\nbreak"');
expect(escapeCsv(' padded ')).toBe('" padded "');
expect(escapeCsv(null)).toBe('');
expect(escapeCsv(undefined)).toBe('');
expect(escapeCsv(42)).toBe('42');
expect(escapeCsv('a;b', { delimiter: ';' })).toBe('"a;b"');
expect(escapeCsv('a;b')).toBe('a;b');
expect(escapeCsv('plain', { quoteAll: true })).toBe('"plain"');
const values = ['a,b', 'c"d', 'e\nf', 'plain'];
const line = values.map((value) => escapeCsv(value)).join(',');
expect(parseCsv(line)).toEqual([values]);
});
});
describe('groupBy', () => {
it('buckets items by key while preserving insertion order', () => {
const people = [
{ name: 'Ada', team: 'core' },
{ name: 'Linus', team: 'kernel' },
{ name: 'Grace', team: 'core' },
];
const grouped = groupBy(people, (person) => person.team);
expect([...grouped.keys()]).toEqual(['core', 'kernel']);
expect(grouped.get('core')).toEqual([
{ name: 'Ada', team: 'core' },
{ name: 'Grace', team: 'core' },
]);
expect(grouped.get('kernel')).toEqual([{ name: 'Linus', team: 'kernel' }]);
expect(grouped.get('missing')).toBeUndefined();
expect(groupBy([], (item: number) => item).size).toBe(0);
const byIndexParity = groupBy(['a', 'b', 'c'], (_item, index) => index % 2);
expect(byIndexParity.get(0)).toEqual(['a', 'c']);
expect(byIndexParity.get(1)).toEqual(['b']);
});
});
describe('sumBy', () => {
it('sums selected numbers and rejects non-finite values', () => {
const orders = [{ total: 10.5 }, { total: 4.5 }, { total: -5 }];
expect(sumBy(orders, (order) => order.total)).toBe(10);
expect(sumBy([], (item: { total: number }) => item.total)).toBe(0);
expect(sumBy(['aa', 'bbb'], (word) => word.length)).toBe(5);
expect(sumBy([1, 2, 3], (value, index) => value * index)).toBe(8);
expect(() => sumBy([{ total: Number.NaN }], (order) => order.total)).toThrow(TypeError);
expect(() => sumBy([{ total: Infinity }], (order) => order.total)).toThrow(TypeError);
});
});
describe('uniqueBy', () => {
it('keeps the first item per key and preserves order', () => {
const rows = [
{ id: 1, label: 'first' },
{ id: 2, label: 'second' },
{ id: 1, label: 'duplicate' },
{ id: 3, label: 'third' },
];
expect(uniqueBy(rows, (row) => row.id)).toEqual([
{ id: 1, label: 'first' },
{ id: 2, label: 'second' },
{ id: 3, label: 'third' },
]);
expect(uniqueBy([], (item: number) => item)).toEqual([]);
expect(uniqueBy(['a', 'A', 'b'], (word) => word.toLowerCase())).toEqual(['a', 'b']);
expect(uniqueBy([Number.NaN, Number.NaN, 1], (value) => value)).toEqual([Number.NaN, 1]);
expect(uniqueBy(['x', 'y', 'z'], (_item, index) => index < 2)).toEqual(['x', 'z']);
});
});
}
```
---
## 執行測試所需的設定(in-source testing)
`vitest.config.ts`:
```ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
includeSource: ['src/**/*.ts'],
},
define: {
'import.meta.vitest': 'undefined',
},
});
```
`define` 那一行讓正式建置時把測試區塊整段搖樹移除,因此產出的 bundle 完全不含 `vitest` 參照。
執行:`npx vitest run`
若你偏好把測試放到獨立檔案(`src/csv-utils.test.ts`),只需刪掉 `if (import.meta.vitest) { ... }` 整個區塊與檔首的 `/// <reference ...>`,把五個 `describe` 原封不動搬進新檔,並在新檔頂端加上:
```ts
import { describe, it, expect } from 'vitest';
import { parseCsv, escapeCsv, groupBy, sumBy, uniqueBy } from './csv-utils';
```
此時 `vitest.config.ts` 的 `includeSource` 與 `define` 兩項皆可移除。
---
**交付檢核**:5 個匯出函式(parseCsv、escapeCsv、groupBy、sumBy、uniqueBy)× 5 個 `it` 測試,全部完整實作;無 `// ...`、無 TODO、無 placeholder、無外部執行期套件。
補充說明:目前處於 plan mode,我沒有寫入任何檔案,以上內容尚未落盤;若要我實際建立 `src/csv-utils.ts` 與 `vitest.config.ts`,請離開 plan mode 後告知。