[EDIT] FILE: is-data-view.tar
test/index.js 0000755 00000003006 15075406053 0007177 0 ustar 00 'use strict'; var test = require('tape'); var isDataView = require('../'); var hasToStringTag = require('has-tostringtag/shams')(); var generators = require('make-generator-function')(); var arrowFns = require('make-arrow-function').list(); var forEach = require('for-each'); var v = require('es-value-fixtures'); var inspect = require('object-inspect'); var availableTypedArrays = require('available-typed-arrays')(); test('not DataViews', function (t) { forEach([].concat( // @ts-expect-error TS sucks at [].concat v.primitives, v.objects, function () {}, generators, arrowFns, [] ), /** @type {(nonDV: unknown) => void} */ function (nonDV) { t.equal( isDataView(nonDV), false, inspect(nonDV) + ' is not a DataView' ); }); forEach(availableTypedArrays, function (typedArray) { var TA = global[typedArray]; var ta = new TA(8); t.equal(isDataView(ta), false, inspect(ta) + ' is not a DataView'); }); t.end(); }); test('@@toStringTag', { skip: !hasToStringTag }, function (t) { forEach(availableTypedArrays, function (typedArray) { // @ts-expect-error var fakeTypedArray = []; // @ts-expect-error fakeTypedArray[Symbol.toStringTag] = typedArray; // @ts-expect-error t.notOk(isDataView(fakeTypedArray), 'faked ' + typedArray + ' is not typed array'); }); t.end(); }); test('Data Views', { skip: typeof DataView !== 'function' }, function (t) { var ab = new ArrayBuffer(1); var dv = new DataView(ab); t.equal(isDataView(dv), true, inspect(dv) + ' is a DataView'); t.end(); }); .nycrc 0000755 00000000213 15075406053 0005667 0 ustar 00 { "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } tsconfig.json 0000755 00000007033 15075406053 0007266 0 ustar 00 { "compilerOptions": { /* Visit https://aka.ms/tsconfig to read more about this file */ /* Projects */ /* Language and Environment */ "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ "typeRoots": ["types"], /* Specify multiple folders that act like './node_modules/@types'. */ "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ /* JavaScript Support */ "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ "maxNodeModuleJsDepth": 0, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ /* Emit */ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ "declarationMap": true, /* Create sourcemaps for d.ts files. */ "noEmit": true, /* Disable emitting files from a compilation. */ /* Interop Constraints */ "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ /* Type Checking */ "strict": true, /* Enable all strict type-checking options. */ /* Completeness */ //"skipLibCheck": true /* Skip type checking all .d.ts files. */ }, "exclude": [ "coverage" ] } .github/FUNDING.yml 0000755 00000001111 15075406053 0007723 0 ustar 00 # 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'] README.md 0000755 00000006071 15075406053 0006037 0 ustar 00 # 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 LICENSE 0000755 00000002053 15075406053 0005561 0 ustar 00 MIT License Copyright (c) 2024 Inspect JS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. index.d.ts 0000755 00000000125 15075406053 0006453 0 ustar 00 declare function isDataView(value: unknown): value is DataView; export = isDataView; CHANGELOG.md 0000755 00000002556 15075406053 0006375 0 ustar 00 # 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). ## [v1.0.1](https://github.com/inspect-js/is-data-view/compare/v1.0.0...v1.0.1) - 2024-02-02 ### Commits - [patch] add types [`c2728ef`](https://github.com/inspect-js/is-data-view/commit/c2728ef20064bba2588eed503a0c2e36985b638a) - [Dev Deps] update `aud`, `available-typed-arrays`, `has-tostringtag`, `npmignore`, `object-inspect`, `tape` [`e7f9ebc`](https://github.com/inspect-js/is-data-view/commit/e7f9ebccf9aacdc112dd4f665271c96417ddfa64) - [Deps] update `is-typed-array` [`2ca9333`](https://github.com/inspect-js/is-data-view/commit/2ca9333516afac321431ddae02d6791d50e8d5c2) ## v1.0.0 - 2024-01-31 ### Commits - Initial implementation, tests, readme [`6f7e424`](https://github.com/inspect-js/is-data-view/commit/6f7e4244ae9d766309b8f050c0b786e9c0692825) - Initial commit [`4b7ea57`](https://github.com/inspect-js/is-data-view/commit/4b7ea57d6942dd268bcda990a96b8cd663b19eb8) - npm init [`25130e2`](https://github.com/inspect-js/is-data-view/commit/25130e2dbecc91d398cf74c39878aa89f5e604ab) - Only apps should have lockfiles [`18cde47`](https://github.com/inspect-js/is-data-view/commit/18cde474201a292ebdaa704d232127c814cb1d0e) .editorconfig 0000755 00000000436 15075406053 0007234 0 ustar 00 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 package.json 0000755 00000005173 15075406053 0007050 0 ustar 00 { "name": "is-data-view", "version": "1.0.1", "description": "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.", "main": "index.js", "exports": { ".": "./index.js", "./package.json": "./package.json" }, "types": "./index.d.ts", "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "prelint": "evalmd README.md", "lint": "eslint --ext=js,mjs .", "postlint": "tsc -p .", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "funding": { "url": "https://github.com/sponsors/ljharb" }, "repository": { "type": "git", "url": "git+https://github.com/inspect-js/is-data-view.git" }, "keywords": [ "javascript", "ecmascript", "dataview", "data", "view", "typedarray", "typedarrays" ], "author": "Jordan Harband <ljharb@gmail.com>", "license": "MIT", "bugs": { "url": "https://github.com/inspect-js/is-data-view/issues" }, "homepage": "https://github.com/inspect-js/is-data-view#readme", "dependencies": { "is-typed-array": "^1.1.13" }, "devDependencies": { "@ljharb/eslint-config": "^21.1.0", "@types/call-bind": "^1.0.5", "@types/es-value-fixtures": "^1.4.4", "@types/for-each": "^0.3.3", "@types/make-arrow-function": "^1.2.2", "@types/make-generator-function": "^2.0.3", "@types/node": "^20.11.14", "@types/object-inspect": "^1.8.4", "@types/tape": "^5.6.4", "aud": "^2.0.4", "auto-changelog": "^2.4.0", "available-typed-arrays": "^1.0.6", "es-value-fixtures": "^1.4.2", "eslint": "=8.8.0", "evalmd": "^0.0.19", "for-each": "^0.3.3", "has-tostringtag": "^1.0.2", "in-publish": "^2.0.1", "make-arrow-function": "^1.2.0", "make-generator-function": "^2.0.0", "npmignore": "^0.3.1", "nyc": "^10.3.2", "object-inspect": "^1.13.1", "safe-publish-latest": "^2.0.0", "tape": "^5.7.4", "typescript": "next" }, "testling": { "files": "test/index.js" }, "engines": { "node": ">= 0.4" }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "publishConfig": { "ignore": [ ".github/workflows" ] } } .eslintrc 0000755 00000000267 15075406053 0006405 0 ustar 00 { "root": true, "extends": "@ljharb", "globals": { "DataView": false }, "rules": { "new-cap": ["error", { "capIsNewExceptions": [ "GetIntrinsic", ], }], }, } index.js 0000755 00000001530 15075406053 0006220 0 ustar 00 'use strict'; var GetIntrinsic = require('get-intrinsic'); var $ArrayBuffer = GetIntrinsic('%ArrayBuffer%'); var $DataView = GetIntrinsic('%DataView%', true); var callBound = require('call-bind/callBound'); // node <= 0.10, < 0.11.4 has a nonconfigurable own property instead of a prototype getter var $dataViewBuffer = callBound('DataView.prototype.buffer', true); var isTypedArray = require('is-typed-array'); /** @type {import('.')} */ 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; } } if ( ('getInt8' in x) && typeof x.getInt8 === 'function' && x.getInt8 === new $DataView(new $ArrayBuffer(1)).getInt8 ) { return true; } return false; };
SAVE
CANCEL