@dan-uni/dan-any 0.7.3 → 0.7.5

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.js CHANGED
@@ -125,8 +125,8 @@ class id_gen_UniID {
125
125
  return this.fromNull(domain);
126
126
  }
127
127
  }
128
- function createDMID(content = '', senderID = id_gen_UniID.fromNull().toString(), ctime = new Date().toISOString(), extraStr, slice = 8) {
129
- return new jssha('SHA3-256', 'TEXT').update(`${content}|${senderID}|${UniDM.transCtime(ctime).toISOString()}|${extraStr}`).getHash('HEX').slice(0, slice);
128
+ function createDMID(dan, slice = 8) {
129
+ return new jssha('SHA3-256', 'TEXT').update(`${dan.content}|${dan.senderID}|${UniDM.transCtime(dan.ctime).toISOString()}|${dan.extraStr}`).getHash('HEX').slice(0, slice);
130
130
  }
131
131
  function _ts_decorate(decorators, target, key, desc) {
132
132
  var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -301,9 +301,9 @@ class UniDM {
301
301
  }
302
302
  toDMID() {
303
303
  if (false === this.options.dmid) return;
304
- if (true === this.options.dmid) return createDMID(this.content, this.senderID, this.ctime, this.extraStr);
305
- if ('number' == typeof this.options.dmid) return createDMID(this.content, this.senderID, this.ctime, this.extraStr, this.options.dmid);
306
- return this.options.dmid(this.content, this.senderID, this.ctime, this.extraStr);
304
+ if (true === this.options.dmid) return createDMID(this);
305
+ if ('number' == typeof this.options.dmid) return createDMID(this, this.options.dmid);
306
+ return this.options.dmid(this);
307
307
  }
308
308
  isSameAs(dan, options) {
309
309
  if (4 === this.mode || 4 === dan.mode) return false;
@@ -1013,11 +1013,13 @@ class UniPool {
1013
1013
  }));
1014
1014
  }
1015
1015
  dedupe() {
1016
- const map = new Map();
1017
- this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
1018
- this.dans = [
1019
- ...map.values()
1020
- ];
1016
+ if (false !== this.options.dmid) {
1017
+ const map = new Map();
1018
+ this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
1019
+ this.dans = [
1020
+ ...map.values()
1021
+ ];
1022
+ }
1021
1023
  this.options.dedupe = false;
1022
1024
  }
1023
1025
  merge(lifetime = 0) {
@@ -1939,11 +1941,13 @@ class src_UniPool {
1939
1941
  }));
1940
1942
  }
1941
1943
  dedupe() {
1942
- const map = new Map();
1943
- this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
1944
- this.dans = [
1945
- ...map.values()
1946
- ];
1944
+ if (false !== this.options.dmid) {
1945
+ const map = new Map();
1946
+ this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
1947
+ this.dans = [
1948
+ ...map.values()
1949
+ ];
1950
+ }
1947
1951
  this.options.dedupe = false;
1948
1952
  }
1949
1953
  merge(lifetime = 0) {
@@ -23095,8 +23095,8 @@ and limitations under the License.
23095
23095
  return this.fromNull(domain);
23096
23096
  }
23097
23097
  }
23098
- function createDMID(content = '', senderID = id_gen_UniID.fromNull().toString(), ctime = new Date().toISOString(), extraStr, slice = 8) {
23099
- return new ht('SHA3-256', 'TEXT').update(`${content}|${senderID}|${UniDM.transCtime(ctime).toISOString()}|${extraStr}`).getHash('HEX').slice(0, slice);
23098
+ function createDMID(dan, slice = 8) {
23099
+ return new ht('SHA3-256', 'TEXT').update(`${dan.content}|${dan.senderID}|${UniDM.transCtime(dan.ctime).toISOString()}|${dan.extraStr}`).getHash('HEX').slice(0, slice);
23100
23100
  }
23101
23101
  function _ts_decorate(decorators, target, key, desc) {
23102
23102
  var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -23271,9 +23271,9 @@ and limitations under the License.
23271
23271
  }
23272
23272
  toDMID() {
23273
23273
  if (false === this.options.dmid) return;
23274
- if (true === this.options.dmid) return createDMID(this.content, this.senderID, this.ctime, this.extraStr);
23275
- if ('number' == typeof this.options.dmid) return createDMID(this.content, this.senderID, this.ctime, this.extraStr, this.options.dmid);
23276
- return this.options.dmid(this.content, this.senderID, this.ctime, this.extraStr);
23274
+ if (true === this.options.dmid) return createDMID(this);
23275
+ if ('number' == typeof this.options.dmid) return createDMID(this, this.options.dmid);
23276
+ return this.options.dmid(this);
23277
23277
  }
23278
23278
  isSameAs(dan, options) {
23279
23279
  if (4 === this.mode || 4 === dan.mode) return false;
@@ -23984,11 +23984,13 @@ and limitations under the License.
23984
23984
  }));
23985
23985
  }
23986
23986
  dedupe() {
23987
- const map = new Map();
23988
- this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
23989
- this.dans = [
23990
- ...map.values()
23991
- ];
23987
+ if (false !== this.options.dmid) {
23988
+ const map = new Map();
23989
+ this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
23990
+ this.dans = [
23991
+ ...map.values()
23992
+ ];
23993
+ }
23992
23994
  this.options.dedupe = false;
23993
23995
  }
