Socket
Socket
Sign inDemoInstall

is-accessor-descriptor

Package Overview
Dependencies
2
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

.editorconfig

95

index.js

@@ -1,69 +0,50 @@

/*!
* is-accessor-descriptor <https://github.com/jonschlinkert/is-accessor-descriptor>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var typeOf = require('kind-of');
var hasOwn = require('hasown');
// accessor descriptor properties
var accessor = {
get: 'function',
set: 'function',
configurable: 'boolean',
enumerable: 'boolean'
__proto__: null,
configurable: 'boolean',
enumerable: 'boolean',
get: 'function',
set: 'function'
};
function isAccessorDescriptor(obj, prop) {
if (typeof prop === 'string') {
var val = Object.getOwnPropertyDescriptor(obj, prop);
return typeof val !== 'undefined';
}
module.exports = function isAccessorDescriptor(obj, prop) {
if (typeof prop === 'string') {
var val = Object.getOwnPropertyDescriptor(obj, prop);
return typeof val !== 'undefined';
}
if (typeOf(obj) !== 'object') {
return false;
}
if (!obj || typeof obj !== 'object') {
return false;
}
if (has(obj, 'value') || has(obj, 'writable')) {
return false;
}
if (hasOwn(obj, 'value') || hasOwn(obj, 'writable')) {
return false;
}
if (!has(obj, 'get') || typeof obj.get !== 'function') {
return false;
}
// one of them must be a function
if (
(!hasOwn(obj, 'get') || typeof obj.get !== 'function')
&& (!hasOwn(obj, 'set') || typeof obj.set !== 'function')
) {
return false;
}
// tldr: it's valid to have "set" be undefined
// "set" might be undefined if `Object.getOwnPropertyDescriptor`
// was used to get the value, and only `get` was defined by the user
if (has(obj, 'set') && typeof obj[key] !== 'function' && typeof obj[key] !== 'undefined') {
return false;
}
// both of them must be a function or undefined
if (
(hasOwn(obj, 'get') && typeof obj.get !== 'function' && typeof obj.get !== 'undefined')
|| (hasOwn(obj, 'set') && typeof obj.set !== 'function' && typeof obj.set !== 'undefined')
) {
return false;
}
for (var key in obj) {
if (!accessor.hasOwnProperty(key)) {
continue;
}
if (typeOf(obj[key]) === accessor[key]) {
continue;
}
if (typeof obj[key] !== 'undefined') {
return false;
}
}
return true;
}
function has(obj, key) {
return {}.hasOwnProperty.call(obj, key);
}
/**
* Expose `isAccessorDescriptor`
*/
module.exports = isAccessorDescriptor;
for (var key in obj) { // eslint-disable-line no-restricted-syntax
if (hasOwn(obj, key) && hasOwn(accessor, key) && typeof obj[key] !== accessor[key] && typeof obj[key] !== 'undefined') {
return false;
}
}
return true;
};

148

package.json
{
"name": "is-accessor-descriptor",
"description": "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/is-accessor-descriptor",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"repository": "jonschlinkert/is-accessor-descriptor",
"bugs": {
"url": "https://github.com/jonschlinkert/is-accessor-descriptor/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"kind-of": "^6.0.0"
},
"devDependencies": {
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},
"keywords": [
"accessor",
"check",
"data",
"descriptor",
"get",
"getter",
"is",
"keys",
"object",
"properties",
"property",
"set",
"setter",
"type",
"valid",
"value"
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"is-accessor-descriptor",
"is-data-descriptor",
"is-descriptor",
"is-plain-object",
"isobject"
]
},
"lint": {
"reflinks": true
}
}
"name": "is-accessor-descriptor",
"version": "1.0.1",
"description": "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.",
"main": "index.js",
"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 .",
"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-accessor-descriptor.git"
},
"keywords": [
"descriptor",
"get",
"getter",
"is",
"keys",
"object",
"properties",
"property",
"set",
"setter",
"type",
"valid",
"value"
],
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/is-accessor-descriptor/issues"
},
"homepage": "https://github.com/inspect-js/is-accessor-descriptor",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"dependencies": {
"hasown": "^2.0.0"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.2"
},
"engines": {
"node": ">= 0.10"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}

@@ -1,22 +0,19 @@

