onchain-utility 0.0.10 → 0.0.11

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/dist/Base64.js CHANGED
@@ -87,7 +87,19 @@ function base64ToFile({
87
87
  type: mimeType
88
88
  });
89
89
  }
90
+ function toBase64UTF8(str) {
91
+ const bytes = new TextEncoder().encode(JSON.stringify(str));
92
+ const binString = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
93
+ return btoa(binString);
94
+ }
95
+ function fromBase64UTF8(base64) {
96
+ const binString = atob(base64);
97
+ const bytes = Uint8Array.from(binString, char => char.charCodeAt(0));
98
+ return JSON.parse(new TextDecoder().decode(bytes));
99
+ }
90
100
 
91
101
  exports.base64ToFile = base64ToFile;
92
102
  exports.base64ToMimeType = base64ToMimeType;
103
+ exports.fromBase64UTF8 = fromBase64UTF8;
93
104
  exports.getBase64Regular = getBase64Regular;
105
+ exports.toBase64UTF8 = toBase64UTF8;
package/dist/Base64.mjs CHANGED
@@ -85,5 +85,15 @@ function base64ToFile({
85
85
  type: mimeType
86
86
  });
87
87
  }
88
+ function toBase64UTF8(str) {
89
+ const bytes = new TextEncoder().encode(JSON.stringify(str));
90
+ const binString = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
91
+ return btoa(binString);
92
+ }
93
+ function fromBase64UTF8(base64) {
94
+ const binString = atob(base64);
95
+ const bytes = Uint8Array.from(binString, char => char.charCodeAt(0));
96
+ return JSON.parse(new TextDecoder().decode(bytes));
97
+ }
88
98
 
89
- export { base64ToFile, base64ToMimeType, getBase64Regular };
99
+ export { base64ToFile, base64ToMimeType, fromBase64UTF8, getBase64Regular, toBase64UTF8 };
@@ -145,6 +145,16 @@ function base64ToFile({
145
145
  type: mimeType
146
146
  });
147
147
  }
148
+ function toBase64UTF8(str) {
149
+ const bytes = new TextEncoder().encode(JSON.stringify(str));
150
+ const binString = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
151
+ return btoa(binString);
152
+ }
153
+ function fromBase64UTF8(base64) {
154
+ const binString = atob(base64);
155
+ const bytes = Uint8Array.from(binString, char => char.charCodeAt(0));
156
+ return JSON.parse(new TextDecoder().decode(bytes));
157
+ }
148
158
 
149
159
  /******************************************************************************
150
160
  Copyright (c) Microsoft Corporation.
@@ -1643,6 +1653,7 @@ exports.createEnumObject = createEnumObject;
1643
1653
  exports.deleteTreeNodes = deleteTreeNodes;
1644
1654
  exports.dfs = dfs;
1645
1655
  exports.downgrade = downgrade;
1656
+ exports.fromBase64UTF8 = fromBase64UTF8;
1646
1657
  exports.generateSecureUUID = generateSecureUUID;
1647
1658
  exports.generatedAcrossHierarchySort = generatedAcrossHierarchySort;
1648
1659
  exports.getBase64Regular = getBase64Regular;
@@ -1662,6 +1673,7 @@ exports.movUp = movUp;
1662
1673
  exports.move = move;
1663
1674
  exports.moveDown = moveDown;
1664
1675
  exports.t = t;
1676
+ exports.toBase64UTF8 = toBase64UTF8;
1665
1677
  exports.toRawType = toRawType;
1666
1678
  exports.toTypeString = toTypeString;
1667
1679
  exports.translateI18n = translateI18n;
@@ -143,6 +143,16 @@ function base64ToFile({
143
143
  type: mimeType
144
144
  });
145
145
  }
146
+ function toBase64UTF8(str) {
147
+ const bytes = new TextEncoder().encode(JSON.stringify(str));
148
+ const binString = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
149
+ return btoa(binString);
150
+ }
151
+ function fromBase64UTF8(base64) {
152
+ const binString = atob(base64);
153
+ const bytes = Uint8Array.from(binString, char => char.charCodeAt(0));
154
+ return JSON.parse(new TextDecoder().decode(bytes));
155
+ }
146
156
 
147
157
  /******************************************************************************
148
158
  Copyright (c) Microsoft Corporation.
@@ -1630,4 +1640,4 @@ function treeSearch({
1630
1640
  }).filter(row => !!row);
1631
1641
  }
1632
1642
 
1633
- export { _isMoment, arrayAttributeFlat, asyncDfs, base64ToFile, base64ToMimeType, baseTemplate, bfs, createEnumObject, deleteTreeNodes, dfs, downgrade, generateSecureUUID, generatedAcrossHierarchySort, getBase64Regular, getHTMLTagString, getI18nText, getSiblings, getTreeRelation, hasOwnProperty, initTranslateI18nFn, insert, isEmptyObject, isIntegerKey, levelTransformTree, makeDestructurable, mergeAdjacent, movUp, move, moveDown, t, toRawType, toTypeString, translateI18n, treeSearch, upgrade, useReactive, useShallowReactive, useStore };
1643
+ export { _isMoment, arrayAttributeFlat, asyncDfs, base64ToFile, base64ToMimeType, baseTemplate, bfs, createEnumObject, deleteTreeNodes, dfs, downgrade, fromBase64UTF8, generateSecureUUID, generatedAcrossHierarchySort, getBase64Regular, getHTMLTagString, getI18nText, getSiblings, getTreeRelation, hasOwnProperty, initTranslateI18nFn, insert, isEmptyObject, isIntegerKey, levelTransformTree, makeDestructurable, mergeAdjacent, movUp, move, moveDown, t, toBase64UTF8, toRawType, toTypeString, translateI18n, treeSearch, upgrade, useReactive, useShallowReactive, useStore };
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.10",
5
+ "version": "0.0.11",
6
6
  "files": [
7
7
  "dist",
8
8
  "src"
@@ -59,3 +59,17 @@ export function base64ToFile({
59
59
  type: mimeType,
60
60
  });
61
61
  }
62
+
63
+ export function toBase64UTF8<T>(str: T): string {
64
+ const bytes = new TextEncoder().encode(JSON.stringify(str));
65
+ const binString = Array.from(bytes, (byte) => String.fromCharCode(byte)).join(
66
+ '',
67
+ );
68
+ return btoa(binString);
69
+ }
70
+
71
+ export function fromBase64UTF8<T>(base64: string): T {
72
+ const binString = atob(base64);
73
+ const bytes = Uint8Array.from(binString, (char) => char.charCodeAt(0));
74
+ return JSON.parse(new TextDecoder().decode(bytes));
75
+ }