@taekwondo-db/database 0.3.0 → 0.4.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 CHANGED
@@ -44,7 +44,7 @@ img/<group>/ illustrations (CC BY 4.0, see License)
44
44
  | `translation` | the name in each language. Required, searchable |
45
45
  | `supplementaryName` | an alternative romanized name in use. Searchable |
46
46
  | `description` | free text per language; may [reference](#references-in-descriptions) techniques and terms. Not searched |
47
- | `terms` | the name word by word; `$space` stands for a space |
47
+ | `terms` | the name word by word; `$space` stands for a space. Their Hangeul is searchable |
48
48
  | `references` | related techniques; `generic` marks the general technique this one is a variant of, `specialization` the reverse |
49
49
  | `generic` | the technique is itself a generic term |
50
50
  | `sources`, `historic`, `videos`, `images`, `weight` | citations, historic names, video links, [images](#images), weight distribution of stances |
@@ -171,8 +171,8 @@ grades or techniques and duplicates are errors.
171
171
  | `getAllTechniques()`, `getAllTerms()`, `getAllSources()` | iterators of `[key, entry]` |
172
172
  | `getGroups()`, `getTechniquesByGroup(group)` | the group names; the techniques of one group in order |
173
173
  | `getGrades()`, `getTechniquesByGrade(key)` | the grades in use, lowest first; the techniques of one grade |
174
- | `searchTechniques(input, lang)` | fuzzy search over name, `supplementaryName` and `translation` |
175
- | `searchTerms(input, lang)` | fuzzy search over name and `description` |
174
+ | `searchTechniques(input, lang)` | fuzzy search over name, `supplementaryName`, Hangeul and `translation` |
175
+ | `searchTerms(input, lang)` | fuzzy search over name, `hangeul` and `description` |
176
176
  | `resolveDescription(text)` | the text split into plain text and resolved references; references to what is not loaded become text |
177
177
 
178
178
  Also exported: `applyPatch(target, patch)`, `parseDescription(text)`,
@@ -192,9 +192,11 @@ const search = createTechniqueSearch(index.techniques, "de");
192
192
  search("Reitstand"); // the matching index entries, best first
193
193
  ```
194
194
 
195
- Entries need `name` and optionally `supplementaryName` and `translation`
196
- (techniques) or `description` (terms) — localized objects as in the database,
197
- or strings already in one language. Other fields are passed through.
195
+ Entries need `name` and optionally `supplementaryName`, `hangeul` and
196
+ `translation` (techniques) or `hangeul` and `description` (terms) —
197
+ localized objects as in the database, or strings already in one language. A
198
+ technique without `hangeul` is searched by the Hangeul of its `terms`, if it
199
+ has any. Other fields are passed through.
198
200
 
199
201
  `@taekwondo-db/database/search.browser.js` is the same module bundled with
200
202
  Fuse.js: one ES module without imports, to serve as is.
@@ -1162,8 +1162,12 @@ function localized(value, lang) {
1162
1162
  if (typeof value === "string") return value;
1163
1163
  return value?.[lang] ?? "";
1164
1164
  }
1165
+ /** A loaded technique has no Hangeul of its own, only that of its terms. */
1166
+ function techniqueHangeul(item) {
1167
+ return item.hangeul ?? item.terms?.map((term) => term.hangeul).join("") ?? "";
1168
+ }
1165
1169
  /**
1166
- * Searches techniques by name, `supplementaryName` and translation.
1170
+ * Searches techniques by name, `supplementaryName`, Hangeul and translation.
1167
1171
  * Returns a function from a query to the matching items, best first.
1168
1172
  */
1169
1173
  function createTechniqueSearch(items, lang) {
@@ -1171,6 +1175,10 @@ function createTechniqueSearch(items, lang) {
1171
1175
  keys: [
1172
1176
  "name",
1173
1177
  "supplementaryName",
1178
+ {
1179
+ getFn: techniqueHangeul,
1180
+ name: "hangeul"
1181
+ },
1174
1182
  {
1175
1183
  getFn: (item) => localized(item.translation, lang),
1176
1184
  name: "translation"
@@ -1181,15 +1189,19 @@ function createTechniqueSearch(items, lang) {
1181
1189
  return (query) => fuse.search(query).map((result) => result.item);
1182
1190
  }
1183
1191
  /**
1184
- * Searches terms by name and description, without reference markup.
1192
+ * Searches terms by name, Hangeul and description, without reference markup.
1185
1193
  * Returns a function from a query to the matching items, best first.
1186
1194
  */
1187
1195
  function createTermSearch(items, lang) {
1188
1196
  const fuse = new entry_default(items, {
1189
- keys: ["name", {
1190
- getFn: (item) => stripRefs(localized(item.description, lang)),
1191
- name: "description"
1192
- }],
1197
+ keys: [
1198
+ "name",
1199
+ "hangeul",
1200
+ {
1201
+ getFn: (item) => stripRefs(localized(item.description, lang)),
1202
+ name: "description"
1203
+ }
1204
+ ],
1193
1205
  threshold: THRESHOLD
1194
1206
  });
1195
1207
  return (query) => fuse.search(query).map((result) => result.item);
package/package.json CHANGED
@@ -47,5 +47,5 @@
47
47
  },
48
48
  "type": "module",
49
49
  "types": "./src/database.ts",
50
- "version": "0.3.0"
50
+ "version": "0.4.0"
51
51
  }
package/src/search.d.ts CHANGED
@@ -4,6 +4,9 @@ import type { LocalizedString } from "../types/localized-string";
4
4
  export interface TechniqueSearchItem {
5
5
  name: string;
6
6
  supplementaryName?: string;
7
+ /** Without it, the Hangeul of `terms` is searched, as in a loaded technique. */
8
+ hangeul?: string;
9
+ terms?: readonly { hangeul?: string }[];
7
10
  /** Localized, or already in the language searched. */
8
11
  translation?: LocalizedString | string;
9
12
  }
@@ -11,6 +14,7 @@ export interface TechniqueSearchItem {
11
14
  /** What the term search matches on; loaded terms qualify. */
12
15
  export interface TermSearchItem {
13
16
  name: string;
17
+ hangeul?: string;
14
18
  /** Localized, or already in the language searched; may contain references. */
15
19
  description?: LocalizedString | string;
16
20
  }
@@ -18,13 +22,13 @@ export interface TermSearchItem {
18
22
  /** A search over fixed items: from a query to the matching items, best first. */
19
23
  export type Search<T> = (query: string) => T[];
20
24
 
21
- /** Searches techniques by name, `supplementaryName` and translation. */
25
+ /** Searches techniques by name, `supplementaryName`, Hangeul and translation. */
22
26
  export declare function createTechniqueSearch<T extends TechniqueSearchItem>(
23
27
  items: readonly T[],
24
28
  lang?: string,
25
29
  ): Search<T>;
26
30
 
27
- /** Searches terms by name and description, without reference markup. */
31
+ /** Searches terms by name, Hangeul and description, without reference markup. */
28
32
  export declare function createTermSearch<T extends TermSearchItem>(
29
33
  items: readonly T[],
30
34
  lang?: string,
package/src/search.js CHANGED
@@ -21,8 +21,13 @@ function localized(value, lang) {
21
21
  return value?.[lang] ?? "";
22
22
  }
23
23
 
24
+ /** A loaded technique has no Hangeul of its own, only that of its terms. */
25
+ function techniqueHangeul(item) {
26
+ return item.hangeul ?? item.terms?.map((term) => term.hangeul).join("") ?? "";
27
+ }
28
+
24
29
  /**
25
- * Searches techniques by name, `supplementaryName` and translation.
30
+ * Searches techniques by name, `supplementaryName`, Hangeul and translation.
26
31
  * Returns a function from a query to the matching items, best first.
27
32
  */
28
33
  export function createTechniqueSearch(items, lang) {
@@ -30,6 +35,7 @@ export function createTechniqueSearch(items, lang) {
30
35
  keys: [
31
36
  "name",
32
37
  "supplementaryName",
38
+ { getFn: techniqueHangeul, name: "hangeul" },
33
39
  {
34
40
  getFn: (item) => localized(item.translation, lang),
35
41
  name: "translation",
@@ -41,13 +47,14 @@ export function createTechniqueSearch(items, lang) {
41
47
  }
42
48
 
43
49
  /**
44
- * Searches terms by name and description, without reference markup.
50
+ * Searches terms by name, Hangeul and description, without reference markup.
45
51
  * Returns a function from a query to the matching items, best first.
46
52
  */
47
53
  export function createTermSearch(items, lang) {
48
54
  const fuse = new Fuse(items, {
49
55
  keys: [
50
56
  "name",
57
+ "hangeul",
51
58
  {
52
59
  getFn: (item) => stripRefs(localized(item.description, lang)),
53
60
  name: "description",