htc 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
..
.github 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
test 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
.editorconfig 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
.eslintrc 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
.nycrc 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
CHANGELOG.md 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
LICENSE 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
README.md 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
index.js 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ
package.json 7ca38fdcbb 善行少年PC端首次提交(基础版) 10 mēneši atpakaļ

README.md

is-accessor-descriptor Version Badge

github actions coverage License Downloads

npm badge

Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.

Examples

var isAccessor = require('is-accessor-descriptor');
var assert = require('assert');

assert.equal(isAccessor({ get: function() {} }), true);

You may also pass an object and property name to check if the property is an accessor:

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

Examples

false when not an object

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:

assert.equal(isAccessor({ get() {}, set() {} }), true);
assert.equal(isAccessor({ get() {} }), true);
assert.equal(isAccessor({ set() {} }), true);

false when the object has invalid properties

assert.equal(isAccessor({ get() {}, set() {}, enumerable: 'baz' }), false);
assert.equal(isAccessor({ get() {}, writable: true }), false);
assert.equal(isAccessor({ get() {}, value: true }), false);

false when an accessor is not a function

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

false when a value is not the correct type

isAccessor({ get() {}, set() {}, enumerable: 'foo' });
isAccessor({ set() {}, configurable: 'foo' });
isAccessor({ get() {}, configurable: 'foo' });
//=> false

Related projects

You might also be interested in these projects:

  • is-data-descriptor: Returns true if a value has the characteristics of a valid JavaScript data descriptor.
  • is-descriptor: Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… more
  • is-object: Returns true if the value is an object and not an array or null.

Tests

Simply clone the repo, npm install, and run npm test