# is-accessor-descriptor [![NPM version](https://img.shields.io/npm/v/is-accessor-descriptor.svg?style=flat)](https://www.npmjs.com/package/is-accessor-descriptor) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-accessor-descriptor.svg?style=flat)](https://npmjs.org/package/is-accessor-descriptor) [![NPM total downloads](https://img.shields.io/npm/dt/is-accessor-descriptor.svg?style=flat)](https://npmjs.org/package/is-accessor-descriptor) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-accessor-descriptor.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-accessor-descriptor)
# is-accessor-descriptor <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
> Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
[![npm badge][npm-badge-png]][package-url]
## Install
> Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
Install with [npm](https://www.npmjs.com/):
## Examples
```sh
$ npm install --save is-accessor-descriptor
```
## Usage
```js
var isAccessor = require('is-accessor-descriptor');
var assert = require('assert');
isAccessor({get: function() {}});
//=> true
assert.equal(isAccessor({ get: function() {} }), true);
```

@@ -27,3 +24,3 @@

```js
isAccessor(foo, 'bar');
assert.equal(isAccessor({ bar: {} }, 'bar'), true);
```

@@ -36,6 +33,4 @@

```js
isAccessor('a')
isAccessor(null)
isAccessor([])
//=> false
assert.equal(isAccessor('a'), false);
assert.equal(isAccessor(null), false);
```

@@ -48,6 +43,5 @@

```js
isAccessor({get: noop, set: noop})
isAccessor({get: noop})
isAccessor({set: noop})
//=> true
assert.equal(isAccessor({ get() {}, set() {} }), true);
assert.equal(isAccessor({ get() {} }), true);
assert.equal(isAccessor({ set() {} }), true);
```

@@ -58,6 +52,5 @@

```js
isAccessor({get: noop, set: noop, bar: 'baz'})
isAccessor({get: noop, writable: true})
isAccessor({get: noop, value: true})
//=> false
assert.equal(isAccessor({ get() {}, set() {}, enumerable: 'baz' }), false);
assert.equal(isAccessor({ get() {}, writable: true }), false);
assert.equal(isAccessor({ get() {}, value: true }), false);
```

@@ -68,6 +61,6 @@

```js
isAccessor({get: noop, set: 'baz'})
isAccessor({get: 'foo', set: noop})
isAccessor({get: 'foo', bar: 'baz'})
isAccessor({get: 'foo', set: 'baz'})
isAccessor({ get() {}, set: 'baz' });
isAccessor({ get: 'foo', set() {} });
isAccessor({ get: 'foo', bar: 'baz' });
isAccessor({ get: 'foo', set: 'baz' });
//=> false

@@ -79,41 +72,8 @@ ```

```js
isAccessor({get: noop, set: noop, enumerable: 'foo'})
isAccessor({set: noop, configurable: 'foo'})
isAccessor({get: noop, configurable: 'foo'})
isAccessor({ get() {}, set() {}, enumerable: 'foo' });
isAccessor({ set() {}, configurable: 'foo' });
isAccessor({ get() {}, configurable: 'foo' });
//=> false
```
## About
<details>
<summary><strong>Contributing</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
</details>
<details>
<summary><strong>Running Tests</strong></summary>
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```
</details>
<details>
<summary><strong>Building docs</strong></summary>
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects

@@ -123,29 +83,23 @@

* [is-accessor-descriptor](https://www.npmjs.com/package/is-accessor-descriptor): Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. | [homepage](https://github.com/jonschlinkert/is-accessor-descriptor "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.")
* [is-data-descriptor](https://www.npmjs.com/package/is-data-descriptor): Returns true if a value has the characteristics of a valid JavaScript data descriptor. | [homepage](https://github.com/jonschlinkert/is-data-descriptor "Returns true if a value has the characteristics of a valid JavaScript data descriptor.")
* [is-descriptor](https://www.npmjs.com/package/is-descriptor): Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… [more](https://github.com/jonschlinkert/is-descriptor) | [homepage](https://github.com/jonschlinkert/is-descriptor "Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.")
* [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.")
* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
* [is-data-descriptor](https://www.npmjs.com/package/is-data-descriptor): Returns true if a value has the characteristics of a valid JavaScript data descriptor.
* [is-descriptor](https://www.npmjs.com/package/is-descriptor): Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… [more](https://github.com/inspect-js/is-descriptor)
* [is-object](https://www.npmjs.com/package/is-object): Returns true if the value is an object and not an array or null.
### Contributors
## Tests
Simply clone the repo, `npm install`, and run `npm test`
| **Commits** | **Contributor** |
| --- | --- |
| 22 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [realityking](https://github.com/realityking) |
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._
[package-url]: https://npmjs.org/package/is-accessor-descriptor
[npm-version-svg]: https://versionbadg.es/inspect-js/is-accessor-descriptor.svg
[deps-svg]: https://david-dm.org/inspect-js/is-accessor-descriptor.svg
[deps-url]: https://david-dm.org/inspect-js/is-accessor-descriptor
[dev-deps-svg]: https://david-dm.org/inspect-js/is-accessor-descriptor/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/is-accessor-descriptor#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/is-accessor-descriptor.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/is-accessor-descriptor.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/is-accessor-descriptor.svg
[downloads-url]: https://npm-stat.com/charts.html?package=is-accessor-descriptor
[codecov-image]: https://codecov.io/gh/inspect-js/is-accessor-descriptor/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-accessor-descriptor/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-accessor-descriptor
[actions-url]: https://github.com/inspect-js/is-accessor-descriptor/actions
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc