onchain-utility 0.0.1 → 0.0.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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "onchain-utility",
3
3
  "description": "This package contains misc utilities for onchain.",
4
4
  "license": "MIT",
5
- "version": "0.0.1",
5
+ "version": "0.0.3",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": {
@@ -33,6 +33,39 @@
33
33
  "types": "./src/Traversal/index.ts",
34
34
  "default": "./dist/Traversal.js"
35
35
  }
36
+ },
37
+ "./hooks": {
38
+ "import": {
39
+ "types": "./src/Hooks/index.ts",
40
+ "default": "./dist/Hooks.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./src/Hooks/index.ts",
44
+ "default": "./dist/Hooks.js"
45
+ }
46
+ },
47
+ "./base64": {
48
+ "import": {
49
+ "types": "./src/Base64/index.ts",
50
+ "default": "./dist/Base64.mjs"
51
+ },
52
+ "require": {
53
+ "types": "./src/Base64/index.ts",
54
+ "default": "./dist/Base64.js"
55
+ }
56
+ },
57
+ "./tree": {
58
+ "import": {
59
+ "types": "./src/Tree/index.ts",
60
+ "default": "./dist/Tree.mjs"
61
+ },
62
+ "require": {
63
+ "types": "./src/Tree/index.ts",
64
+ "default": "./dist/Tree.js"
65
+ }
36
66
  }
67
+ },
68
+ "dependencies": {
69
+ "ahooks": "^3.9.0"
37
70
  }
38
71
  }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import {generateSecureUUID} from '../base';
10
+
11
+ export function getBase64Regular() {
12
+ return /data:(.+?)\/(.+?);base64,(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?/g;
13
+ }
14
+
15
+ export function base64ToMimeType(base64Src: string) {
16
+ const regular = new RegExp(`^data:(.*?)/(.*?);base64`);
17
+ const [, type, suffix] = base64Src.match(regular) || [];
18
+ return {
19
+ mimeType: `${type}/${suffix}`,
20
+ suffix,
21
+ type,
22
+ };
23
+ }
24
+
25
+ /** base64 转 文件 */
26
+ export function base64ToFile({
27
+ type,
28
+ text,
29
+ suffix,
30
+ filename,
31
+ }: {
32
+ text: string;
33
+ type?: string;
34
+ filename?: string;
35
+ suffix?: string;
36
+ }) {
37
+ const mimeType =
38
+ type && suffix ? `${type}/${suffix}` : base64ToMimeType(text).mimeType;
39
+ const base64WithoutPrefix = text.split(';base64,').pop()!;
40
+
41
+ const byteCharacters = atob(base64WithoutPrefix);
42
+ const byteArrays = [];
43
+
44
+ for (let offset = 0; offset < byteCharacters.length; offset += 512) {
45
+ const slice = byteCharacters.slice(offset, offset + 512);
46
+ const byteNumbers = new Array(slice.length);
47
+
48
+ for (let i = 0; i < slice.length; i++) {
49
+ byteNumbers[i] = slice.charCodeAt(i);
50
+ }
51
+
52
+ const byteArray = new Uint8Array(byteNumbers);
53
+ byteArrays.push(byteArray);
54
+ }
55
+
56
+ const blob = new Blob(byteArrays, {type: mimeType});
57
+
58
+ return new File([blob], `${filename || generateSecureUUID()}.${suffix}`, {
59
+ type: mimeType,
60
+ });
61
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export {useReactive, useShallowReactive} from './reactive';
9
+ export {default as useStore} from './useStore';