bgmt 0.1.0 → 0.1.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.
package/dist/index.mjs CHANGED
@@ -1,56 +1,119 @@
1
- import { fullToHalf, tradToSimple } from 'simptrad';
1
+ import { fullToHalf, tradToSimple } from "simptrad";
2
2
 
3
+ //#region src/utils/tags.ts
4
+ const MERGE_TAGS = [
5
+ ["漫改", "漫画改"],
6
+ ["轻改", "轻小说改"],
7
+ ["东映アニメーション", "东映动画"],
8
+ ["TV", "TVA"]
9
+ ];
10
+ const REMOVE_TAGS = new Set([
11
+ "未定档",
12
+ "未确定",
13
+ "日本",
14
+ "日本动画"
15
+ ]);
3
16
  function normalizeTags(tags, options = {}) {
4
- const merged = mergeSimpleTags(tags);
5
- const reliable = options.count ? merged.filter((t) => t.count >= options.count) : merged;
6
- return reliable.map((t) => t.name).sort();
17
+ const merged = mergeSimpleTags(tags.filter((t) => !REMOVE_TAGS.has(t.name)));
18
+ return (options.count ? merged.filter((t) => t.count >= options.count) : merged).map((t) => t.name).sort();
7
19
  }
8
20
  function mergeSimpleTags(tags) {
9
- const map = /* @__PURE__ */ new Map();
10
- for (const t of tags) {
11
- const name = fullToHalf(tradToSimple(t.name), { punctuation: true });
12
- map.set(name, (map.get(name) ?? 0) + t.count);
13
- }
14
- return [...map.entries()].map(([k, v]) => ({ name: k, count: v }));
21
+ const map = /* @__PURE__ */ new Map();
22
+ for (const t of tags) {
23
+ if (/(19|20)\d{2}(春|夏|秋|冬)/.test(t.name)) {
24
+ if (t.name.includes("春")) t.name = t.name.replace("春", "年4月");
25
+ else if (t.name.includes("夏")) t.name = t.name.replace("夏", "年7月");
26
+ else if (t.name.includes("秋")) t.name = t.name.replace("秋", "年10月");
27
+ else if (t.name.includes("冬")) t.name = t.name.replace("冬", "年1月");
28
+ }
29
+ if (/(19|20)\d{2}年(春|夏|秋|冬)/.test(t.name)) {
30
+ if (t.name.includes("春")) t.name = t.name.replace("春", "4月");
31
+ else if (t.name.includes("夏")) t.name = t.name.replace("夏", "7月");
32
+ else if (t.name.includes("秋")) t.name = t.name.replace("秋", "10月");
33
+ else if (t.name.includes("冬")) t.name = t.name.replace("冬", "1月");
34
+ }
35
+ if (/(19|20)\d{2}?|\d{1,2}月/.test(t.name)) {
36
+ let target = t.name;
37
+ for (const tt of tags) if (tt.name.indexOf(t.name) !== -1 && tt.name.length > target.length) target = tt.name;
38
+ t.name = target;
39
+ }
40
+ const name0 = t.name;
41
+ const name1 = fullToHalf(tradToSimple(name0), { punctuation: true });
42
+ const name = MERGE_TAGS.find((arr) => arr.includes(name1))?.[0] ?? name1;
43
+ map.set(name, (map.get(name) ?? 0) + t.count);
44
+ }
45
+ return [...map.entries()].map(([k, v]) => ({
46
+ name: k,
47
+ count: v
48
+ }));
15
49
  }
16
50
 
51
+ //#endregion
52
+ //#region src/utils/season.ts
17
53
  const REs = [
18
- /(?:S|Season|season\s?)(\d+)$/,
19
- /(1st|2nd|3rd|[456789]th) Season$/,
20
- /第?(\d+)[季期]$/,
21
- /第?((?:[零一二三四五六七八九]十|十)?[零一二三四五六七八九])[季期]$/,
22
- /\((?:19|20)\d{2}\)$/
54
+ /(?:S|Season|season\s?)(\d+)$/,
55
+ /(1st|2nd|3rd|[456789]th) Season$/,
56
+ /第?(\d+)[季期]$/,
57
+ /第?((?:[零一二三四五六七八九]十|十)?[零一二三四五六七八九])[季期]$/,
58
+ /\((?:19|20)\d{2}\)$/
23
59
  ];
