*/
export const { isView: isArrayBufferView } = Buffer;
+/** Returns whether the provided value is an array buffer. */
+export const isArrayBuffer = ($) => {
+ try {
+ // Try to see if the provided argument has array buffer internal
+ // slots and return true if so.
+ return call(getBufferByteLength, $, []), true;
+ } catch {
+ // The provided argument does not have array buffer internal slots.
+ return false;
+ }
+};
+
/**
* Returns whether the provided value is a base16 string.
*
}
};
+/** Returns whether the provided value is a data view. */
+export const isDataView = ($) => {
+ try {
+ // Try to see if the provided argument has data view internal slots
+ // and return true if so.
+ return call(getViewBuffer, $, []), true;
+ } catch {
+ // The provided argument does not have data view internal slots.
+ return false;
+ }
+};
+
/**
* Returns whether the provided value is a filename‐safe base64 string.
*
}
};
+/** Returns whether the provided value is a typed array. */
+export const isTypedArray = ($) => {
+ try {
+ // Try to see if the provided argument has typed array internal
+ // slots and return true if so.
+ return call(getTypedArrayBuffer, $, []), true;
+ } catch {
+ // The provided argument does not have typed array internal slots.
+ return false;
+ }
+};
+
/**
* Returns whether the provided value is a W·R·M·G (Crockford) base32
* string. Check digits are not supported.
base64String,
filenameSafeBase64Binary,
filenameSafeBase64String,
+ isArrayBuffer,
isArrayBufferView,
isBase16,
isBase32,
isBase64,
+ isDataView,
isFilenameSafeBase64,
+ isTypedArray,
isWRMGBase32,
toArrayBuffer,
wrmgBase32Binary,
});
});
+describe("isArrayBuffer", () => {
+ it("[[Call]] returns true for array buffers", () => {
+ assertStrictEquals(
+ isArrayBuffer(new ArrayBuffer()),
+ true,
+ );
+ });
+
+ it("[[Call]] returns false for others", () => {
+ [
+ undefined,
+ null,
+ true,
+ Symbol(),
+ 27,
+ 98n,
+ {},
+ [],
+ () => {},
+ new Proxy({}, {}),
+ "string",
+ new SharedArrayBuffer(),
+ new DataView(new ArrayBuffer()),
+ new Uint8Array(),
+ ].forEach((value) =>
+ assertStrictEquals(isArrayBuffer(value), false)
+ );
+ });
+});
+
describe("isArrayBufferView", () => {
it("[[Call]] returns true for data views", () => {
assertStrictEquals(
});
});
+describe("isDataView", () => {
+ it("[[Call]] returns true for data views", () => {
+ assertStrictEquals(
+ isDataView(new DataView(new ArrayBuffer())),
+ true,
+ );
+ });
+
+ it("[[Call]] returns false for others", () => {
+ [
+ undefined,
+ null,
+ true,
+ Symbol(),
+ 27,
+ 98n,
+ {},
+ [],
+ () => {},
+ new Proxy({}, {}),
+ "string",
+ new ArrayBuffer(),
+ new SharedArrayBuffer(),
+ new Uint8Array(),
+ ].forEach((value) => assertStrictEquals(isDataView(value), false));
+ });
+});
+
describe("isFilenameSafeBase64", () => {
it("[[Call]] returns true for filename‐safe base64 strings", () => {
for (const { base64 } of data.values()) {
});
});
+describe("isTypedArray", () => {
+ it("[[Call]] returns true for typed arrays", () => {
+ assertStrictEquals(
+ isTypedArray(new Uint8Array()),
+ true,
+ );
+ assertStrictEquals(
+ isTypedArray(new BigInt64Array()),
+ true,
+ );
+ });
+
+ it("[[Call]] returns false for others", () => {
+ [
+ undefined,
+ null,
+ true,
+ Symbol(),
+ 27,
+ 98n,
+ {},
+ [],
+ () => {},
+ new Proxy({}, {}),
+ "string",
+ new ArrayBuffer(),
+ new SharedArrayBuffer(),
+ new DataView(new ArrayBuffer()),
+ ].forEach((value) =>
+ assertStrictEquals(isTypedArray(value), false)
+ );
+ });
+});
+
describe("isWRMGBase32", () => {
it("[[Call]] returns true for W·R·M·G base32 strings", () => {
for (const { wrmg } of data.values()) {