@oddstate/core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -83
- package/dist/corpus-data.js +1 -1
- package/dist/search-data.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,103 +1,111 @@
|
|
|
1
1
|
# Oddstate core
|
|
2
2
|
|
|
3
|
-
`@oddstate/core`
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Use `@oddstate/core` when you want Oddstate’s case records or fixture data in
|
|
4
|
+
JavaScript or TypeScript. The library reads from a bundled snapshot. Lookups are
|
|
5
|
+
synchronous and work offline.
|
|
6
|
+
|
|
7
|
+
Browse the cases and guides on the [Oddstate website](https://oddstate.dev).
|
|
8
|
+
|
|
9
|
+
Install it in a Node.js 24+ project that uses ES modules.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @oddstate/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## From a question to a test input
|
|
16
|
+
|
|
17
|
+
A search returns short summaries. Open a case for the explanation, the evidence
|
|
18
|
+
from its recorded run, and the list of fixtures you can reuse.
|
|
6
19
|
|
|
7
20
|
```ts
|
|
8
21
|
import { getCase, getFixture, searchCases } from "@oddstate/core";
|
|
9
22
|
|
|
10
23
|
const results = searchCases("date UTC", { category: "dates-and-times" });
|
|
11
|
-
const
|
|
12
|
-
const evidence =
|
|
13
|
-
const
|
|
24
|
+
const example = getCase("date-only-utc");
|
|
25
|
+
const evidence = example?.verification.evidence;
|
|
26
|
+
const input = getFixture("date-only-utc", "date-inputs");
|
|
14
27
|
```
|
|
15
28
|
|
|
16
|
-
|
|
29
|
+
If a lookup returns `undefined`, check the case or fixture ID. IDs are exact
|
|
30
|
+
and case-sensitive. The fixture’s `file` field gives its original filename.
|
|
31
|
+
Its `content` is a string for JSON and text, with the original whitespace
|
|
32
|
+
preserved. Binary fixtures return a `Uint8Array`. Each call gives you results
|
|
33
|
+
you can modify independently.
|
|
34
|
+
|
|
35
|
+
## API at a glance
|
|
17
36
|
|
|
18
|
-
| Function |
|
|
19
|
-
| ------------------------------- |
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
22
|
-
| `
|
|
23
|
-
| `
|
|
24
|
-
| `getRelatedCases(id)` | Directly related
|
|
25
|
-
| `getFixture(caseId, fixtureId)` |
|
|
37
|
+
| Function | What it returns |
|
|
38
|
+
| ------------------------------- | ----------------------------------------------------------------- |
|
|
39
|
+
| `listCategories()` | Categories in registry order. |
|
|
40
|
+
| `listCases(filters?)` | Summaries in case ID order. |
|
|
41
|
+
| `searchCases(query, filters?)` | Summaries in relevance order. |
|
|
42
|
+
| `getCase(id)` | Case metadata and Markdown, or `undefined`. |
|
|
43
|
+
| `getRelatedCases(id)` | Directly related summaries in the case’s declared order, or `[]`. |
|
|
44
|
+
| `getFixture(caseId, fixtureId)` | The fixture descriptor and its content, or `undefined`. |
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
references,
|
|
29
|
-
verification evidence. Case and fixture IDs are exact and case-sensitive. A
|
|
30
|
-
fixture's `file` is its original filename. JSON and text fixture contents are
|
|
31
|
-
strings with the original whitespace. Binary fixtures return `Uint8Array`.
|
|
32
|
-
Results can be modified independently of subsequent calls.
|
|
46
|
+
A summary includes `id`, `title`, `summary`, and `category`. The full case
|
|
47
|
+
adds references, related cases, compatibility, and verification evidence.
|
|
33
48
|
|
|
34
|
-
`listCases` and `searchCases` accept `category` and `nodeMajor
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
the positive safe integer range throws
|
|
39
|
-
|
|
49
|
+
`listCases` and `searchCases` accept both `category` and `nodeMajor`. The Node
|
|
50
|
+
filter includes cases whose minimum verification major is at or below the
|
|
51
|
+
requested major. Check `verification.evidence` for the exact Node version and
|
|
52
|
+
environment used in the recorded run. An unknown category returns `[]`.
|
|
53
|
+
A `nodeMajor` value outside the positive safe integer range throws a
|
|
54
|
+
`RangeError`.
|
|
40
55
|
|
|
41
|
-
## Search
|
|
56
|
+
## Search in a browser
|
|
42
57
|
|
|
43
|
-
|
|
58
|
+
Import the search entry point when your UI only needs to show matching cases.
|
|
59
|
+
It bundles summaries and search terms. Full explanations, evidence, and
|
|
60
|
+
fixture bytes are available through the main entry point.
|
|
44
61
|
|
|
45
62
|
```ts
|
|
46
63
|
import { searchCases } from "@oddstate/core/search";
|
|
47
64
|
|
|
48
|
-
const results = searchCases("
|
|
65
|
+
const results = searchCases("TextDecoder split chunks");
|
|
49
66
|
```
|
|
50
67
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
the
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
the
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
directory.
|
|
96
|
-
|
|
97
|
-
| Cases | Binary bytes per case | Previous gzip bytes | Browser entry gzip bytes |
|
|
98
|
-
| ----: | --------------------: | ------------------: | -----------------------: |
|
|
99
|
-
| 3,000 | 1,024 | 3,281,129 | 91,862 |
|
|
100
|
-
| 1,000 | 16,384 | 17,381,848 | 33,442 |
|
|
101
|
-
|
|
102
|
-
Measurements used the pre-hardening core, Webpack 5.98.0 and Next's bundled SWC
|
|
103
|
-
on Node 24.22.3. They measure bundle size and result equivalence in a JS context.
|
|
68
|
+
Search looks for each distinct query word in the case ID, title, summary,
|
|
69
|
+
Markdown, and fixture IDs. It compares lowercase, NFC-normalized whole words.
|
|
70
|
+
Punctuation separates words, with code points like `U+FFFD` kept together.
|
|
71
|
+
For each word, the strongest field wins. IDs and titles score 3 points,
|
|
72
|
+
summaries 2, and Markdown and fixture IDs 1.
|
|
73
|
+
|
|
74
|
+
If there are no exact matches within the filters, search drops common
|
|
75
|
+
connecting words and folds simple plurals and spelling variants. A partial
|
|
76
|
+
match can miss one word when at least two words match and one appears in the
|
|
77
|
+
ID, title, or summary. Results sort by matched words, then score, then case ID.
|
|
78
|
+
Empty or unmatched queries return `[]`.
|
|
79
|
+
|
|
80
|
+
## Build and verify from a checkout
|
|
81
|
+
|
|
82
|
+
Run these commands from the repository root.
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
pnpm --filter @oddstate/core build
|
|
86
|
+
pnpm --filter @oddstate/core test
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The build verifies the corpus and generates the snapshots in `dist/`.
|
|
90
|
+
Those snapshots retain the evidence recorded in the case metadata. Both
|
|
91
|
+
entry points ship TypeScript declarations and use standard ES2022 APIs.
|
|
92
|
+
The package has zero runtime dependencies.
|
|
93
|
+
|
|
94
|
+
The package tests exercise the built entry points. The release smoke test
|
|
95
|
+
installs the actual tarballs in a fresh npm project and checks strict
|
|
96
|
+
TypeScript consumers.
|
|
97
|
+
|
|
98
|
+
### Measure the browser bundle
|
|
99
|
+
|
|
100
|
+
After building core, run `node scripts/measure-search-bundle.mts` from the
|
|
101
|
+
repository root. It bundles the full and search entries with two synthetic
|
|
102
|
+
corpora, runs them without Node globals, and compares their results. Pass
|
|
103
|
+
`--before-dist <path>` with an earlier build to compare bundle sizes.
|
|
104
|
+
|
|
105
|
+
| Cases | Binary bytes per case | Previous gzip bytes | Browser search gzip bytes |
|
|
106
|
+
| ----: | --------------------: | ------------------: | ------------------------: |
|
|
107
|
+
| 3,000 | 1,024 | 3,281,129 | 91,862 |
|
|
108
|
+
| 1,000 | 16,384 | 17,381,848 | 33,442 |
|
|
109
|
+
|
|
110
|
+
These measurements used the pre-hardening core, Webpack 5.98.0, Next’s
|
|
111
|
+
bundled SWC, and Node.js 24.22.3.
|