Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
066dac4bdc | |||
e1faf34660 | |||
031f6449bd | |||
4f5282e5cd |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartbuffer",
|
"name": "@push.rocks/smartbuffer",
|
||||||
"version": "1.0.5",
|
"version": "1.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "handle ArrayBufferLike structures",
|
"description": "handle ArrayBufferLike structures",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
21
test/test.both.ts
Normal file
21
test/test.both.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||||
|
import * as smartbuffer from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('first test', async () => {
|
||||||
|
console.log(smartbuffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should recognize different buffer like objects', async () => {
|
||||||
|
// const testBuffer = Buffer.from('test');
|
||||||
|
const testArrayBuffer = new ArrayBuffer(4);
|
||||||
|
const testUint8Array = new Uint8Array(testArrayBuffer);
|
||||||
|
testUint8Array[0] = 116;
|
||||||
|
testUint8Array[1] = 101;
|
||||||
|
testUint8Array[2] = 115;
|
||||||
|
testUint8Array[3] = 116;
|
||||||
|
// expect(smartbuffer.isBufferLike(testBuffer)).toBeTrue();
|
||||||
|
expect(smartbuffer.isBufferLike(testArrayBuffer)).toBeTrue();
|
||||||
|
expect(smartbuffer.isBufferLike(testUint8Array)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,8 +0,0 @@
|
|||||||
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as smartbuffer from '../ts/index.js';
|
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
|
||||||
console.log(smartbuffer);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartbuffer',
|
name: '@push.rocks/smartbuffer',
|
||||||
version: '1.0.5',
|
version: '1.0.7',
|
||||||
description: 'handle ArrayBufferLike structures'
|
description: 'handle ArrayBufferLike structures'
|
||||||
}
|
}
|
||||||
|
16
ts/index.ts
16
ts/index.ts
@ -62,6 +62,16 @@ export function base64ToArrayBuffer(base64: string): Uint8Array {
|
|||||||
return arrayBuffer;
|
return arrayBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isArrayBufferLike(obj: any): obj is ArrayBufferLike {
|
export function isBufferLike(obj: any): obj is ArrayBufferLike | Buffer {
|
||||||
return obj && typeof obj.byteLength === 'number';
|
// Check for ArrayBufferLike objects in any environment
|
||||||
}
|
if (obj && typeof obj.byteLength === 'number') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional check specific to Node.js environment for Buffer objects
|
||||||
|
if (typeof Buffer !== 'undefined' && Buffer.isBuffer) {
|
||||||
|
return Buffer.isBuffer(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
Reference in New Issue
Block a user