Comparing version 1.3.0 to 1.3.1
@@ -78,2 +78,21 @@ /*! | ||
static isEqual(a: BufferSource, b: BufferSource): boolean; | ||
/** | ||
* Concatenates buffers | ||
* @param buffers List of buffers | ||
* @returns Concatenated buffer | ||
*/ | ||
static concat(...buffers: BufferSource[]): ArrayBuffer; | ||
/** | ||
* Concatenates buffers | ||
* @param buffers List of buffers | ||
* @returns Concatenated buffer | ||
*/ | ||
static concat(buffers: BufferSource[]): ArrayBuffer; | ||
/** | ||
* Concatenates buffers and converts it into specified ArrayBufferView | ||
* @param buffers List of buffers | ||
* @param type ArrayBufferView constructor | ||
* @returns Concatenated buffer of specified type | ||
*/ | ||
static concat<T extends ArrayBufferView>(buffers: BufferSource[], type: ArrayBufferViewConstructor<T>): T; | ||
} | ||
@@ -80,0 +99,0 @@ |
@@ -41,2 +41,5 @@ /*! | ||
static toView(data, type) { | ||
if (data.constructor === type) { | ||
return data; | ||
} | ||
if (this.isArrayBuffer(data)) { | ||
@@ -71,2 +74,25 @@ return new type(data); | ||
} | ||
static concat(...args) { | ||
if (Array.isArray(args[0])) { | ||
const buffers = args[0]; | ||
let size = 0; | ||
for (const buffer of buffers) { | ||
size += buffer.byteLength; | ||
} | ||
const res = new Uint8Array(size); | ||
let offset = 0; | ||
for (const buffer of buffers) { | ||
const view = this.toUint8Array(buffer); | ||
res.set(view, offset); | ||
offset += view.length; | ||
} | ||
if (args[1]) { | ||
return this.toView(res, args[1]); | ||
} | ||
return res.buffer; | ||
} | ||
else { | ||
return this.concat(args); | ||
} | ||
} | ||
} | ||
@@ -73,0 +99,0 @@ |
@@ -45,2 +45,5 @@ /*! | ||
static toView(data, type) { | ||
if (data.constructor === type) { | ||
return data; | ||
} | ||
if (this.isArrayBuffer(data)) { | ||
@@ -75,2 +78,25 @@ return new type(data); | ||
} | ||
static concat(...args) { | ||
if (Array.isArray(args[0])) { | ||
const buffers = args[0]; | ||
let size = 0; | ||
for (const buffer of buffers) { | ||
size += buffer.byteLength; | ||
} | ||
const res = new Uint8Array(size); | ||
let offset = 0; | ||
for (const buffer of buffers) { | ||
const view = this.toUint8Array(buffer); | ||
res.set(view, offset); | ||
offset += view.length; | ||
} | ||
if (args[1]) { | ||
return this.toView(res, args[1]); | ||
} | ||
return res.buffer; | ||
} | ||
else { | ||
return this.concat(args); | ||
} | ||
} | ||
} | ||
@@ -77,0 +103,0 @@ |
{ | ||
"name": "pvtsutils", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "pvtsutils is a set of common utility functions used in various Peculiar Ventures TypeScript based projects.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37802
892