@atcute/uint8array 1.1.0 → 1.1.2

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/lib/index.ts CHANGED
@@ -142,67 +142,119 @@ const _fromCharCode = String.fromCharCode;
142
142
  const _shortString = (from: Uint8Array, p: number, length: number): string | null => {
143
143
  if (length < 4) {
144
144
  if (length < 2) {
145
- if (length === 0) return '';
145
+ if (length === 0) {
146
+ return '';
147
+ }
146
148
  const a = from[p];
147
- if (a & 0x80) return null;
149
+ if (a & 0x80) {
150
+ return null;
151
+ }
148
152
  return _fromCharCode(a);
149
153
  }
150
154
  const a = from[p];
151
155
  const b = from[p + 1];
152
- if ((a | b) & 0x80) return null;
153
- if (length === 2) return _fromCharCode(a, b);
156
+ if ((a | b) & 0x80) {
157
+ return null;
158
+ }
159
+ if (length === 2) {
160
+ return _fromCharCode(a, b);
161
+ }
154
162
  const c = from[p + 2];
155
- if (c & 0x80) return null;
163
+ if (c & 0x80) {
164
+ return null;
165
+ }
156
166
  return _fromCharCode(a, b, c);
157
167
  }
158
168
  const a = from[p];
159
169
  const b = from[p + 1];
160
170
  const c = from[p + 2];
161
171
  const d = from[p + 3];
162
- if ((a | b | c | d) & 0x80) return null;
172
+ if ((a | b | c | d) & 0x80) {
173
+ return null;
174
+ }
163
175
  if (length < 8) {
164
- if (length === 4) return _fromCharCode(a, b, c, d);
176
+ if (length === 4) {
177
+ return _fromCharCode(a, b, c, d);
178
+ }
165
179
  const e = from[p + 4];
166
- if (e & 0x80) return null;
167
- if (length === 5) return _fromCharCode(a, b, c, d, e);
180
+ if (e & 0x80) {
181
+ return null;
182
+ }
183
+ if (length === 5) {
184
+ return _fromCharCode(a, b, c, d, e);
185
+ }
168
186
  const f = from[p + 5];
169
- if (f & 0x80) return null;
170
- if (length === 6) return _fromCharCode(a, b, c, d, e, f);
187
+ if (f & 0x80) {
188
+ return null;
189
+ }
190
+ if (length === 6) {
191
+ return _fromCharCode(a, b, c, d, e, f);
192
+ }
171
193
  const g = from[p + 6];
172
- if (g & 0x80) return null;
194
+ if (g & 0x80) {
195
+ return null;
196
+ }
173
197
  return _fromCharCode(a, b, c, d, e, f, g);
174
198
  }
175
199
  const e = from[p + 4];
176
200
  const f = from[p + 5];
177
201
  const g = from[p + 6];
178
202
  const h = from[p + 7];
179
- if ((e | f | g | h) & 0x80) return null;
203
+ if ((e | f | g | h) & 0x80) {
204
+ return null;
205
+ }
180
206
  if (length < 12) {
181
- if (length === 8) return _fromCharCode(a, b, c, d, e, f, g, h);
207
+ if (length === 8) {
208
+ return _fromCharCode(a, b, c, d, e, f, g, h);
209
+ }
182
210
  const i = from[p + 8];
183
- if (i & 0x80) return null;
184
- if (length === 9) return _fromCharCode(a, b, c, d, e, f, g, h, i);
211
+ if (i & 0x80) {
212
+ return null;
213
+ }
214
+ if (length === 9) {
215
+ return _fromCharCode(a, b, c, d, e, f, g, h, i);
216
+ }
185
217
  const j = from[p + 9];
186
- if (j & 0x80) return null;
187
- if (length === 10) return _fromCharCode(a, b, c, d, e, f, g, h, i, j);
218
+ if (j & 0x80) {
219
+ return null;
220
+ }
221
+ if (length === 10) {
222
+ return _fromCharCode(a, b, c, d, e, f, g, h, i, j);
223
+ }
188
224
  const k = from[p + 10];
189
- if (k & 0x80) return null;
225
+ if (k & 0x80) {
226
+ return null;
227
+ }
190
228
  return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
191
229
  }
192
230
  const i = from[p + 8];
193
231
  const j = from[p + 9];
194
232
  const k = from[p + 10];
195
233
  const l = from[p + 11];
196
- if ((i | j | k | l) & 0x80) return null;
197
- if (length === 12) return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
234
+ if ((i | j | k | l) & 0x80) {
235
+ return null;
236
+ }
237
+ if (length === 12) {
238
+ return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
239
+ }
198
240
  const m = from[p + 12];
199
- if (m & 0x80) return null;
200
- if (length === 13) return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
241
+ if (m & 0x80) {
242
+ return null;
243
+ }
244
+ if (length === 13) {
245
+ return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
246
+ }
201
247
  const n = from[p + 13];
202
- if (n & 0x80) return null;
203
- if (length === 14) return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
248
+ if (n & 0x80) {
249
+ return null;
250
+ }
251
+ if (length === 14) {
252
+ return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
253
+ }
204
254
  const o = from[p + 14];
205
- if (o & 0x80) return null;
255
+ if (o & 0x80) {
256
+ return null;
257
+ }
206
258
  return _fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
207
259
  };
208
260
 
@@ -220,7 +272,12 @@ export const decodeUtf8From = (
220
272
  ): string => {
221
273
  if (length <= 15) {
222
274
  const result = _shortString(from, offset, length);
223
- if (result !== null) return result;
275
+ if (result !== null) {
276
+ return result;
277
+ }
278
+ }
279
+ if (offset === 0 && length === from.length) {
280
+ return textDecoder.decode(from);
224
281
  }
225
282
  return textDecoder.decode(from.subarray(offset, offset + length));
226
283
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atcute/uint8array",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "uint8array utilities",
5
5
  "license": "0BSD",
6
6
  "repository": {
@@ -11,7 +11,8 @@
11
11
  "dist/",
12
12
  "lib/",
13
13
  "!lib/**/*.bench.ts",
14
- "!lib/**/*.test.ts"
14
+ "!lib/**/*.test.ts",
15
+ "!dist/**/*.{test,bench}.*"
15
16
  ],
16
17
  "type": "module",
17
18
  "sideEffects": false,
@@ -26,10 +27,10 @@
26
27
  "access": "public"
27
28
  },
28
29
  "devDependencies": {
29
- "@types/bun": "^1.3.5"
30
+ "@types/bun": "^1.3.13"
30
31
  },
31
32
  "scripts": {
32
- "build": "tsgo --project tsconfig.build.json",
33
+ "build": "tsgo",
33
34
  "prepublish": "rm -rf dist; pnpm run build"
34
35
  }
35
36
  }