diff --git a/packages/util/src/has.ts b/packages/util/src/has.ts index 844bff5786..e8941f5f0c 100644 --- a/packages/util/src/has.ts +++ b/packages/util/src/has.ts @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BufferObjClass } from './types.js'; +import type { BufferClass } from './types.js'; import { BigInt } from '@polkadot/x-bigint'; import { xglobal } from '@polkadot/x-global'; @@ -32,7 +32,7 @@ export const hasWasm = typeof WebAssembly !== 'undefined'; // that some bundlers such as parcel would add (this is a check, not a use) /** true if the environment has support for Buffer (typically Node.js) */ -export const hasBuffer = typeof xglobal.Buffer === 'function' && typeof (xglobal.Buffer as unknown as BufferObjClass).isBuffer === 'function'; +export const hasBuffer = typeof xglobal.Buffer === 'function' && typeof (xglobal.Buffer as unknown as BufferClass).isBuffer === 'function'; /** true if the environment has process available (typically Node.js) */ export const hasProcess = typeof xglobal.process === 'object'; diff --git a/packages/util/src/is/buffer.ts b/packages/util/src/is/buffer.ts index 0f8f67aab4..6cf63169de 100644 --- a/packages/util/src/is/buffer.ts +++ b/packages/util/src/is/buffer.ts @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BufferObj, BufferObjClass } from '../types.js'; +import type { BufferClass, BufferObject } from '../types.js'; import { xglobal } from '@polkadot/x-global'; @@ -22,7 +22,7 @@ import { isFunction } from './function.js'; * console.log('isBuffer', isBuffer(Buffer.from([]))); // => true * ``` */ -export function isBuffer (value: unknown): value is T { +export function isBuffer (value: unknown): value is T { // we do check a function first, since it is slightly faster than isBuffer itself - return hasBuffer && !!value && isFunction((value as unknown as BufferObj).readDoubleLE) && (xglobal.Buffer as unknown as BufferObjClass).isBuffer(value); + return hasBuffer && !!value && isFunction((value as unknown as BufferObject).readDoubleLE) && (xglobal.Buffer as unknown as BufferClass).isBuffer(value); } diff --git a/packages/util/src/types.ts b/packages/util/src/types.ts index 019719e393..4332210399 100644 --- a/packages/util/src/types.ts +++ b/packages/util/src/types.ts @@ -77,12 +77,12 @@ export type HexDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' // One day when template strings support regex, we can improve this export type HexString = `0x${string}`; -// BufferObj interface compatible with Buffer since we don't want to require +// BufferObject interface compatible with Buffer since we don't want to require // references to the Buffer types from the node typings // // Caveat: the references still do sneak in in the d.ts files, specifically // inside u8a/toBuffer & is/buffer (but not in compiled outputs) -export interface BufferObj extends Uint8Array { +export interface BufferObject extends Uint8Array { // Possibly used externally via type imports equals: (otherBuffer: Uint8Array) => boolean; // As used in is/buffer @@ -91,9 +91,9 @@ export interface BufferObj extends Uint8Array { // We define a scappy low-level interface to mock Buffer // (this removes the need for the node typings in built bundles) -export interface BufferObjClass extends Class { +export interface BufferClass extends Class { // As used in u8a/toBuffer - from: (value: unknown) => T; + from: (value: unknown) => T; // As used in is/buffer isBuffer: (value: unknown) => boolean; } diff --git a/packages/util/src/u8a/toBuffer.ts b/packages/util/src/u8a/toBuffer.ts index 0d30ae23c0..0aff1b8ea8 100644 --- a/packages/util/src/u8a/toBuffer.ts +++ b/packages/util/src/u8a/toBuffer.ts @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { BufferObj, BufferObjClass } from '../types.js'; +import type { BufferClass, BufferObject } from '../types.js'; import { xglobal } from '@polkadot/x-global'; @@ -19,6 +19,6 @@ import { xglobal } from '@polkadot/x-global'; * console.log('Buffer', u8aToBuffer(new Uint8Array([1, 2, 3]))); * ``` */ -export function u8aToBuffer (value?: Uint8Array | null): T { - return (xglobal.Buffer as unknown as BufferObjClass).from(value || []); +export function u8aToBuffer (value?: Uint8Array | null): T { + return (xglobal.Buffer as unknown as BufferClass).from(value || []); }