bgmt 0.0.11 → 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/dist/index.cjs CHANGED
@@ -1,5 +1,60 @@
1
1
  'use strict';
2
2
 
3
- const hello = 1;
3
+ const simptrad = require('simptrad');
4
4
 
5
- exports.hello = hello;
5
+ function normalizeTags(tags, options = {}) {
6
+ const merged = mergeSimpleTags(tags);
7
+ const reliable = options.count ? merged.filter((t) => t.count >= options.count) : merged;
8
+ return reliable.map((t) => t.name).sort();
9
+ }
10
+ function mergeSimpleTags(tags) {
11
+ const map = /* @__PURE__ */ new Map();
12
+ for (const t of tags) {
13
+ const name = simptrad.fullToHalf(simptrad.tradToSimple(t.name), { punctuation: true });
14
+ map.set(name, (map.get(name) ?? 0) + t.count);
15
+ }
16
+ return [...map.entries()].map(([k, v]) => ({ name: k, count: v }));
17
+ }
18
+
19
+ const REs = [
20
+ /(?:S|Season|season\s?)(\d+)$/,
21
+ /(1st|2nd|3rd|[456789]th) Season$/,
22
+ /第?(\d+)[季期]$/,
23
+ /第?((?:[零一二三四五六七八九]十|十)?[零一二三四五六七八九])[季期]$/,
24
+ /\((?:19|20)\d{2}\)$/
25
+ ];
26
+ function trimSeason(bgm) {
27
+ let changed = false;
28
+ function trim(t) {
29
+ for (const RE of REs) {
30
+ const match = RE.exec(t);
31
+ if (match) {
32
+ changed = true;
33
+ return t.slice(0, t.length - match[0].length).trimEnd();
34
+ }
35
+ }
36
+ }
37
+ const trimmed = bgm.alias.map(trim);
38
+ trimmed.push(trim(bgm.name));
39
+ const original = [...new Set(trimmed.filter(Boolean))].sort();
40
+ if (original.length === bgm.alias.length && !changed) {
41
+ return {
42
+ name: bgm.name,
43
+ original: void 0
44
+ };
45
+ }
46
+ return {
47
+ name: bgm.name,
48
+ original
49
+ };
50
+ }
51
+
52
+ function normalizeSummary(text) {
53
+ if (!text) return "";
54
+ const t = text.trim().replace(/\u2028|\r\n/g, "\n");
55
+ return t;
56
+ }
57
+
58
+ exports.normalizeSummary = normalizeSummary;
59
+ exports.normalizeTags = normalizeTags;
60
+ exports.trimSeason = trimSeason;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,26 @@
1
- declare const hello = 1;
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[];
2
12
 
3
- export { hello };
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 };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,26 @@
1
- declare const hello = 1;
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[];
2
12
 
3
- export { hello };
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 };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,26 @@
1
- declare const hello = 1;
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[];
2
12
 
3
- export { hello };
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 };
package/dist/index.mjs CHANGED
@@ -1,3 +1,56 @@
1
- const hello = 1;
1
+ import { fullToHalf, tradToSimple } from 'simptrad';
2
2
 
3
- export { hello };
3
+ 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();
7
+ }
8
+ 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 }));
15
+ }
16
+
17
+ const REs = [
18
+ /(?:S|Season|season\s?)(\d+)$/,
19
+ /(1st|2nd|3rd|[456789]th) Season$/,
20
+ /第?(\d+)[季期]$/,
21
+ /第?((?:[零一二三四五六七八九]十|十)?[零一二三四五六七八九])[季期]$/,
22
+ /\((?:19|20)\d{2}\)$/
23
+ ];
24
+ 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
+ };
48
+ }
49
+
50
+ function normalizeSummary(text) {
51
+ if (!text) return "";
52
+ const t = text.trim().replace(/\u2028|\r\n/g, "\n");
53
+ return t;
54
+ }
55
+
56
+ export { normalizeSummary, normalizeTags, trimSeason };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bgmt",
3
- "version": "0.0.11",
3
+ "version": "0.1.0",
4
4
  "description": "Bangumi Data Toolkit",
5
5
  "keywords": [
6
6
  "bangumi",
@@ -39,8 +39,10 @@
39
39
  "files": [
40
40
  "dist"
41
41
  ],
42
- "dependencies": {},
43
- "devDependencies": {},
42
+ "dependencies": {
43
+ "simptrad": "^0.2.0",
44
+ "bgmc": "0.0.10"
45
+ },
44
46
  "engines": {
45
47
  "node": ">=v20.8.0"
46
48
  },