Skip to content

Commit ae8677c

Browse files
committed
Added Notes from name-alias data
1 parent fb7b586 commit ae8677c

File tree

2 files changed

+89
-20
lines changed

2 files changed

+89
-20
lines changed

bin/ucd_to_json.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type SearchEntry = {
1616
category: string;
1717
script: string;
1818
tags?: string[];
19+
notes?: string[];
1920
}
2021

2122
type SearchData = {
@@ -49,8 +50,10 @@ async function main() {
4950
console.log(`INFO: parsed ${jsonObj.ucd.repertoire.char.length} characters`);
5051

5152
if (true) {
53+
const allJsonPath = path.join(__dirname, "..", "tmp", "ucd.all.flat.json");
54+
console.log(`INFO: writing full JSON data to ${allJsonPath}`);
5255
fs.writeFile(
53-
path.join(__dirname, "..", "tmp", "ucd.all.flat.json"),
56+
allJsonPath,
5457
JSON.stringify(jsonObj, null, 2),
5558
"utf-8"
5659
);
@@ -158,6 +161,42 @@ async function main() {
158161
name = charData['name-alias'][0].alias;
159162
}
160163

164+
var notes: string[] = [];
165+
166+
try {
167+
if (charData['name-alias']) {
168+
const nameAliasArray = Array.isArray(charData['name-alias']) ? charData['name-alias'] : [charData['name-alias']];
169+
for (const aliasEntry of nameAliasArray) {
170+
if (aliasEntry.type === "correction") {
171+
notes.push(`Corrected from: ${aliasEntry.alias}`);
172+
tags.push("Corrected");
173+
} else if (aliasEntry.type === "abbreviation") {
174+
if (name.indexOf('(') === -1) {
175+
name = `${name} (${aliasEntry.alias})`;
176+
} else if (name.indexOf(`(${aliasEntry.alias})`) === -1) {
177+
notes.push(`Abbreviation: ${aliasEntry.alias}`);
178+
}
179+
} else if (aliasEntry.type === "control") {
180+
if (aliasEntry.alias != name && name.indexOf(`${aliasEntry.alias} (`) === -1) {
181+
notes.push(`Control Name: ${aliasEntry.alias}`);
182+
}
183+
} else if (aliasEntry.type === "alternate") {
184+
notes.push(`Also known as: ${aliasEntry.alias}`);
185+
} else if (aliasEntry.type === "figment") {
186+
notes.push(`Figment Name: ${aliasEntry.alias}`);
187+
tags.push("Figment");
188+
} else {
189+
console.log(
190+
`WARN: unknown name-alias type '${aliasEntry.type}' for codepoint ${charData.cp} `
191+
);
192+
}
193+
}
194+
}
195+
} catch (err) {
196+
console.log(`ERROR: processing name-alias for codepoint ${charData.cp}: ${err}`);
197+
console.log(`INFO: name-alias data: ${JSON.stringify(charData['name-alias'])}`);
198+
}
199+
161200
entries.push({
162201
code: charData.cp,
163202
name: name || "(no name)",
@@ -166,6 +205,7 @@ async function main() {
166205
category: charData.gc,
167206
script: charData.sc,
168207
tags: tags.length ? tags : undefined,
208+
notes: notes.length ? notes : undefined,
169209
});
170210
}
171211

src/index.ts

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type SearchEntry = {
2626
block: string;
2727
category: string;
2828
tags?: string[];
29+
notes?: string[];
2930
};
3031

3132
type SearchData = {
@@ -139,7 +140,10 @@ function filterName(
139140
) {
140141
if (!headerValue) return true;
141142

142-
const rowValue = rowData.name;
143+
const rowValues = [ rowData.name ];
144+
if (rowData.notes) {
145+
rowValues.push(...rowData.notes);
146+
}
143147

144148
if (headerValue.length == 1) {
145149
if (headerValue == "^") {
@@ -154,15 +158,25 @@ function filterName(
154158
return true;
155159
}
156160
const search = headerValue.substring(1).toLowerCase();
157-
return rowValue.toLowerCase().startsWith(search);
161+
for (const rowValue of rowValues) {
162+
if (rowValue.toLowerCase().startsWith(search)) {
163+
return true;
164+
}
165+
}
166+
return false;
158167
}
159168

160169
if (headerValue.startsWith("/") && headerValue.endsWith("/")) {
161170
// regex
162171
const pattern = headerValue.substring(1, headerValue.length - 1);
163172
try {
164173
const re = new RegExp(pattern, "i");
165-
return re.test(rowValue);
174+
for (const rowValue of rowValues) {
175+
if (re.test(rowValue)) {
176+
return true;
177+
}
178+
}
179+
return false;
166180
} catch (e) {
167181
// bad regex
168182
return false;
@@ -171,7 +185,12 @@ function filterName(
171185

172186
// contains
173187
const search = headerValue.toLowerCase();
174-
return rowValue.toLowerCase().includes(search);
188+
for (const rowValue of rowValues) {
189+
if (rowValue.toLowerCase().includes(search)) {
190+
return true;
191+
}
192+
}
193+
return false;
175194
}
176195

177196
function filterTags(
@@ -226,26 +245,33 @@ function fmtExample(cell: CellComponent) {
226245

227246
function fmtTags(cell: CellComponent) {
228247
const tags = cell.getValue() as string[];
229-
if (!tags || tags.length === 0) {
248+
const notes = cell.getRow().getData().notes as string[] | undefined;
249+
if (!tags && !notes) {
230250
return "";
231251
}
232252

233253
const container = document.createElement("div");
234254

235-
const keys = tags.sort();
236-
237-
for (const key of keys) {
238-
var el = document.createElement("span");
239-
el.className =
240-
"badge border border-primary text-primary me-1 mb-1 text-decoration-none";
241-
el.textContent = key.replace(/_/g, " ");
242-
el.style.cursor = "pointer";
243-
el.onclick = (e) => {
244-
e.preventDefault();
245-
e.stopPropagation();
246-
toggleTagFilter(cell, key);
255+
if (notes) {
256+
container.textContent = notes.join(", ") + " ";
257+
}
258+
259+
if (tags) {
260+
const keys = tags.sort();
261+
262+
for (const key of keys) {
263+
var el = document.createElement("span");
264+
el.className =
265+
"badge border border-primary text-primary me-1 mb-1 text-decoration-none";
266+
el.textContent = key.replace(/_/g, " ");
267+
el.style.cursor = "pointer";
268+
el.onclick = (e) => {
269+
e.preventDefault();
270+
e.stopPropagation();
271+
toggleTagFilter(cell, key);
272+
}
273+
container.appendChild(el);
247274
}
248-
container.appendChild(el);
249275
}
250276

251277
return container;
@@ -421,6 +447,7 @@ async function main() {
421447
}
422448
if (key == "dir") {
423449
sort[0].dir = (value == "desc") ? "desc" : "asc";
450+
continue;
424451
}
425452
if (key && value) {
426453
filters.push({ field: key, type: "=", value: value });
@@ -570,7 +597,9 @@ async function main() {
570597
formatter: fmtTags,
571598
headerFilter: "input",
572599
headerFilterFunc: filterTags,
573-
headerPopup: `Separate multiple tags with space or comma.<br/>Prefix a tag with <code>!</code> to exclude it.`,
600+
headerPopup: `Separate multiple tags with space or comma.<br/>
601+
Prefix a tag with <code>!</code> to exclude it.<br/>
602+
Notes are searched under Name.`,
574603
headerPopupIcon:
575604
'<span class="badge rounded-pill text-bg-primary">?</span>',
576605
headerSort: false,

0 commit comments

Comments
 (0)