ddan-js 2.0.6 → 2.0.7

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.
@@ -2,19 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const is_1 = require("../util/is");
4
4
  class DTask {
5
- source;
5
+ __source__;
6
6
  constructor(source) {
7
- this.source = source;
7
+ this.__source__ = source;
8
8
  }
9
9
  run() {
10
10
  let promise;
11
11
  try {
12
12
  let temp;
13
- if (is_1.default.isFunction(this.source)) {
14
- temp = this.source();
13
+ if (is_1.default.isFunction(this.__source__)) {
14
+ temp = this.__source__();
15
15
  }
16
16
  else {
17
- temp = this.source;
17
+ temp = this.__source__;
18
18
  }
19
19
  promise = is_1.default.isPromise(temp) ? temp : Promise.resolve(temp);
20
20
  return promise.then(data => [null, data]).catch(err => [err, undefined]);
@@ -48,12 +48,12 @@ class DTrack {
48
48
  }
49
49
  exports.DTrack = DTrack;
50
50
  class DTracker {
51
- _map = new Map();
52
- _trackList = [];
51
+ __map__ = new Map();
52
+ __trackList__ = [];
53
53
  can = true;
54
54
  clear() {
55
- this._map.clear();
56
- this._trackList = [];
55
+ this.__map__.clear();
56
+ this.__trackList__ = [];
57
57
  return this;
58
58
  }
59
59
  add(name, { desc = "", type = "" } = {}) {
@@ -63,13 +63,13 @@ class DTracker {
63
63
  _track.name = name;
64
64
  _track.type = type;
65
65
  _track.desc = desc;
66
- this._trackList.push(_track);
66
+ this.__trackList__.push(_track);
67
67
  return _track.id;
68
68
  }
69
69
  done(id) {
70
70
  if (!id || !this.can)
71
71
  return;
72
- const _track = this._trackList.find(e => e.id === id);
72
+ const _track = this.__trackList__.find(e => e.id === id);
73
73
  if (!_track || _track.isDone)
74
74
  return;
75
75
  _track.done();
@@ -77,38 +77,38 @@ class DTracker {
77
77
  endTrack.id = this._endId(id);
78
78
  endTrack.flag = 1;
79
79
  endTrack.desc = `${_track.desc} | end`;
80
- this._trackList.push(endTrack);
80
+ this.__trackList__.push(endTrack);
81
81
  }
82
82
  getTrack(id) {
83
- return this._trackList.find(e => e.id === id);
83
+ return this.__trackList__.find(e => e.id === id);
84
84
  }
85
85
  getLine(id) {
86
86
  if (!id || id.endsWith("-end"))
87
87
  return [];
88
- const idx_s = this._trackList.findIndex(e => e.id === id);
88
+ const idx_s = this.__trackList__.findIndex(e => e.id === id);
89
89
  if (idx_s < 0)
90
90
  return [];
91
91
  const endid = this._endId(id);
92
- const idx_e = this._trackList.findIndex(e => e.id === endid);
93
- const count = idx_e < 0 ? this._trackList.length - idx_s : idx_e - idx_s + 1;
94
- return list_1.default.take(this._trackList, count, idx_s);
92
+ const idx_e = this.__trackList__.findIndex(e => e.id === endid);
93
+ const count = idx_e < 0 ? this.__trackList__.length - idx_s : idx_e - idx_s + 1;
94
+ return list_1.default.take(this.__trackList__, count, idx_s);
95
95
  }
96
96
  getListByName(name, id = "") {
97
97
  if (!name)
98
98
  return [];
99
- const _nameList = this._trackList.filter(e => e.name === name);
99
+ const _nameList = this.__trackList__.filter(e => e.name === name);
100
100
  if (_nameList.length <= 0)
101
101
  return [];
102
102
  if (!id)
103
103
  return _nameList;
104
104
  const endid = this._endId(id);
105
- return this._trackList.filter(e => e.id === id || e.id === endid);
105
+ return this.__trackList__.filter(e => e.id === id || e.id === endid);
106
106
  }
107
107
  getList() {
108
- return this._trackList;
108
+ return this.__trackList__;
109
109
  }
110
110
  size() {
111
- return this._trackList.length;
111
+ return this.__trackList__.length;
112
112
  }
113
113
  _endId = (id) => `${id}-end`;
114
114
  }
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const const_1 = require("./const");
4
- class DTimeFormat {
4
+ class DTime {
5
5
  date;
6
- countdown = 0;
7
- countdownS = 0;
8
6
  timestamp = 0;
9
7
  yyyy = 0;
10
8
  yy = "";
@@ -52,47 +50,70 @@ class DTimeFormat {
52
50
  this.SSS = this.S.toString().padStart(3, "0");
53
51
  return this;
54
52
  }
55
- toCountdown() {
53
+ toCountdown(reg = "") {
54
+ const result = {
55
+ countdown: 0,
56
+ timestamp: 0,
57
+ seconds: 0,
58
+ d: 0,
59
+ dd: "",
60
+ h: 0,
61
+ hh: "",
62
+ m: 0,
63
+ mm: "",
64
+ s: 0,
65
+ ss: "",
66
+ S: 0,
67
+ SS: "",
68
+ SSS: "",
69
+ desc: "",
70
+ };
56
71
  if (!this.timestamp)
57
- return this;
58
- this.countdown = Math.max(this.timestamp - Date.now(), 0);
59
- this.countdownS = Math.floor(this.countdown / const_1.default.oneSecond);
60
- let amount = this.countdown;
61
- this.d = Math.floor(amount / const_1.default.oneDay);
62
- this.dd = (this.d < 10 ? "0" : "") + this.d;
72
+ return result;
73
+ result.timestamp = this.timestamp;
74
+ result.countdown = Math.max(result.timestamp - Date.now(), 0);
75
+ result.seconds = Math.floor(result.countdown / const_1.default.oneSecond);
76
+ let amount = result.countdown;
77
+ result.d = Math.floor(amount / const_1.default.oneDay);
78
+ result.dd = (result.d < 10 ? "0" : "") + result.d;
63
79
  amount = amount % const_1.default.oneDay;
64
- this.h = Math.floor(amount / const_1.default.oneHour);
65
- this.hh = (this.h < 10 ? "0" : "") + this.h;
80
+ result.h = Math.floor(amount / const_1.default.oneHour);
81
+ result.hh = (result.h < 10 ? "0" : "") + result.h;
66
82
  amount = amount % const_1.default.oneHour;
67
- this.m = Math.floor(amount / const_1.default.oneMinute);
68
- this.mm = (this.m < 10 ? "0" : "") + this.m;
83
+ result.m = Math.floor(amount / const_1.default.oneMinute);
84
+ result.mm = (result.m < 10 ? "0" : "") + result.m;
69
85
  amount = amount % const_1.default.oneMinute;
70
- this.s = Math.floor(amount / const_1.default.oneSecond);
71
- this.ss = (this.s < 10 ? "0" : "") + this.s;
86
+ result.s = Math.floor(amount / const_1.default.oneSecond);
87
+ result.ss = (result.s < 10 ? "0" : "") + result.s;
72
88
  amount = amount % const_1.default.oneSecond;
73
- this.S = amount;
74
- this.SS = (this.S < 10 ? "0" : "") + this.S;
75
- this.SSS = this.S.toString().padStart(3, "0");
76
- return this;
77
- }
78
- format(reg = "yyyy-MM-dd hh:mm:ss") {
79
- return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => this[$1]);
80
- }
81
- countdownFormat(reg = "") {
89
+ result.S = amount;
90
+ result.SS = (result.S < 10 ? "0" : "") + result.S;
91
+ result.SSS = result.S.toString().padStart(3, "0");
82
92
  let _reg = reg;
83
93
  if (!_reg) {
84
- if (this.countdown > const_1.default.oneHour) {
94
+ if (result.countdown > const_1.default.oneHour) {
85
95
  _reg = "hh:mm:ss";
86
96
  }
87
- else if (this.countdown > const_1.default.oneMinute) {
97
+ else if (result.countdown > const_1.default.oneMinute) {
88
98
  _reg = "mm:ss";
89
99
  }
90
100
  else {
91
101
  _reg = "ss";
92
102
  }
93
103
  }
94
- return _reg.replace(/\bdd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => this[$1]);
104
+ result.desc = _reg.replace(/\bdd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => result[$1]);
105
+ return result;
106
+ }
107
+ add(ms = 0) {
108
+ if (!ms)
109
+ return this;
110
+ this.timestamp = this.timestamp + ms;
111
+ this.date = new Date(this.timestamp);
112
+ this.toDate();
113
+ return this;
114
+ }
115
+ format(reg = "yyyy-MM-dd hh:mm:ss") {
116
+ return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => this[$1]);
95
117
  }
96
- ;
97
118
  }
98
- exports.default = DTimeFormat;
119
+ exports.default = DTime;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const frame_1 = require("./frame");
4
- const timeFormat_1 = require("./timeFormat");
4
+ const dtime_1 = require("./dtime");
5
5
  const const_1 = require("./const");
6
6
  /**
7
7
  * 是否是今天
@@ -23,18 +23,18 @@ const format = (time, reg = "yyyy-MM-dd hh:mm:ss") => {
23
23
  const date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
24
24
  if (!date)
25
25
  return "";
26
- return timeformat(date).format(reg);
26
+ return dtime(date).format(reg);
27
27
  };
28
28
  /**
29
29
  *
30
30
  * @param time 时间戳|日期时间字符串|Date
31
31
  * @returns
32
32
  */
33
- const timeformat = (time) => {
33
+ const dtime = (time) => {
34
34
  const date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
35
35
  if (!date)
36
- return new timeFormat_1.default(0);
37
- return new timeFormat_1.default(date);
36
+ return new dtime_1.default(0);
37
+ return new dtime_1.default(date);
38
38
  };
39
39
  /**
40
40
  * 解析时间
@@ -50,7 +50,7 @@ function parseTimestamp({ year = 0, month = 0, date = 0, hour = 0, minute = 0, s
50
50
  * @returns
51
51
  */
52
52
  function now() {
53
- return timeformat(Date.now());
53
+ return dtime(new Date());
54
54
  }
55
55
  ;
56
56
  /**
@@ -64,10 +64,10 @@ const countdown = (endTime, reg = "") => {
64
64
  const date = typeof endTime === "string" || typeof endTime === "number" ? new Date(endTime) : endTime;
65
65
  if (!date)
66
66
  return "";
67
- const map = timeformat(date);
68
- return map.toCountdown().countdownFormat(reg);
67
+ const map = dtime(date);
68
+ return map.toCountdown(reg);
69
69
  };
70
70
  const loopFrame = (interval = 500) => {
71
71
  return new frame_1.default(interval);
72
72
  };
73
- exports.default = { ...const_1.default, now, isToday, parseTimestamp, todayZero, format, countdown, timeformat, loopFrame };
73
+ exports.default = { ...const_1.default, now, isToday, parseTimestamp, todayZero, format, countdown, dtime, loopFrame };
@@ -4,9 +4,9 @@ export interface IDEvent {
4
4
  tag: string;
5
5
  }
6
6
  export default class DEvent {
7
- _map: Map<string, Set<Function | any>>;
8
- _tagList: IDEvent[];
9
- _event_id_: string;
7
+ __map__: Map<string, Set<Function | any>>;
8
+ __tagList__: IDEvent[];
9
+ __eventId__: string;
10
10
  constructor();
11
11
  clear(): this;
12
12
  /**
@@ -1,7 +1,7 @@
1
1
  export type TSVG = "back" | "right" | "home" | "close" | "close_circle" | "close_circle_fill" | "warning" | "play" | "lock" | "lock_fill" | "plus" | "plus_circle" | "plus_circle_fill" | "star" | "star_fill" | "share" | "love" | "love_fill";
2
2
  export declare class DIcon {
3
- _defStyle: string;
4
- _map: Record<TSVG, string>;
3
+ __defStyle__: string;
4
+ __map__: Record<TSVG, string>;
5
5
  getBase64: (svgType: TSVG) => string;
6
6
  getSVG: (svgType: TSVG) => {
7
7
  url: string;
@@ -1,5 +1,5 @@
1
1
  export default class DPipeTask {
2
- _list: any[];
2
+ __list__: any[];
3
3
  constructor(_task?: any);
4
4
  push(_task?: any): this;
5
5
  clear(): this;
@@ -1,7 +1,7 @@
1
1
  export default class DPipeline {
2
- _list: any[];
3
- _running: boolean;
4
- _waitting: boolean;
2
+ __list__: any[];
3
+ __running__: boolean;
4
+ __waitting__: boolean;
5
5
  constructor();
6
6
  pipe(_task?: any): this;
7
7
  delay(t?: number): this;
@@ -1,5 +1,5 @@
1
1
  export default class DPipeparallel {
2
- _list: any[];
2
+ __list__: any[];
3
3
  constructor();
4
4
  add(_task?: any): this;
5
5
  clear(): this;
@@ -1,5 +1,5 @@
1
1
  export default class DTask {
2
- source: any;
2
+ __source__: any;
3
3
  constructor(source?: any);
4
4
  run(): Promise<any[]>;
5
5
  static _lockedMap: Map<string, Promise<any[]>>;
@@ -25,8 +25,8 @@ export declare class DTrack {
25
25
  done: (t?: number) => void;
26
26
  }
27
27
  export declare class DTracker {
28
- _map: Map<string, DTrack>;
29
- _trackList: DTrack[];
28
+ __map__: Map<string, DTrack>;
29
+ __trackList__: DTrack[];
30
30
  can: boolean;
31
31
  clear(): this;
32
32
  add(name: string, { desc, type }?: {
@@ -8,7 +8,7 @@ declare const _default: {
8
8
  gbkCut: (source: string, len: number) => string;
9
9
  };
10
10
  time: {
11
- now: () => import("./modules/time/timeFormat").default;
11
+ now: () => import("./modules/time/dtime").default;
12
12
  isToday: (date: any) => any;
13
13
  parseTimestamp: ({ year, month, date, hour, minute, second }: {
14
14
  year?: number | undefined;
@@ -20,8 +20,8 @@ declare const _default: {
20
20
  }) => number;
21
21
  todayZero: () => number;
22
22
  format: (time: string | number | Date, reg?: string) => string;
23
- countdown: (endTime: string | number | Date, reg?: string) => string;
24
- timeformat: (time: string | number | Date) => import("./modules/time/timeFormat").default;
23
+ countdown: (endTime: string | number | Date, reg?: string) => "" | import("./modules/time/dtime").IDCountdownFormat;
24
+ dtime: (time: string | number | Date) => import("./modules/time/dtime").default;
25
25
  loopFrame: (interval?: number) => import("./modules/time/frame").default;
26
26
  oneDay: number;
27
27
  oneHour: number;
@@ -1,7 +1,22 @@
1
- export default class DTimeFormat {
2
- date?: Date;
1
+ export interface IDCountdownFormat {
3
2
  countdown: number;
4
- countdownS: number;
3
+ timestamp: number;
4
+ seconds: number;
5
+ d: number;
6
+ dd: string;
7
+ h: number;
8
+ hh: string;
9
+ m: number;
10
+ mm: string;
11
+ s: number;
12
+ ss: string;
13
+ S: number;
14
+ SS: string;
15
+ SSS: string;
16
+ desc: string;
17
+ }
18
+ export default class DTime {
19
+ date?: Date;
5
20
  timestamp: number;
6
21
  yyyy?: number;
7
22
  yy?: string;
@@ -20,7 +35,7 @@ export default class DTimeFormat {
20
35
  SSS: string;
21
36
  constructor(time: string | number | Date);
22
37
  toDate(): this;
23
- toCountdown(): this;
38
+ toCountdown(reg?: string): IDCountdownFormat;
39
+ add(ms?: number): this;
24
40
  format(reg?: string): string;
25
- countdownFormat(reg?: string): string;
26
41
  }
@@ -1,5 +1,5 @@
1
1
  import LoopFrame from "./frame";
2
- import TimeFormat from "./timeFormat";
2
+ import DTime from "./dtime";
3
3
  /**
4
4
  * 解析时间
5
5
  * @param param0
@@ -17,15 +17,15 @@ declare function parseTimestamp({ year, month, date, hour, minute, second }: {
17
17
  * 当前时间格式类
18
18
  * @returns
19
19
  */
20
- declare function now(): TimeFormat;
20
+ declare function now(): DTime;
21
21
  declare const _default: {
22
22
  now: typeof now;
23
23
  isToday: (date: any) => any;
24
24
  parseTimestamp: typeof parseTimestamp;
25
25
  todayZero: () => number;
26
26
  format: (time: string | number | Date, reg?: string) => string;
27
- countdown: (endTime: string | number | Date, reg?: string) => string;
28
- timeformat: (time: string | number | Date) => TimeFormat;
27
+ countdown: (endTime: string | number | Date, reg?: string) => "" | import("./dtime").IDCountdownFormat;
28
+ dtime: (time: string | number | Date) => DTime;
29
29
  loopFrame: (interval?: number) => LoopFrame;
30
30
  oneDay: number;
31
31
  oneHour: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "main": "bin/ddan-js.js",