bgmt 0.1.3 → 0.2.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/dist/cdn.d.mts +1 -1
- package/dist/cdn.mjs +1 -2
- package/dist/index.d.mts +7 -3813
- package/dist/index.mjs +71 -28
- package/package.json +13 -21
- package/dist/cdn.cjs +0 -25
- package/dist/cdn.d.cts +0 -32
- package/dist/index.cjs +0 -125
- package/dist/index.d.cts +0 -3848
- package/dist/types-qUxe1mrZ.d.cts +0 -31
- /package/dist/{types-CDKF8vJi.d.mts → types-B_6x1YN9.d.mts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { fullToHalf, tradToSimple } from "simptrad";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/tags.ts
|
|
4
3
|
const MERGE_TAGS = [
|
|
5
4
|
["漫改", "漫画改"],
|
|
@@ -47,40 +46,86 @@ function mergeSimpleTags(tags) {
|
|
|
47
46
|
count: v
|
|
48
47
|
}));
|
|
49
48
|
}
|
|
50
|
-
|
|
51
49
|
//#endregion
|
|
52
50
|
//#region src/utils/season.ts
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const digits = {
|
|
52
|
+
零: 0,
|
|
53
|
+
一: 1,
|
|
54
|
+
二: 2,
|
|
55
|
+
三: 3,
|
|
56
|
+
四: 4,
|
|
57
|
+
五: 5,
|
|
58
|
+
六: 6,
|
|
59
|
+
七: 7,
|
|
60
|
+
八: 8,
|
|
61
|
+
九: 9
|
|
62
|
+
};
|
|
63
|
+
const seasonMatchers = [
|
|
64
|
+
{
|
|
65
|
+
re: /(?:S|Season|season)\s?(\d+)$/,
|
|
66
|
+
parse: (match) => +match[1]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
re: /(\d+)(?:st|nd|rd|th) Season$/,
|
|
70
|
+
parse: (match) => +match[1]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
re: /第?(\d+)(?:季|期|部分)$/,
|
|
74
|
+
parse: (match) => +match[1]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
re: /第?([零一二三四五六七八九]?十[零一二三四五六七八九]?|[零一二三四五六七八九])(?:季|期|部分)$/,
|
|
78
|
+
parse: (match) => parseChineseNumber(match[1])
|
|
79
|
+
}
|
|
59
80
|
];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
const extraMatchers = [/\((?:19|20)\d{2}\)$/];
|
|
82
|
+
function parseChineseNumber(value) {
|
|
83
|
+
if (!value.includes("十")) return digits[value];
|
|
84
|
+
const [tensRaw, onesRaw] = value.split("十");
|
|
85
|
+
const tens = tensRaw ? digits[tensRaw] : 1;
|
|
86
|
+
const ones = onesRaw ? digits[onesRaw] : 0;
|
|
87
|
+
return tens * 10 + ones;
|
|
88
|
+
}
|
|
89
|
+
function trimTitle(title) {
|
|
90
|
+
for (const matcher of seasonMatchers) {
|
|
91
|
+
const match = matcher.re.exec(title);
|
|
92
|
+
if (match) return {
|
|
93
|
+
value: title.slice(0, title.length - match[0].length).trimEnd(),
|
|
94
|
+
changed: true,
|
|
95
|
+
season: match[0],
|
|
96
|
+
seasonNumber: matcher.parse(match)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
for (const re of extraMatchers) {
|
|
100
|
+
const match = re.exec(title);
|
|
101
|
+
if (match) return {
|
|
102
|
+
value: title.slice(0, title.length - match[0].length).trimEnd(),
|
|
103
|
+
changed: true
|
|
104
|
+
};
|
|
70
105
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
return {
|
|
107
|
+
value: void 0,
|
|
108
|
+
changed: false
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function trimSeason(bgm) {
|
|
112
|
+
const nameResult = trimTitle(bgm.name);
|
|
113
|
+
const aliasResults = bgm.alias.map(trimTitle);
|
|
114
|
+
const original = [...new Set([...aliasResults, nameResult].map((item) => item.value).filter(Boolean))].sort();
|
|
115
|
+
if (original.length === bgm.alias.length && !nameResult.changed && aliasResults.every((item) => !item.changed)) return {
|
|
75
116
|
name: bgm.name,
|
|
76
|
-
original: void 0
|
|
117
|
+
original: void 0,
|
|
118
|
+
season: void 0,
|
|
119
|
+
seasonNumber: void 0
|
|
77
120
|
};
|
|
121
|
+
const seasonResult = nameResult.season ? nameResult : aliasResults.find((item) => item.season);
|
|
78
122
|
return {
|
|
79
123
|
name: bgm.name,
|
|
80
|
-
original
|
|
124
|
+
original,
|
|
125
|
+
season: seasonResult?.season,
|
|
126
|
+
seasonNumber: seasonResult?.seasonNumber
|
|
81
127
|
};
|
|
82
128
|
}
|
|
83
|
-
|
|
84
129
|
//#endregion
|
|
85
130
|
//#region src/utils/title.ts
|
|
86
131
|
function normalizeTitle(t) {
|
|
@@ -107,13 +152,11 @@ function getSubjectAlias(subject) {
|
|
|
107
152
|
function decodeSubjectTitle(name) {
|
|
108
153
|
return name.replace(/"/g, "\"").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
109
154
|
}
|
|
110
|
-
|
|
111
155
|
//#endregion
|
|
112
156
|
//#region src/utils/summary.ts
|
|
113
157
|
function normalizeSummary(text) {
|
|
114
158
|
if (!text) return "";
|
|
115
159
|
return text.trim().replace(/\u2028|\r\n/g, "\n");
|
|
116
160
|
}
|
|
117
|
-
|
|
118
161
|
//#endregion
|
|
119
|
-
export { decodeSubjectTitle, getSubjectAlias, getSubjectDisplayName, normalizeSummary, normalizeTags, normalizeTitle, trimSeason };
|
|
162
|
+
export { decodeSubjectTitle, getSubjectAlias, getSubjectDisplayName, normalizeSummary, normalizeTags, normalizeTitle, trimSeason };
|
package/package.json
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bgmt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Bangumi Data Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bangumi",
|
|
7
7
|
"bgm"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://github.com/yjl9903/
|
|
9
|
+
"homepage": "https://github.com/yjl9903/bgmx#readme",
|
|
10
10
|
"bugs": {
|
|
11
|
-
"url": "https://github.com/yjl9903/
|
|
11
|
+
"url": "https://github.com/yjl9903/bgmx/issues"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/yjl9903/
|
|
15
|
+
"url": "git+https://github.com/yjl9903/bgmx.git"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"author": "XLor",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
|
-
".":
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"require": "./dist/index.cjs"
|
|
26
|
-
},
|
|
27
|
-
"./cdn": {
|
|
28
|
-
"types": "./dist/cdn.d.ts",
|
|
29
|
-
"import": "./dist/cdn.mjs",
|
|
30
|
-
"require": "./dist/cdn.cjs"
|
|
31
|
-
}
|
|
22
|
+
".": "./dist/index.mjs",
|
|
23
|
+
"./cdn": "./dist/cdn.mjs",
|
|
24
|
+
"./package.json": "./package.json"
|
|
32
25
|
},
|
|
33
|
-
"
|
|
34
|
-
"module": "dist/index.mjs",
|
|
35
|
-
"types": "dist/index.d.ts",
|
|
26
|
+
"types": "dist/index.d.mts",
|
|
36
27
|
"typesVersions": {
|
|
37
28
|
"*": {
|
|
38
29
|
"*": [
|
|
@@ -46,19 +37,20 @@
|
|
|
46
37
|
],
|
|
47
38
|
"dependencies": {
|
|
48
39
|
"simptrad": "^0.2.0",
|
|
49
|
-
"bgmc": "0.0
|
|
40
|
+
"bgmc": "0.3.0"
|
|
50
41
|
},
|
|
51
42
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
43
|
+
"node": ">=v24.0.0"
|
|
53
44
|
},
|
|
54
45
|
"release-it": {
|
|
55
46
|
"git": {
|
|
56
47
|
"commitMessage": "chore(bgmt): release v${version}",
|
|
57
|
-
"tag":
|
|
48
|
+
"tag": true,
|
|
49
|
+
"tagName": "${npm.name}@${version}",
|
|
58
50
|
"push": true
|
|
59
51
|
},
|
|
60
52
|
"npm": {
|
|
61
|
-
"publish":
|
|
53
|
+
"publish": false
|
|
62
54
|
},
|
|
63
55
|
"hooks": {
|
|
64
56
|
"after:version": "pnpm run build",
|
package/dist/cdn.cjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/cdn/index.ts
|
|
3
|
-
async function fetchBasicSubjects(options = {}) {
|
|
4
|
-
const { version = "0", baseURL = "https://unpkg.com" } = options;
|
|
5
|
-
const resp = await fetch(`${baseURL}/bgmd@${version}/dist/index.json`);
|
|
6
|
-
if (!resp.ok) throw new Error(`Fetch bgmd index.json failed`, { cause: resp });
|
|
7
|
-
return await resp.json();
|
|
8
|
-
}
|
|
9
|
-
async function fetchFullSubjects(options = {}) {
|
|
10
|
-
const { version = "0", baseURL = "https://unpkg.com" } = options;
|
|
11
|
-
const resp = await fetch(`${baseURL}/bgmd@${version}/dist/full.json`);
|
|
12
|
-
if (!resp.ok) throw new Error(`Fetch bgmd full.json failed`, { cause: resp });
|
|
13
|
-
return await resp.json();
|
|
14
|
-
}
|
|
15
|
-
async function fetchCalendarSubjects(options = {}) {
|
|
16
|
-
const { version = "0", baseURL = "https://unpkg.com" } = options;
|
|
17
|
-
const resp = await fetch(`${baseURL}/bgmd@${version}/dist/calendar.json`);
|
|
18
|
-
if (!resp.ok) throw new Error(`Fetch bgmd calendar.json failed`, { cause: resp });
|
|
19
|
-
return await resp.json();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.fetchBasicSubjects = fetchBasicSubjects;
|
|
24
|
-
exports.fetchCalendarSubjects = fetchCalendarSubjects;
|
|
25
|
-
exports.fetchFullSubjects = fetchFullSubjects;
|
package/dist/cdn.d.cts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { a as SubjectSearch, i as SubjectRating, n as FullSubject, r as SubjectImage, t as BasicSubject } from "./types-qUxe1mrZ.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/cdn/index.d.ts
|
|
4
|
-
interface CdnOptions {
|
|
5
|
-
/**
|
|
6
|
-
* bgmd version
|
|
7
|
-
*
|
|
8
|
-
* @default '0'
|
|
9
|
-
*/
|
|
10
|
-
version?: string;
|
|
11
|
-
/**
|
|
12
|
-
* cdn base URL
|
|
13
|
-
*
|
|
14
|
-
* @default 'https://unpkg.com'
|
|
15
|
-
*/
|
|
16
|
-
baseURL?: string;
|
|
17
|
-
}
|
|
18
|
-
declare function fetchBasicSubjects(options?: CdnOptions): Promise<{
|
|
19
|
-
version: string;
|
|
20
|
-
subjects: BasicSubject[];
|
|
21
|
-
}>;
|
|
22
|
-
declare function fetchFullSubjects(options?: CdnOptions): Promise<{
|
|
23
|
-
version: string;
|
|
24
|
-
subjects: FullSubject[];
|
|
25
|
-
}>;
|
|
26
|
-
declare function fetchCalendarSubjects(options?: CdnOptions): Promise<{
|
|
27
|
-
version: string;
|
|
28
|
-
calendar: [BasicSubject[], BasicSubject[], BasicSubject[], BasicSubject[], BasicSubject[], BasicSubject[], BasicSubject[]];
|
|
29
|
-
web: BasicSubject[];
|
|
30
|
-
}>;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { BasicSubject, CdnOptions, FullSubject, SubjectImage, SubjectRating, SubjectSearch, fetchBasicSubjects, fetchCalendarSubjects, fetchFullSubjects };
|
package/dist/index.cjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
let simptrad = require("simptrad");
|
|
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
|
-
]);
|
|
16
|
-
function normalizeTags(tags, options = {}) {
|
|
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();
|
|
19
|
-
}
|
|
20
|
-
function mergeSimpleTags(tags) {
|
|
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 = (0, simptrad.fullToHalf)((0, simptrad.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
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/utils/season.ts
|
|
53
|
-
const REs = [
|
|
54
|
-
/(?:S|Season|season\s?)(\d+)$/,
|
|
55
|
-
/(1st|2nd|3rd|[456789]th) Season$/,
|
|
56
|
-
/第?(\d+)[季期]$/,
|
|
57
|
-
/第?((?:[零一二三四五六七八九]十|十)?[零一二三四五六七八九])[季期]$/,
|
|
58
|
-
/\((?:19|20)\d{2}\)$/
|
|
59
|
-
];
|
|
60
|
-
function trimSeason(bgm) {
|
|
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 (0, simptrad.fullToHalf)((0, simptrad.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(/"/g, "\"").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/utils/summary.ts
|
|
113
|
-
function normalizeSummary(text) {
|
|
114
|
-
if (!text) return "";
|
|
115
|
-
return text.trim().replace(/\u2028|\r\n/g, "\n");
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
exports.decodeSubjectTitle = decodeSubjectTitle;
|
|
120
|
-
exports.getSubjectAlias = getSubjectAlias;
|
|
121
|
-
exports.getSubjectDisplayName = getSubjectDisplayName;
|
|
122
|
-
exports.normalizeSummary = normalizeSummary;
|
|
123
|
-
exports.normalizeTags = normalizeTags;
|
|
124
|
-
exports.normalizeTitle = normalizeTitle;
|
|
125
|
-
exports.trimSeason = trimSeason;
|