Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06afa73

Browse filesBrowse files
committed
Initial implementation, tests, readme
1 parent ca4c446 commit 06afa73
Copy full SHA for 06afa73

File tree

Expand file treeCollapse file tree

14 files changed

+269
-2
lines changed
Filter options
Expand file treeCollapse file tree

14 files changed

+269
-2
lines changed

‎.eslintrc

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"new-cap": ["error", {
8+
"capIsNewExceptions": [
9+
"GetIntrinsic",
10+
],
11+
}],
12+
},
13+
}

‎.github/FUNDING.yml

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [ljharb]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: npm/is-array-buffer
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

‎.github/workflows/node-aught.yml

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Tests: node.js < 10'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/node.yml@main
8+
with:
9+
range: '< 10'
10+
type: minors
11+
command: npm run tests-only
12+
13+
node:
14+
name: 'node < 10'
15+
needs: [tests]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- run: 'echo tests completed'

‎.github/workflows/node-pretest.yml

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Tests: pretest/posttest'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/pretest.yml@main

‎.github/workflows/node-tens.yml

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Tests: node.js >= 10'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/node.yml@main
8+
with:
9+
range: '>= 10'
10+
type: minors
11+
command: npm run tests-only
12+
13+
node:
14+
name: 'node >= 10'
15+
needs: [tests]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- run: 'echo tests completed'

‎.github/workflows/rebase.yml

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Automatic Rebase
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
_:
7+
uses: ljharb/actions/.github/workflows/rebase.yml@main
8+
secrets:
9+
token: ${{ secrets.GITHUB_TOKEN }}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Require “Allow Edits”
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
_:
7+
name: "Require “Allow Edits”"
8+
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: ljharb/require-allow-edits@main

‎.npmrc

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
package-lock=false
2+
allow-same-version=true
3+
message=v%s

‎.nycrc

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text-summary", "text", "html", "json"],
5+
"exclude": [
6+
"coverage",
7+
"test"
8+
]
9+
}

‎CHANGELOG.md

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

‎README.md

