@kecan0406/aninames 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +90 -2
- package/lib/client/chunks.d.ts +26 -0
- package/lib/client/chunks.js +121 -0
- package/lib/client/engine.d.ts +20 -0
- package/lib/client/engine.js +244 -0
- package/lib/client/format.d.ts +74 -0
- package/lib/client/format.js +212 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +2 -0
- package/lib/client/names.d.ts +37 -0
- package/lib/client/names.js +202 -0
- package/lib/client/order.d.ts +1 -0
- package/lib/client/order.js +13 -0
- package/lib/client/source.d.ts +14 -0
- package/lib/client/source.js +180 -0
- package/lib/match.d.ts +9 -0
- package/lib/match.js +58 -0
- package/lib/model.d.ts +34 -0
- package/lib/model.js +5 -0
- package/lib/text.d.ts +24 -0
- package/lib/text.js +611 -0
- package/package.json +34 -4
package/lib/match.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { convertHangulToQwerty, convertQwertyToHangul } from 'es-hangul';
|
|
2
|
+
export const TOP = '\u{10FFFF}';
|
|
3
|
+
const NAME_WEIGHT = {
|
|
4
|
+
main: 1,
|
|
5
|
+
official: 1,
|
|
6
|
+
reading: 1,
|
|
7
|
+
synonym: 0.95,
|
|
8
|
+
short: 0.95,
|
|
9
|
+
redirect: 0.92,
|
|
10
|
+
section: 0.6,
|
|
11
|
+
generated: 0.85,
|
|
12
|
+
};
|
|
13
|
+
const WEAK = new Set(['synonym', 'short', 'redirect', 'section']);
|
|
14
|
+
export function weightOf(row) {
|
|
15
|
+
return NAME_WEIGHT[row.kind] * (row.variant ? 0.9 : 1) * (row.support <= 1 && WEAK.has(row.kind) ? 0.93 : 1);
|
|
16
|
+
}
|
|
17
|
+
const INITIAL_JAMO = 'ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ';
|
|
18
|
+
export function typing(q) {
|
|
19
|
+
const ranges = [[q, `${q}${TOP}`]];
|
|
20
|
+
const chars = [...q];
|
|
21
|
+
const last = chars.at(-1) ?? '';
|
|
22
|
+
const head = chars.slice(0, -1).join('');
|
|
23
|
+
const code = (last.codePointAt(0) ?? 0) - 0xac00;
|
|
24
|
+
if (code >= 0 && code < 11172 && code % 28 === 0) {
|
|
25
|
+
ranges.push([
|
|
26
|
+
`${head}${String.fromCodePoint(0xac00 + code + 1)}`,
|
|
27
|
+
`${head}${String.fromCodePoint(0xac00 + code + 27)}${TOP}`,
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
const conjoined = (last.codePointAt(0) ?? 0) - 0x1100;
|
|
31
|
+
const initial = conjoined >= 0 && conjoined < 19 ? conjoined : INITIAL_JAMO.indexOf(last);
|
|
32
|
+
if (initial >= 0 && head) {
|
|
33
|
+
ranges.push([
|
|
34
|
+
`${head}${String.fromCodePoint(0xac00 + initial * 588)}`,
|
|
35
|
+
`${head}${String.fromCodePoint(0xac00 + initial * 588 + 587)}${TOP}`,
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
const kana = /^([\p{Script=Hiragana}\p{Script=Katakana}ー]+)[a-z]+$/u.exec(q)?.[1];
|
|
39
|
+
if (kana)
|
|
40
|
+
ranges.push([kana, `${kana}${TOP}`]);
|
|
41
|
+
return ranges;
|
|
42
|
+
}
|
|
43
|
+
export function swapLayout(query) {
|
|
44
|
+
const text = query.trim();
|
|
45
|
+
try {
|
|
46
|
+
if (/[a-z]/i.test(text) && !/[\p{Script=Hangul}\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(text)) {
|
|
47
|
+
const hangul = text.replace(/[a-z]+/gi, (run) => convertQwertyToHangul(run));
|
|
48
|
+
return /[ㄱ-ㅎㅏ-ㅣ]/.test(hangul) || !/\p{Script=Hangul}/u.test(hangul) ? undefined : hangul;
|
|
49
|
+
}
|
|
50
|
+
if (/\p{Script=Hangul}/u.test(text) && !/[a-z\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/iu.test(text)) {
|
|
51
|
+
return text.replace(/[\p{Script=Hangul}]+/gu, (run) => convertHangulToQwerty(run)).toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
package/lib/model.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type Kind = 'work' | 'character';
|
|
2
|
+
export type Layer = 'core' | 'kowiki' | 'unlicensed';
|
|
3
|
+
export declare const LAYERS: readonly Layer[];
|
|
4
|
+
export declare const USER_AGENT = "aninames/0.1 (+https://github.com/kecan0406/aninames)";
|
|
5
|
+
export type NameKind = 'main' | 'official' | 'synonym' | 'short' | 'reading' | 'redirect' | 'section' | 'generated';
|
|
6
|
+
export type Namespace = 'wikidata' | 'mal' | 'anilist' | 'anidb' | 'kitsu' | 'ann' | 'animeplanet' | 'anisearch' | 'livechart' | 'simkl' | 'animecountdown' | 'vndb' | 'bangumi' | 'danbooru' | 'kowiki' | 'anissia';
|
|
7
|
+
export type Ref = `${Namespace}:${string}`;
|
|
8
|
+
export interface Name {
|
|
9
|
+
text: string;
|
|
10
|
+
lang?: string;
|
|
11
|
+
kind: NameKind;
|
|
12
|
+
}
|
|
13
|
+
export interface Entry {
|
|
14
|
+
id: Ref;
|
|
15
|
+
kind?: Kind;
|
|
16
|
+
attach?: boolean;
|
|
17
|
+
refs?: Ref[];
|
|
18
|
+
names: Name[];
|
|
19
|
+
works?: Ref[];
|
|
20
|
+
related?: Ref[];
|
|
21
|
+
link?: string[];
|
|
22
|
+
rank?: number;
|
|
23
|
+
adult?: boolean;
|
|
24
|
+
type?: string;
|
|
25
|
+
year?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface Source {
|
|
28
|
+
name: string;
|
|
29
|
+
layer: Layer;
|
|
30
|
+
license: string;
|
|
31
|
+
fetch(raw: string): Promise<void>;
|
|
32
|
+
stage(raw: string): AsyncIterable<Entry> | Iterable<Entry>;
|
|
33
|
+
}
|
|
34
|
+
export declare function ref(ns: Namespace, id: string | number): Ref;
|
package/lib/model.js
ADDED
package/lib/text.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function toHiragana(text: string): string;
|
|
2
|
+
export declare function isKana(text: string): boolean;
|
|
3
|
+
export declare function hasHangul(text: string): boolean;
|
|
4
|
+
export declare function hasKanji(text: string): boolean;
|
|
5
|
+
export declare function kanaToRomaji(kana: string): string;
|
|
6
|
+
export declare function hangulToLatin(text: string): string;
|
|
7
|
+
export declare function foldLatin(text: string): string;
|
|
8
|
+
export declare function soundKeys(text: string): string[];
|
|
9
|
+
export declare function flat(text: string): string;
|
|
10
|
+
export declare function latinKey(text: string): string;
|
|
11
|
+
export declare function partKey(token: string): string;
|
|
12
|
+
export declare function qualifiers(text: string): {
|
|
13
|
+
base: string;
|
|
14
|
+
quals: string[];
|
|
15
|
+
};
|
|
16
|
+
type HangulStyle = 'standard' | 'fan' | 'fan-long';
|
|
17
|
+
export declare function kanaToHangul(kana: string, style: HangulStyle): string;
|
|
18
|
+
export declare function initials(text: string): string;
|
|
19
|
+
export declare function editDistance(a: string, b: string, limit: number): number;
|
|
20
|
+
export declare function hangulForms(kana: string): {
|
|
21
|
+
text: string;
|
|
22
|
+
preferred: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
export {};
|