Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/twlite/is-buffer-like
Checks if the given src is buffer-like object
https://github.com/twlite/is-buffer-like
buffer buffer-like is-buffer node
Last synced: about 1 month ago
JSON representation
Checks if the given src is buffer-like object
- Host: GitHub
- URL: https://github.com/twlite/is-buffer-like
- Owner: twlite
- Created: 2022-06-27T17:59:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-27T18:00:37.000Z (over 2 years ago)
- Last Synced: 2024-09-20T00:27:42.960Z (about 2 months ago)
- Topics: buffer, buffer-like, is-buffer, node
- Language: JavaScript
- Homepage: https://npm.im/is-buffer-like
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is-buffer-like
Checks if the given src is buffer-like object.
# Example
```js
const isBufferLike = require("is-buffer-like");// Buffer like src
// these can be constructed into nodejs Buffer object using Buffer.from(x)
const ns = [
Uint8ClampedArray,
Uint8Array,
Uint16Array,
Uint32Array,
Float32Array,
Float64Array,
Int16Array,
Int32Array,
Int8Array,
ArrayBuffer,
Array,
SharedArrayBuffer,
BigInt64Array,
BigUint64Array,
Array
];console.log(ns.map(m => isBufferLike(new m)));
/*
[
true, true, true, true,
true, true, true, true,
true, true, true, true,
true, true, true
]
*/
console.log(isBufferLike(Buffer.from("test"))); // true
console.log(isBufferLike(null)); // false
console.log(isBufferLike(true)); // false
console.log(isBufferLike(0)); // false
console.log(isBufferLike("test")); // false
console.log(isBufferLike({})); // false
console.log(isBufferLike(undefined)); // false
console.log(isBufferLike(null)); // false
console.log(isBufferLike(function(){})); // false
```