23994
23996
  merge(lifetime = 0) {
@@ -24915,11 +24917,13 @@ and limitations under the License.
24915
24917
  }));
24916
24918
  }
24917
24919
  dedupe() {
24918
- const map = new Map();
24919
- this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
24920
- this.dans = [
24921
- ...map.values()
24922
- ];
24920
+ if (false !== this.options.dmid) {
24921
+ const map = new Map();
24922
+ this.dans.forEach((d)=>map.set(d.DMID || d.toDMID(), d));
24923
+ this.dans = [
24924
+ ...map.values()
24925
+ ];
24926
+ }
24923
24927
  this.options.dedupe = false;
24924
24928
  }
24925
24929
  merge(lifetime = 0) {
@@ -1,5 +1,5 @@
1
- import type { ctime } from './dm-gen';
2
1
  import type { PlatformSource } from './platform';
2
+ import { UniDM } from './dm-gen';
3
3
  export declare class UniID {
4
4
  /**
5
5
  * @description 每个domain下应为唯一值
@@ -46,5 +46,5 @@ export declare class UniID {
46
46
  */
47
47
  domain: PlatformSource | string): UniID;
48
48
  }
49
- export type DMIDGenerator = (content?: string, senderID?: string, ctime?: ctime, extraStr?: string, slice?: number) => string;
50
- export declare function createDMID(content?: string, senderID?: string, ctime?: ctime, extraStr?: string, slice?: number): string;
49
+ export type DMIDGenerator = (dan: UniDM, slice?: number) => string;
50
+ export declare function createDMID(dan: UniDM, slice?: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dan-uni/dan-any",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "A danmaku transformer lib, supporting danmaku from different platforms.",
5
5
  "keywords": [
6
6
  "bangumi",
package/src/index.test.ts CHANGED
@@ -92,8 +92,7 @@ describe('其它', () => {
92
92
  it('自定义DMID生成器', () => {
93
93
  console.info(
94
94
  UniPool.fromBiliXML(xml, {
95
- dmid: (_content, _senderID, ctime = new Date(), _extraStr) =>
96
- ctime.toString() + Math.random(),
95
+ dmid: (dan) => dan.ctime.toString() + Math.random(),
97
96
  }),
98
97
  )
99
98
  })
package/src/index.ts CHANGED
@@ -256,9 +256,11 @@ export class UniPool {
256
256
  * 基于DMID的基本去重功能,用于解决该class下dans为array而非Set的问题
257
257
  */
258
258
  private dedupe() {
259
- const map = new Map()
260
- this.dans.forEach((d) => map.set(d.DMID || d.toDMID(), d))
261
- this.dans = [...map.values()]
259
+ if (this.options.dmid !== false) {
260
+ const map = new Map()
261
+ this.dans.forEach((d) => map.set(d.DMID || d.toDMID(), d))
262
+ this.dans = [...map.values()]
263
+ }
262
264
  this.options.dedupe = false
263
265
  }
264
266
  /**
@@ -548,22 +548,10 @@ export class UniDM {
548
548
  @Expose()
549
549
  toDMID() {
550
550
  if (this.options.dmid === false) return
551
- else if (this.options.dmid === true)
552
- return createDMID(this.content, this.senderID, this.ctime, this.extraStr)
551
+ else if (this.options.dmid === true) return createDMID(this)
553
552
  else if (typeof this.options.dmid === 'number')
554
- return createDMID(
555
- this.content,
556
- this.senderID,
557
- this.ctime,
558
- this.extraStr,
559
- this.options.dmid,
560
- )
561
- return this.options.dmid!(
562
- this.content,
563
- this.senderID,
564
- this.ctime,
565
- this.extraStr,
566
- )
553
+ return createDMID(this, this.options.dmid)
554
+ return this.options.dmid!(this)
567
555
  }
568
556
  @Expose()
569
557
  isSameAs(dan: UniDM, options?: { skipDanuniMerge?: boolean }): boolean {
@@ -1,5 +1,4 @@
1
1
  import jsSHA from 'jssha'
2
- import type { ctime } from './dm-gen'
3
2
  import type { PlatformSource } from './platform'
4
3
 
5
4
  import { UniDM } from './dm-gen'
@@ -62,24 +61,12 @@ export class UniID {
62
61
  }
63
62
  }
64
63
 
65
- export type DMIDGenerator = (
66
- content?: string,
67
- senderID?: string,
68
- ctime?: ctime,
69
- extraStr?: string,
70
- slice?: number,
71
- ) => string
64
+ export type DMIDGenerator = (dan: UniDM, slice?: number) => string
72
65
 
73
- export function createDMID(
74
- content: string = '',
75
- senderID: string = UniID.fromNull().toString(),
76
- ctime: ctime = new Date().toISOString(),
77
- extraStr?: string,
78
- slice = 8,
79
- ) {
66
+ export function createDMID(dan: UniDM, slice = 8) {
80
67
  return new jsSHA('SHA3-256', 'TEXT')
81
68
  .update(
82
- `${content}|${senderID}|${UniDM.transCtime(ctime).toISOString()}|${extraStr}`,
69
+ `${dan.content}|${dan.senderID}|${UniDM.transCtime(dan.ctime).toISOString()}|${dan.extraStr}`,
83
70
  )
84
71
  .getHash('HEX')
85
72
  .slice(0, slice)