From 4f5282e5cd9d60f69bd78beb4d10f0d855347c50 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 25 Feb 2024 01:45:48 +0100 Subject: [PATCH] fix(core): update --- test/test.ts | 15 ++++++++++++++- ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/test.ts b/test/test.ts index e640cb6..cbba239 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,21 @@ -import { expect, expectAsync, tap } from '@pushrocks/tapbundle'; +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(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 407e15e..42d106a 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartbuffer', - version: '1.0.5', + version: '1.0.6', description: 'handle ArrayBufferLike structures' } diff --git a/ts/index.ts b/ts/index.ts index 48f05c4..7eea4a2 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -62,6 +62,6 @@ export function base64ToArrayBuffer(base64: string): Uint8Array { return arrayBuffer; } -export function isArrayBufferLike(obj: any): obj is ArrayBufferLike { +export function isBufferLike(obj: any): obj is ArrayBufferLike { return obj && typeof obj.byteLength === 'number'; }