-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation, tests, readme
- Loading branch information
Showing
17 changed files
with
377 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
max_line_length = 150 | ||
|
||
[CHANGELOG.md] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.json] | ||
max_line_length = off | ||
|
||
[Makefile] | ||
max_line_length = off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
|
||
"globals": { | ||
"DataView": false | ||
}, | ||
|
||
"rules": { | ||
"new-cap": ["error", { | ||
"capIsNewExceptions": [ | ||
"GetIntrinsic", | ||
], | ||
}], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [ljharb] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: npm/is-typed-array | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Tests: node.js < 10' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '< 10' | ||
type: minors | ||
command: npm run tests-only | ||
|
||
node: | ||
name: 'node < 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: 'Tests: node.js (harmony)' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '>=0.4 <16' | ||
type: minors | ||
command: npm run test:harmony | ||
skip-ls-check: true | ||
|
||
node: | ||
name: 'node: harmony' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'Tests: pretest/posttest' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/pretest.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Tests: node.js >= 10' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '>= 10' | ||
type: minors | ||
command: npm run tests-only | ||
|
||
node: | ||
name: 'node >= 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Automatic Rebase | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
uses: ljharb/actions/.github/workflows/rebase.yml@main | ||
secrets: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Require “Allow Edits” | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
name: "Require “Allow Edits”" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: ljharb/require-allow-edits@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,5 @@ dist | |
npm-shrinkwrap.json | ||
package-lock.json | ||
yarn.lock | ||
|
||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
package-lock=false | ||
allow-same-version=true | ||
message=v%s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"all": true, | ||
"check-coverage": false, | ||
"reporter": ["text-summary", "text", "html", "json"], | ||
"exclude": [ | ||
"coverage", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,69 @@ | ||
# is-data-view | ||
Is this value a JS DataView? This module works cross-realm/iframe, does not depend on instanceof or mutable properties, and despite ES6 Symbol.toStringTag. | ||
# is-data-view <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
|
||
[![github actions][actions-image]][actions-url] | ||
[![coverage][codecov-image]][codecov-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
|
||
[![npm badge][npm-badge-png]][package-url] | ||
|
||
Is this value a JS DataView? This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and despite ES6 Symbol.toStringTag. | ||
|
||
## Example | ||
|
||
```js | ||
var isDataView = require('is-data-view'); | ||
var assert = require('assert'); | ||
|
||
assert.equal(false, isDataView(undefined)); | ||
assert.equal(false, isDataView(null)); | ||
assert.equal(false, isDataView(false)); | ||
assert.equal(false, isDataView(true)); | ||
assert.equal(false, isDataView([])); | ||
assert.equal(false, isDataView({})); | ||
assert.equal(false, isDataView(/a/g)); | ||
assert.equal(false, isDataView(new RegExp('a', 'g'))); | ||
assert.equal(false, isDataView(new Date())); | ||
assert.equal(false, isDataView(42)); | ||
assert.equal(false, isDataView(NaN)); | ||
assert.equal(false, isDataView(Infinity)); | ||
assert.equal(false, isDataView(new Number(42))); | ||
assert.equal(false, isDataView('foo')); | ||
assert.equal(false, isDataView(Object('foo'))); | ||
assert.equal(false, isDataView(function () {})); | ||
assert.equal(false, isDataView(function* () {})); | ||
assert.equal(false, isDataView(x => x * x)); | ||
assert.equal(false, isDataView([])); | ||
assert.equal(false, isDataView(new Int8Array())); | ||
assert.equal(false, isDataView(new Uint8Array())); | ||
assert.equal(false, isDataView(new Uint8ClampedArray())); | ||
assert.equal(false, isDataView(new Int16Array())); | ||
assert.equal(false, isDataView(new Uint16Array())); | ||
assert.equal(false, isDataView(new Int32Array())); | ||
assert.equal(false, isDataView(new Uint32Array())); | ||
assert.equal(false, isDataView(new Float32Array())); | ||
assert.equal(false, isDataView(new Float64Array())); | ||
assert.equal(false, isDataView(new BigInt64Array())); | ||
assert.equal(false, isDataView(new BigUint64Array())); | ||
|
||
assert.ok(isDataView(new DataView(new ArrayBuffer(0)))); | ||
``` | ||
|
||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
|
||
[package-url]: https://npmjs.org/package/is-data-view | ||
[npm-version-svg]: https://versionbadg.es/inspect-js/is-data-view.svg | ||
[deps-svg]: https://david-dm.org/inspect-js/is-data-view.svg | ||
[deps-url]: https://david-dm.org/inspect-js/is-data-view | ||
[dev-deps-svg]: https://david-dm.org/inspect-js/is-data-view/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/inspect-js/is-data-view#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/is-data-view.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/is-data-view.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/is-data-view.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=is-data-view | ||
[codecov-image]: https://codecov.io/gh/inspect-js/is-data-view/branch/main/graphs/badge.svg | ||
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-data-view/ | ||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-data-view | ||
[actions-url]: https://github.com/inspect-js/is-data-view/actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
var GetIntrinsic = require('get-intrinsic'); | ||
|
||
var $ArrayBuffer = GetIntrinsic('%ArrayBuffer%'); | ||
var $DataView = GetIntrinsic('%DataView%', true); | ||
|
||
var callBound = require('call-bind/callBound'); | ||
|
||
var $dataViewBuffer = callBound('DataView.prototype.buffer', true); | ||
|
||
var isTypedArray = require('is-typed-array'); | ||
|
||
// node <= 0.10, < 0.11.4 has a nonconfigurable own property instead of a prototype getter | ||
module.exports = function isDataView(x) { | ||
if (!x || typeof x !== 'object' || !$DataView || isTypedArray(x)) { | ||
return false; | ||
} | ||
|
||
if ($dataViewBuffer) { | ||
try { | ||
$dataViewBuffer(x); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
/* | ||
* try { | ||
* new $DataView(x); // eslint-disable-line no-new | ||
* x is an ArrayBuffer | ||
* } catch (e) { | ||
*/ | ||
if ( | ||
('getInt8' in x) | ||
&& typeof x.getInt8 === 'function' | ||
&& x.getInt8 === new $DataView(new $ArrayBuffer(1)).getInt8 | ||
) { | ||
return true; | ||
} | ||
// } | ||
|
||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.