@fpw/en-wiktionary-la-modules 0.2.2 → 0.3.1

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.
Files changed (63) hide show
  1. package/LICENSE +75 -75
  2. package/README.md +19 -15
  3. package/dist/LaEngine.d.ts +23 -23
  4. package/dist/LaEngine.js +64 -66
  5. package/dist/index.d.ts +12 -11
  6. package/dist/index.js +12 -28
  7. package/dist/modules/common.d.ts +67 -66
  8. package/dist/modules/common.js +145 -157
  9. package/dist/modules/conjugation/LaVerb.d.ts +118 -109
  10. package/dist/modules/conjugation/LaVerb.js +2861 -2295
  11. package/dist/modules/conjugation/VerbAffix.d.ts +18 -18
  12. package/dist/modules/conjugation/VerbAffix.js +19 -23
  13. package/dist/modules/conjugation/VerbForm.d.ts +204 -182
  14. package/dist/modules/conjugation/VerbForm.js +215 -199
  15. package/dist/modules/conjugation/VerbType.d.ts +54 -40
  16. package/dist/modules/conjugation/VerbType.js +66 -58
  17. package/dist/modules/declination/LaAdjData.d.ts +16 -16
  18. package/dist/modules/declination/LaAdjData.js +1474 -908
  19. package/dist/modules/declination/LaNominal.d.ts +136 -130
  20. package/dist/modules/declination/LaNominal.js +1884 -1804
  21. package/dist/modules/declination/LaNounData.d.ts +16 -2
  22. package/dist/modules/declination/LaNounData.js +935 -855
  23. package/dist/modules/declination/LaPersonalPronoun.d.ts +12 -12
  24. package/dist/modules/declination/LaPersonalPronoun.js +80 -85
  25. package/dist/modules/declination/NominalForm.d.ts +85 -69
  26. package/dist/modules/declination/NominalForm.js +101 -91
  27. package/dist/modules/declination/NominalType.d.ts +191 -120
  28. package/dist/modules/declination/NominalType.js +211 -146
  29. package/dist/modules/headword/HeadWord.d.ts +107 -107
  30. package/dist/modules/headword/HeadWord.js +28 -32
  31. package/dist/modules/headword/HeadwordParser.d.ts +29 -29
  32. package/dist/modules/headword/HeadwordParser.js +456 -452
  33. package/package.json +23 -15
  34. package/dist/LaEngine.js.map +0 -1
  35. package/dist/index.js.map +0 -1
  36. package/dist/modules/common.js.map +0 -1
  37. package/dist/modules/conjugation/LaVerb.js.map +0 -1
  38. package/dist/modules/conjugation/VerbAffix.js.map +0 -1
  39. package/dist/modules/conjugation/VerbForm.js.map +0 -1
  40. package/dist/modules/conjugation/VerbType.js.map +0 -1
  41. package/dist/modules/declination/LaAdjData.js.map +0 -1
  42. package/dist/modules/declination/LaNominal.js.map +0 -1
  43. package/dist/modules/declination/LaNounData.js.map +0 -1
  44. package/dist/modules/declination/LaPersonalPronoun.js.map +0 -1
  45. package/dist/modules/declination/NominalForm.js.map +0 -1
  46. package/dist/modules/declination/NominalType.js.map +0 -1
  47. package/dist/modules/headword/HeadWord.js.map +0 -1
  48. package/dist/modules/headword/HeadwordParser.js.map +0 -1
  49. package/src/LaEngine.ts +0 -86
  50. package/src/index.ts +0 -16
  51. package/src/modules/common.ts +0 -164
  52. package/src/modules/conjugation/LaVerb.ts +0 -2669
  53. package/src/modules/conjugation/VerbAffix.ts +0 -18
  54. package/src/modules/conjugation/VerbForm.ts +0 -223
  55. package/src/modules/conjugation/VerbType.ts +0 -55
  56. package/src/modules/declination/LaAdjData.ts +0 -1036
  57. package/src/modules/declination/LaNominal.ts +0 -2025
  58. package/src/modules/declination/LaNounData.ts +0 -897
  59. package/src/modules/declination/LaPersonalPronoun.ts +0 -92
  60. package/src/modules/declination/NominalForm.ts +0 -89
  61. package/src/modules/declination/NominalType.ts +0 -157
  62. package/src/modules/headword/HeadWord.ts +0 -132
  63. package/src/modules/headword/HeadwordParser.ts +0 -515
