is-array-buffer
Advanced tools
Comparing version 2.0.0 to 3.0.0
# 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). | ||
## [v3.0.0](https://github.com/fengyuanchen/is-array-buffer/compare/v2.0.0...v3.0.0) - 2023-01-04 | ||
### Commits | ||
- [Breaking] replace package implementation [`b65f929`](https://github.com/fengyuanchen/is-array-buffer/commit/b65f929d856d2a42f043be0f5a0fc2e067370ed1) | ||
- Initial implementation, tests, readme [`06afa73`](https://github.com/fengyuanchen/is-array-buffer/commit/06afa73e775960802ea9257cc6b4cdf768c72d3f) | ||
- Initial commit [`051813f`](https://github.com/fengyuanchen/is-array-buffer/commit/051813f15e3cbf515e2447306761dd9c42819150) | ||
- npm init [`946d3de`](https://github.com/fengyuanchen/is-array-buffer/commit/946d3de82b15471fb2c00a4a2a5a52eb0515eb04) | ||
- [meta] use `npmignore` to autogenerate an npmignore file [`ca4c446`](https://github.com/fengyuanchen/is-array-buffer/commit/ca4c446f37daf5ab8cc590f2194574c2706561ed) | ||
- Only apps should have lockfiles [`be7d8eb`](https://github.com/fengyuanchen/is-array-buffer/commit/be7d8eb09dc5033c04df85d7ba9a8714f4e54357) | ||
- docs: fix badge link [`9ea7fb6`](https://github.com/fengyuanchen/is-array-buffer/commit/9ea7fb638e79f8938161b3b7370cb965d8e93a8b) | ||
<!-- auto-changelog-above --> | ||
## 2.0.0 (Feb 12, 2021) | ||
@@ -4,0 +23,0 @@ |
55
index.js
'use strict'; | ||
const hasArrayBuffer = typeof ArrayBuffer === 'function'; | ||
const { toString } = Object.prototype; | ||
/** | ||
* Check if the given value is an ArrayBuffer. | ||
* @param {*} value - The value to check. | ||
* @returns {boolean} Returns `true` if the given value is an ArrayBuffer, else `false`. | ||
* @example | ||
* isArrayBuffer(new ArrayBuffer()) | ||
* // => true | ||
* isArrayBuffer([]) | ||
* // => false | ||
*/ | ||
function isArrayBuffer(value) { | ||
return hasArrayBuffer && (value instanceof ArrayBuffer || toString.call(value) === '[object ArrayBuffer]'); | ||
} | ||
var callBind = require('call-bind'); | ||
var callBound = require('call-bind/callBound'); | ||
var GetIntrinsic = require('get-intrinsic'); | ||
module.exports = isArrayBuffer; | ||
var $ArrayBuffer = GetIntrinsic('ArrayBuffer', true); | ||
var $Float32Array = GetIntrinsic('Float32Array', true); | ||
var $byteLength = callBound('ArrayBuffer.prototype.byteLength', true); | ||
// in node 0.10, ArrayBuffers have no prototype methods, but have an own slot-checking `slice` method | ||
var abSlice = $ArrayBuffer && !$byteLength && new $ArrayBuffer().slice; | ||
var $abSlice = abSlice && callBind(abSlice); | ||
module.exports = $byteLength || $abSlice | ||
? function isArrayBuffer(obj) { | ||
if (!obj || typeof obj !== 'object') { | ||
return false; | ||
} | ||
try { | ||
if ($byteLength) { | ||
$byteLength(obj); | ||
} else { | ||
$abSlice(obj, 0); | ||
} | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
: $Float32Array | ||
// in node 0.8, ArrayBuffers have no prototype or own methods | ||
? function IsArrayBuffer(obj) { | ||
try { | ||
return (new $Float32Array(obj)).buffer === obj; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
: function isArrayBuffer(obj) { // eslint-disable-line no-unused-vars | ||
return false; | ||
}; |
122
package.json
{ | ||
"name": "is-array-buffer", | ||
"description": "Check if the given value is an ArrayBuffer.", | ||
"version": "2.0.0", | ||
"main": "index.js", | ||
"module": "index.esm.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.esm.js", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build:dts": "tsc --declaration --emitDeclarationOnly", | ||
"clean": "del-cli index.js index.esm.js index.d.ts", | ||
"lint": "eslint . --ext .js,.ts --fix", | ||
"release": "npm run clean && npm run lint && npm run build && npm run build:dts && npm test", | ||
"test": "nyc mocha", | ||
"test:coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fengyuanchen/is-array-buffer.git" | ||
}, | ||
"keywords": [ | ||
"is", | ||
"array", | ||
"buffer", | ||
"ArrayBuffer" | ||
], | ||
"author": "Chen Fengyuan (https://chenfengyuan.com/)", | ||
"license": "MIT", | ||
"bugs": "https://github.com/fengyuanchen/is-array-buffer/issues", | ||
"homepage": "https://github.com/fengyuanchen/is-array-buffer/#readme", | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^8.1.1", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"codecov": "^3.8.1", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.19.0", | ||
"eslint-config-airbnb-typescript": "^12.3.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0", | ||
"rollup": "^2.38.5", | ||
"typescript": "^4.1.5" | ||
} | ||
"name": "is-array-buffer", | ||
"version": "3.0.0", | ||
"description": "Is this value a JS ArrayBuffer?", | ||
"main": "index.js", | ||
"exports": { | ||
".": "./index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"prepack": "npmignore --auto --commentLines=autogenerated", | ||
"prepublishOnly": "safe-publish-latest", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"lint": "eslint --ext=.js,.mjs .", | ||
"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)\")\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/inspect-js/is-array-buffer.git" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"ecmascript", | ||
"is", | ||
"arraybuffer", | ||
"array", | ||
"buffer" | ||
], | ||
"author": "Jordan Harband <ljharb@gmail.com>", | ||
"funding": { | ||
"url": "https://github.com/sponsors/ljharb" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/inspect-js/is-array-buffer/issues" | ||
}, | ||
"homepage": "https://github.com/inspect-js/is-array-buffer#readme", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.0", | ||
"aud": "^2.0.1", | ||
"auto-changelog": "^2.4.0", | ||
"es-value-fixtures": "^1.4.2", | ||
"eslint": "=8.8.0", | ||
"for-each": "^0.3.3", | ||
"in-publish": "^2.0.1", | ||
"npmignore": "^0.3.0", | ||
"nyc": "^10.3.2", | ||
"object-inspect": "^1.12.2", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.6.1" | ||
}, | ||
"auto-changelog": { | ||
"output": "CHANGELOG.md", | ||
"template": "keepachangelog", | ||
"unreleased": false, | ||
"commitLimit": false, | ||
"backfillLimit": false, | ||
"hideCredit": true, | ||
"startingVersion": "2.0.1" | ||
}, | ||
"dependencies": { | ||
"call-bind": "^1.0.2", | ||
"get-intrinsic": "^1.1.3" | ||
}, | ||
"publishConfig": { | ||
"ignore": [ | ||
".github/workflows" | ||
] | ||
} | ||
} |
@@ -1,40 +0,56 @@ | ||
# is-array-buffer | ||
# is-array-buffer <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
[![Build Status](https://img.shields.io/github/workflow/status/fengyuanchen/is-array-buffer/ci/main.svg)](https://github.com/fengyuanchen/is-array-buffer/actions) [![Coverage Status](https://img.shields.io/codecov/c/github/fengyuanchen/is-array-buffer.svg)](https://codecov.io/gh/fengyuanchen/is-array-buffer) [![Downloads](https://img.shields.io/npm/dm/is-array-buffer.svg)](https://www.npmjs.com/package/is-array-buffer) [![Version](https://img.shields.io/npm/v/is-array-buffer.svg)](https://www.npmjs.com/package/is-array-buffer) [![Gzip Size](https://img.shields.io/bundlephobia/minzip/is-array-buffer.svg)](https://unpkg.com/is-array-buffer/dist/cropper.common.js) [![Dependencies](https://img.shields.io/david/fengyuanchen/is-array-buffer.svg)](https://www.npmjs.com/package/is-array-buffer) | ||
[![github actions][actions-image]][actions-url] | ||
[![coverage][codecov-image]][codecov-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
> Check if the given value is an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). | ||
[![npm badge][npm-badge-png]][package-url] | ||
## Main files | ||
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. | ||
```text | ||
/ | ||
├── index.js (CommonJS, default) | ||
├── index.esm.js (ECMAScript Module) | ||
└── index.d.ts (TypeScript Declaration File) | ||
``` | ||
## Example | ||
## Install | ||
```js | ||
var assert = require('assert'); | ||
var isArrayBuffer = require('is-array-buffer'); | ||
```shell | ||
npm install is-array-buffer | ||
``` | ||
assert(!isArrayBuffer(function () {})); | ||
assert(!isArrayBuffer(null)); | ||
assert(!isArrayBuffer(function* () { yield 42; return Infinity; }); | ||
assert(!isArrayBuffer(Symbol('foo'))); | ||
assert(!isArrayBuffer(1n)); | ||
assert(!isArrayBuffer(Object(1n))); | ||
## Usage | ||
assert(!isArrayBuffer(new Set())); | ||
assert(!isArrayBuffer(new WeakSet())); | ||
assert(!isArrayBuffer(new Map())); | ||
assert(!isArrayBuffer(new WeakMap())); | ||
assert(!isArrayBuffer(new WeakRef({}))); | ||
assert(!isArrayBuffer(new FinalizationRegistry(() => {}))); | ||
assert(!isArrayBuffer(new SharedArrayBuffer())); | ||
```js | ||
import isArrayBuffer from 'is-array-buffer'; | ||
assert(isArrayBuffer(new ArrayBuffer())); | ||
isArrayBuffer(new ArrayBuffer()); | ||
// > true | ||
isArrayBuffer([]); | ||
// > false | ||
class MyArrayBuffer extends ArrayBuffer {} | ||
assert(isArrayBuffer(new MyArrayBuffer())); | ||
``` | ||
## Versioning | ||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
Maintained under the [Semantic Versioning guidelines](https://semver.org/). | ||
## License | ||
[MIT](https://opensource.org/licenses/MIT) © [Chen Fengyuan](https://chenfengyuan.com/) | ||
[package-url]: https://npmjs.org/package/is-array-buffer | ||
[npm-version-svg]: https://versionbadg.es/inspect-js/is-array-buffer.svg | ||
[deps-svg]: https://david-dm.org/inspect-js/is-array-buffer.svg | ||
[deps-url]: https://david-dm.org/inspect-js/is-array-buffer | ||
[dev-deps-svg]: https://david-dm.org/inspect-js/is-array-buffer/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/inspect-js/is-array-buffer#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/is-array-buffer.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/is-array-buffer.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/is-array-buffer.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=is-array-buffer | ||
[codecov-image]: https://codecov.io/gh/inspect-js/is-array-buffer/branch/main/graphs/badge.svg | ||
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-array-buffer/ | ||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-array-buffer | ||
[actions-url]: https://github.com/inspect-js/is-array-buffer/actions |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
10033
9
60
0
57
2
+ Addedcall-bind@^1.0.2
+ Addedget-intrinsic@^1.1.3
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedset-function-length@1.2.2(transitive)