is-accessor-descriptor
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -8,2 +8,8 @@ # Changelog | ||
## [v3.0.5](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.4...v3.0.5) - 2023-10-27 | ||
### Commits | ||
- [Fix] fix a bad merge and refactor checkProto logic [`1acdf9d`](https://github.com/inspect-js/is-accessor-descriptor/commit/1acdf9deb55f1616da5b8dd3c2991d2de56faec3) | ||
## [v3.0.4](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.3...v3.0.4) - 2023-10-26 | ||
@@ -10,0 +16,0 @@ |
59
index.js
'use strict'; | ||
<<<<<<< .merge_file_ESYIpc | ||
var hasOwn = require('hasown'); | ||
var gOPD = require('gopd'); | ||
var isObject = function (val) { | ||
@@ -14,12 +15,11 @@ return val !== null && typeof val === 'object' && !Array.isArray(val); | ||
var desc = arguments.length > 1 ? Object.getOwnPropertyDescriptor(obj, key) : obj; | ||
if (arguments.length > 1 && !desc && checkProto !== false) { | ||
obj = obj.constructor.prototype; | ||
desc = Object.getOwnPropertyDescriptor(obj, key); | ||
if (arguments.length > 1) { | ||
var hasKey = hasOwn(obj, key); | ||
if (!hasKey && checkProto !== false) { | ||
return isAccessorDescriptor(obj.constructor.prototype, key, false); | ||
} | ||
return gOPD ? isAccessorDescriptor(gOPD(obj, key)) : hasKey; | ||
} | ||
if (!isObject(desc)) { | ||
return false; | ||
} | ||
var desc = obj; | ||
if ( | ||
@@ -30,32 +30,2 @@ !hasOwn(desc, 'get') | ||
|| !hasOwn(desc, 'configurable') | ||
======= | ||
var gOPD = require('gopd'); | ||
var hasOwn = require('hasown'); | ||
// accessor descriptor properties | ||
var accessor = { | ||
__proto__: null, | ||
configurable: 'boolean', | ||
enumerable: 'boolean', | ||
get: 'function', | ||
set: 'function' | ||
}; | ||
module.exports = function isAccessorDescriptor(obj, prop) { | ||
if (typeof prop === 'string') { | ||
return gOPD ? isAccessorDescriptor(gOPD(obj, prop)) : hasOwn(obj, prop); | ||
} | ||
if ( | ||
!obj | ||
|| typeof obj !== 'object' | ||
|| hasOwn(obj, 'value') | ||
|| hasOwn(obj, 'writable') | ||
|| (hasOwn(obj, 'get') && typeof obj.get !== 'function' && typeof obj.get !== 'undefined') | ||
|| (hasOwn(obj, 'set') && typeof obj.set !== 'function' && typeof obj.set !== 'undefined') | ||
|| !( | ||
(hasOwn(obj, 'get') && typeof obj.get === 'function') | ||
|| (hasOwn(obj, 'set') && typeof obj.set === 'function') | ||
) | ||
>>>>>>> .merge_file_5gBVbH | ||
) { | ||
@@ -65,3 +35,2 @@ return false; | ||
<<<<<<< .merge_file_ESYIpc | ||
for (var descKey in desc) { // eslint-disable-line no-restricted-syntax | ||
@@ -86,12 +55,2 @@ if (hasOwn(desc, descKey)) { | ||
} | ||
======= | ||
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; | ||
>>>>>>> .merge_file_5gBVbH | ||
} | ||
@@ -98,0 +57,0 @@ } |
{ | ||
"name": "is-accessor-descriptor", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
116
README.md
# is-accessor-descriptor <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
<<<<<<< .merge_file_oXHkzP | ||
[![github actions][actions-image]][actions-url] | ||
@@ -8,27 +7,5 @@ [![coverage][codecov-image]][codecov-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
======= | ||
> Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Examples](#examples) | ||
- [API](#api) | ||
- [Related projects](#related-projects) | ||
- [Running tests](#running-tests) | ||
- [Contributing](#contributing) | ||
- [Author](#author) | ||
- [License](#license) | ||
## Install | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm i is-accessor-descriptor --save | ||
``` | ||
>>>>>>> .merge_file_OTGJy6 | ||
[![npm badge][npm-badge-png]][package-url] | ||
<<<<<<< .merge_file_oXHkzP | ||
> Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. | ||
@@ -84,94 +61,1 @@ | ||
[actions-url]: https://github.com/inspect-js/is-accessor-descriptor/actions | ||
======= | ||
```js | ||
var isAccessor = require('is-accessor-descriptor'); | ||
var assert = require('assert'); | ||
assert.equal(isAccessor({ get() {} }), true); | ||
``` | ||
You may also pass an object and property name to check if the property is an accessor: | ||
```js | ||
assert.equal(isAccessor({ bar: 'foo' }, 'bar'), false); | ||
``` | ||
## Examples | ||
`false` when not an object | ||
```js | ||
assert.equal(isAccessor('a'), false); | ||
assert.equal(isAccessor(null), false); | ||
``` | ||
`true` when the object has valid properties | ||
and the properties all have the correct JavaScript types: | ||
```js | ||
assert.equal(isAccessor({ get() {}, set() {} }), true); | ||
assert.equal(isAccessor({ get() {} }), true); | ||
assert.equal(isAccessor({ set() {} }), true); | ||
``` | ||
`false` when the object has invalid properties | ||
```js | ||
assert.equal(isAccessor({ get() {}, set() {}, enumerable: 'baz' }), false); | ||
assert.equal(isAccessor({ get() {}, writable: true }), false); | ||
assert.equal(isAccessor({ get() {}, value: true }), false); | ||
//=> false | ||
``` | ||
`false` when an accessor is not a function | ||
```js | ||
assert.equal(isAccessor({ get() {}, set: 'baz' }), false); | ||
assert.equal(isAccessor({ get: 'foo', set() {} }), false); | ||
assert.equal(isAccessor({ get: 'foo', bar: 'baz' }), false); | ||
assert.equal(isAccessor({ get: 'foo', set: 'baz' }), false); | ||
//=> false | ||
``` | ||
`false` when a value is not the correct type | ||
```js | ||
assert.equal(isAccessor({ get() {}, set() {}, enumerable: 'foo' }), false); | ||
assert.equal(isAccessor({ set() {}, configurable: 'foo' }), false); | ||
assert.equal(isAccessor({ get() {}, configurable: 'foo' }), false); | ||
//=> false | ||
``` | ||
## Related projects | ||
* [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) | ||
* [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) | ||
* [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://www.npmjs.com/package/is-descriptor) | [homepage](https://github.com/jonschlinkert/is-descriptor) | ||
* [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) | ||
* [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) | ||
## Running tests | ||
Install dev dependencies: | ||
```sh | ||
$ npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-accessor-descriptor/issues/new). | ||
## Author | ||
**Jon Schlinkert** | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the MIT license. | ||
>>>>>>> .merge_file_OTGJy6 |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var hasPropertyDescriptors = require('has-property-descriptors')(); | ||
var gOPD = require('gopd'); | ||
var isAccessorDescriptor = require('../'); | ||
@@ -41,3 +42,3 @@ var noop = function () {}; | ||
st.ok(isAccessorDescriptor(obj, 'bar')); | ||
st.ok(isAccessorDescriptor(Object.getOwnPropertyDescriptor(obj, 'bar'))); | ||
st.ok(isAccessorDescriptor(gOPD(obj, 'bar'))); | ||
@@ -44,0 +45,0 @@ st.end(); |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
28528
163
60