@starci/eslint-canon-fe 8.4.40 → 8.4.41

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.
@@ -0,0 +1,34 @@
1
+ // source-phrases.mjs - the Vietnamese phrase lists runtime source matches against owner or product text are DATA,
2
+ // not source: they live in modules/goal/source-phrases.yaml (its leaf keys are declared Vietnamese fields,
3
+ // scripts/lib/language.mjs DECLARED_VIETNAMESE_FIELDS - like the archetypes.yaml phrase lists) so the matchers'
4
+ // source stays English. A list is plain words or regex alternatives, per its comment in the lexicon.
5
+ //
6
+ // phrasesOf('owed.ownerWord') -> the list as written (['<owner word>', ...])
7
+ // altOf('owed.ownerWord') -> the regex alternation 'a|b|c'; '(?!)' - never matches - when absent
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import { skillRoot } from '../../engine/runtime-root.mjs';
11
+ import { parseYaml } from '../../engine/yaml.mjs';
12
+
13
+ const SOURCE_PHRASES_FILE = 'modules/goal/source-phrases.yaml';
14
+
15
+ const cache = new Map();
16
+
17
+ /** The lexicon's `phrases` map ({<group>: {<list>: string[]}}), cached per root. */
18
+ function sourcePhrases(root = skillRoot) {
19
+ if (!cache.has(root)) {
20
+ let doc = null;
21
+ try { doc = parseYaml(fs.readFileSync(path.join(root, ...SOURCE_PHRASES_FILE.split('/')), 'utf8')); } catch { doc = null; }
22
+ cache.set(root, doc?.phrases && typeof doc.phrases === 'object' ? doc.phrases : {});
23
+ }
24
+ return cache.get(root);
25
+ }
26
+
27
+ /** The phrase list `dotKey` (`<group>.<list>`) of `root`, [] when absent. */
28
+ export function phrasesOf(dotKey, root = skillRoot) {
29
+ const value = dotKey.split('.').reduce((v, k) => (v && typeof v === 'object' ? v[k] : undefined), sourcePhrases(root));
30
+ return (Array.isArray(value) ? value : []).map(String);
31
+ }
32
+
33
+ /** The regex alternation of `dotKey` ('a|b|c'); '(?!)' - a never-match - when the list is empty. */
34
+ export const altOf = (dotKey, root = skillRoot) => phrasesOf(dotKey, root).join('|') || '(?!)';