Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 1 | # is-shared-array-buffer <sup>[![Version Badge][npm-version-svg]][package-url]</sup> |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 2 | |
Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 3 | [![github actions][actions-image]][actions-url] |
| 4 | [![coverage][codecov-image]][codecov-url] |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 5 | [![License][license-image]][license-url] |
| 6 | [![Downloads][downloads-image]][downloads-url] |
| 7 | |
Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 8 | [![npm badge][npm-badge-png]][package-url] |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 9 | |
| 10 | Is this value a JS SharedArrayBuffer? This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and despite ES6 Symbol.toStringTag. |
| 11 | |
| 12 | ## Example |
| 13 | |
| 14 | ```js |
| 15 | var assert = require('assert'); |
| 16 | var isSharedArrayBuffer = require('is-shared-array-buffer'); |
| 17 | |
| 18 | assert(!isSharedArrayBuffer(function () {})); |
| 19 | assert(!isSharedArrayBuffer(null)); |
| 20 | assert(!isSharedArrayBuffer(function* () { yield 42; return Infinity; }); |
| 21 | assert(!isSharedArrayBuffer(Symbol('foo'))); |
| 22 | assert(!isSharedArrayBuffer(1n)); |
| 23 | assert(!isSharedArrayBuffer(Object(1n))); |
| 24 | |
| 25 | assert(!isSharedArrayBuffer(new Set())); |
| 26 | assert(!isSharedArrayBuffer(new WeakSet())); |
| 27 | assert(!isSharedArrayBuffer(new Map())); |
| 28 | assert(!isSharedArrayBuffer(new WeakMap())); |
| 29 | assert(!isSharedArrayBuffer(new WeakRef({}))); |
| 30 | assert(!isSharedArrayBuffer(new FinalizationRegistry(() => {}))); |
| 31 | assert(!isSharedArrayBuffer(new ArrayBuffer())); |
| 32 | |
| 33 | assert(isSharedArrayBuffer(new SharedArrayBuffer())); |
| 34 | |
| 35 | class MySharedArrayBuffer extends SharedArrayBuffer {} |
| 36 | assert(isSharedArrayBuffer(new MySharedArrayBuffer())); |
| 37 | ``` |
| 38 | |
| 39 | ## Tests |
| 40 | Simply clone the repo, `npm install`, and run `npm test` |
| 41 | |
Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 42 | [package-url]: https://npmjs.org/package/is-shared-array-buffer |
| 43 | [npm-version-svg]: https://versionbadg.es/inspect-js/is-shared-array-buffer.svg |
| 44 | [deps-svg]: https://david-dm.org/inspect-js/is-shared-array-buffer.svg |
| 45 | [deps-url]: https://david-dm.org/inspect-js/is-shared-array-buffer |
| 46 | [dev-deps-svg]: https://david-dm.org/inspect-js/is-shared-array-buffer/dev-status.svg |
| 47 | [dev-deps-url]: https://david-dm.org/inspect-js/is-shared-array-buffer#info=devDependencies |
| 48 | [npm-badge-png]: https://nodei.co/npm/is-shared-array-buffer.png?downloads=true&stars=true |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 49 | [license-image]: https://img.shields.io/npm/l/is-shared-array-buffer.svg |
| 50 | [license-url]: LICENSE |
| 51 | [downloads-image]: https://img.shields.io/npm/dm/is-shared-array-buffer.svg |
| 52 | [downloads-url]: https://npm-stat.com/charts.html?package=is-shared-array-buffer |
Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 53 | [codecov-image]: https://codecov.io/gh/inspect-js/is-shared-array-buffer/branch/main/graphs/badge.svg |
| 54 | [codecov-url]: https://app.codecov.io/gh/inspect-js/is-shared-array-buffer/ |
| 55 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-shared-array-buffer |
| 56 | [actions-url]: https://github.com/inspect-js/is-shared-array-buffer/actions |