Socket
Socket
Sign inDemoInstall

is-data-descriptor

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-data-descriptor - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

.editorconfig

60

index.js
'use strict';
const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
const isObject = val => {
return val !== null && typeof val === 'object' && !Array.isArray(val);
var hasOwn = function (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
};
var isObject = function (val) {
return val !== null && typeof val === 'object' && !Array.isArray(val);
};
const isDescriptor = (obj, key) => {
if (!isObject(obj)) return false;
let desc = key ? Object.getOwnPropertyDescriptor(obj, key) : obj;
if (isObject(desc)) {
let booleans = ['configurable', 'enumerable', 'writable'];
if (!hasOwn(desc, 'value') || hasOwn(desc, 'get') || hasOwn(desc, 'set')) {
return false;
}
for (let key of Object.keys(desc)) {
if (booleans.includes(key) && typeof desc[key] !== 'boolean') {
return false;
}
if (!booleans.includes(key) && key !== 'value') {
return false;
}
}
return true;
}
return false;
module.exports = function isDataDescriptor(obj, key) {
if (!isObject(obj)) {
return false;
}
var desc = key ? Object.getOwnPropertyDescriptor(obj, key) : obj;
if (isObject(desc)) {
if (
!hasOwn(desc, 'value')
|| hasOwn(desc, 'get')
|| hasOwn(desc, 'set')
|| (hasOwn(desc, 'configurable') && typeof desc.configurable !== 'boolean')
|| (hasOwn(desc, 'enumerable') && typeof desc.enumerable !== 'boolean')
|| (hasOwn(desc, 'writable') && typeof desc.writable !== 'boolean')
) {
return false;
}
for (var descKey in desc) { // eslint-disable-line no-restricted-syntax
if (
hasOwn(desc, descKey)
&& descKey !== 'configurable'
&& descKey !== 'enumerable'
&& descKey !== 'writable'
&& descKey !== 'value'
) {
return false;
}
}
return true;
}
return false;
};
module.exports = isDescriptor;

152

package.json
{
"name": "is-data-descriptor",
"description": "Returns true if a value has the characteristics of a valid JavaScript data descriptor.",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/is-data-descriptor",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"repository": "jonschlinkert/is-data-descriptor",
"bugs": {
"url": "https://github.com/jonschlinkert/is-data-descriptor/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=6"
},
"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",
"isobject"
]
},
"lint": {
"reflinks": true
}
}
"name": "is-data-descriptor",
"version": "2.1.0",
"description": "Returns true if a value has the characteristics of a valid JavaScript data descriptor.",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"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",
"prelint": "evalmd README.md",
"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-data-descriptor.git"
},
"keywords": [
"accessor",
"check",
"data",
"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-data-descriptor/issues"
},
"homepage": "https://github.com/inspect-js/is-data-descriptor",
"contributors": [
"Jordan Harband (https://github.com/ljharb)",
"Jon Schlinkert (https://twitter.com/jonschlinkert)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"devDependencies": {
"@ljharb/eslint-config": "^21.0.1",
"aud": "^2.0.2",
"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.6.3"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}

@@ -1,19 +0,15 @@

# is-data-descriptor [![NPM version](https://img.shields.io/npm/v/is-data-descriptor.svg?style=flat)](https://www.npmjs.com/package/is-data-descriptor) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-data-descriptor.svg?style=flat)](https://npmjs.org/package/is-data-descriptor) [![NPM total downloads](https://img.shields.io/npm/dt/is-data-descriptor.svg?style=flat)](https://npmjs.org/package/is-data-descriptor) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-data-descriptor.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-data-descriptor)
# is-data-descriptor <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
> Returns true if a value has the characteristics of a valid JavaScript data 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 data descriptor.
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save is-data-descriptor
```
## Usage
```js
var isDataDesc = require('is-data-descriptor');
```

@@ -24,46 +20,26 @@

`true` when the descriptor has valid properties with valid values.
`false` when not an object or when the object has invalid properties.
```js
// `value` can be anything
isDataDesc({value: 'foo'})
isDataDesc({value: function() {}})
isDataDesc({value: true})
//=> true
```
var isDataDesc = require('is-data-descriptor');
var assert = require('assert');
`false` when not an object
assert.equal(true, isDataDesc({ value: 'foo' }));
assert.equal(true, isDataDesc({ value: function () {} }));
assert.equal(true, isDataDesc({ value: true }));
```js
isDataDesc('a')
//=> false
isDataDesc(null)
//=> false
isDataDesc([])
//=> false
```
assert.equal(false, isDataDesc('a'));
assert.equal(false, isDataDesc(null));
assert.equal(false, isDataDesc([]));
`false` when the object has invalid properties
```js
isDataDesc({value: 'foo', bar: 'baz'})
//=> false
isDataDesc({value: 'foo', bar: 'baz'})
//=> false
isDataDesc({value: 'foo', get: function(){}})
//=> false
isDataDesc({get: function(){}, value: 'foo'})
//=> false
assert.equal(false, isDataDesc({ value: 'foo', bar: 'baz' }));
assert.equal(false, isDataDesc({ value: 'foo', bar: 'baz' }));
assert.equal(false, isDataDesc({ value: 'foo', get: function () {} }));
assert.equal(false, isDataDesc({ get: function () {}, value: 'foo' }) );
assert.equal(false, isDataDesc({ value: 'foo', enumerable: 'foo' }));
assert.equal(false, isDataDesc({ value: 'foo', configurable: 'foo' }));
assert.equal(false, isDataDesc({ value: 'foo', writable: 'foo' }));
```
`false` when a value is not the correct type
```js
isDataDesc({value: 'foo', enumerable: 'foo'})
//=> false
isDataDesc({value: 'foo', configurable: 'foo'})
//=> false
isDataDesc({value: 'foo', writable: 'foo'})
//=> false
```
## Valid properties

@@ -88,7 +64,7 @@

Object.defineProperty(foo, 'bar', {
enumerable: true,
whatever: 'blah', // invalid, but doesn't cause an error
get: function() {
return 'baz';
}
enumerable: true,
whatever: 'blah', // invalid, but doesn't cause an error
get: function() {
return 'baz';
}
});

@@ -100,35 +76,2 @@

## 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

@@ -138,28 +81,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.")
* [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-accessor-descriptor](https://www.npmjs.com/package/is-accessor-descriptor): Returns true if a value has the characteristics of a valid JavaScript accessor 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)
* [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** |
| --- | --- |
| 21 | [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-data-descriptor
[npm-version-svg]: https://versionbadg.es/inspect-js/is-data-descriptor.svg
[deps-svg]: https://david-dm.org/inspect-js/is-data-descriptor.svg
[deps-url]: https://david-dm.org/inspect-js/is-data-descriptor
[dev-deps-svg]: https://david-dm.org/inspect-js/is-data-descriptor/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/is-data-descriptor#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/is-data-descriptor.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/is-data-descriptor.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/is-data-descriptor.svg
[downloads-url]: https://npm-stat.com/charts.html?package=is-data-descriptor
[codecov-image]: https://codecov.io/gh/inspect-js/is-data-descriptor/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-data-descriptor/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-data-descriptor
[actions-url]: https://github.com/inspect-js/is-data-descriptor/actions
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc