@upstash/redis 1.16.1-rc.0 → 1.16.1-rc.1

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/README.md CHANGED
@@ -81,24 +81,6 @@ data = await redis.spop('animals', 1)
81
81
  console.log(data)
82
82
  ```
83
83
 
84
- ### Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
85
-
86
- If you are running on nodejs v17 and earlier, `fetch` will not be natively
87
- supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
88
- for you. But if you are running on bare node, you need to either specify a
89
- polyfill yourself or change the import path to:
90
-
91
- ```typescript
92
- import { Redis } from "@upstash/redis/with-fetch";
93
- ```
94
-
95
- ### Upgrading from v0.2.0?
96
-
97
- Please read the
98
- [migration guide](https://docs.upstash.com/redis/sdks/javascriptsdk/migration).
99
- For further explanation we wrote a
100
- [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
101
-
102
84
  ## Docs
103
85
 
104
86
  See [the documentation](https://docs.upstash.com/features/javascriptsdk) for
@@ -118,6 +100,3 @@ the url and token
118
100
  ```sh
119
101
  UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
120
102
  ```
121
-
122
- ```
123
- ```
package/esm/pkg/http.js CHANGED
@@ -1,6 +1,4 @@
1
1
  import { UpstashError } from "./error.js";
2
- import * as utf8 from "../deps/deno.land/std@0.82.0/encoding/utf8.js";
3
- import * as base64 from "../deps/deno.land/std@0.82.0/encoding/base64.js";
4
2
  export class HttpClient {
5
3
  constructor(config) {
6
4
  Object.defineProperty(this, "baseUrl", {
@@ -27,13 +25,19 @@ export class HttpClient {
27
25
  writable: true,
28
26
  value: void 0
29
27
  });
28
+ this.options = {
29
+ backend: config.options?.backend,
30
+ agent: config.agent,
31
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
32
+ };
30
33
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
31
34
  this.headers = {
32
35
  "Content-Type": "application/json",
33
- "Upstash-Encoding": "base64",
34
36
  ...config.headers,
35
37
  };
36
- this.options = { backend: config.options?.backend, agent: config.agent };
38
+ if (this.options.responseEncoding === "base64") {
39
+ this.headers["Upstash-Encoding"] = "base64";
40
+ }
37
41
  if (typeof config?.retry === "boolean" && config?.retry === false) {
38
42
  this.retry = {
39
43
  attempts: 1,
@@ -79,28 +83,30 @@ export class HttpClient {
79
83
  if (!res.ok) {
80
84
  throw new UpstashError(body.error);
81
85
  }
82
- console.time("decode");
83
- const resp = Array.isArray(body) ? body.map(decode) : decode(body);
84
- console.timeEnd("decode");
85
- return resp;
86
+ if (this.options?.responseEncoding === "base64") {
87
+ console.log("decoding base64");
88
+ return Array.isArray(body) ? body.map(decode) : decode(body);
89
+ }
90
+ return body;
86
91
  }
87
92
  }
88
93
  function base64decode(b64) {
89
94
  let dec = "";
90
95
  try {
91
- console.time("atob");
92
96
  /**
93
- * THIS WORKS
97
+ * Using only atob() is not enough because it doesn't work with unicode characters
94
98
  */
95
- const s = utf8.decode(base64.decode(b64));
96
- console.timeEnd("atob");
97
- console.time("escape");
98
- console.timeEnd("escape");
99
- dec = decodeURIComponent(s);
99
+ const binString = atob(b64);
100
+ const size = binString.length;
101
+ const bytes = new Uint8Array(size);
102
+ for (let i = 0; i < size; i++) {
103
+ bytes[i] = binString.charCodeAt(i);
104
+ }
105
+ dec = new TextDecoder().decode(bytes);
100
106
  }
101
107
  catch (e) {
102
108
  console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
103
- return dec;
109
+ return b64;
104
110
  }
105
111
  try {
106
112
  return decodeURIComponent(dec);
@@ -30,6 +30,7 @@ export class Redis extends core.Redis {
30
30
  retry: config.retry,
31
31
  baseUrl: config.url,
32
32
  headers: { authorization: `Bearer ${config.token}` },
33
+ responseEncoding: config.responseEncoding,
33
34
  });
34
35
  super(client, {
35
36
  automaticDeserialization: config.automaticDeserialization,
@@ -32,6 +32,7 @@ export class Redis extends core.Redis {
32
32
  retry: config.retry,
33
33
  headers: { authorization: `Bearer ${config.token}` },
34
34
  options: { backend: config.backend },
35
+ responseEncoding: config.responseEncoding,
35
36
  });
36
37
  super(client, {
37
38
  automaticDeserialization: config.automaticDeserialization,
@@ -25,7 +25,8 @@ export class Redis extends core.Redis {
25
25
  baseUrl: configOrRequester.url,
26
26
  retry: configOrRequester.retry,
27
27
  headers: { authorization: `Bearer ${configOrRequester.token}` },
28
- // agent: configOrRequester.agent,
28
+ // agent: configOrRequester.agent,
29
+ responseEncoding: configOrRequester.responseEncoding,
29
30
  });
30
31
  super(client, {
31
32
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -25,6 +25,7 @@ export class Redis extends core.Redis {
25
25
  retry: configOrRequester.retry,
26
26
  headers: { authorization: `Bearer ${configOrRequester.token}` },
27
27
  agent: configOrRequester.agent,
28
+ responseEncoding: configOrRequester.responseEncoding,
28
29
  });
29
30
  super(client, {
30
31
  automaticDeserialization: configOrRequester.automaticDeserialization,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/platforms/nodejs.js",
4
4
  "types": "./types/platforms/nodejs.d.ts",
5
5
  "name": "@upstash/redis",
6
- "version": "v1.16.1-rc.0",
6
+ "version": "v1.16.1-rc.1",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -1,32 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.HttpClient = void 0;
27
4
  const error_js_1 = require("./error.js");
28
- const utf8 = __importStar(require("../deps/deno.land/std@0.82.0/encoding/utf8.js"));
29
- const base64 = __importStar(require("../deps/deno.land/std@0.82.0/encoding/base64.js"));
30
5
  class HttpClient {
31
6
  constructor(config) {
32
7
  Object.defineProperty(this, "baseUrl", {
@@ -53,13 +28,19 @@ class HttpClient {
53
28
  writable: true,
54
29
  value: void 0
55
30
  });
31
+ this.options = {
32
+ backend: config.options?.backend,
33
+ agent: config.agent,
34
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
35
+ };
56
36
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
57
37
  this.headers = {
58
38
  "Content-Type": "application/json",
59
- "Upstash-Encoding": "base64",
60
39
  ...config.headers,
61
40
  };
62
- this.options = { backend: config.options?.backend, agent: config.agent };
41
+ if (this.options.responseEncoding === "base64") {
42
+ this.headers["Upstash-Encoding"] = "base64";
43
+ }
63
44
  if (typeof config?.retry === "boolean" && config?.retry === false) {
64
45
  this.retry = {
65
46
  attempts: 1,
@@ -105,29 +86,31 @@ class HttpClient {
105
86
  if (!res.ok) {
106
87
  throw new error_js_1.UpstashError(body.error);
107
88
  }
108
- console.time("decode");
109
- const resp = Array.isArray(body) ? body.map(decode) : decode(body);
110
- console.timeEnd("decode");
111
- return resp;
89
+ if (this.options?.responseEncoding === "base64") {
90
+ console.log("decoding base64");
91
+ return Array.isArray(body) ? body.map(decode) : decode(body);
92
+ }
93
+ return body;
112
94
  }
113
95
  }
114
96
  exports.HttpClient = HttpClient;
115
97
  function base64decode(b64) {
116
98
  let dec = "";
117
99
  try {
118
- console.time("atob");
119
100
  /**
120
- * THIS WORKS
101
+ * Using only atob() is not enough because it doesn't work with unicode characters
121
102
  */
122
- const s = utf8.decode(base64.decode(b64));
123
- console.timeEnd("atob");
124
- console.time("escape");
125
- console.timeEnd("escape");
126
- dec = decodeURIComponent(s);
103
+ const binString = atob(b64);
104
+ const size = binString.length;
105
+ const bytes = new Uint8Array(size);
106
+ for (let i = 0; i < size; i++) {
107
+ bytes[i] = binString.charCodeAt(i);
108
+ }
109
+ dec = new TextDecoder().decode(bytes);
127
110
  }
128
111
  catch (e) {
129
112
  console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
130
- return dec;
113
+ return b64;
131
114
  }
132
115
  try {
133
116
  return decodeURIComponent(dec);
@@ -56,6 +56,7 @@ class Redis extends core.Redis {
56
56
  retry: config.retry,
57
57
  baseUrl: config.url,
58
58
  headers: { authorization: `Bearer ${config.token}` },
59
+ responseEncoding: config.responseEncoding,
59
60
  });
60
61
  super(client, {
61
62
  automaticDeserialization: config.automaticDeserialization,
@@ -58,6 +58,7 @@ class Redis extends core.Redis {
58
58
  retry: config.retry,
59
59
  headers: { authorization: `Bearer ${config.token}` },
60
60
  options: { backend: config.backend },
61
+ responseEncoding: config.responseEncoding,
61
62
  });
62
63
  super(client, {
63
64
  automaticDeserialization: config.automaticDeserialization,
@@ -51,7 +51,8 @@ class Redis extends core.Redis {
51
51
  baseUrl: configOrRequester.url,
52
52
  retry: configOrRequester.retry,
53
53
  headers: { authorization: `Bearer ${configOrRequester.token}` },
54
- // agent: configOrRequester.agent,
54
+ // agent: configOrRequester.agent,
55
+ responseEncoding: configOrRequester.responseEncoding,
55
56
  });
56
57
  super(client, {
57
58
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -51,6 +51,7 @@ class Redis extends core.Redis {
51
51
  retry: configOrRequester.retry,
52
52
  headers: { authorization: `Bearer ${configOrRequester.token}` },
53
53
  agent: configOrRequester.agent,
54
+ responseEncoding: configOrRequester.responseEncoding,
54
55
  });
55
56
  super(client, {
56
57
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -29,22 +29,52 @@ export declare type RetryConfig = false | {
29
29
  */
30
30
  backoff?: (retryCount: number) => number;
31
31
  };
32
- declare type Options = {
32
+ export declare type Options = {
33
33
  backend?: string;
34
34
  };
35
+ export declare type RequesterConfig = {
36
+ /**
37
+ * Configure the retry behaviour in case of network errors
38
+ */
39
+ retry?: RetryConfig;
40
+ /**
41
+ * Due to the nature of dynamic and custom data, it is possible to write data to redis that is not
42
+ * valid json and will therefore cause errors when deserializing. This used to happen very
43
+ * frequently with non-utf8 data, such as emojis.
44
+ *
45
+ * By default we will therefore encode the data as base64 on the server, before sending it to the
46
+ * client. The client will then decode the base64 data and parse it as utf8.
47
+ *
48
+ * For very large entries, this can add a few milliseconds, so if you are sure that your data is
49
+ * valid utf8, you can disable this behaviour by setting this option to false.
50
+ *
51
+ * Here's what the response body looks like:
52
+ *
53
+ * ```json
54
+ * {
55
+ * result?: "base64-encoded",
56
+ * error?: string
57
+ * }
58
+ * ```
59
+ *
60
+ * @default "base64"
61
+ */
62
+ responseEncoding?: false | "base64";
63
+ };
35
64
  export declare type HttpClientConfig = {
36
65
  headers?: Record<string, string>;
37
66
  baseUrl: string;
38
67
  options?: Options;
39
68
  retry?: RetryConfig;
40
69
  agent?: any;
41
- };
70
+ } & RequesterConfig;
42
71
  export declare class HttpClient implements Requester {
43
72
  baseUrl: string;
44
73
  headers: Record<string, string>;
45
74
  readonly options?: {
46
75
  backend?: string;
47
76
  agent: any;
77
+ responseEncoding?: false | "base64";
48
78
  };
49
79
  readonly retry: {
50
80
  attempts: number;
@@ -53,4 +83,3 @@ export declare class HttpClient implements Requester {
53
83
  constructor(config: HttpClientConfig);
54
84
  request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
55
85
  }
56
- export {};
@@ -1,5 +1,6 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
+ import { RequesterConfig } from "../pkg/http.js";
3
4
  export type { Requester, UpstashRequest, UpstashResponse };
4
5
  /**
5
6
  * Connection credentials for upstash redis.
@@ -14,11 +15,7 @@ export declare type RedisConfigCloudflare = {
14
15
  * UPSTASH_REDIS_REST_TOKEN
15
16
  */
16
17
  token: string;
17
- /**
18
- * Configure the retry behaviour in case of network errors
19
- */
20
- retry?: RetryConfig;
21
- } & core.RedisOptions;
18
+ } & core.RedisOptions & RequesterConfig;
22
19
  /**
23
20
  * Serverless redis client for upstash.
24
21
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -20,11 +20,7 @@ export declare type RedisConfigFastly = {
20
20
  * referenced by name.
21
21
  */
22
22
  backend: string;
23
- /**
24
- * Configure the retry behaviour in case of network errors
25
- */
26
- retry?: RetryConfig;
27
- } & core.RedisOptions;
23
+ } & core.RedisOptions & RequesterConfig;
28
24
  /**
29
25
  * Serverless redis client for upstash.
30
26
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  import "isomorphic-fetch";
4
4
  export type { Requester, UpstashRequest, UpstashResponse };
5
5
  /**
@@ -15,26 +15,7 @@ export declare type RedisConfigNodejs = {
15
15
  * UPSTASH_REDIS_REST_TOKEN
16
16
  */
17
17
  token: string;
18
- /**
19
- * An agent allows you to reuse connections to reduce latency for multiple sequential requests.
20
- *
21
- * This is a node specific implementation and is not supported in various runtimes like Vercel
22
- * edge functions.
23
- *
24
- * @example
25
- * ```ts
26
- * import https from "https"
27
- *
28
- * const options: RedisConfigNodejs = {
29
- * agent: new https.Agent({ keepAlive: true })
30
- * }
31
- * ```
32
- */
33
- /**
34
- * Configure the retry behaviour in case of network errors
35
- */
36
- retry?: RetryConfig;
37
- } & core.RedisOptions;
18
+ } & core.RedisOptions & RequesterConfig;
38
19
  /**
39
20
  * Serverless redis client for upstash.
40
21
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -30,11 +30,7 @@ export declare type RedisConfigNodejs = {
30
30
  * ```
31
31
  */
32
32
  agent?: any;
33
- /**
34
- * Configure the retry behaviour in case of network errors
35
- */
36
- retry?: RetryConfig;
37
- } & core.RedisOptions;
33
+ } & core.RedisOptions & RequesterConfig;
38
34
  /**
39
35
  * Serverless redis client for upstash.
40
36
  */
@@ -1,54 +0,0 @@
1
- // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2
- // deno-fmt-ignore
3
- const base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
4
- "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
5
- "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
6
- "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4",
7
- "5", "6", "7", "8", "9", "+", "/"];
8
- /**
9
- * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
10
- * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
11
- * @param data
12
- */
13
- export function encode(data) {
14
- const uint8 = typeof data === "string"
15
- ? new TextEncoder().encode(data)
16
- : data instanceof Uint8Array
17
- ? data
18
- : new Uint8Array(data);
19
- let result = "", i;
20
- const l = uint8.length;
21
- for (i = 2; i < l; i += 3) {
22
- result += base64abc[uint8[i - 2] >> 2];
23
- result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
24
- result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
25
- result += base64abc[uint8[i] & 0x3f];
26
- }
27
- if (i === l + 1) {
28
- // 1 octet yet to write
29
- result += base64abc[uint8[i - 2] >> 2];
30
- result += base64abc[(uint8[i - 2] & 0x03) << 4];
31
- result += "==";
32
- }
33
- if (i === l) {
34
- // 2 octets yet to write
35
- result += base64abc[uint8[i - 2] >> 2];
36
- result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
37
- result += base64abc[(uint8[i - 1] & 0x0f) << 2];
38
- result += "=";
39
- }
40
- return result;
41
- }
42
- /**
43
- * Decodes a given RFC4648 base64 encoded string
44
- * @param b64
45
- */
46
- export function decode(b64) {
47
- const binString = atob(b64);
48
- const size = binString.length;
49
- const bytes = new Uint8Array(size);
50
- for (let i = 0; i < size; i++) {
51
- bytes[i] = binString.charCodeAt(i);
52
- }
53
- return bytes;
54
- }
@@ -1,13 +0,0 @@
1
- // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2
- /** A default TextEncoder instance */
3
- export const encoder = new TextEncoder();
4
- /** Shorthand for new TextEncoder().encode() */
5
- export function encode(input) {
6
- return encoder.encode(input);
7
- }
8
- /** A default TextDecoder instance */
9
- export const decoder = new TextDecoder();
10
- /** Shorthand for new TextDecoder().decode() */
11
- export function decode(input) {
12
- return decoder.decode(input);
13
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.decode = exports.encode = void 0;
5
- // deno-fmt-ignore
6
- const base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
7
- "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
8
- "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
9
- "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4",
10
- "5", "6", "7", "8", "9", "+", "/"];
11
- /**
12
- * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
13
- * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
14
- * @param data
15
- */
16
- function encode(data) {
17
- const uint8 = typeof data === "string"
18
- ? new TextEncoder().encode(data)
19
- : data instanceof Uint8Array
20
- ? data
21
- : new Uint8Array(data);
22
- let result = "", i;
23
- const l = uint8.length;
24
- for (i = 2; i < l; i += 3) {
25
- result += base64abc[uint8[i - 2] >> 2];
26
- result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
27
- result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
28
- result += base64abc[uint8[i] & 0x3f];
29
- }
30
- if (i === l + 1) {
31
- // 1 octet yet to write
32
- result += base64abc[uint8[i - 2] >> 2];
33
- result += base64abc[(uint8[i - 2] & 0x03) << 4];
34
- result += "==";
35
- }
36
- if (i === l) {
37
- // 2 octets yet to write
38
- result += base64abc[uint8[i - 2] >> 2];
39
- result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
40
- result += base64abc[(uint8[i - 1] & 0x0f) << 2];
41
- result += "=";
42
- }
43
- return result;
44
- }
45
- exports.encode = encode;
46
- /**
47
- * Decodes a given RFC4648 base64 encoded string
48
- * @param b64
49
- */
50
- function decode(b64) {
51
- const binString = atob(b64);
52
- const size = binString.length;
53
- const bytes = new Uint8Array(size);
54
- for (let i = 0; i < size; i++) {
55
- bytes[i] = binString.charCodeAt(i);
56
- }
57
- return bytes;
58
- }
59
- exports.decode = decode;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.decode = exports.decoder = exports.encode = exports.encoder = void 0;
5
- /** A default TextEncoder instance */
6
- exports.encoder = new TextEncoder();
7
- /** Shorthand for new TextEncoder().encode() */
8
- function encode(input) {
9
- return exports.encoder.encode(input);
10
- }
11
- exports.encode = encode;
12
- /** A default TextDecoder instance */
13
- exports.decoder = new TextDecoder();
14
- /** Shorthand for new TextDecoder().decode() */
15
- function decode(input) {
16
- return exports.decoder.decode(input);
17
- }
18
- exports.decode = decode;
@@ -1,11 +0,0 @@
1
- /**
2
- * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
3
- * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
4
- * @param data
5
- */
6
- export declare function encode(data: ArrayBuffer | string): string;
7
- /**
8
- * Decodes a given RFC4648 base64 encoded string
9
- * @param b64
10
- */
11
- export declare function decode(b64: string): Uint8Array;
@@ -1,8 +0,0 @@
1
- /** A default TextEncoder instance */
2
- export declare const encoder: any;
3
- /** Shorthand for new TextEncoder().encode() */
4
- export declare function encode(input?: string): Uint8Array;
5
- /** A default TextDecoder instance */
6
- export declare const decoder: any;
7
- /** Shorthand for new TextDecoder().decode() */
8
- export declare function decode(input?: Uint8Array): string;