@@ -1,66 +1,67 @@
1
- export declare type ArgMap = Map<string, string>;
2
- export declare type FormMap<T> = Map<T, string[]>;
3
- /**
4
- * Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
5
- * Unnamed parameters will use number strings starting at '0'.
6
- * @param desc the MediaWiki template string
7
- * @returns a map of keys and values
8
- */
9
- export declare function parse_template(desc: string): ArgMap;
10
- /**
11
- * Read a parameter list from a MediaWiki template string.
12
- * Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
13
- * @param args a parsed MediaWiki template string
14
- * @param elem the name of the list
15
- * @returns elemnts of the lists
16
- */
17
- export declare function read_list(args: ArgMap, elem: string): string[];
18
- /**
19
- * Removes MediaWiki links by replacing them with their displayed value.
20
- * Example [[a|title]] will be replaced with 'title'
21
- * @param str a string that can contain MediaWiki links
22
- * @returns the string with all links replaced by their title
23
- */
24
- export declare function remove_links(str: string): string;
25
- /**
26
- * Very basic HTML remover to remove simple, non-nested tags from a string.
27
- * @param str a string containing simple HTML markup
28
- * @returns a string with HTML tags removed
29
- */
30
- export declare function remove_html(str: string): string;
31
- /**
32
- * Removes macrons from a string.
33
- * Example: 'Āfrica' will become 'Africa'
34
- * @param str a string containing macrons
35
- * @returns string without macrons
36
- */
37
- export declare function strip_macrons(str: string): string;
38
- /**
39
- * Removes all diacritical parts from a string except for macrons.
40
- * Example: 'Thēse͡us' will become 'Thēseus'
41
- * @param str string containing diactricial characters
42
- * @returns string with all diactricial marks except macrons removed
43
- */
44
- export declare function remove_diacritical(str: string): string;
45
- /**
46
- * Given a word and an ending, returns the base part of the word excluding the ending.
47
- * The given ending can be a RegEx with a capture group - in that case, the first group will be returned.
48
- * @param lemma word to extract the base from
49
- * @param ending ending to remove, can be a RegEx
50
- * @returns
51
- */
52
- export declare function extract_base(lemma: string, ending: string): string | undefined;
53
- /**
54
- * Checks if two one-dimensional arrays are equal.
55
- * @param a array a
56
- * @param b array b
57
- * @returns true if the arrays are equal
58
- */
59
- export declare function array_equals(a: string[] | undefined, b: string[] | undefined): boolean;
60
- /**
61
- * Check if a value is a value of a given enum
62
- * @param enumType pass the enum type as value
63
- * @param val the value to check
64
- * @returns whether the value is part of the enum values
65
- */
66
- export declare function is_enum_value<E>(enumType: E, val: any): val is E[keyof E];
1
+ export type ArgMap = Map<string, string>;
2
+ export type FormMap<T> = Map<T, string[]>;
3
+ /**
4
+ * Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
5
+ * Unnamed parameters will use number strings starting at '0'.
6
+ * @param desc the MediaWiki template string
7
+ * @returns a map of keys and values
8
+ */
9
+ export declare function parse_template(desc: string): ArgMap;
10
+ /**
11
+ * Read a parameter list from a MediaWiki template string.
12
+ * Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
13
+ * @param args a parsed MediaWiki template string
14
+ * @param elem the name of the list
15
+ * @returns elemnts of the lists
16
+ */
17
+ export declare function read_list(args: ArgMap, elem: string): string[];
18
+ /**
19
+ * Removes MediaWiki links by replacing them with their displayed value.
20
+ * Example [[a|title]] will be replaced with 'title'
21
+ * @param str a string that can contain MediaWiki links
22
+ * @param displayed whether to keep the displayed part of the link (e.g. 'title' in [[a|title]]) or the linked part (e.g. 'a' in [[a|title]])
23
+ * @returns the string with all links replaced by their title
24
+ */
25
+ export declare function remove_links(str: string, displayed?: boolean): string;
26
+ /**
27
+ * Very basic HTML remover to remove simple, non-nested tags from a string.
28
+ * @param str a string containing simple HTML markup
29
+ * @returns a string with HTML tags removed
30
+ */
31
+ export declare function remove_html(str: string): string;
32
+ /**
33
+ * Removes macrons from a string.
34
+ * Example: 'Āfrica' will become 'Africa'
35
+ * @param str a string containing macrons
36
+ * @returns string without macrons
37
+ */
38
+ export declare function strip_macrons(str: string): string;
39
+ /**
40
+ * Removes all diacritical parts from a string except for macrons.
41
+ * Example: 'Thēse͡us' will become 'Thēseus'
42
+ * @param str string containing diactricial characters
43
+ * @returns string with all diactricial marks except macrons removed
44
+ */
45
+ export declare function remove_diacritical(str: string): string;
46
+ /**
47
+ * Given a word and an ending, returns the base part of the word excluding the ending.
48
+ * The given ending can be a RegEx with a capture group - in that case, the first group will be returned.
49
+ * @param lemma word to extract the base from
50
+ * @param ending ending to remove, can be a RegEx
51
+ * @returns
52
+ */
53
+ export declare function extract_base(lemma: string, ending: string): string | undefined;
54
+ /**
55
+ * Checks if two one-dimensional arrays are equal.
56
+ * @param a array a
57
+ * @param b array b
58
+ * @returns true if the arrays are equal
59
+ */
60
+ export declare function array_equals(a: string[] | undefined, b: string[] | undefined): boolean;
61
+ /**
62
+ * Check if a value is a value of a given enum
63
+ * @param enumType pass the enum type as value
64
+ * @param val the value to check
65
+ * @returns whether the value is part of the enum values
66
+ */
67
+ export declare function is_enum_value<E>(enumType: E, val: unknown): val is E[keyof E];
@@ -1,157 +1,145 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.is_enum_value = exports.array_equals = exports.extract_base = exports.remove_diacritical = exports.strip_macrons = exports.remove_html = exports.remove_links = exports.read_list = exports.parse_template = void 0;
4
- /**
5
- * Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
6
- * Unnamed parameters will use number strings starting at '0'.
7
- * @param desc the MediaWiki template string
8
- * @returns a map of keys and values
9
- */
10
- function parse_template(desc) {
11
- // remove {{ }}
12
- const paramStr = desc
13
- .replace(/[\r\n]/g, "")
14
- .replace(/^{{(.*)}}$/, "$1");
15
- const partStr = remove_links(paramStr);
16
- const parts = partStr.split("|");
17
- const res = new Map();
18
- let i = 0;
19
- for (const part of parts) {
20
- if (part.includes("=")) {
21
- const [key, value] = part.split("=");
22
- res.set(key, value);
23
- }
24
- else {
25
- res.set(`${i++}`, part);
26
- }
27
- }
28
- return res;
29
- }
30
- exports.parse_template = parse_template;
31
- /**
32
- * Read a parameter list from a MediaWiki template string.
33
- * Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
34
- * @param args a parsed MediaWiki template string
35
- * @param elem the name of the list
36
- * @returns elemnts of the lists
37
- */
38
- function read_list(args, elem) {
39
- const entries = [];
40
- for (const [key, value] of args.entries()) {
41
- const match = key.match(new RegExp(`^${elem}([0-9]*)$`));
42
- if (!match) {
43
- continue;
44
- }
45
- let idx = 0;
46
- if (match[1]) {
47
- idx = Number.parseInt(match[1], 10) - 1;
48
- }
49
- entries[idx] = value;
50
- }
51
- return entries.filter(x => x !== undefined);
52
- }
53
- exports.read_list = read_list;
54
- /**
55
- * Removes MediaWiki links by replacing them with their displayed value.
56
- * Example [[a|title]] will be replaced with 'title'
57
- * @param str a string that can contain MediaWiki links
58
- * @returns the string with all links replaced by their title
59
- */
60
- function remove_links(str) {
61
- // flatten links [[a|b]] to [[b]]
62
- const norm1 = str.replace(/\[\[[^\]]*?\|([^\]]*?)\]\]/g, "[[$1]]");
63
- // replace [[b]] with b
64
- const norm2 = norm1.replace(/\[\[([^\]]*?)\]\]/g, "$1");
65
- return norm2;
66
- }
67
- exports.remove_links = remove_links;
68
- /**
69
- * Very basic HTML remover to remove simple, non-nested tags from a string.
70
- * @param str a string containing simple HTML markup
71
- * @returns a string with HTML tags removed
72
- */
73
- function remove_html(str) {
74
- return str.replace(/<.*?>(.*?)<\/.*?>/g, "$1");
75
- }
76
- exports.remove_html = remove_html;
77
- /**
78
- * Removes macrons from a string.
79
- * Example: 'Āfrica' will become 'Africa'
80
- * @param str a string containing macrons
81
- * @returns string without macrons
82
- */
83
- function strip_macrons(str) {
84
- return str
85
- .normalize("NFD")
86
- .replace(/\u0304/g, "")
87
- .normalize("NFC");
88
- }
89
- exports.strip_macrons = strip_macrons;
90
- /**
91
- * Removes all diacritical parts from a string except for macrons.
92
- * Example: 'Thēse͡us' will become 'Thēseus'
93
- * @param str string containing diactricial characters
94
- * @returns string with all diactricial marks except macrons removed
95
- */
96
- function remove_diacritical(str) {
97
- const noDias = str
98
- .normalize("NFD")
99
- .replace(/[\u0300-\u0303\u0305-\u036F]/g, "")
100
- .normalize("NFC");
101
- return noDias;
102
- }
103
- exports.remove_diacritical = remove_diacritical;
104
- /**
105
- * Given a word and an ending, returns the base part of the word excluding the ending.
106
- * The given ending can be a RegEx with a capture group - in that case, the first group will be returned.
107
- * @param lemma word to extract the base from
108
- * @param ending ending to remove, can be a RegEx
109
- * @returns
110
- */
111
- function extract_base(lemma, ending) {
112
- let regex;
113
- if (ending.includes("(")) {
114
- regex = ending;
115
- }
116
- else {
117
- regex = `^(.*)${ending}$`;
118
- }
119
- const match = lemma.match(new RegExp(regex));
120
- if (match) {
121
- return match[1];
122
- }
123
- return undefined;
124
- }
125
- exports.extract_base = extract_base;
126
- /**
127
- * Checks if two one-dimensional arrays are equal.
128
- * @param a array a
129
- * @param b array b
130
- * @returns true if the arrays are equal
131
- */
132
- function array_equals(a, b) {
133
- if ((!a && b) || (a && !b)) {
134
- return false;
135
- }
136
- if (!a || !b) {
137
- return true;
138
- }
139
- return (a.length == b.length) && a.every((x, i) => b[i] == x);
140
- }
141
- exports.array_equals = array_equals;
142
- /**
143
- * Check if a value is a value of a given enum
144
- * @param enumType pass the enum type as value
145
- * @param val the value to check
146
- * @returns whether the value is part of the enum values
147
- */
148
- function is_enum_value(enumType, val) {
149
- for (const key in enumType) {
150
- if (enumType[key] === val) {
151
- return true;
152
- }
153
- }
154
- return false;
155
- }
156
- exports.is_enum_value = is_enum_value;
157
- //# sourceMappingURL=common.js.map
1
+ /**
2
+ * Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
3
+ * Unnamed parameters will use number strings starting at '0'.
4
+ * @param desc the MediaWiki template string
5
+ * @returns a map of keys and values
6
+ */
7
+ export function parse_template(desc) {
8
+ // remove {{ }}
9
+ const paramStr = desc
10
+ .replace(/[\r\n]/g, "")
11
+ .replace(/^{{(.*)}}$/, "$1");
12
+ const partStr = remove_links(paramStr, false);
13
+ const parts = partStr.split("|");
14
+ const res = new Map();
15
+ let i = 0;
16
+ for (const part of parts) {
17
+ if (part.includes("=")) {
18
+ const [key, value] = part.split("=");
19
+ res.set(key, value);
20
+ }
21
+ else {
22
+ res.set(`${i++}`, part);
23
+ }
24
+ }
25
+ return res;
26
+ }
27
+ /**
28
+ * Read a parameter list from a MediaWiki template string.
29
+ * Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
30
+ * @param args a parsed MediaWiki template string
31
+ * @param elem the name of the list
32
+ * @returns elemnts of the lists
33
+ */
34
+ export function read_list(args, elem) {
35
+ const entries = [];
36
+ for (const [key, value] of args.entries()) {
37
+ const match = key.match(new RegExp(`^${elem}([0-9]*)$`));
38
+ if (!match) {
39
+ continue;
40
+ }
41
+ let idx = 0;
42
+ if (match[1]) {
43
+ idx = Number.parseInt(match[1], 10) - 1;
44
+ }
45
+ entries[idx] = value;
46
+ }
47
+ return entries.filter(x => x !== undefined);
48
+ }
49
+ /**
50
+ * Removes MediaWiki links by replacing them with their displayed value.
51
+ * Example [[a|title]] will be replaced with 'title'
52
+ * @param str a string that can contain MediaWiki links
53
+ * @param displayed whether to keep the displayed part of the link (e.g. 'title' in [[a|title]]) or the linked part (e.g. 'a' in [[a|title]])
54
+ * @returns the string with all links replaced by their title
55
+ */
56
+ export function remove_links(str, displayed = true) {
57
+ // flatten links [[a|b]] to [[b]]
58
+ const norm1 = str.replace(/\[\[([^\]]*?\|([^\]]*?))\]\]/g, displayed ? "[[$2]]" : "[[$1]]");
59
+ // replace [[b]] with b
60
+ const norm2 = norm1.replace(/\[\[([^\]]*?)\]\]/g, "$1");
61
+ return norm2;
62
+ }
63
+ /**
64
+ * Very basic HTML remover to remove simple, non-nested tags from a string.
65
+ * @param str a string containing simple HTML markup
66
+ * @returns a string with HTML tags removed
67
+ */
68
+ export function remove_html(str) {
69
+ return str.replace(/<.*?>(.*?)<\/.*?>/g, "$1");
70
+ }
71
+ /**
72
+ * Removes macrons from a string.
73
+ * Example: 'Āfrica' will become 'Africa'
74
+ * @param str a string containing macrons
75
+ * @returns string without macrons
76
+ */
77
+ export function strip_macrons(str) {
78
+ return str
79
+ .normalize("NFD")
80
+ .replace(/\u0304/g, "")
81
+ .normalize("NFC");
82
+ }
83
+ /**
84
+ * Removes all diacritical parts from a string except for macrons.
85
+ * Example: 'Thēse͡us' will become 'Thēseus'
86
+ * @param str string containing diactricial characters
87
+ * @returns string with all diactricial marks except macrons removed
88
+ */
89
+ export function remove_diacritical(str) {
90
+ const noDias = str
91
+ .normalize("NFD")
92
+ .replace(/[\u0300-\u0303\u0305-\u036F]/g, "")
93
+ .normalize("NFC");
94
+ return noDias;
95
+ }
96
+ /**
97
+ * Given a word and an ending, returns the base part of the word excluding the ending.
98
+ * The given ending can be a RegEx with a capture group - in that case, the first group will be returned.
99
+ * @param lemma word to extract the base from
100
+ * @param ending ending to remove, can be a RegEx
101
+ * @returns
102
+ */
103
+ export function extract_base(lemma, ending) {
104
+ let regex;
105
+ if (ending.includes("(")) {
106
+ regex = ending;
107
+ }
108
+ else {
109
+ regex = `^(.*)${ending}$`;
110
+ }
111
+ const match = lemma.match(new RegExp(regex));
112
+ if (match) {
113
+ return match[1];
114
+ }
115
+ return undefined;
116
+ }
117
+ /**
118
+ * Checks if two one-dimensional arrays are equal.
119
+ * @param a array a
120
+ * @param b array b
121
+ * @returns true if the arrays are equal
122
+ */
123
+ export function array_equals(a, b) {
124
+ if ((!a && b) || (a && !b)) {
125
+ return false;
126
+ }
127
+ if (!a || !b) {
128
+ return true;
129
+ }
130
+ return (a.length == b.length) && a.every((x, i) => b[i] == x);
131
+ }
132
+ /**
133
+ * Check if a value is a value of a given enum
134
+ * @param enumType pass the enum type as value
135
+ * @param val the value to check
136
+ * @returns whether the value is part of the enum values
137
+ */
138
+ export function is_enum_value(enumType, val) {
139
+ for (const key in enumType) {
140
+ if (enumType[key] === val) {
141
+ return true;
142
+ }
143
+ }
144
+ return false;
145
+ }