Copy file name to clipboard
+55-1Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
1-
# is-array-buffer
1+
# is-array-buffer <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2+
3+
[![github actions][actions-image]][actions-url]
4+
[![coverage][codecov-image]][codecov-url]
5+
[![License][license-image]][license-url]
6+
[![Downloads][downloads-image]][downloads-url]
7+
8+
[![npm badge][npm-badge-png]][package-url]
9+
210
Is this value a JS ArrayBuffer? 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 isArrayBuffer = require('is-array-buffer');
17+
18+
assert(!isArrayBuffer(function () {}));
19+
assert(!isArrayBuffer(null));
20+
assert(!isArrayBuffer(function* () { yield 42; return Infinity; });
21+
assert(!isArrayBuffer(Symbol('foo')));
22+
assert(!isArrayBuffer(1n));
23+
assert(!isArrayBuffer(Object(1n)));
24+
25+
assert(!isArrayBuffer(new Set()));
26+
assert(!isArrayBuffer(new WeakSet()));
27+
assert(!isArrayBuffer(new Map()));
28+
assert(!isArrayBuffer(new WeakMap()));
29+
assert(!isArrayBuffer(new WeakRef({})));
30+
assert(!isArrayBuffer(new FinalizationRegistry(() => {})));
31+
assert(!isArrayBuffer(new SharedArrayBuffer()));
32+
33+
assert(isArrayBuffer(new ArrayBuffer()));
34+
35+
class MyArrayBuffer extends ArrayBuffer {}
36+
assert(isArrayBuffer(new MyArrayBuffer()));
37+
```
38+
39+
## Tests
40+
Simply clone the repo, `npm install`, and run `npm test`
41+
42+
[package-url]: https://npmjs.org/package/is-array-buffer
43+
[npm-version-svg]: https://versionbadg.es/inspect-js/is-array-buffer.svg
44+
[deps-svg]: https://david-dm.org/inspect-js/is-array-buffer.svg
45+
[deps-url]: https://david-dm.org/inspect-js/is-array-buffer
46+
[dev-deps-svg]: https://david-dm.org/inspect-js/is-array-buffer/dev-status.svg
47+
[dev-deps-url]: https://david-dm.org/inspect-js/is-array-buffer#info=devDependencies
48+
[npm-badge-png]: https://nodei.co/npm/is-array-buffer.png?downloads=true&stars=true
49+
[license-image]: https://img.shields.io/npm/l/is-array-buffer.svg
50+
[license-url]: LICENSE
51+
[downloads-image]: https://img.shields.io/npm/dm/is-array-buffer.svg
52+
[downloads-url]: https://npm-stat.com/charts.html?package=is-array-buffer
53+
[codecov-image]: https://codecov.io/gh/inspect-js/is-array-buffer/branch/main/graphs/badge.svg
54+
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-array-buffer/
55+
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-array-buffer
56+
[actions-url]: https://github.com/inspect-js/is-array-buffer/actions

‎index.js

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var callBind = require('call-bind');
4+
var callBound = require('call-bind/callBound');
5+
var GetIntrinsic = require('get-intrinsic');
6+
7+
var $ArrayBuffer = GetIntrinsic('ArrayBuffer', true);
8+
var $Float32Array = GetIntrinsic('Float32Array', true);
9+
var $byteLength = callBound('ArrayBuffer.prototype.byteLength', true);
10+
11+
// in node 0.10, ArrayBuffers have no prototype methods, but have an own slot-checking `slice` method
12+
var abSlice = $ArrayBuffer && !$byteLength && new $ArrayBuffer().slice;
13+
var $abSlice = abSlice && callBind(abSlice);
14+
15+
module.exports = $byteLength || $abSlice
16+
? function isArrayBuffer(obj) {
17+
if (!obj || typeof obj !== 'object') {
18+
return false;
19+
}
20+
try {
21+
if ($byteLength) {
22+
$byteLength(obj);
23+
} else {
24+
$abSlice(obj, 0);
25+
}
26+
return true;
27+
} catch (e) {
28+
return false;
29+
}
30+
}
31+
: $Float32Array
32+
// in node 0.8, ArrayBuffers have no prototype or own methods
33+
? function IsArrayBuffer(obj) {
34+
try {
35+
return (new $Float32Array(obj)).buffer === obj;
36+
} catch (e) {
37+
return false;
38+
}
39+
}
40+
: function isArrayBuffer(obj) { // eslint-disable-line no-unused-vars
41+
return false;
42+
};

‎package.json

Copy file name to clipboardExpand all lines: package.json
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77
".": "./index.js",
88
"./package.json": "./package.json"
99
},
10+
"sideEffects": false,
1011
"scripts": {
1112
"prepack": "npmignore --auto --commentLines=autogenerated",
12-
"test": "echo \"Error: no test specified\" && exit 1"
13+
"prepublishOnly": "safe-publish-latest",
14+
"prepublish": "not-in-publish || npm run prepublishOnly",
15+
"lint": "eslint --ext=.js,.mjs .",
16+
"pretest": "npm run lint",
17+
"tests-only": "nyc tape 'test/**/*.js'",
18+
"test": "npm run tests-only --",
19+
"posttest": "aud --production",
20+
"version": "auto-changelog && git add CHANGELOG.md",
21+
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
1322
},
1423
"repository": {
1524
"type": "git",
@@ -24,13 +33,39 @@
2433
"buffer"
2534
],
2635
"author": "Jordan Harband <ljharb@gmail.com>",
36+
"funding": {
37+
"url": "https://github.com/sponsors/ljharb"
38+
},
2739
"license": "MIT",
2840
"bugs": {
2941
"url": "https://github.com/inspect-js/is-array-buffer/issues"
3042
},
3143
"homepage": "https://github.com/inspect-js/is-array-buffer#readme",
3244
"devDependencies": {
45+
"@ljharb/eslint-config": "^21.0.0",
46+
"aud": "^2.0.1",
47+
"auto-changelog": "^2.4.0",
48+
"es-value-fixtures": "^1.4.2",
49+
"eslint": "=8.8.0",
50+
"for-each": "^0.3.3",
51+
"in-publish": "^2.0.1",
3352
"npmignore": "^0.3.0",
53+
"nyc": "^10.3.2",
54+
"object-inspect": "^1.12.2",
55+
"safe-publish-latest": "^2.0.0",
56+
"tape": "^5.6.1"
57+
},
58+
"auto-changelog": {
59+
"output": "CHANGELOG.md",
60+
"template": "keepachangelog",
61+
"unreleased": false,
62+
"commitLimit": false,
63+
"backfillLimit": false,
64+
"hideCredit": true
65+
},
66+
"dependencies": {
67+
"call-bind": "^1.0.2",
68+
"get-intrinsic": "^1.1.3"
3469
},
3570
"publishConfig": {
3671
"ignore": [

‎test/index.js

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var test = require('tape');
4+
var inspect = require('object-inspect');
5+
var forEach = require('for-each');
6+
var v = require('es-value-fixtures');
7+
8+
var isArrayBuffer = require('..');
9+
10+
test('isArrayBuffer', function (t) {
11+
t.equal(typeof isArrayBuffer, 'function', 'is a function');
12+
13+
var nonABs = v.primitives.concat(
14+
v.objects,
15+
typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer() : []
16+
);
17+
forEach(nonABs, function (nonAB) {
18+
t.equal(isArrayBuffer(nonAB), false, inspect(nonAB) + ' is not an ArrayBuffer');
19+
});
20+
21+
t.test('actual ArrayBuffer instances', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
22+
var ab = new ArrayBuffer();
23+
24+
st.equal(isArrayBuffer(ab), true, inspect(ab) + ' is an ArrayBuffer');
25+
26+
st.end();
27+
});
28+
29+
t.end();
30+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.