@finbheara/domain 0.30.0 → 0.32.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 +74 -5
- package/dist/age.js +73 -688
- package/dist/chunks/{place-h2s1w0tq.js → place-6qvca8eg.js} +1 -1
- package/dist/chunks/place-8k74cr5j.js +655 -0
- package/dist/chunks/place-bhedwqd1.js +139 -0
- package/dist/geocode.js +143 -131
- package/dist/place.js +1 -1
- package/dist/schedule.js +70 -0
- package/dist/school.js +1 -1
- package/dist/title.js +19 -0
- package/dist/types/geocode.d.ts +1 -0
- package/dist/types/place-towns.d.ts +1 -1
- package/dist/types/place-within.d.ts +1 -1
- package/dist/types/schedule.d.ts +21 -0
- package/dist/types/title.d.ts +45 -0
- package/package.json +10 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Age2,
|
|
3
|
+
ageRelation2
|
|
4
|
+
} from "./place-8k74cr5j.js";
|
|
5
|
+
import {
|
|
6
|
+
validity
|
|
7
|
+
} from "./place-q9kwsmzd.js";
|
|
8
|
+
|
|
9
|
+
import { toAscii } from "@finbheara/names/lexicon";
|
|
10
|
+
var GIRLS_WORD = /\b(?:girls?|lad(?:y|ies)|wom[ae]ns?|cailini|mna)(?![a-z])/;
|
|
11
|
+
var BOYS_WORD = /\b(?:boys?|mens?|man|gents?|gentlem[ae]n|buachailli|fir)(?![a-z])/;
|
|
12
|
+
var MIXED_WORD = /\b(?:mixed|mix|meascaithe|measctha)\b/;
|
|
13
|
+
function populationIn2(text) {
|
|
14
|
+
const w = toAscii(text).toLowerCase();
|
|
15
|
+
if (MIXED_WORD.test(w))
|
|
16
|
+
return "mixed";
|
|
17
|
+
const g = GIRLS_WORD.test(w);
|
|
18
|
+
const b = BOYS_WORD.test(w);
|
|
19
|
+
if (g && b)
|
|
20
|
+
return "mixed";
|
|
21
|
+
if (g)
|
|
22
|
+
return "girls";
|
|
23
|
+
if (b)
|
|
24
|
+
return "boys";
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
function roundNumbersIn2(folded, printed) {
|
|
28
|
+
const out = new Set;
|
|
29
|
+
for (const m of folded.matchAll(/ rounds? ((?:\d+ (?:and )?)+)/g))
|
|
30
|
+
for (const n of m[1].match(/\d+/g) ?? [])
|
|
31
|
+
out.add(Number(n));
|
|
32
|
+
for (const m of folded.matchAll(/ r([1-9])(?= )/g))
|
|
33
|
+
out.add(Number(m[1]));
|
|
34
|
+
if (printed)
|
|
35
|
+
for (const m of folded.matchAll(/ (\d) (?:st|nd|rd|th)(?= )/g))
|
|
36
|
+
out.add(Number(m[1]));
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function roundFold(print) {
|
|
40
|
+
return ` ${toAscii(print).toLowerCase().replace(/(\d)(\p{L})/gu, "$1 $2").replace(/[-–—,/()&+:;|.']/g, " ").replace(/\s+/g, " ").trim()} `;
|
|
41
|
+
}
|
|
42
|
+
var SPLIT = / ([a-d]) $|(?:\d|girls?|boys?|lad(?:y|ies)|m[ae]n|mixed) ([a-d])(?= )/;
|
|
43
|
+
var spoken = (print) => print.replace(/\b(under|over)-(?=\d)/giu, "$1 ");
|
|
44
|
+
function read(print, ctx, agePrint) {
|
|
45
|
+
const actx = { year: ctx.year ?? null, ...ctx.ladder ? { ladder: ctx.ladder } : {} };
|
|
46
|
+
let age;
|
|
47
|
+
let ageSpan = null;
|
|
48
|
+
if (agePrint !== undefined && agePrint.trim() !== "") {
|
|
49
|
+
age = Age2.from(agePrint, actx);
|
|
50
|
+
} else {
|
|
51
|
+
const t = Age2.fromTitle(spoken(print), actx);
|
|
52
|
+
age = t.age;
|
|
53
|
+
ageSpan = t.span;
|
|
54
|
+
}
|
|
55
|
+
const folded = roundFold(print);
|
|
56
|
+
const rounds = [...roundNumbersIn2(folded, / rounds? /.test(folded))].sort((a, b) => a - b);
|
|
57
|
+
const split = SPLIT.exec(folded);
|
|
58
|
+
const empty = print.trim() === "" && (agePrint ?? "").trim() === "";
|
|
59
|
+
const refusal = empty || age.isAge() ? null : "no-age";
|
|
60
|
+
return Object.freeze({
|
|
61
|
+
[Symbol.toStringTag]: "CompTitle",
|
|
62
|
+
...validity(empty, refusal),
|
|
63
|
+
print,
|
|
64
|
+
age,
|
|
65
|
+
ageSpan,
|
|
66
|
+
population: populationIn2(print),
|
|
67
|
+
round: rounds.length === 1 ? rounds[0] : null,
|
|
68
|
+
rounds: Object.freeze(rounds),
|
|
69
|
+
split: split ? split[1] ?? split[2] : null,
|
|
70
|
+
isTitle: () => !empty && refusal === null
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function compTitle2(print, ctx = {}) {
|
|
74
|
+
return read(print, ctx);
|
|
75
|
+
}
|
|
76
|
+
function populationRelation2(a, b) {
|
|
77
|
+
if (a === "" || b === "")
|
|
78
|
+
return "silent";
|
|
79
|
+
return a === b ? "same" : "disjoint";
|
|
80
|
+
}
|
|
81
|
+
function titleRelation2(a, b) {
|
|
82
|
+
const age = ageRelation2(a.age, b.age);
|
|
83
|
+
const population = populationRelation2(a.population, b.population);
|
|
84
|
+
const relation = population === "disjoint" || age.relation === "disjoint" ? "disjoint" : age.relation;
|
|
85
|
+
return Object.freeze({ relation, age, population });
|
|
86
|
+
}
|
|
87
|
+
function ladderOf2(bands) {
|
|
88
|
+
const caps = new Set;
|
|
89
|
+
const overs = new Set;
|
|
90
|
+
const ranges = [];
|
|
91
|
+
let adult = false;
|
|
92
|
+
for (const b of bands) {
|
|
93
|
+
const bare = Age2.from(b.ag0, { year: null });
|
|
94
|
+
if (!bare.isValid())
|
|
95
|
+
continue;
|
|
96
|
+
if (bare.isAdult())
|
|
97
|
+
adult = true;
|
|
98
|
+
const [p, q] = bare.parts;
|
|
99
|
+
if (bare.kind === "under" && p !== undefined)
|
|
100
|
+
caps.add(p);
|
|
101
|
+
else if (bare.kind === "over" && p !== undefined)
|
|
102
|
+
overs.add(p);
|
|
103
|
+
else if (bare.kind === "range" && p !== undefined && q !== undefined) {
|
|
104
|
+
caps.add(q);
|
|
105
|
+
ranges.push([p, q]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const asc = (s) => [...s].sort((x, y) => x - y);
|
|
109
|
+
return Object.freeze({
|
|
110
|
+
caps: asc(caps),
|
|
111
|
+
overs: asc(overs),
|
|
112
|
+
ranges: ranges.sort((x, y) => x[0] - y[0] || x[1] - y[1]),
|
|
113
|
+
...adult ? { adult: true } : {}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function matchTitle2(print, entries, ctx = {}) {
|
|
117
|
+
const bare = read(print, ctx);
|
|
118
|
+
const line = entries.filter((e) => populationRelation2(bare.population, populationIn2(e.title)) !== "disjoint");
|
|
119
|
+
const ladder = ladderOf2(line.map((e) => read(e.title, ctx, e.age).age));
|
|
120
|
+
const title = read(print, { ...ctx, ladder });
|
|
121
|
+
const hits = [];
|
|
122
|
+
if (title.isTitle())
|
|
123
|
+
for (const e of line) {
|
|
124
|
+
const r = titleRelation2(title, read(e.title, { ...ctx, ladder }, e.age));
|
|
125
|
+
if (r.relation === "same")
|
|
126
|
+
hits.push(e);
|
|
127
|
+
}
|
|
128
|
+
const split = title.split;
|
|
129
|
+
const same = split === null ? [] : hits.filter((e) => read(e.title, ctx, e.age).split === split);
|
|
130
|
+
const out = same.length > 0 ? same : hits;
|
|
131
|
+
return Object.freeze({
|
|
132
|
+
title,
|
|
133
|
+
entries: Object.freeze(out),
|
|
134
|
+
round: title.round,
|
|
135
|
+
isSingular: () => out.length === 1
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { populationIn2, roundNumbersIn2, compTitle2, populationRelation2, titleRelation2, ladderOf2, matchTitle2 };
|