Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/_util/is.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ArrayBufferPrototypeGetByteLength,
ArrayBufferPrototypeGetResizable,
ArrayIsArray,
ArrayIteratorPrototype,
ArrayIteratorPrototypeNext,
Expand All @@ -15,7 +16,7 @@

/**
* @param {unknown} value
* @returns {value is {}}

Check warning on line 19 in src/_util/is.mjs

View workflow job for this annotation

GitHub Actions / Lint

No empty object type
*/
export function isObject(value) {
return (
Expand All @@ -26,7 +27,7 @@

/**
* @param {unknown} value
* @returns {value is {}}

Check warning on line 30 in src/_util/is.mjs

View workflow job for this annotation

GitHub Actions / Lint

No empty object type
*/
export function isObjectLike(value) {
return value !== null && typeof value === "object";
Expand Down Expand Up @@ -65,7 +66,7 @@
if (ArrayIsArray(value)) {
return false;
}
ArrayBufferPrototypeGetByteLength(/** @type {any} */ (value));

Check warning on line 69 in src/_util/is.mjs

View workflow job for this annotation

GitHub Actions / Lint

Prefer a more specific type to `any`
return true;
} catch (e) {
return false;
Expand All @@ -82,7 +83,7 @@
}

try {
SharedArrayBufferPrototypeGetByteLength(/** @type {any} */ (value));

Check warning on line 86 in src/_util/is.mjs

View workflow job for this annotation

GitHub Actions / Lint

Prefer a more specific type to `any`
return true;
} catch (e) {
return false;
Expand All @@ -97,6 +98,22 @@
return isArrayBuffer(value) || isSharedArrayBuffer(value);
}

/**
* @param {unknown} value
* @returns {boolean}
*/
export function isResizableArrayBuffer(value) {
if (ArrayBufferPrototypeGetResizable === null) {
return false;
}

try {
return ArrayBufferPrototypeGetResizable(/** @type {any} */ (value));

Check warning on line 111 in src/_util/is.mjs

View workflow job for this annotation

GitHub Actions / Lint

Prefer a more specific type to `any`
} catch (e) {
return false;
}
}

/**
* @param {unknown} value
* @returns {value is unknown[]}
Expand Down
3 changes: 3 additions & 0 deletions src/_util/primordials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT } from "./messages.mjs";

/** @type {<T extends (...args: any) => any>(target: T) => (thisArg: ThisType<T>, ...args: any[]) => any} */

Check warning on line 6 in src/_util/primordials.mjs

View workflow job for this annotation

GitHub Actions / Lint

Prefer a more specific type to `any`
function uncurryThis(target) {
return (thisArg, ...args) => {
return ReflectApply(target, thisArg, args);
Expand Down Expand Up @@ -118,6 +118,9 @@
export const ArrayBufferPrototypeSlice = uncurryThis(ArrayBufferPrototype.slice);
/** @type {(buffer: ArrayBuffer) => ArrayBuffer} */
export const ArrayBufferPrototypeGetByteLength = uncurryThisGetter(ArrayBufferPrototype, "byteLength");
/** @type {null | ((buffer: ArrayBuffer) => boolean)} */
export const ArrayBufferPrototypeGetResizable = typeof ArrayBufferPrototype["resize"] !== "undefined" ?
uncurryThisGetter(ArrayBufferPrototype, "resizable") : null;

// SharedArrayBuffer
export const NativeSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : null;
Expand Down
Loading