ddan-js 2.5.4 → 2.5.6

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.
@@ -9,55 +9,29 @@ const https = (url) => {
9
9
  };
10
10
  const RegHost = /^(http[s]?):\/\/([\w.]+)(?::(\d+))?/;
11
11
  const parseUrl = (url) => {
12
- let host = '';
13
- let origin = '';
14
- // if (/^http[s]?:\/\/([\w.]+)/.test(url)) {
15
- // host = url.replace(/^http[s]?:\/\/([\w.]+)[\w\W]+/, '$1')
16
- // origin = url.replace(/^(http[s]?:\/\/)([\w.]+)[\w\W]+/, '$1$2')
17
- // }
18
12
  const hostInfo = parseHost(url);
19
- if (hostInfo) {
20
- host = hostInfo.host;
21
- origin = hostInfo.origin;
22
- }
23
- const arr = url.split('?');
24
- const _path = arr[0];
25
- const query = arr.length > 1 ? arr[1] : '';
26
- let page = '';
27
- const mat = _path.match(/[\/]?([\w\_\-]+)[.]?[\w]*[?]?$/);
28
- if (mat) {
29
- page = mat[1];
30
- }
13
+ const { origin = '', url: _url = '', query = '' } = hostInfo;
14
+ const pathInfo = parsePath(_url);
31
15
  const params = (0, decode_1.default)(query, { multiple: true, uri: false });
32
- const idx = _path.lastIndexOf('/') + 1;
33
- const filename = _path.substring(idx);
34
- const last = filename.lastIndexOf('.');
35
- const filenameWithoutExtension = filename.substring(0, last);
36
- const extension = filename.substring(last);
37
- const root = _path.substring(0, idx);
38
- return {
39
- host,
40
- origin,
41
- url,
42
- path: _path,
43
- page,
44
- query,
45
- filename: filenameWithoutExtension ? filename : '',
46
- filenameWithoutExtension,
47
- extension: filenameWithoutExtension ? extension : '',
48
- route: filenameWithoutExtension ? root : '',
16
+ const result = {
17
+ ...hostInfo,
18
+ ...pathInfo,
19
+ pathname: _url.substring(_url.indexOf(origin || '') + origin.length),
49
20
  params,
50
21
  };
22
+ return result;
51
23
  };
52
- const parsePath = (path) => {
53
- const _path = (path || '').replace(/\\/g, '/').split('?')[0];
54
- const idx = _path.lastIndexOf('/') + 1;
55
- const name = _path.substring(idx);
24
+ const parsePath = (url) => {
25
+ const _url = (url || '').replace(/\\/g, '/').split('?')[0];
26
+ const mat = _url.match(/[\/]?([\w\_\-]+)[.]?[\w]*[?]?$/);
27
+ const page = mat ? mat[1] : '';
28
+ const idx = _url.lastIndexOf('/') + 1;
29
+ const name = _url.substring(idx);
56
30
  const last = name.lastIndexOf('.');
57
- const withoutExtension = name.substring(0, last);
58
- const extension = name.substring(last);
59
- const root = _path.substring(0, idx);
60
- return { root, name, withoutExtension, extension };
31
+ const withoutExtension = name.substring(0, last) || '';
32
+ const extname = last >= 0 ? name.substring(last) : '';
33
+ const route = _url.substring(0, idx) || '';
34
+ return { route, page, name, withoutExtension, extname };
61
35
  };
62
36
  const join = (...args) => {
63
37
  const arr = [];
@@ -70,18 +44,28 @@ const join = (...args) => {
70
44
  return arr.join('/');
71
45
  };
72
46
  const parseHost = (url) => {
47
+ const result = {
48
+ href: url,
49
+ url: '',
50
+ origin: '',
51
+ protocol: '',
52
+ host: '',
53
+ port: '',
54
+ query: '',
55
+ };
73
56
  if (!url)
74
- return undefined;
57
+ return result;
75
58
  const matches = url.match(RegHost);
76
59
  if (!matches || matches.length < 4)
77
- return undefined;
60
+ return result;
78
61
  const port = matches[3] || '';
79
- const result = {
80
- origin: matches[0],
81
- protocol: matches[1],
82
- host: `${matches[2]}${port ? ':' + port : ''}`,
83
- port,
84
- };
62
+ const arr = url.split('?');
63
+ result.url = arr[0];
64
+ result.origin = matches[0];
65
+ result.protocol = `${matches[1]}:`;
66
+ result.host = `${matches[2]}${port ? ':' + port : ''}`;
67
+ result.port = port;
68
+ result.query = arr.length > 1 ? arr[1] : '';
85
69
  return result;
86
70
  };
87
71
  exports.default = { parse: decode_1.default, stringify: encode_1.default, https, parseUrl, parsePath, parseHost, join };
@@ -1,12 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dd = exports.Ddan = void 0;
4
- var Ddan;
5
- (function (Ddan) {
6
- ;
7
- ;
8
- })(Ddan || (exports.Ddan = Ddan = {}));
9
- var dd;
10
- (function (dd) {
11
- ;
12
- })(dd || (exports.dd = dd = {}));
@@ -16,6 +16,9 @@ function singleton() {
16
16
  }
17
17
  return Singleton.__instance__;
18
18
  }
19
+ static get I() {
20
+ return this.Instance;
21
+ }
19
22
  }
20
23
  return Singleton;
21
24
  }
