@extable/sequence
v0.3.7
Published
[](https://www.npmjs.com/package/@extable/sequence) [](https://www.typescriptlang
Readme
@extable/sequence
Sequence inference engine for Extable auto-fill.
This package provides a small, composable sequence engine that can detect list patterns, arithmetic/geometric progressions, and structured string patterns (embedded numbers, roman numerals, English ordinals) and then generate subsequent values.
Install
npm install @extable/sequenceUsage
import { inferSequence, createBuiltInRegistry } from "@extable/sequence";
const registry = createBuiltInRegistry(["ja", "en"]);
const seq = inferSequence(["Jan", "Feb"], { registry });
// The iterator yields values *after* the seed.
seq.next().value; // "March"API
inferSequence
inferSequence(seed: readonly number[], options?: { registry?: SequenceRegistry }): Sequence<number>
inferSequence(seed: readonly Date[], options?: { registry?: SequenceRegistry }): Sequence<Date>
inferSequence(seed: readonly string[], options?: { registry?: SequenceRegistry }): Sequence<string>Inference priority:
- Single-item seed -> copy
- Built-in/custom list match
- Arithmetic progression
- Geometric progression (numbers only)
- Seed repeat
SequenceRegistry
const registry = new SequenceRegistry({ langs: ["ja", "en"] });
registry.register(list);
registry.registerMatch(matcher);langscontrols language preference (nonavigatordependency).enis appended if missing.
Built-in Lists
Cycle lists (wrap-around):
- Weekdays (en/ja)
- Months (en/ja, traditional Japanese month names)
- Quarters (en/ja)
- Zodiac animals (十二支)
- Zodiac signs (en/ja)
- Directions (16-wind, en/ja)
- AM/PM (en/ja)
- Seasons (en/ja)
- Solfege (en/ja)
- Rokuyo (六曜)
- Greek letters (en/ja/symbols)
Finite lists (stop at end):
- Ten Heavenly Stems (十干)
- Planets (en/ja, 8 planets)
- Kuji-in (九字)
- Eight virtues (八徳)
Custom Matchers
You can register custom matchers with a score to override built-ins:
registry.registerMatch({
id: "custom",
match(seed) {
if (seed[0] === "A" && seed[1] === "B") return { score: 100 };
return null;
},
createIterator() {
return {
next() {
return { value: "Z", done: false };
}
};
}
});License
Apache-2.0
