# Literal keyed table join v1

Save `keyed-join.mjs` beside `keyed-join-example.mjs` containing this example.
Run `node keyed-join-example.mjs` with Node 18+; no runtime dependencies.

```js
import assert from 'node:assert/strict';
import { keyedJoin } from './keyed-join.mjs';
const options = { leftKey: '1', rightKey: '1', mode: 'left', header: true };
const result = keyedJoin('id\tname\n01\tAlex\n02\tJo',
  'id\tteam\n01\tRed\n01\tBlue', options);
assert.equal(result.tsv, 'left.id\tleft.name\tright.id\tright.team\n01\tAlex\t01\tRed\n01\tAlex\t01\tBlue\n02\tJo\t\t');
assert.equal(result.rows, 3);
assert.equal(result.matches, 2);
assert.equal(result.unmatchedLeft, 1);
assert.throws(() => keyedJoin('id\n', 'id\n\n', options));
console.log('Keyed join example passed.');
```

Choose one explicit one-based key column in each rectangular literal TSV table.
`mode` is `inner` (matching rows only) or `left` (also retain unmatched left
rows, padding the right fields with empty strings). All duplicate matches are
emitted in left-row order, then right-row order. Both complete source rows,
including keys, remain in the output. Matching is case-sensitive and never trims
spaces or converts numbers. Exactly empty data keys are rejected in either table;
spaces are literal keys. No inferred key, deduplication, aggregation or fuzzy match.

`header: true` treats the first row of both tables as a header. Output names
have `left.` and `right.` prefixes; blank or duplicate names remain literal.
Header-only tables are valid. `header: false` treats every row as data.
CRLF and bare CR become LF; one terminal newline is ignored. Quotes do not
escape tabs or newlines. Empty input and ragged rows are errors.

`tsv` is the joined table. `report` records original one-based source row
positions, including headers in numbering. `rows` counts output data rows;
`matches` counts matching pairs and `unmatchedLeft` counts source left rows
without a match, regardless of join mode. No matching inner rows returns only
the header when enabled, or an empty string without headers.

Each input is capped at 100,000 characters, 500 rows including any header,
and 50 columns. Output has at most 1,000 data rows and 100 columns. TSV and
report are each capped at 300,000 characters. Duplicate expansion is checked
before output is constructed. Exceeded limits throw without partial output.

No network requests, telemetry, formulas or spreadsheet writes. Input stays
in the calling process. Formula-like cells remain literal here but may execute
when imported into a spreadsheet: inspect the result and import as text.
Native spreadsheet lookup/join is an alternative. Downloading does not establish
independent use or time savings.

Generate with `node scripts/build-keyed-join.mjs`; check exact browser-core
bytes with `node scripts/build-keyed-join.mjs --check`.

## License

MIT License

Copyright (c) 2026 QuasiLife

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
