[Pkg-javascript-commits] [node-is-accessor-descriptor] 01/05: New upstream version 2.0.0
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Thu Jan 11 16:55:12 UTC 2018
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-is-accessor-descriptor.
commit ada0df15156f9ba544a1e869afd7c4fce2f1773f
Author: Pirate Praveen <praveen at debian.org>
Date: Thu Jan 11 22:08:13 2018 +0530
New upstream version 2.0.0
---
.editorconfig | 18 ++---
.eslintrc.json | 233 +++++++++------------------------------------------------
.gitignore | 30 ++++++--
.travis.yml | 20 +++--
.verb.md | 69 +++--------------
LICENSE | 2 +-
README.md | 128 +++++++++++++------------------
index.js | 72 +++++++++---------
package.json | 28 +++++--
test.js | 157 ++++++++++++++++++++++++++------------
10 files changed, 308 insertions(+), 449 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 991900b..449f0da 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,22 +1,14 @@
-# http://editorconfig.org
+# http://editorconfig.org/
root = true
[*]
-indent_style = space
-end_of_line = lf
charset = utf-8
+end_of_line = lf
indent_size = 2
-trim_trailing_whitespace = true
+indent_style = space
insert_final_newline = true
+trim_trailing_whitespace = true
-[*.md]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[test/**]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[templates/**]
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
index cc6a867..61e8895 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,100 +1,36 @@
{
- "ecmaFeatures": {
- "modules": true,
- "experimentalObjectRestSpread": true
- },
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
+
"globals": {
"document": false,
"navigator": false,
"window": false
},
+
"rules": {
"accessor-pairs": 2,
- "arrow-spacing": [
- 2,
- {
- "before": true,
- "after": true
- }
- ],
- "block-spacing": [
- 2,
- "always"
- ],
- "brace-style": [
- 2,
- "1tbs",
- {
- "allowSingleLine": true
- }
- ],
- "comma-dangle": [
- 2,
- "never"
- ],
- "comma-spacing": [
- 2,
- {
- "before": false,
- "after": true
- }
- ],
- "comma-style": [
- 2,
- "last"
- ],
+ "arrow-spacing": [2, { "before": true, "after": true }],
+ "block-spacing": [2, "always"],
+ "brace-style": [2, "1tbs", { "allowSingleLine": true }],
+ "comma-dangle": [2, "never"],
+ "comma-spacing": [2, { "before": false, "after": true }],
+ "comma-style": [2, "last"],
"constructor-super": 2,
- "curly": [
- 2,
- "multi-line"
- ],
- "dot-location": [
- 2,
- "property"
- ],
+ "curly": [2, "multi-line"],
+ "dot-location": [2, "property"],
"eol-last": 2,
- "eqeqeq": [
- 2,
- "allow-null"
- ],
- "generator-star-spacing": [
- 2,
- {
- "before": true,
- "after": true
- }
- ],
- "handle-callback-err": [
- 2,
- "^(err|error)$"
- ],
- "indent": [
- 2,
- 2,
- {
- "SwitchCase": 1
- }
- ],
- "key-spacing": [
- 2,
- {
- "beforeColon": false,
- "afterColon": true
- }
- ],
- "new-cap": [
- 2,
- {
- "newIsCap": true,
- "capIsNew": false
- }
- ],
+ "eqeqeq": [2, "allow-null"],
+ "generator-star-spacing": [2, { "before": true, "after": true }],
+ "handle-callback-err": [2, "^(err|error)$" ],
+ "indent": [2, 2, { "SwitchCase": 1 }],
+ "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
+ "keyword-spacing": [2, { "before": true, "after": true }],
+ "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
@@ -109,24 +45,17 @@
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
- "no-empty-label": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
- "no-extra-parens": [
- 2,
- "functions"
- ],
+ "no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
- "no-inner-declarations": [
- 2,
- "functions"
- ],
+ "no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
@@ -136,13 +65,8 @@
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
- "no-multiple-empty-lines": [
- 2,
- {
- "max": 1
- }
- ],
- "no-native-reassign": 2,
+ "no-multiple-empty-lines": [2, { "max": 1 }],
+ "no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
@@ -167,112 +91,27 @@
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
- "no-unneeded-ternary": [
- 2,
- {
- "defaultAssignment": false
- }
- ],
+ "no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
- "no-unused-vars": [
- 2,
- {
- "vars": "all",
- "args": "none"
- }
- ],
+ "no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-with": 2,
- "one-var": [
- 0,
- {
- "initialized": "never"
- }
- ],
- "operator-linebreak": [
- 0,
- "after",
- {
- "overrides": {
- "?": "before",
- ":": "before"
- }
- }
- ],
- "padded-blocks": [
- 0,
- "never"
- ],
- "quotes": [
- 2,
- "single",
- "avoid-escape"
- ],
+ "one-var": [0, { "initialized": "never" }],
+ "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
+ "padded-blocks": [0, "never"],
+ "quotes": [2, "single", "avoid-escape"],
"radix": 2,
- "semi": [
- 2,
- "always"
- ],
- "semi-spacing": [
- 2,
- {
- "before": false,
- "after": true
- }
- ],
- "space-after-keywords": [
- 2,
- "always"
- ],
- "space-before-blocks": [
- 2,
- "always"
- ],
- "space-before-function-paren": [
- 2,
- "never"
- ],
- "space-before-keywords": [
- 2,
- "always"
- ],
- "space-in-parens": [
- 2,
- "never"
- ],
+ "semi": [2, "always"],
+ "semi-spacing": [2, { "before": false, "after": true }],
+ "space-before-blocks": [2, "always"],
+ "space-before-function-paren": [2, "never"],
+ "space-in-parens": [2, "never"],
"space-infix-ops": 2,
- "space-return-throw-case": 2,
- "space-unary-ops": [
- 2,
- {
- "words": true,
- "nonwords": false
- }
- ],
- "spaced-comment": [
- 0,
- "always",
- {
- "markers": [
- "global",
- "globals",
- "eslint",
- "eslint-disable",
- "*package",
- "!",
- ","
- ]
- }
- ],
+ "space-unary-ops": [2, { "words": true, "nonwords": false }],
+ "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
- "wrap-iife": [
- 2,
- "any"
- ],
- "yoda": [
- 2,
- "never"
- ]
+ "wrap-iife": [2, "any"],
+ "yoda": [2, "never"]
}
}
diff --git a/.gitignore b/.gitignore
index 80a228c..4bf0a60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,29 @@
+# always ignore files
*.DS_Store
+.idea
*.sublime-*
-_gh_pages
-bower_components
+
+# test related, or directories generated by tests
+test/actual
+actual
+coverage
+.nyc*
+
+# npm
node_modules
npm-debug.log
-actual
-test/actual
+
+# yarn
+yarn.lock
+yarn-error.log
+
+# misc
+_gh_pages
+_draft
+_drafts
+bower_components
+vendor
temp
tmp
TODO.md
-vendor
-.idea
-benchmark
-coverage
+package-lock.json
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 6caa76a..1686664 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,15 @@
sudo: false
+os:
+ - linux
+ - osx
language: node_js
node_js:
- - "stable"
- - "4"
- - "0.12"
- - "0.10"
-matrix:
- fast_finish: true
- allow_failures:
- - node_js: "0.10"
+ - node
+ - '9'
+ - '8'
+ - '7'
+ - '6'
+ - '5'
+ - '4'
+ - '0.12'
+ - '0.10'
diff --git a/.verb.md b/.verb.md
index 79316d0..1aa02d2 100644
--- a/.verb.md
+++ b/.verb.md
@@ -1,64 +1,19 @@
## Usage
```js
-var isAccessor = require('{%= name %}');
+const isAccessor = require('{%= name %}');
+const obj = {
+ get foo() {},
+ bar: {get: function() {}}
+};
-isAccessor({get: function() {}});
-//=> true
-```
-
-You may also pass an object and property name to check if the property is an accessor:
-
-```js
-isAccessor(foo, 'bar');
-```
-
-## Examples
-
-`false` when not an object
-
-```js
-isAccessor('a')
-isAccessor(null)
-isAccessor([])
-//=> false
-```
-
-`true` when the object has valid properties
-
-and the properties all have the correct JavaScript types:
+isAccessor(obj, 'foo'); //=> true
+isAccessor(obj, 'bar'); //=> false
-```js
-isAccessor({get: noop, set: noop})
-isAccessor({get: noop})
-isAccessor({set: noop})
-//=> true
-```
-
-`false` when the object has invalid properties
-
-```js
-isAccessor({get: noop, set: noop, bar: 'baz'})
-isAccessor({get: noop, writable: true})
-isAccessor({get: noop, value: true})
-//=> false
-```
+// or, if you already have the descriptor you can pass it directly
+const foo = Object.getOwnPropertyDescriptor(obj, 'foo');
+isAccessor(foo); //=> true
-`false` when an accessor is not a function
-
-```js
-isAccessor({get: noop, set: 'baz'})
-isAccessor({get: 'foo', set: noop})
-isAccessor({get: 'foo', bar: 'baz'})
-isAccessor({get: 'foo', set: 'baz'})
-//=> false
-```
-
-`false` when a value is not the correct type
-
-```js
-isAccessor({get: noop, set: noop, enumerable: 'foo'})
-isAccessor({set: noop, configurable: 'foo'})
-isAccessor({get: noop, configurable: 'foo'})
-//=> false
+const bar = Object.getOwnPropertyDescriptor(obj, 'bar');
+isAccessor(bar); //=> false
```
diff --git a/LICENSE b/LICENSE
index 65f90ac..e33d14b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2015, Jon Schlinkert.
+Copyright (c) 2015-2017, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 3743fe6..13edb28 100644
--- a/README.md
+++ b/README.md
@@ -1,123 +1,99 @@
-# is-accessor-descriptor [![NPM version](https://img.shields.io/npm/v/is-accessor-descriptor.svg)](https://www.npmjs.com/package/is-accessor-descriptor) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-accessor-descriptor.svg)](https://travis-ci.org/jonschlinkert/is-accessor-descriptor)
+# 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.shi [...]
> 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)
-
-_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
+Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
-$ npm i is-accessor-descriptor --save
+$ npm install --save is-accessor-descriptor
```
## Usage
```js
-var isAccessor = require('is-accessor-descriptor');
+const isAccessor = require('is-accessor-descriptor');
+const obj = {
+ get foo() {},
+ bar: {get: function() {}}
+};
-isAccessor({get: function() {}});
-//=> true
-```
+isAccessor(obj, 'foo'); //=> true
+isAccessor(obj, 'bar'); //=> false
-You may also pass an object and property name to check if the property is an accessor:
+// or, if you already have the descriptor you can pass it directly
+const foo = Object.getOwnPropertyDescriptor(obj, 'foo');
+isAccessor(foo); //=> true
-```js
-isAccessor(foo, 'bar');
+const bar = Object.getOwnPropertyDescriptor(obj, 'bar');
+isAccessor(bar); //=> false
```
-## Examples
+## About
-`false` when not an object
+<details>
+<summary><strong>Contributing</strong></summary>
-```js
-isAccessor('a')
-isAccessor(null)
-isAccessor([])
-//=> false
-```
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
-`true` when the object has valid properties
+</details>
-and the properties all have the correct JavaScript types:
+<details>
+<summary><strong>Running Tests</strong></summary>
-```js
-isAccessor({get: noop, set: noop})
-isAccessor({get: noop})
-isAccessor({set: noop})
-//=> true
-```
+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:
-`false` when the object has invalid properties
-
-```js
-isAccessor({get: noop, set: noop, bar: 'baz'})
-isAccessor({get: noop, writable: true})
-isAccessor({get: noop, value: true})
-//=> false
+```sh
+$ npm install && npm test
```
-`false` when an accessor is not a function
+</details>
+<details>
+<summary><strong>Building docs</strong></summary>
-```js
-isAccessor({get: noop, set: 'baz'})
-isAccessor({get: 'foo', set: noop})
-isAccessor({get: 'foo', bar: 'baz'})
-isAccessor({get: 'foo', set: 'baz'})
-//=> false
-```
+_(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.)_
-`false` when a value is not the correct type
+To generate the readme, run the following command:
-```js
-isAccessor({get: noop, set: noop, enumerable: 'foo'})
-isAccessor({set: noop, configurable: 'foo'})
-isAccessor({get: noop, configurable: 'foo'})
-//=> false
+```sh
+$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
-## 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)
-* [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)
+</details>
-## Running tests
+### Related projects
-Install dev dependencies:
+You might also be interested in these projects:
-```sh
-$ npm i -d && npm test
-```
+* [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.")
-## Contributing
+### Contributors
-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).
+| **Commits** | **Contributor** |
+| --- | --- |
+| 26 | [jonschlinkert](https://github.com/jonschlinkert) |
+| 2 | [realityking](https://github.com/realityking) |
-## Author
+### Author
**Jon Schlinkert**
+* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert)
-* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
-## License
+### License
-Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
-Released under the MIT license.
+Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT License](LICENSE).
***
-_This file was generated by [verb](https://github.com/verbose/verb) on December 28, 2015._
\ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 04, 2017._
\ No newline at end of file
diff --git a/index.js b/index.js
index 2ca4af8..5cd3b09 100644
--- a/index.js
+++ b/index.js
@@ -1,65 +1,67 @@
/*!
* is-accessor-descriptor <https://github.com/jonschlinkert/is-accessor-descriptor>
*
- * Copyright (c) 2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2015-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
var typeOf = require('kind-of');
-// accessor descriptor properties
-var accessor = {
- get: 'function',
- set: 'function',
- configurable: 'boolean',
- enumerable: 'boolean'
-};
-
-function isAccessorDescriptor(obj, prop) {
+function isAccessorDescriptor(obj, prop, checkProto) {
+ if (typeof prop === 'boolean') {
+ checkProto = prop;
+ prop = null;
+ }
if (typeof prop === 'string') {
- var val = Object.getOwnPropertyDescriptor(obj, prop);
- return typeof val !== 'undefined';
+ return isGetterSetter(obj, prop, checkProto);
}
+ return looksLikeGetterSetter(obj);
+}
- if (typeOf(obj) !== 'object') {
- return false;
+function isGetterSetter(obj, key, checkProto) {
+ const descriptor = Object.getOwnPropertyDescriptor(obj, key);
+ if (descriptor) {
+ return looksLikeGetterSetter(descriptor);
}
-
- if (has(obj, 'value') || has(obj, 'writable')) {
- return false;
+ if (checkProto !== false && obj.constructor && obj.constructor.prototype) {
+ return isGetterSetter(obj.constructor.prototype, key, false);
}
+ return false;
+}
- if (!has(obj, 'get') || typeof obj.get !== 'function') {
+function looksLikeGetterSetter(descriptor) {
+ if (typeOf(descriptor) !== 'object') {
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;
- }
+ const keys = Object.keys(descriptor);
+ const len = keys.length;
- for (var key in obj) {
- if (!accessor.hasOwnProperty(key)) {
- continue;
- }
+ const validKeys = {
+ get: 'function',
+ set: 'function',
+ enumerable: 'boolean',
+ configurable: 'boolean'
+ };
- if (typeOf(obj[key]) === accessor[key]) {
- continue;
+ if (len !== 4) return false;
+ for (let i = 0; i < len; i++) {
+ const key = keys[i];
+ if (!validKeys.hasOwnProperty(key)) {
+ return false;
}
-
- if (typeof obj[key] !== 'undefined') {
+ const val = descriptor[key];
+ if (val != null && typeOf(val) !== validKeys[key]) {
return false;
}
}
return true;
}
-function has(obj, key) {
- return {}.hasOwnProperty.call(obj, key);
+function isValidType(obj, key) {
+ return typeof obj[key] === 'function' || typeof obj[key] === 'undefined';
}
/**
diff --git a/package.json b/package.json
index 0f39c64..45a249e 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,13 @@
{
"name": "is-accessor-descriptor",
"description": "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.",
- "version": "0.1.6",
+ "version": "2.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"
@@ -20,11 +24,11 @@
"test": "mocha"
},
"dependencies": {
- "kind-of": "^3.0.2"
+ "kind-of": "^6.0.0"
},
"devDependencies": {
- "mocha": "*",
- "should": "*"
+ "gulp-format-md": "^1.0.0",
+ "mocha": "^3.5.3"
},
"keywords": [
"accessor",
@@ -45,17 +49,25 @@
"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"
]
},
- "plugins": [
- "gulp-format-md"
- ],
- "layout": "default"
+ "lint": {
+ "reflinks": true
+ }
}
}
diff --git a/test.js b/test.js
index 70a9238..1516cbf 100644
--- a/test.js
+++ b/test.js
@@ -2,51 +2,116 @@
require('mocha');
var assert = require('assert');
-var should = require('should');
-var isDescriptor = require('./');
-var noop = function(){};
-
-describe('isDescriptor', function () {
- describe('value type', function () {
- it('should be false when not an object:', function () {
- assert(!isDescriptor('a'));
- assert(!isDescriptor(null));
- assert(!isDescriptor([]));
- });
- });
-
- describe('accessor descriptor:', function () {
- it('should be false when the object has data descriptor properties:', function () {
- assert(!isDescriptor({get: noop, writable: true}));
- assert(!isDescriptor({get: noop, value: true}));
- });
-
- it('should not be false when unrecognized properties are defined:', function () {
- assert(isDescriptor({get: noop, foo: true}));
- assert(isDescriptor({get: noop, bar: true}));
- });
-
- it('should be false when a get or set are not functions:', function () {
- assert(!isDescriptor({get: noop, set: 'baz'}));
- assert(!isDescriptor({get: 'foo', set: noop}));
- assert(!isDescriptor({get: 'foo', bar: 'baz'}));
- assert(!isDescriptor({get: 'foo', set: 'baz'}));
- assert(!isDescriptor({get: 'foo'}));
- });
-
- it('should be false when "get" is not defined:', function () {
- assert(!isDescriptor({set: noop}));
- });
-
- it('should be true when the object has valid properties:', function () {
- assert(isDescriptor({get: noop, set: noop}));
- assert(isDescriptor({get: noop}));
- });
-
- it('should be false when a value is not the correct type:', function () {
- assert(!isDescriptor({get: noop, set: noop, enumerable: 'foo'}));
- assert(!isDescriptor({set: noop, configurable: 'foo'}));
- assert(!isDescriptor({get: noop, configurable: 'foo'}));
- });
+var isAccessor = require('./');
+var noop = function() {};
+
+describe('isAccessor', function() {
+ it('should be false when not an object', function() {
+ assert(!isAccessor('a'));
+ assert(!isAccessor(null));
+ assert(!isAccessor([]));
+ });
+
+ it('should be false when the property has data descriptor properties', function() {
+ var obj = {
+ foo: {
+ writable: true,
+ enumerable: true,
+ configurable: true,
+ get: noop,
+ set: noop
+ }
+ };
+ assert(!isAccessor(obj, 'foo'));
+ });
+
+ it('should be true when the property is a valid getter/setter', function() {
+ const obj = {get foo() {}};
+ assert(isAccessor(obj, 'foo'));
+ assert(isAccessor(Object.getOwnPropertyDescriptor(obj, 'foo')));
+ });
+
+ it('should check ctor.prototype', function() {
+ class Foo {
+ get bar() {
+ return 'baz';
+ }
+ }
+ var obj = new Foo();
+ assert(isAccessor(obj, 'bar'));
+ });
+
+ it('should not check ctor.prototype when disabled', function() {
+ class Foo {
+ get bar() {
+ return 'baz';
+ }
+ }
+ var obj = new Foo();
+ assert(!isAccessor(obj, 'bar', false));
+ });
+
+ it('should be false when get or set are not functions', function() {
+ assert(!isAccessor({
+ configurable: true,
+ enumerable: true,
+ set: 'baz',
+ get: noop
+ }));
+
+ assert(!isAccessor({
+ configurable: true,
+ enumerable: true,
+ set: noop,
+ get: 'foo'
+ }));
+
+ assert(!isAccessor({
+ configurable: true,
+ enumerable: true,
+ bar: 'baz',
+ get: 'foo'
+ }));
+
+ assert(!isAccessor({
+ configurable: true,
+ enumerable: true,
+ set: 'baz',
+ get: 'foo'
+ }));
+
+ assert(!isAccessor({
+ get: 'foo',
+ enumerable: true,
+ configurable: true
+ }));
+ });
+
+ it('should be false when the object lacks necessary properties', function() {
+ assert(!isAccessor({ set: noop }));
+ assert(!isAccessor({ get: noop, set: noop }));
+ assert(!isAccessor({ get: noop }));
+ });
+
+ it('should be false when invalid properties are defined', function() {
+ assert(!isAccessor({
+ enumerable: true,
+ configurable: true,
+ get: noop,
+ foo: true
+ }));
+
+ assert(!isAccessor({
+ enumerable: true,
+ configurable: true,
+ get: noop,
+ bar: true,
+ }));
+ });
+
+ it('should be false when a value is not the correct type', function() {
+ assert(!isAccessor({ get: noop, set: noop, enumerable: 'foo' }));
+ assert(!isAccessor({ set: noop, configurable: 'foo' }));
+ assert(!isAccessor({ get: noop, configurable: 'foo' }));
});
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-is-accessor-descriptor.git
More information about the Pkg-javascript-commits
mailing list