hono 0.5.7 → 0.5.8

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.
@@ -6,5 +6,6 @@ declare type Data = string | object | boolean;
6
6
  export declare const sha256: (data: Data) => Promise<string>;
7
7
  export declare const sha1: (data: Data) => Promise<string>;
8
8
  export declare const createHash: (data: Data, algorithm: Algorithm) => Promise<string>;
9
+ export declare const encodeBase64: (str: string) => any;
9
10
  export declare const decodeBase64: (str: string) => any;
10
11
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeBase64 = exports.createHash = exports.sha1 = exports.sha256 = void 0;
3
+ exports.decodeBase64 = exports.encodeBase64 = exports.createHash = exports.sha1 = exports.sha256 = void 0;
4
4
  const sha256 = async (data) => {
5
5
  const algorithm = { name: 'SHA-256', alias: 'sha256' };
6
6
  const hash = await (0, exports.createHash)(data, algorithm);
@@ -34,6 +34,28 @@ const createHash = async (data, algorithm) => {
34
34
  }
35
35
  };
36
36
  exports.createHash = createHash;
37
+ const encodeBase64 = (str) => {
38
+ try {
39
+ const encoder = new TextEncoder();
40
+ const bytes = encoder.encode(str);
41
+ const length = bytes.byteLength;
42
+ let binary = '';
43
+ for (let i = 0; i < length; i++) {
44
+ binary += String.fromCharCode(bytes[i]);
45
+ }
46
+ return btoa(binary);
47
+ }
48
+ catch (_a) { }
49
+ try {
50
+ const { Buffer } = require('buffer');
51
+ return Buffer.from(str).toString('base64');
52
+ }
53
+ catch (e) {
54
+ console.error('If you want to do "encodeBase64", polyfill "buffer" module.');
55
+ throw e;
56
+ }
57
+ };
58
+ exports.encodeBase64 = encodeBase64;
37
59
  const decodeBase64 = (str) => {
38
60
  try {
39
61
  const text = atob(str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "[炎] Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,6 +29,7 @@
29
29
  "./router/trie-router": "./dist/router/trie-router/router.js",
30
30
  "./router/reg-exp-router": "./dist/router/reg-exp-router/index.js",
31
31
  "./utils/cloudflare": "./dist/utils/cloudflare.js",
32
+ "./utils/crypto": "./dist/utils/crypto.js",
32
33
  "./utils/mime": "./dist/utils/mime.js"
33
34
  },
34
35
  "typesVersions": {
@@ -72,6 +73,9 @@
72
73
  "utils/cloudflare": [
73
74
  "./dist/utils/cloudflare.d.ts"
74
75
  ],
76
+ "utils/crypto": [
77
+ "./dist/utils/crypto.d.ts"
78
+ ],
75
79
  "utils/mime": [
76
80
  "./dist/utils/mime.d.ts"
77
81
  ]