@@ -1,6 +1,5 @@
1
1
  import Store from "./store";
2
2
  import LoopFrame from "../modules/time/frame";
3
- import DPipeline from "./pipeline";
4
3
  import DPipeparallel from "./pipeparallel";
5
4
  export interface ITriggerRecord {
6
5
  time: number;
@@ -46,7 +45,6 @@ export declare class Joker {
46
45
  * @returns
47
46
  */
48
47
  timesClean: (mode?: "storage" | "running") => void;
49
- pipeline: () => DPipeline;
50
48
  parallel: () => DPipeparallel;
51
49
  }
52
50
  declare const joker: Joker;
@@ -11,6 +11,7 @@ declare const dUtil: {
11
11
  new (): {};
12
12
  __instance__: any;
13
13
  readonly Instance: T;
14
+ readonly I: T;
14
15
  };
15
16
  getset: <T_1 = any>(t?: T_1 | undefined) => import("./typings").Ddan.IGetset<T_1>;
16
17
  copy: (source: any, options?: {
@@ -186,12 +187,14 @@ declare const dUtil: {
186
187
  declare const dHook: {
187
188
  sleep: (ms?: number) => Promise<unknown>;
188
189
  run: <T = any>(task?: Function | Promise<T> | undefined, wait?: number) => Promise<[any, undefined] | [null, T]>;
189
- exec: (func: Function, taskId?: string) => Promise<any[]>;
190
+ exec: (func: Function, taskId?: string) => Promise<[any, undefined] | [null, any]>;
190
191
  debounce: typeof import("./modules/hook/debounce").default;
191
192
  throttle: typeof import("./modules/hook/throttle").default;
192
193
  task: (param?: import("./typings").Ddan.Func1<any, any> | undefined) => import("./class/pipeTask").default;
193
194
  mutex: typeof import("./modules/hook/mutex").default;
194
195
  polling: typeof import("./modules/hook/polling").default;
196
+ pipe: (func: Function) => import("./modules/hook/modules/pipeline").default;
197
+ pipeline: () => import("./modules/hook/modules/pipeline").default;
195
198
  to: <T_1 = any, U extends object = any>(promise: Promise<T_1>, errorExt?: object | undefined) => Promise<[null, T_1] | [U, undefined]>;
196
199
  go: <T_2 = any>(task?: Function | Promise<T_2> | undefined) => Promise<[any, undefined] | [null, T_2]>;
197
200
  delay: (ms?: number) => Promise<unknown>;
@@ -252,25 +255,29 @@ declare const dMini: {
252
255
  }) => string;
253
256
  https: (url: string) => string;
254
257
  parseUrl: (url: string) => {
255
- host: string;
256
- origin: string;
257
- url: string;
258
- path: string;
258
+ pathname: string;
259
+ params: {};
260
+ route: string;
259
261
  page: string;
262
+ name: string;
263
+ withoutExtension: string;
264
+ extname: string;
265
+ href: string;
266
+ url: string;
267
+ origin: string;
268
+ host: string;
269
+ protocol: string;
270
+ port: string;
260
271
  query: string;
261
- filename: string;
262
- filenameWithoutExtension: string;
263
- extension: string;
264
- route: string;
265
- params: {};
266
272
  };
267
- parsePath: (path: string) => {
268
- root: string;
273
+ parsePath: (url: string) => {
274
+ route: string;
275
+ page: string;
269
276
  name: string;
270
277
  withoutExtension: string;
271
- extension: string;
278
+ extname: string;
272
279
  };
273
- parseHost: (url: string) => import("./typings").Ddan.IHttpHost | undefined;
280
+ parseHost: (url: string) => import("./typings").Ddan.IHttpHost;
274
281
  join: (...args: string[]) => string;
275
282
  };
276
283
  icon: import("./class/icon").DIcon;
@@ -385,25 +392,29 @@ declare const dWeb: {
385
392
  }) => string;
386
393
  https: (url: string) => string;
387
394
  parseUrl: (url: string) => {
388
- host: string;
389
- origin: string;
390
- url: string;
391
- path: string;
395
+ pathname: string;
396
+ params: {};
397
+ route: string;
392
398
  page: string;
399
+ name: string;
400
+ withoutExtension: string;
401
+ extname: string;
402
+ href: string;
403
+ url: string;
404
+ origin: string;
405
+ host: string;
406
+ protocol: string;
407
+ port: string;
393
408
  query: string;
394
- filename: string;
395
- filenameWithoutExtension: string;
396
- extension: string;
397
- route: string;
398
- params: {};
399
409
  };
400
- parsePath: (path: string) => {
401
- root: string;
410
+ parsePath: (url: string) => {
411
+ route: string;
412
+ page: string;
402
413
  name: string;
403
414
  withoutExtension: string;
404
- extension: string;
415
+ extname: string;
405
416
  };
406
- parseHost: (url: string) => import("./typings").Ddan.IHttpHost | undefined;
417
+ parseHost: (url: string) => import("./typings").Ddan.IHttpHost;
407
418
  join: (...args: string[]) => string;
408
419
  };
409
420
  icon: import("./class/icon").DIcon;
@@ -461,12 +472,14 @@ declare const _default: {
461
472
  hook: {
462
473
  sleep: (ms?: number) => Promise<unknown>;
463
474
  run: <T = any>(task?: Function | Promise<T> | undefined, wait?: number) => Promise<[any, undefined] | [null, T]>;
464
- exec: (func: Function, taskId?: string) => Promise<any[]>;
475
+ exec: (func: Function, taskId?: string) => Promise<[any, undefined] | [null, any]>;
465
476
  debounce: typeof import("./modules/hook/debounce").default;
466
477
  throttle: typeof import("./modules/hook/throttle").default;
467
478
  task: (param?: import("./typings").Ddan.Func1<any, any> | undefined) => import("./class/pipeTask").default;
468
479
  mutex: typeof import("./modules/hook/mutex").default;
469
480
  polling: typeof import("./modules/hook/polling").default;
481
+ pipe: (func: Function) => import("./modules/hook/modules/pipeline").default;
482
+ pipeline: () => import("./modules/hook/modules/pipeline").default;
470
483
  to: <T_1 = any, U extends object = any>(promise: Promise<T_1>, errorExt?: object | undefined) => Promise<[null, T_1] | [U, undefined]>;
471
484
  go: <T_2 = any>(task?: Function | Promise<T_2> | undefined) => Promise<[any, undefined] | [null, T_2]>;
472
485
  delay: (ms?: number) => Promise<unknown>;
@@ -499,6 +512,7 @@ declare const _default: {
499
512
  new (): {};
500
513
  __instance__: any;
501
514
  readonly Instance: T_4;
515
+ readonly I: T_4;
502
516
  };
503
517
  getset: <T_5 = any>(t?: T_5 | undefined) => import("./typings").Ddan.IGetset<T_5>;
504
518
  copy: (source: any, options?: {
@@ -630,25 +644,29 @@ declare const _default: {
630
644
  }) => string;
631
645
  https: (url: string) => string;
632
646
  parseUrl: (url: string) => {
633
- host: string;
634
- origin: string;
635
- url: string;
636
- path: string;
647
+ pathname: string;
648
+ params: {};
649
+ route: string;
637
650
  page: string;
651
+ name: string;
652
+ withoutExtension: string;
653
+ extname: string;
654
+ href: string;
655
+ url: string;
656
+ origin: string;
657
+ host: string;
658
+ protocol: string;
659
+ port: string;
638
660
  query: string;
639
- filename: string;
640
- filenameWithoutExtension: string;
641
- extension: string;
642
- route: string;
643
- params: {};
644
661
  };
645
- parsePath: (path: string) => {
646
- root: string;
662
+ parsePath: (url: string) => {
663
+ route: string;
664
+ page: string;
647
665
  name: string;
648
666
  withoutExtension: string;
649
- extension: string;
667
+ extname: string;
650
668
  };
651
- parseHost: (url: string) => import("./typings").Ddan.IHttpHost | undefined;
669
+ parseHost: (url: string) => import("./typings").Ddan.IHttpHost;
652
670
  join: (...args: string[]) => string;
653
671
  };
654
672
  css: {
@@ -0,0 +1,16 @@
1
+ import DPipeline from './modules/pipeline';
2
+ declare const DHooker_base: {
3
+ new (): {};
4
+ __instance__: any;
5
+ readonly Instance: DHooker;
6
+ readonly I: DHooker;
7
+ };
8
+ export default class DHooker extends DHooker_base {
9
+ __lockedMap: Map<string, Promise<[any, undefined] | [null, any]>>;
10
+ pipeline: DPipeline;
11
+ constructor();
12
+ lock(id: string, func: Function): Promise<[any, undefined] | [null, any]> | undefined;
13
+ unlock(id: string): void;
14
+ exec(func: Function, taskId: string): Promise<[any, undefined] | [null, any]>;
15
+ }
16
+ export {};
@@ -1,9 +1,10 @@
1
+ import { Ddan } from '../../typings';
1
2
  import debounce from './debounce';
2
3
  import throttle from './throttle';
3
4
  import mutex from './mutex';
4
5
  import DPipeTask from '../../class/pipeTask';
5
- import { Ddan } from '../../typings';
6
6
  import polling from './polling';
7
+ import DPipeline from './modules/pipeline';
7
8
  /**
8
9
  *
9
10
  * @param task 任务
@@ -14,12 +15,14 @@ declare function run<T = any>(task?: Promise<T> | Function, wait?: number): Prom
14
15
  declare const _default: {
15
16
  sleep: (ms?: number) => Promise<unknown>;
16
17
  run: typeof run;
17
- exec: (func: Function, taskId?: string) => Promise<any[]>;
18
+ exec: (func: Function, taskId?: string) => Promise<[any, undefined] | [null, any]>;
18
19
  debounce: typeof debounce;
19
20
  throttle: typeof throttle;
20
21
  task: (param?: Ddan.Func1<any, any> | undefined) => DPipeTask;
21
22
  mutex: typeof mutex;
22
23
  polling: typeof polling;
24
+ pipe: (func: Function) => DPipeline;
25
+ pipeline: () => DPipeline;
23
26
  to: <T = any, U extends object = any>(promise: Promise<T>, errorExt?: object | undefined) => Promise<[null, T] | [U, undefined]>;
24
27
  go: <T_1 = any>(task?: Function | Promise<T_1> | undefined) => Promise<[any, undefined] | [null, T_1]>;
25
28
  delay: (ms?: number) => Promise<unknown>;
@@ -1,4 +1,5 @@
1
- export default class DPipeline {
1
+ import { Ddan } from '../../../typings';
2
+ export default class DPipeline implements Ddan.IPipeline {
2
3
  __list: any[];
3
4
  __running: boolean;
4
5
  __waitting: boolean;
@@ -1,4 +1,4 @@
1
- import { Ddan } from '../..';
1
+ import { Ddan } from '../../typings';
2
2
  declare const _default: {
3
3
  parse: (qs: any, { sep, eq, max, multiple, uri, parseNumber, parseBoolean }?: {
4
4
  sep?: string | undefined;
@@ -20,25 +20,29 @@ declare const _default: {
20
20
  }) => string;
21
21
  https: (url: string) => string;
22
22
  parseUrl: (url: string) => {
23
- host: string;
24
- origin: string;
25
- url: string;
26
- path: string;
23
+ pathname: string;
24
+ params: {};
25
+ route: string;
27
26
  page: string;
27
+ name: string;
28
+ withoutExtension: string;
29
+ extname: string;
30
+ href: string;
31
+ url: string;
32
+ origin: string;
33
+ host: string;
34
+ protocol: string;
35
+ port: string;
28
36
  query: string;
29
- filename: string;
30
- filenameWithoutExtension: string;
31
- extension: string;
32
- route: string;
33
- params: {};
34
37
  };
35
- parsePath: (path: string) => {
36
- root: string;
38
+ parsePath: (url: string) => {
39
+ route: string;
40
+ page: string;
37
41
  name: string;
38
42
  withoutExtension: string;
39
- extension: string;
43
+ extname: string;
40
44
  };
41
- parseHost: (url: string) => Ddan.IHttpHost | undefined;
45
+ parseHost: (url: string) => Ddan.IHttpHost;
42
46
  join: (...args: string[]) => string;
43
47
  };
44
48
  export default _default;
@@ -16,10 +16,13 @@ export declare namespace Ddan {
16
16
  type Func4<T0 = any, T1 = any, T2 = any, T3 = any, R = any> = Callback<[T0, T1, T2, T3], R>;
17
17
  type Result<T = any> = T | Promise<T>;
18
18
  interface IHttpHost {
19
+ href: string;
20
+ url: string;
19
21
  origin: string;
20
22
  host: string;
21
23
  protocol: string;
22
24
  port: string;
25
+ query: string;
23
26
  }
24
27
  interface IGetset<T> {
25
28
  set(value?: T): void;
@@ -119,7 +122,7 @@ export declare namespace Ddan {
119
122
  }
120
123
  interface IRegexRule {
121
124
  key: string;
122
- flag?: "i" | "g" | "m" | "gi" | "mi";
125
+ flag?: 'i' | 'g' | 'm' | 'gi' | 'mi';
123
126
  value: string;
124
127
  }
125
128
  interface IIgnoreParams {
@@ -139,6 +142,12 @@ export declare namespace Ddan {
139
142
  maxWait?: number;
140
143
  trailing?: boolean;
141
144
  }
145
+ interface IPipeline {
146
+ pipe(func?: any): IPipeline;
147
+ delay(t?: number): IPipeline;
148
+ clear(): IPipeline;
149
+ whenAll(): Promise<IPipeline>;
150
+ }
142
151
  }
143
152
  export declare namespace dd {
144
153
  interface IHttpRequest {
@@ -162,7 +171,7 @@ export declare namespace dd {
162
171
  [key: string]: any;
163
172
  url: string;
164
173
  model?: string;
165
- method: "get" | "post" | "put";
174
+ method: 'get' | 'post' | 'put';
166
175
  body?: string;
167
176
  plugins?: Record<string, any>;
168
177
  }
@@ -190,7 +199,7 @@ export declare namespace dd {
190
199
  interface IDWatermarkParams {
191
200
  [key: string]: any;
192
201
  t?: number;
193
- g?: "nw" | "north" | "ne" | "west" | "center" | "east" | "sw" | "south" | "se";
202
+ g?: 'nw' | 'north' | 'ne' | 'west' | 'center' | 'east' | 'sw' | 'south' | 'se';
194
203
  x?: number;
195
204
  y?: number;
196
205
  voffset?: number;
@@ -199,7 +208,7 @@ export declare namespace dd {
199
208
  pady?: number;
200
209
  }
201
210
  interface IDWatermarkText {
202
- type?: "d3F5LXplbmhlaQ" | "d3F5LW1pY3JvaGVp" | "ZmFuZ3poZW5nc2h1c29uZw" | "ZmFuZ3poZW5na2FpdGk" | "ZmFuZ3poZW5naGVpdGk" | "ZmFuZ3poZW5nZmFuZ3Nvbmc" | "ZHJvaWRzYW5zZmFsbGJhY2s";
211
+ type?: 'd3F5LXplbmhlaQ' | 'd3F5LW1pY3JvaGVp' | 'ZmFuZ3poZW5nc2h1c29uZw' | 'ZmFuZ3poZW5na2FpdGk' | 'ZmFuZ3poZW5naGVpdGk' | 'ZmFuZ3poZW5nZmFuZ3Nvbmc' | 'ZHJvaWRzYW5zZmFsbGJhY2s';
203
212
  color?: string;
204
213
  size?: number;
205
214
  shadow?: number;
@@ -7,6 +7,7 @@ declare function singleton<T>(): {
7
7
  new (): {};
8
8
  __instance__: any;
9
9
  readonly Instance: T;
10
+ readonly I: T;
10
11
  };
11
12
  declare function getset<T = any>(t?: T): Ddan.IGetset<T>;
12
13
  declare const _default: {
@@ -6,6 +6,7 @@ declare const _default: {
6
6
  new (): {};
7
7
  __instance__: any;
8
8
  readonly Instance: T;
9
+ readonly I: T;
9
10
  };
10
11
  getset: <T_1 = any>(t?: T_1 | undefined) => import("..").Ddan.IGetset<T_1>;
11
12
  copy: (source: any, options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const base_1 = require("../modules/hook/base");
4
- class DTask {
5
- __source;
6
- constructor(source) {
7
- this.__source = source;
8
- }
9
- run = () => base_1.default.safeDo(this.__source);
10
- static _lockedMap = new Map();
11
- static _lock(id, func) {
12
- if (!id || !func)
13
- return undefined;
14
- const task = new DTask(func).run();
15
- this._lockedMap.set(id, task);
16
- return task;
17
- }
18
- static _unlock(id) {
19
- if (!id)
20
- return;
21
- this._lockedMap.delete(id);
22
- }
23
- static async exec(func, taskId) {
24
- if (!func || !taskId) {
25
- return new DTask(func).run();
26
- }
27
- const _task = this._lockedMap.get(taskId);
28
- if (_task) {
29
- return _task;
30
- }
31
- const _newTask = this._lock(taskId, func);
32
- if (!_newTask)
33
- return new DTask(func).run();
34
- const result = await _newTask;
35
- this._unlock(taskId);
36
- return result;
37
- }
38
- }
39
- exports.default = DTask;
@@ -1,9 +0,0 @@
1
- export default class DTask<T = any> {
2
- __source: any;
3
- constructor(source?: any);
4
- run: () => Promise<[any, undefined] | [null, T]>;
5
- static _lockedMap: Map<string, Promise<any[]>>;
6
- static _lock(id: string, func: Function): Promise<[any, undefined] | [null, any]> | undefined;
7
- static _unlock(id: string): void;
8
- static exec(func: Function, taskId: string): Promise<any[]>;
9
- }