ddan-js 2.9.2 → 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
  };
@@ -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: {
@@ -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<{
@@ -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: {
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.9.2",
3
+ "version": "2.9.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",