bare-buffer 2.6.0 → 2.7.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/global.js ADDED
@@ -0,0 +1 @@
1
+ global.Buffer = require('.')
package/index.d.ts ADDED
@@ -0,0 +1,181 @@
1
+ type BufferEncoding =
2
+ | 'ascii'
3
+ | 'base64'
4
+ | 'hex'
5
+ | 'ucs-2'
6
+ | 'ucs2'
7
+ | 'utf-16le'
8
+ | 'utf-8'
9
+ | 'utf16le'
10
+ | 'utf8'
11
+
12
+ declare class Buffer extends Uint8Array {
13
+ static Buffer: Buffer
14
+
15
+ static poolSize: number
16
+
17
+ compare(
18
+ target: Buffer,
19
+ targetStart?: number,
20
+ targetEnd?: number,
21
+ sourceStart?: number,
22
+ sourceEnd?: number
23
+ ): number
24
+
25
+ copy(
26
+ target: Buffer,
27
+ targetStart?: number,
28
+ sourceStart?: number,
29
+ sourceEnd?: number
30
+ ): number
31
+
32
+ equals(target: Buffer): boolean
33
+
34
+ fill(value: string, encoding?: BufferEncoding): this
35
+ fill(value: string, offset?: number, encoding?: BufferEncoding): this
36
+ fill(
37
+ value: string,
38
+ offset?: number,
39
+ end?: number,
40
+ encoding?: BufferEncoding
41
+ ): this
42
+ fill(value: Buffer | number | boolean, offset?: number, end?: number): this
43
+
44
+ includes(value: string, encoding?: BufferEncoding): boolean
45
+ includes(value: string, offset?: number, encoding?: BufferEncoding): boolean
46
+ includes(value: Buffer | number | boolean, offset?: number): boolean
47
+
48
+ indexOf(value: string, encoding?: BufferEncoding): number
49
+ indexOf(value: string, offset?: number, encoding?: BufferEncoding): number
50
+ indexOf(value: Buffer | number | boolean, offset?: number): number
51
+
52
+ lastIndexOf(value: string, encoding?: BufferEncoding): number
53
+ lastIndexOf(value: string, offset?: number, encoding?: BufferEncoding): number
54
+ lastIndexOf(value: Buffer | number | boolean, offset?: number): number
55
+
56
+ swap16(): this
57
+ swap32(): this
58
+ swap64(): this
59
+
60
+ toString(encoding?: BufferEncoding, start?: number, end?: number): string
61
+
62
+ readDoubleBE(offset?: number): number
63
+ readDoubleLE(offset?: number): number
64
+
65
+ readFloatBE(offset?: number): number
66
+ readFloatLE(offset?: number): number
67
+
68
+ readInt8(offset?: number): number
69
+
70
+ readInt16BE(offset?: number): number
71
+ readInt16LE(offset?: number): number
72
+
73
+ readInt32BE(offset?: number): number
74
+ readInt32LE(offset?: number): number
75
+
76
+ readBigInt64BE(offset?: number): bigint
77
+ readBigInt64LE(offset?: number): bigint
78
+
79
+ readUInt8(offset?: number): number
80
+ readUint8(offset?: number): number
81
+
82
+ readUInt16BE(offset?: number): number
83
+ readUint16BE(offset?: number): number
84
+ readUInt16LE(offset?: number): number
85
+ readUint16LE(offset?: number): number
86
+
87
+ readUInt32BE(offset?: number): number
88
+ readUint32BE(offset?: number): number
89
+ readUInt32LE(offset?: number): number
90
+ readUint32LE(offset?: number): number
91
+
92
+ readBigUInt64BE(offset?: number): bigint
93
+ readBigUint64BE(offset?: number): bigint
94
+ readBigUInt64LE(offset?: number): bigint
95
+ readBigUint64LE(offset?: number): bigint
96
+
97
+ write(string: string, encoding?: BufferEncoding): number
98
+ write(string: string, offset?: number, encoding?: BufferEncoding): number
99
+ write(
100
+ string: string,
101
+ offset?: number,
102
+ length?: number,
103
+ encoding?: BufferEncoding
104
+ ): number
105
+
106
+ writeDoubleBE(value: number, offset?: number): number
107
+ writeDoubleLE(value: number, offset?: number): number
108
+
109
+ writeFloatBE(value: number, offset?: number): number
110
+ writeFloatLE(value: number, offset?: number): number
111
+
112
+ writeInt8(value: number, offset?: number): number
113
+
114
+ writeInt16BE(value: number, offset?: number): number
115
+ writeInt16LE(value: number, offset?: number): number
116
+
117
+ writeInt32BE(value: number, offset?: number): number
118
+ writeInt32LE(value: number, offset?: number): number
119
+
120
+ writeBigInt64BE(value: bigint, offset?: number): number
121
+ writeBigInt64LE(value: bigint, offset?: number): number
122
+
123
+ writeUInt8(value: number, offset?: number): number
124
+ writeUint8(value: number, offset?: number): number
125
+
126
+ writeUInt16BE(value: number, offset?: number): number
127
+ writeUint16BE(value: number, offset?: number): number
128
+ writeUInt16LE(value: number, offset?: number): number
129
+ writeUint16LE(value: number, offset?: number): number
130
+
131
+ writeUInt32BE(value: number, offset?: number): number
132
+ writeUint32BE(value: number, offset?: number): number
133
+ writeUInt32LE(value: number, offset?: number): number
134
+ writeUint32LE(value: number, offset?: number): number
135
+
136
+ writeBigUint64BE(value: bigint, offset?: number): number
137
+ writeBigUInt64BE(value: bigint, offset?: number): number
138
+ writeBigUint64LE(value: bigint, offset?: number): number
139
+ writeBigUInt64LE(value: bigint, offset?: number): number
140
+ }
141
+
142
+ declare namespace Buffer {
143
+ export function isBuffer(value: unknown): value is Buffer
144
+
145
+ export function isEncoding(encoding: string): encoding is BufferEncoding
146
+
147
+ export function alloc(
148
+ size: number,
149
+ fill: string,
150
+ encoding?: BufferEncoding
151
+ ): Buffer
152
+ export function alloc(size: number, fill?: Buffer | number | boolean): Buffer
153
+
154
+ export function allocUnsafe(size: number): Buffer
155
+
156
+ export function allocUnsafeSlow(size: number): Buffer
157
+
158
+ export function byteLength(
159
+ string: ArrayBufferView | ArrayBufferLike | string,
160
+ encoding?: BufferEncoding
161
+ ): number
162
+
163
+ export function compare(a: Buffer, b: Buffer): number
164
+
165
+ export function concat(buffers: Buffer[], length?: number): Buffer
166
+
167
+ export function coerce(buffer: Buffer): Buffer
168
+
169
+ export function from(data: Iterable<number>): Buffer
170
+ export function from(data: ArrayLike<number>): Buffer
171
+ export function from(string: string, encoding?: BufferEncoding): Buffer
172
+ export function from(
173
+ arrayBuffer: ArrayBufferLike,
174
+ offset?: number,
175
+ length?: number
176
+ ): Buffer
177
+
178
+ export const constants: { MAX_LENGTH: number; MAX_STRING_LENGTH: number }
179
+ }
180
+
181
+ export = Buffer
package/index.js CHANGED
@@ -8,24 +8,24 @@ const binding = require('./binding')
8
8
 