24
60
  function trimSeason(bgm) {
25
- let changed = false;
26
- function trim(t) {
27
- for (const RE of REs) {
28
- const match = RE.exec(t);
29
- if (match) {
30
- changed = true;
31
- return t.slice(0, t.length - match[0].length).trimEnd();
32
- }
33
- }
34
- }
35
- const trimmed = bgm.alias.map(trim);
36
- trimmed.push(trim(bgm.name));
37
- const original = [...new Set(trimmed.filter(Boolean))].sort();
38
- if (original.length === bgm.alias.length && !changed) {
39
- return {
40
- name: bgm.name,
41
- original: void 0
42
- };
43
- }
44
- return {
45
- name: bgm.name,
46
- original
47
- };
61
+ let changed = false;
62
+ function trim(t) {
63
+ for (const RE of REs) {
64
+ const match = RE.exec(t);
65
+ if (match) {
66
+ changed = true;
67
+ return t.slice(0, t.length - match[0].length).trimEnd();
68
+ }
69
+ }
70
+ }
71
+ const trimmed = bgm.alias.map(trim);
72
+ trimmed.push(trim(bgm.name));
73
+ const original = [...new Set(trimmed.filter(Boolean))].sort();
74
+ if (original.length === bgm.alias.length && !changed) return {
75
+ name: bgm.name,
76
+ original: void 0
77
+ };
78
+ return {
79
+ name: bgm.name,
80
+ original
81
+ };
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/utils/title.ts
86
+ function normalizeTitle(t) {
87
+ return fullToHalf(tradToSimple(t), { punctuation: true });
88
+ }
89
+ function getSubjectDisplayName(bgm) {
90
+ return bgm?.name_cn || bgm?.name || "";
91
+ }
92
+ function getSubjectInfoboxArray(infobox) {
93
+ return Array.isArray(infobox?.value) ? infobox?.value.map((v) => v?.v).filter(Boolean) ?? [] : typeof infobox?.value === "string" ? [infobox.value] : [];
94
+ }
95
+ function getSubjectAlias(subject) {
96
+ const translations = (subject.infobox?.filter((box) => [
97
+ "别名",
98
+ "中文名",
99
+ "英文名"
100
+ ].includes(box.key)) ?? [])?.flatMap((box) => getSubjectInfoboxArray(box)) ?? [];
101
+ return [...new Set([
102
+ subject.name,
103
+ subject.name_cn,
104
+ ...translations
105
+ ].filter(Boolean).map(decodeSubjectTitle))].sort();
106
+ }
107
+ function decodeSubjectTitle(name) {
108
+ return name.replace(/&quot;/g, "\"").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
48
109
  }
49
110
 
111
+ //#endregion
112
+ //#region src/utils/summary.ts
50
113
  function normalizeSummary(text) {
51
- if (!text) return "";
52
- const t = text.trim().replace(/\u2028|\r\n/g, "\n");
53
- return t;
114
+ if (!text) return "";
115
+ return text.trim().replace(/\u2028|\r\n/g, "\n");
54
116
  }
55
117
 
56
- export { normalizeSummary, normalizeTags, trimSeason };
118
+ //#endregion
119
+ export { decodeSubjectTitle, getSubjectAlias, getSubjectDisplayName, normalizeSummary, normalizeTags, normalizeTitle, trimSeason };
@@ -0,0 +1,31 @@
1
+ //#region src/types.d.ts
2
+ type SubjectRating = {
3
+ score: number;
4
+ rank: number;
5
+ };
6
+ type SubjectImage = {
7
+ provider: 'bgm' | 'tmdb';
8
+ quality: string;
9
+ src: string;
10
+ };
11
+ type SubjectSearch = {
12
+ include: string[];
13
+ exclude?: string[] | null | undefined;
14
+ };
15
+ type BasicSubject = {
16
+ id: number;
17
+ title: string;
18
+ platform: string;
19
+ onair_date?: string | null | undefined;
20
+ rating: SubjectRating;
21
+ poster: string;
22
+ tags: string[];
23
+ search: SubjectSearch;
24
+ };
25
+ type FullSubject = BasicSubject & {
26
+ summary: string;
27
+ alias: string[];
28
+ images: SubjectImage[];
29
+ };
30
+ //#endregion
31
+ export { SubjectSearch as a, SubjectRating as i, FullSubject as n, SubjectImage as r, BasicSubject as t };
@@ -0,0 +1,31 @@
1
+ //#region src/types.d.ts
2
+ type SubjectRating = {
3
+ score: number;
4
+ rank: number;
5
+ };
6
+ type SubjectImage = {
7
+ provider: 'bgm' | 'tmdb';
8
+ quality: string;
9
+ src: string;
10
+ };
11
+ type SubjectSearch = {
12
+ include: string[];
13
+ exclude?: string[] | null | undefined;
14
+ };
15
+ type BasicSubject = {
16
+ id: number;
17
+ title: string;
18
+ platform: string;
19
+ onair_date?: string | null | undefined;
20
+ rating: SubjectRating;
21
+ poster: string;
22
+ tags: string[];
23
+ search: SubjectSearch;
24
+ };
25
+ type FullSubject = BasicSubject & {
26
+ summary: string;
27
+ alias: string[];
28
+ images: SubjectImage[];
29
+ };
30
+ //#endregion
31
+ export { SubjectSearch as a, SubjectRating as i, FullSubject as n, SubjectImage as r, BasicSubject as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bgmt",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Bangumi Data Toolkit",
5
5
  "keywords": [
6
6
  "bangumi",
@@ -20,9 +20,14 @@
20
20
  "type": "module",
21
21
  "exports": {
22
22
  ".": {
23
- "require": "./dist/index.cjs",
23
+ "types": "./dist/index.d.ts",
24
24
  "import": "./dist/index.mjs",
25
- "types": "./dist/index.d.ts"
25
+ "require": "./dist/index.cjs"
26
+ },
27
+ "./cdn": {
28
+ "types": "./dist/cdn.d.ts",
29
+ "import": "./dist/cdn.mjs",
30
+ "require": "./dist/cdn.cjs"
26
31
  }
27
32
  },
28
33
  "main": "dist/index.cjs",
@@ -41,7 +46,7 @@
41
46
  ],
42
47
  "dependencies": {
43
48
  "simptrad": "^0.2.0",
44
- "bgmc": "0.0.10"
49
+ "bgmc": "0.0.12"
45
50
  },
46
51
  "engines": {
47
52
  "node": ">=v20.8.0"
@@ -61,8 +66,8 @@
61
66
  }
62
67
  },
63
68
  "scripts": {
64
- "build": "unbuild",
65
- "format": "prettier --write src/**/*.ts test/**/*.ts",
69
+ "build": "tsdown",
70
+ "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
66
71
  "release": "release-it",
67
72
  "test": "vitest",
68
73
  "test:ci": "vitest --run",
package/dist/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- interface Tag {
2
- name: string;
3
- count: number;
4
- }
5
- interface NormalizeTagsOptions {
6
- /**
7
- * @default 0
8
- */
9
- count?: number;
10
- }
11
- declare function normalizeTags(tags: Tag[], options?: NormalizeTagsOptions): string[];
12
-
13
- declare function trimSeason(bgm: {
14
- name: string;
15
- alias: string[];
16
- }): {
17
- name: string;
18
- original: undefined;
19
- } | {
20
- name: string;
21
- original: string[];
22
- };
23
-
24
- declare function normalizeSummary(text: string): string;
25
-
26
- export { type NormalizeTagsOptions, type Tag, normalizeSummary, normalizeTags, trimSeason };