ddan-js 2.9.1 → 2.9.3

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.
@@ -3,44 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const base_1 = require("./hook/base");
4
4
  const convert_1 = require("./convert");
5
5
  const math_1 = require("./math");
6
- const getDataURL = (url) => {
6
+ const getDataURL = (url, cache) => {
7
7
  const result = {
8
8
  contentType: '',
9
9
  dataUrl: '',
10
10
  };
11
- return base_1.default.to(fetch(url)
11
+ return base_1.default.to(fetch(url, { cache })
12
12
  .then((response) => {
13
13
  result.contentType = response.headers.get('content-type') || '';
14
14
  return response.arrayBuffer();
15
15
  })
16
16
  .then((data) => {
17
- result.dataUrl =
18
- `data:${result.contentType};base64,` + convert_1.default.ab2str(data, true);
17
+ result.dataUrl = `data:${result.contentType};base64,` + convert_1.default.ab2str(data, true);
19
18
  return result;
20
19
  }));
21
20
  };
22
- const getArrayBuffer = async (url) => {
23
- return base_1.default.to(fetch(url).then((response) => {
21
+ const getArrayBuffer = async (url, cache) => {
22
+ return base_1.default.to(fetch(url, { cache }).then((response) => {
24
23
  return response.arrayBuffer();
25
24
  }));
26
25
  };
27
- const getJson = async (url) => {
28
- return base_1.default.to(fetch(url).then((response) => {
26
+ const getJson = async (url, cache) => {
27
+ return base_1.default.to(fetch(url, { cache }).then((response) => {
29
28
  return response.json();
30
29
  }));
31
30
  };
32
- const getText = async (url) => {
33
- return base_1.default.to(fetch(url).then((response) => {
31
+ const getText = async (url, cache) => {
32
+ return base_1.default.to(fetch(url, { cache }).then((response) => {
34
33
  return response.text();
35
34
  }));
36
35
  };
36
+ const cache = async (url, cache) => {
37
+ return base_1.default.to(fetch(url, { cache }).then(() => {
38
+ return true;
39
+ }));
40
+ };
37
41
  const download = (url, opts = {}) => {
38
- return new Promise(resolve => fetch(url)
42
+ return new Promise((resolve) => fetch(url)
39
43
  .then(async (response) => {
40
44
  if (!response.ok || response.status !== 200) {
41
45
  throw new Error(response.statusText);
42
46
  }
43
- const contentLength = +(response.headers.get("content-length") || "");
47
+ const contentLength = +(response.headers.get('content-length') || '');
44
48
  const reader = response.body?.getReader();
45
49
  let receivedLength = 0;
46
50
  const chunks = [];
@@ -63,7 +67,7 @@ const download = (url, opts = {}) => {
63
67
  opts?.success && opts?.success(chunksAll);
64
68
  resolve(chunksAll);
65
69
  })
66
- .catch(err => {
70
+ .catch((err) => {
67
71
  opts?.fail && opts?.fail(err);
68
72
  resolve(undefined);
69
73
  }));
@@ -73,5 +77,6 @@ exports.default = {
73
77
  getArrayBuffer,
74
78
  getJson,
75
79
  download,
76
- getText
80
+ getText,
81
+ cache,
77
82
  };
@@ -252,16 +252,17 @@ const isAllowed = (status, prompt = true) => {
252
252
  const takeHtmlLinks = (htmlContent) => {
253
253
  if (!htmlContent)
254
254
  return [];
255
- const resgexs = [
255
+ const regexs = [
256
256
  /<script[^>]+src="([^"]+)"/g,
257
257
  /<link[^>]+rel="stylesheet"[^>]+href="([^"]+)"/g,
258
258
  /<link[^>]+rel="icon"[^>]+href="([^"]+)"/g,
259
259
  ];
260
260
  const results = [];
261
- resgexs.forEach((e) => {
262
- results.concat(takeHtml(htmlContent, e));
261
+ regexs.forEach((e) => {
262
+ const r = takeHtml(htmlContent, e);
263
+ results.push(r);
263
264
  });
264
- return results;
265
+ return [].concat(...results);
265
266
  };
266
267
  const takeHtml = (htmlContent, regex) => {
267
268
  if (!htmlContent || !regex)
@@ -501,7 +501,7 @@ declare const dMini: {
501
501
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
502
502
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
503
503
  legacyCopy: (text: string) => boolean;
504
- takeHtmlLinks: (htmlContent: string) => string[];
504
+ takeHtmlLinks: (htmlContent: string) => never[];
505
505
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
506
506
  };
507
507
  };
@@ -550,18 +550,19 @@ declare const dLogger: {
550
550
  declare const dWeb: {
551
551
  Ecdh: typeof import("./modules/browser/ecdh").default;
552
552
  fetch: {
553
- getDataURL: (url: string) => Promise<[any, undefined] | [null, {
553
+ getDataURL: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, {
554
554
  contentType: string;
555
555
  dataUrl: string;
556
556
  }]>;
557
- getArrayBuffer: (url: string) => Promise<[any, undefined] | [null, ArrayBuffer]>;
558
- getJson: (url: string) => Promise<[any, undefined] | [null, any]>;
557
+ getArrayBuffer: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, ArrayBuffer]>;
558
+ getJson: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, any]>;
559
559
  download: (url: string, opts?: {
560
560
  success?: ((buffer: Uint8Array) => void) | undefined;
561
561
  progress?: ((percentage: number, current: number, total: number) => void) | undefined;
562
562
  fail?: ((error: Error) => void) | undefined;
563
563
  }) => Promise<Uint8Array | undefined>;
564
- getText: (url: string) => Promise<[any, undefined] | [null, string]>;
564
+ getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
565
+ cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
565
566
  };
566
567
  Http: typeof Http;
567
568
  css: {
@@ -645,7 +646,7 @@ declare const dWeb: {
645
646
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
646
647
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
647
648
  legacyCopy: (text: string) => boolean;
648
- takeHtmlLinks: (htmlContent: string) => string[];
649
+ takeHtmlLinks: (htmlContent: string) => never[];
649
650
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
650
651
  };
651
652
  rsa: {
@@ -975,7 +976,7 @@ declare const _default: {
975
976
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
976
977
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
977
978
  legacyCopy: (text: string) => boolean;
978
- takeHtmlLinks: (htmlContent: string) => string[];
979
+ takeHtmlLinks: (htmlContent: string) => never[];
979
980
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
980
981
  };
981
982
  icon: import("./class/icon").DIcon;
@@ -1064,18 +1065,19 @@ declare const _default: {
1064
1065
  }) => void;
1065
1066
  };
1066
1067
  fetch: {
1067
- getDataURL: (url: string) => Promise<[any, undefined] | [null, {
1068
+ getDataURL: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, {
1068
1069
  contentType: string;
1069
1070
  dataUrl: string;
1070
1071
  }]>;
1071
- getArrayBuffer: (url: string) => Promise<[any, undefined] | [null, ArrayBuffer]>;
1072
- getJson: (url: string) => Promise<[any, undefined] | [null, any]>;
1072
+ getArrayBuffer: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, ArrayBuffer]>;
1073
+ getJson: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, any]>;
1073
1074
  download: (url: string, opts?: {
1074
1075
  success?: ((buffer: Uint8Array) => void) | undefined;
1075
1076
  progress?: ((percentage: number, current: number, total: number) => void) | undefined;
1076
1077
  fail?: ((error: Error) => void) | undefined;
1077
1078
  }) => Promise<Uint8Array | undefined>;
1078
- getText: (url: string) => Promise<[any, undefined] | [null, string]>;
1079
+ getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
1080
+ cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
1079
1081
  };
1080
1082
  rsa: {
1081
1083
  generateKeys: () => Promise<{
@@ -501,7 +501,7 @@ declare const dMini: {
501
501
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
502
502
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
503
503
  legacyCopy: (text: string) => boolean;
504
- takeHtmlLinks: (htmlContent: string) => string[];
504
+ takeHtmlLinks: (htmlContent: string) => never[];
505
505
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
506
506
  };
507
507
  };
@@ -550,18 +550,19 @@ declare const dLogger: {
550
550
  declare const dWeb: {
551
551
  Ecdh: typeof import("./modules/browser/ecdh").default;
552
552
  fetch: {
553
- getDataURL: (url: string) => Promise<[any, undefined] | [null, {
553
+ getDataURL: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, {
554
554
  contentType: string;
555
555
  dataUrl: string;
556
556
  }]>;
557
- getArrayBuffer: (url: string) => Promise<[any, undefined] | [null, ArrayBuffer]>;
558
- getJson: (url: string) => Promise<[any, undefined] | [null, any]>;
557
+ getArrayBuffer: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, ArrayBuffer]>;
558
+ getJson: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, any]>;
559
559
  download: (url: string, opts?: {
560
560
  success?: ((buffer: Uint8Array) => void) | undefined;
561
561
  progress?: ((percentage: number, current: number, total: number) => void) | undefined;
562
562
  fail?: ((error: Error) => void) | undefined;
563
563
  }) => Promise<Uint8Array | undefined>;
564
- getText: (url: string) => Promise<[any, undefined] | [null, string]>;
564
+ getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
565
+ cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
565
566
  };
566
567
  Http: typeof Http;
567
568
  css: {
@@ -645,7 +646,7 @@ declare const dWeb: {
645
646
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
646
647
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
647
648
  legacyCopy: (text: string) => boolean;
648
- takeHtmlLinks: (htmlContent: string) => string[];
649
+ takeHtmlLinks: (htmlContent: string) => never[];
649
650
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
650
651
  };
651
652
  rsa: {
@@ -1011,7 +1012,7 @@ declare const _default: {
1011
1012
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
1012
1013
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
1013
1014
  legacyCopy: (text: string) => boolean;
1014
- takeHtmlLinks: (htmlContent: string) => string[];
1015
+ takeHtmlLinks: (htmlContent: string) => never[];
1015
1016
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
1016
1017
  };
1017
1018
  icon: import("./class/icon").DIcon;
@@ -1100,18 +1101,19 @@ declare const _default: {
1100
1101
  }) => void;
1101
1102
  };
1102
1103
  fetch: {
1103
- getDataURL: (url: string) => Promise<[any, undefined] | [null, {
1104
+ getDataURL: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, {
1104
1105
  contentType: string;
1105
1106
  dataUrl: string;
1106
1107
  }]>;
1107
- getArrayBuffer: (url: string) => Promise<[any, undefined] | [null, ArrayBuffer]>;
1108
- getJson: (url: string) => Promise<[any, undefined] | [null, any]>;
1108
+ getArrayBuffer: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, ArrayBuffer]>;
1109
+ getJson: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, any]>;
1109
1110
  download: (url: string, opts?: {
1110
1111
  success?: ((buffer: Uint8Array) => void) | undefined;
1111
1112
  progress?: ((percentage: number, current: number, total: number) => void) | undefined;
1112
1113
  fail?: ((error: Error) => void) | undefined;
1113
1114
  }) => Promise<Uint8Array | undefined>;
1114
- getText: (url: string) => Promise<[any, undefined] | [null, string]>;
1115
+ getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
1116
+ cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
1115
1117
  };
1116
1118
  rsa: {
1117
1119
  generateKeys: () => Promise<{
@@ -1,15 +1,16 @@
1
1
  declare const _default: {
2
- getDataURL: (url: string) => Promise<[null, {
2
+ getDataURL: (url: string, cache?: RequestCache | undefined) => Promise<[null, {
3
3
  contentType: string;
4
4
  dataUrl: string;
5
5
  }] | [any, undefined]>;
6
- getArrayBuffer: (url: string) => Promise<[any, undefined] | [null, ArrayBuffer]>;
7
- getJson: (url: string) => Promise<[any, undefined] | [null, any]>;
6
+ getArrayBuffer: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, ArrayBuffer]>;
7
+ getJson: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, any]>;
8
8
  download: (url: string, opts?: {
9
9
  success?: ((buffer: Uint8Array) => void) | undefined;
10
10
  progress?: ((percentage: number, current: number, total: number) => void) | undefined;
11
11
  fail?: ((error: Error) => void) | undefined;
12
12
  }) => Promise<Uint8Array | undefined>;
13
- getText: (url: string) => Promise<[any, undefined] | [null, string]>;
13
+ getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
14
+ cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
14
15
  };
15
16
  export default _default;
@@ -20,7 +20,7 @@ declare const _default: {
20
20
  queryPermission: (name: string, def?: PermissionState) => Promise<PermissionState>;
21
21
  isAllowed: (status: PermissionState | undefined, prompt?: boolean) => boolean;
22
22
  legacyCopy: (text: string) => boolean;
23
- takeHtmlLinks: (htmlContent: string) => string[];
23
+ takeHtmlLinks: (htmlContent: string) => never[];
24
24
  takeHtml: (htmlContent: string, regex: RegExp) => string[];
25
25
  };
26
26
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.9.1",
3
+ "version": "2.9.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",