9
9
  let poolSize = 0
10
10
 
11
- const Buffer = module.exports = exports = class Buffer extends Uint8Array {
11
+ module.exports = exports = class Buffer extends Uint8Array {
12
12
  static {
13
13
  binding.tag(this)
14
14
  }
15
15
 
16
- static get poolSize () {
16
+ static get poolSize() {
17
17
  return poolSize
18
18
  }
19
19
 
20
- static set poolSize (value) {
20
+ static set poolSize(value) {
21
21
  poolSize = Math.max(0, value)
22
22
  }
23
23
 
24
- [Symbol.species] () {
24
+ [Symbol.species]() {
25
25
  return Buffer
26
26
  }
27
27
 
28
- copy (target, targetStart = 0, sourceStart = 0, sourceEnd = this.byteLength) {
28
+ copy(target, targetStart = 0, sourceStart = 0, sourceEnd = this.byteLength) {
29
29
  let source = this
30
30
 
31
31
  if (targetStart < 0) targetStart = 0
@@ -39,14 +39,18 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
39
39
  if (sourceEnd <= sourceStart) return 0
40
40
  if (sourceEnd > source.byteLength) sourceEnd = source.byteLength
41
41
 
42
- if (sourceEnd - sourceStart > targetLength) sourceEnd = sourceStart + targetLength
42
+ if (sourceEnd - sourceStart > targetLength) {
43
+ sourceEnd = sourceStart + targetLength
44
+ }
43
45
 
44
46
  const sourceLength = sourceEnd - sourceStart
45
47
 
46
48
  if (source === target) {
47
49
  target.copyWithin(targetStart, sourceStart, sourceEnd)
48
50
  } else {
49
- if (sourceStart !== 0 || sourceEnd !== source.byteLength) source = source.subarray(sourceStart, sourceEnd)
51
+ if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
52
+ source = source.subarray(sourceStart, sourceEnd)
53
+ }
50
54
 
51
55
  target.set(source, targetStart)
52
56
  }
@@ -54,7 +58,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
54
58
  return sourceLength
55
59
  }
56
60
 
57
- equals (target) {
61
+ equals(target) {
58
62
  const source = this
59
63
 
60
64
  if (source === target) return true
@@ -64,7 +68,13 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
64
68
  return binding.compare(source, target) === 0
65
69
  }
66
70
 
67
- compare (target, targetStart = 0, targetEnd = target.byteLength, sourceStart = 0, sourceEnd = this.byteLength) {
71
+ compare(
72
+ target,
73
+ targetStart = 0,
74
+ targetEnd = target.byteLength,
75
+ sourceStart = 0,
76
+ sourceEnd = this.byteLength
77
+ ) {
68
78
  let source = this
69
79
 
70
80
  if (source === target) return 0
@@ -83,14 +93,18 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
83
93
  if (sourceEnd < sourceStart) sourceEnd = sourceStart
84
94
  if (sourceEnd > source.byteLength) sourceEnd = source.byteLength
85
95
 
86
- if (sourceStart !== 0 || sourceEnd !== source.byteLength) source = source.subarray(sourceStart, sourceEnd)
96
+ if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
97
+ source = source.subarray(sourceStart, sourceEnd)
98
+ }
87
99
 
88
- if (targetStart !== 0 || targetEnd !== target.byteLength) target = target.subarray(targetStart, targetEnd)
100
+ if (targetStart !== 0 || targetEnd !== target.byteLength) {
101
+ target = target.subarray(targetStart, targetEnd)
102
+ }
89
103
 
90
104
  return binding.compare(source, target)
91
105
  }
92
106
 
93
- fill (value, offset = 0, end = this.byteLength, encoding = 'utf8') {
107
+ fill(value, offset = 0, end = this.byteLength, encoding = 'utf8') {
94
108
  if (typeof value === 'string') {
95
109
  // fill(string, encoding)
96
110
  if (typeof offset === 'string') {
@@ -98,7 +112,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
98
112
  offset = 0
99
113
  end = this.byteLength
100
114
 
101
- // fill(string, offset, encoding)
115
+ // fill(string, offset, encoding)
102
116
  } else if (typeof end === 'string') {
103
117
  encoding = end
104
118
  end = this.byteLength
@@ -128,36 +142,48 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
128
142
  return this
129
143
  }
130
144
 
131
- includes (value, offset, encoding) {
145
+ includes(value, offset, encoding) {
132
146
  return this.indexOf(value, offset, encoding) !== -1
133
147
  }
134
148
 
135
- indexOf (value, offset = 0, encoding) {
136
- if (typeof value === 'number') return super.indexOf(value & 0xff, offset)
149
+ indexOf(value, offset = 0, encoding) {
150
+ if (typeof value === 'boolean') value = +value
151
+
152
+ if (typeof value === 'number') {
153
+ return super.indexOf(value & 0xff, offset)
154
+ }
137
155
 
138
156
  return bidirectionalIndexOf(this, value, offset, encoding, true /* first */)
139
157
  }
140
158
 
141
- lastIndexOf (value, offset = this.byteLength - 1, encoding) {
142
- if (typeof value === 'number') return super.lastIndexOf(value & 0xff, offset)
159
+ lastIndexOf(value, offset = this.byteLength - 1, encoding) {
160
+ if (typeof value === 'boolean') value = +value
161
+
162
+ if (typeof value === 'number') {
163
+ return super.lastIndexOf(value & 0xff, offset)
164
+ }
143
165
 
144
166
  return bidirectionalIndexOf(this, value, offset, encoding, false /* last */)
145
167
  }
146
168
 
147
- swap16 () {
169
+ swap16() {
148
170
  const length = this.byteLength
149
171
 
150
- if (length % 2 !== 0) throw new RangeError('Buffer size must be a multiple of 16-bits')
172
+ if (length % 2 !== 0) {
173
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
174
+ }
151
175
 
152
176
  for (let i = 0; i < length; i += 2) swap(this, i, i + 1)
153
177
 
154
178
  return this
155
179
  }
156
180
 
157
- swap32 () {
181
+ swap32() {
158
182
  const length = this.byteLength
159
183
 
160
- if (length % 4 !== 0) throw new RangeError('Buffer size must be a multiple of 32-bits')
184
+ if (length % 4 !== 0) {
185
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
186
+ }
161
187
 
162
188
  for (let i = 0; i < length; i += 4) {
163
189
  swap(this, i, i + 3)
@@ -167,10 +193,12 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
167
193
  return this
168
194
  }
169
195
 
170
- swap64 () {
196
+ swap64() {
171
197
  const length = this.byteLength
172
198
 
173
- if (length % 8 !== 0) throw new RangeError('Buffer size must be a multiple of 64-bits')
199
+ if (length % 8 !== 0) {
200
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
201
+ }
174
202
 
175
203
  for (let i = 0; i < length; i += 8) {
176
204
  swap(this, i, i + 7)
@@ -182,7 +210,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
182
210
  return this
183
211
  }
184
212
 
185
- toString (encoding, start = 0, end = this.byteLength) {
213
+ toString(encoding = 'utf8', start = 0, end = this.byteLength) {
186
214
  // toString()
187
215
  if (arguments.length === 0) return utf8.toString(this)
188
216
 
@@ -197,12 +225,19 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
197
225
 
198
226
  let buffer = this
199
227
 
200
- if (start !== 0 || end !== this.byteLength) buffer = buffer.subarray(start, end)
228
+ if (start !== 0 || end !== this.byteLength) {
229
+ buffer = buffer.subarray(start, end)
230
+ }
201
231
 
202
232
  return codecFor(encoding).toString(buffer)
203
233
  }
204
234
 
205
- write (string, offset = 0, length = this.byteLength - offset, encoding = 'utf8') {
235
+ write(
236
+ string,
237
+ offset = 0,
238
+ length = this.byteLength - offset,
239
+ encoding = 'utf8'
240
+ ) {
206
241
  // write(string)
207
242
  if (arguments.length === 1) return utf8.write(this, string)
208
243
 
@@ -212,7 +247,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
212
247
  offset = 0
213
248
  length = this.byteLength
214
249
 
215
- // write(string, offset, encoding)
250
+ // write(string, offset, encoding)
216
251
  } else if (typeof length === 'string') {
217
252
  encoding = length
218
253
  length = this.byteLength - offset
@@ -230,91 +265,213 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
230
265
 
231
266
  let buffer = this
232
267
 
233
- if (start !== 0 || end !== this.byteLength) buffer = buffer.subarray(start, end)
268
+ if (start !== 0 || end !== this.byteLength) {
269
+ buffer = buffer.subarray(start, end)
270
+ }
234
271
 
235
272
  return codecFor(encoding).write(buffer, string)
236
273
  }
237
274
 
238
- readBigInt64BE (offset = 0) { return viewOf(this).getBigInt64(offset, false) }
239
- readBigInt64LE (offset = 0) { return viewOf(this).getBigInt64(offset, true) }
275
+ readBigInt64BE(offset = 0) {
276
+ return viewOf(this).getBigInt64(offset, false)
277
+ }
278
+ readBigInt64LE(offset = 0) {
279
+ return viewOf(this).getBigInt64(offset, true)
280
+ }
240
281
 
241
- readBigUint64BE (offset = 0) { return viewOf(this).getBigUint64(offset, false) }
242
- readBigUint64LE (offset = 0) { return viewOf(this).getBigUint64(offset, true) }
282
+ readBigUint64BE(offset = 0) {
283
+ return viewOf(this).getBigUint64(offset, false)
284
+ }
285
+ readBigUint64LE(offset = 0) {
286
+ return viewOf(this).getBigUint64(offset, true)
287
+ }
243
288
 
244
- readDoubleBE (offset = 0) { return viewOf(this).getFloat64(offset, false) }
245
- readDoubleLE (offset = 0) { return viewOf(this).getFloat64(offset, true) }
289
+ readDoubleBE(offset = 0) {
290
+ return viewOf(this).getFloat64(offset, false)
291
+ }
292
+ readDoubleLE(offset = 0) {
293
+ return viewOf(this).getFloat64(offset, true)
294
+ }
246
295
 
247
- readFloatBE (offset = 0) { return viewOf(this).getFloat32(offset, false) }
248
- readFloatLE (offset = 0) { return viewOf(this).getFloat32(offset, true) }
296
+ readFloatBE(offset = 0) {
297
+ return viewOf(this).getFloat32(offset, false)
298
+ }
299
+ readFloatLE(offset = 0) {
300
+ return viewOf(this).getFloat32(offset, true)
301
+ }
249
302
 
250
- readInt8 (offset = 0) { return viewOf(this).getInt8(offset) }
303
+ readInt8(offset = 0) {
304
+ return viewOf(this).getInt8(offset)
305
+ }
251
306
 
252
- readInt16BE (offset = 0) { return viewOf(this).getInt16(offset, false) }
253
- readInt16LE (offset = 0) { return viewOf(this).getInt16(offset, true) }
307
+ readInt16BE(offset = 0) {
308
+ return viewOf(this).getInt16(offset, false)
309
+ }
310
+ readInt16LE(offset = 0) {
311
+ return viewOf(this).getInt16(offset, true)
312
+ }
254
313
 
255
- readInt32BE (offset = 0) { return viewOf(this).getInt32(offset, false) }
256
- readInt32LE (offset = 0) { return viewOf(this).getInt32(offset, true) }
314
+ readInt32BE(offset = 0) {
315
+ return viewOf(this).getInt32(offset, false)
316
+ }
317
+ readInt32LE(offset = 0) {
318
+ return viewOf(this).getInt32(offset, true)
319
+ }
257
320
 
258
- readUint8 (offset = 0) { return viewOf(this).getUint8(offset) }
321
+ readUint8(offset = 0) {
322
+ return viewOf(this).getUint8(offset)
323
+ }
259
324
 
260
- readUint16BE (offset = 0) { return viewOf(this).getUint16(offset, false) }
261
- readUint16LE (offset = 0) { return viewOf(this).getUint16(offset, true) }
325
+ readUint16BE(offset = 0) {
326
+ return viewOf(this).getUint16(offset, false)
327
+ }
328
+ readUint16LE(offset = 0) {
329
+ return viewOf(this).getUint16(offset, true)
330
+ }
262
331
 
263
- readUint32BE (offset = 0) { return viewOf(this).getUint32(offset, false) }
264
- readUint32LE (offset = 0) { return viewOf(this).getUint32(offset, true) }
332
+ readUint32BE(offset = 0) {
333
+ return viewOf(this).getUint32(offset, false)
334
+ }
335
+ readUint32LE(offset = 0) {
336
+ return viewOf(this).getUint32(offset, true)
337
+ }
265
338
 
266
- readBigUInt64BE (...args) { return this.readBigUint64BE(...args) }
267
- readBigUInt64LE (...args) { return this.readBigUint64LE(...args) }
339
+ readBigUInt64BE(...args) {
340
+ return this.readBigUint64BE(...args)
341
+ }
342
+ readBigUInt64LE(...args) {
343
+ return this.readBigUint64LE(...args)
344
+ }
268
345
 
269
- readUInt8 (...args) { return this.readUint8(...args) }
346
+ readUInt8(...args) {
347
+ return this.readUint8(...args)
348
+ }
270
349
 
271
- readUInt16BE (...args) { return this.readUint16BE(...args) }
272
- readUInt16LE (...args) { return this.readUint16LE(...args) }
350
+ readUInt16BE(...args) {
351
+ return this.readUint16BE(...args)
352
+ }
353
+ readUInt16LE(...args) {
354
+ return this.readUint16LE(...args)
355
+ }
273
356
 
274
- readUInt32BE (...args) { return this.readUint32BE(...args) }
275
- readUInt32LE (...args) { return this.readUint32LE(...args) }
357
+ readUInt32BE(...args) {
358
+ return this.readUint32BE(...args)
359
+ }
360
+ readUInt32LE(...args) {
361
+ return this.readUint32LE(...args)
362
+ }
276
363
 
277
- writeBigInt64BE (value, offset = 0) { viewOf(this).setBigInt64(offset, value, false); return offset + 8 }
278
- writeBigInt64LE (value, offset = 0) { viewOf(this).setBigInt64(offset, value, true); return offset + 8 }
364
+ writeBigInt64BE(value, offset = 0) {
365
+ viewOf(this).setBigInt64(offset, value, false)
366
+ return offset + 8
367
+ }
368
+ writeBigInt64LE(value, offset = 0) {
369
+ viewOf(this).setBigInt64(offset, value, true)
370
+ return offset + 8
371
+ }
279
372
 
280
- writeBigUint64BE (value, offset = 0) { viewOf(this).setBigUint64(offset, value, false); return offset + 8 }
281
- writeBigUint64LE (value, offset = 0) { viewOf(this).setBigUint64(offset, value, true); return offset + 8 }
373
+ writeBigUint64BE(value, offset = 0) {
374
+ viewOf(this).setBigUint64(offset, value, false)
375
+ return offset + 8
376
+ }
377
+ writeBigUint64LE(value, offset = 0) {
378
+ viewOf(this).setBigUint64(offset, value, true)
379
+ return offset + 8
380
+ }
282
381
 
283
- writeDoubleBE (value, offset = 0) { viewOf(this).setFloat64(offset, value, false); return offset + 8 }
284
- writeDoubleLE (value, offset = 0) { viewOf(this).setFloat64(offset, value, true); return offset + 8 }
382
+ writeDoubleBE(value, offset = 0) {
383
+ viewOf(this).setFloat64(offset, value, false)
384
+ return offset + 8
385
+ }
386
+ writeDoubleLE(value, offset = 0) {
387
+ viewOf(this).setFloat64(offset, value, true)
388
+ return offset + 8
389
+ }
285
390
 
286
- writeFloatBE (value, offset = 0) { viewOf(this).setFloat32(offset, value, false); return offset + 4 }
287
- writeFloatLE (value, offset = 0) { viewOf(this).setFloat32(offset, value, true); return offset + 4 }
391
+ writeFloatBE(value, offset = 0) {
392
+ viewOf(this).setFloat32(offset, value, false)
393
+ return offset + 4
394
+ }
395
+ writeFloatLE(value, offset = 0) {
396
+ viewOf(this).setFloat32(offset, value, true)
397
+ return offset + 4
398
+ }
288
399
 
289
- writeInt8 (value, offset = 0) { viewOf(this).setInt8(offset, value); return offset + 1 }
400
+ writeInt8(value, offset = 0) {
401
+ viewOf(this).setInt8(offset, value)
402
+ return offset + 1
403
+ }
290
404
 
291
- writeInt16BE (value, offset = 0) { viewOf(this).setInt16(offset, value, false); return offset + 2 }
292
- writeInt16LE (value, offset = 0) { viewOf(this).setInt16(offset, value, true); return offset + 2 }
405
+ writeInt16BE(value, offset = 0) {
406
+ viewOf(this).setInt16(offset, value, false)
407
+ return offset + 2
408
+ }
409
+ writeInt16LE(value, offset = 0) {
410
+ viewOf(this).setInt16(offset, value, true)
411
+ return offset + 2
412
+ }
293
413
 
294
- writeInt32BE (value, offset = 0) { viewOf(this).setInt32(offset, value, false); return offset + 4 }
295
- writeInt32LE (value, offset = 0) { viewOf(this).setInt32(offset, value, true); return offset + 4 }
414
+ writeInt32BE(value, offset = 0) {
415
+ viewOf(this).setInt32(offset, value, false)
416
+ return offset + 4
417
+ }
418
+ writeInt32LE(value, offset = 0) {
419
+ viewOf(this).setInt32(offset, value, true)
420
+ return offset + 4
421
+ }
296
422
 
297
- writeUint8 (value, offset = 0) { viewOf(this).setUint8(offset, value, true); return offset + 1 }
423
+ writeUint8(value, offset = 0) {
424
+ viewOf(this).setUint8(offset, value, true)
425
+ return offset + 1
426
+ }
298
427
 
299
- writeUint16BE (value, offset = 0) { viewOf(this).setUint16(offset, value, false); return offset + 2 }
300
- writeUint16LE (value, offset = 0) { viewOf(this).setUint16(offset, value, true); return offset + 2 }
428
+ writeUint16BE(value, offset = 0) {
429
+ viewOf(this).setUint16(offset, value, false)
430
+ return offset + 2
431
+ }
432
+ writeUint16LE(value, offset = 0) {
433
+ viewOf(this).setUint16(offset, value, true)
434
+ return offset + 2
435
+ }
301
436
 
302
- writeUint32LE (value, offset = 0) { viewOf(this).setUint32(offset, value, true); return offset + 4 }
303
- writeUint32BE (value, offset = 0) { viewOf(this).setUint32(offset, value, false); return offset + 4 }
437
+ writeUint32LE(value, offset = 0) {
438
+ viewOf(this).setUint32(offset, value, true)
439
+ return offset + 4
440
+ }
441
+ writeUint32BE(value, offset = 0) {
442
+ viewOf(this).setUint32(offset, value, false)
443
+ return offset + 4
444
+ }
304
445
 
305
- writeBigUInt64BE (...args) { return this.writeBigUint64BE(...args) }
306
- writeBigUInt64LE (...args) { return this.writeBigUint64LE(...args) }
446
+ writeBigUInt64BE(...args) {
447
+ return this.writeBigUint64BE(...args)
448
+ }
449
+ writeBigUInt64LE(...args) {
450
+ return this.writeBigUint64LE(...args)
451
+ }
307
452
 
308
- writeUInt8 (...args) { return this.writeUint8(...args) }
453
+ writeUInt8(...args) {
454
+ return this.writeUint8(...args)
455
+ }
309
456
 
310
- writeUInt16BE (...args) { return this.writeUint16BE(...args) }
311
- writeUInt16LE (...args) { return this.writeUint16LE(...args) }
457
+ writeUInt16BE(...args) {
458
+ return this.writeUint16BE(...args)
459
+ }
460
+ writeUInt16LE(...args) {
461
+ return this.writeUint16LE(...args)
462
+ }
312
463
 
313
- writeUInt32BE (...args) { return this.writeUint32BE(...args) }
314
- writeUInt32LE (...args) { return this.writeUint32LE(...args) }
464
+ writeUInt32BE(...args) {
465
+ return this.writeUint32BE(...args)
466
+ }
467
+ writeUInt32LE(...args) {
468
+ return this.writeUint32LE(...args)
469
+ }
315
470
  }
316
471
 
317
- exports.Buffer = exports
472
+ const Buffer = exports
473
+
474
+ exports.Buffer = Buffer // For Node.js compatibility
318
475
 
319
476
  exports.constants = constants
320
477
 
@@ -326,7 +483,7 @@ codecs.hex = hex
326
483
  codecs.utf8 = codecs['utf-8'] = utf8
327
484
  codecs.utf16le = codecs.ucs2 = codecs['utf-16le'] = codecs['ucs-2'] = utf16le
328
485
 
329
- function codecFor (encoding = 'utf8') {
486
+ function codecFor(encoding = 'utf8') {
330
487
  if (encoding in codecs) return codecs[encoding]
331
488
 
332
489
  encoding = encoding.toLowerCase()
@@ -338,7 +495,7 @@ function codecFor (encoding = 'utf8') {
338
495
 
339
496
  const views = new WeakMap()
340
497
 
341
- function viewOf (buffer) {
498
+ function viewOf(buffer) {
342
499
  let view = views.get(buffer)
343
500
  if (view === undefined) {
344
501
  view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
@@ -347,7 +504,7 @@ function viewOf (buffer) {
347
504
  return view
348
505
  }
349
506
 
350
- exports.isBuffer = function isBuffer (value) {
507
+ exports.isBuffer = function isBuffer(value) {
351
508
  if (typeof value !== 'object' || value === null) return false
352
509
 
353
510
  let constructor = value.constructor
@@ -361,7 +518,7 @@ exports.isBuffer = function isBuffer (value) {
361
518
  return false
362
519
  }
363
520
 
364
- exports.isEncoding = function isEncoding (encoding) {
521
+ exports.isEncoding = function isEncoding(encoding) {
365
522
  try {
366
523
  codecFor(encoding)
367
524
  return true
@@ -370,13 +527,13 @@ exports.isEncoding = function isEncoding (encoding) {
370
527
  }
371
528
  }
372
529
 
373
- exports.alloc = function alloc (size, fill, encoding) {
530
+ exports.alloc = function alloc(size, fill, encoding) {
374
531
  const buffer = new Buffer(size)
375
532
  if (fill !== undefined) buffer.fill(fill, 0, buffer.byteLength, encoding)
376
533
  return buffer
377
534
  }
378
535
 
379
- exports.allocUnsafe = function allocUnsafe (size) {
536
+ exports.allocUnsafe = function allocUnsafe(size) {
380
537
  binding.setZeroFillEnabled(0)
381
538
  try {
382
539
  return new Buffer(size)
@@ -385,11 +542,11 @@ exports.allocUnsafe = function allocUnsafe (size) {
385
542
  }
386
543
  }
387
544
 
388
- exports.allocUnsafeSlow = function allocUnsafeSlow (size) {
545
+ exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
389
546
  return exports.allocUnsafe(size)
390
547
  }
391
548
 
392
- exports.byteLength = function byteLength (string, encoding) {
549
+ exports.byteLength = function byteLength(string, encoding) {
393
550
  if (typeof string === 'string') {
394
551
  return codecFor(encoding).byteLength(string)
395
552
  }
@@ -397,11 +554,11 @@ exports.byteLength = function byteLength (string, encoding) {
397
554
  return string.byteLength
398
555
  }
399
556
 
400
- exports.compare = function compare (a, b) {
557
+ exports.compare = function compare(a, b) {
401
558
  return binding.compare(a, b)
402
559
  }
403
560
 
404
- exports.concat = function concat (buffers, length) {
561
+ exports.concat = function concat(buffers, length) {
405
562
  if (length === undefined) {
406
563
  length = buffers.reduce((length, buffer) => length + buffer.byteLength, 0)
407
564
  }
@@ -424,12 +581,12 @@ exports.concat = function concat (buffers, length) {
424
581
  return result
425
582
  }
426
583
 
427
- exports.coerce = function coerce (buffer) {
584
+ exports.coerce = function coerce(buffer) {
428
585
  if (exports.isBuffer(buffer)) return buffer
429
586
  return new Buffer(buffer.buffer, buffer.byteOffset, buffer.byteLength)
430
587
  }
431
588
 
432
- exports.from = function from (value, encodingOrOffset, length) {
589
+ exports.from = function from(value, encodingOrOffset, length) {
433
590
  // from(string, encoding)
434
591
  if (typeof value === 'string') return fromString(value, encodingOrOffset)
435
592
 
@@ -443,37 +600,37 @@ exports.from = function from (value, encodingOrOffset, length) {
443
600
  return fromArrayBuffer(value, encodingOrOffset, length)
444
601
  }
445
602
 
446
- function fromString (string, encoding) {
603
+ function fromString(string, encoding) {
447
604
  const codec = codecFor(encoding)
448
605
  const buffer = new Buffer(codec.byteLength(string))
449
606
  codec.write(buffer, string)
450
607
  return buffer
451
608
  }
452
609
 
453
- function fromArray (array) {
610
+ function fromArray(array) {
454
611
  const buffer = new Buffer(array.length)
455
612
  buffer.set(array)
456
613
  return buffer
457
614
  }
458
615
 
459
- function fromBuffer (buffer) {
616
+ function fromBuffer(buffer) {
460
617
  const copy = new Buffer(buffer.byteLength)
461
618
  copy.set(buffer)
462
619
  return copy
463
620
  }
464
621
 
465
- function fromArrayBuffer (arrayBuffer, offset, length) {
622
+ function fromArrayBuffer(arrayBuffer, offset, length) {
466
623
  return new Buffer(arrayBuffer, offset, length)
467
624
  }
468
625
 
469
- function bidirectionalIndexOf (buffer, value, offset, encoding, first) {
626
+ function bidirectionalIndexOf(buffer, value, offset, encoding, first) {
470
627
  if (buffer.byteLength === 0) return -1
471
628
 
472
629
  if (typeof offset === 'string') {
473
630
  encoding = offset
474
631
  offset = 0
475
632
  } else if (offset === undefined) {
476
- offset = first ? 0 : (buffer.byteLength - 1)
633
+ offset = first ? 0 : buffer.byteLength - 1
477
634
  } else if (offset < 0) {
478
635
  offset += buffer.byteLength
479
636
  }
@@ -524,7 +681,7 @@ function bidirectionalIndexOf (buffer, value, offset, encoding, first) {
524
681
  return -1
525
682
  }
526
683
 
527
- function swap (buffer, n, m) {
684
+ function swap(buffer, n, m) {
528
685
  const i = buffer[n]
529
686
  buffer[n] = buffer[m]
530
687
  buffer[m] = i
package/lib/ascii.js CHANGED
@@ -1,8 +1,8 @@
1
- exports.byteLength = function byteLength (string) {
1
+ exports.byteLength = function byteLength(string) {
2
2
  return string.length
3
3
  }
4
4
 
5
- exports.toString = function toString (buffer) {
5
+ exports.toString = function toString(buffer) {
6
6
  const len = buffer.byteLength
7
7
 
8
8
  let result = ''
@@ -14,7 +14,7 @@ exports.toString = function toString (buffer) {
14
14
  return result
15
15
  }
16
16
 
17
- exports.write = function write (buffer, string) {
17
+ exports.write = function write(buffer, string) {
18
18
  const len = buffer.byteLength
19
19
 
20
20
  for (let i = 0; i < len; i++) {
package/lib/base64.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const binding = require('../binding')
2
2
 
3
- exports.byteLength = function byteLength (string) {
3
+ exports.byteLength = function byteLength(string) {
4
4
  let len = string.length
5
5
 
6
6
  if (string.charCodeAt(len - 1) === 0x3d) len--
package/lib/hex.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const binding = require('../binding')
2
2
 
3
- exports.byteLength = function byteLength (string) {
3
+ exports.byteLength = function byteLength(string) {
4
4
  return string.length >>> 1
5
5
  }
6
6
 
package/lib/utf16le.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const binding = require('../binding')
2
2
 
3
- exports.byteLength = function byteLength (string) {
3
+ exports.byteLength = function byteLength(string) {
4
4
  return string.length * 2
5
5
  }
6
6
 
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "bare-buffer",
3
- "version": "2.6.0",
3
+ "version": "2.7.1",
4
4
  "description": "Native buffers for JavaScript",
5
5
  "exports": {
6
- ".": "./index.js",
6
+ ".": {
7
+ "types": "./index.d.ts",
8
+ "default": "./index.js"
9
+ },
7
10
  "./package": "./package.json",
11
+ "./global": "./global.js",
8
12
  "./constants": "./lib/constants.js"
9
13
  },
10
14
  "files": [
11
15
  "index.js",
16
+ "index.d.ts",
17
+ "global.js",
12
18
  "binding.c",
13
19
  "binding.js",
14
20
  "CMakeLists.txt",
@@ -17,7 +23,7 @@
17
23
  ],
18
24
  "addon": true,
19
25
  "scripts": {
20
- "test": "standard && bare test/all.js"
26
+ "test": "prettier . --check && bare test/all.js"
21
27
  },
22
28
  "repository": {
23
29
  "type": "git",
@@ -33,6 +39,7 @@
33
39
  "brittle": "^3.1.1",
34
40
  "cmake-bare": "^1.1.6",
35
41
  "cmake-fetch": "^1.0.0",
36
- "standard": "^17.0.0"
42
+ "prettier": "^3.3.3",
43
+ "prettier-config-standard": "^7.0.0"
37
44
  }
38
45
  }