is-data-descriptor
Advanced tools
Comparing version 1.0.0 to 2.0.0
64
index.js
@@ -1,49 +0,29 @@ | ||
/*! | ||
* is-data-descriptor <https://github.com/jonschlinkert/is-data-descriptor> | ||
* | ||
* Copyright (c) 2015-2017, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
'use strict'; | ||
var typeOf = require('kind-of'); | ||
const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key); | ||
const isObject = val => { | ||
return val !== null && typeof val === 'object' && !Array.isArray(val); | ||
}; | ||
module.exports = function isDataDescriptor(obj, prop) { | ||
// data descriptor properties | ||
var data = { | ||
configurable: 'boolean', | ||
enumerable: 'boolean', | ||
writable: 'boolean' | ||
}; | ||
if (typeOf(obj) !== 'object') { | ||
return false; | ||
} | ||
if (typeof prop === 'string') { | ||
var val = Object.getOwnPropertyDescriptor(obj, prop); | ||
return typeof val !== 'undefined'; | ||
} | ||
if (!('value' in obj) && !('writable' in obj)) { | ||
return false; | ||
} | ||
for (var key in obj) { | ||
if (key === 'value') continue; | ||
if (!data.hasOwnProperty(key)) { | ||
continue; | ||
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; | ||
} | ||
if (typeOf(obj[key]) === data[key]) { | ||
continue; | ||
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; | ||
} | ||
} | ||
if (typeof obj[key] !== 'undefined') { | ||
return false; | ||
} | ||
return true; | ||
} | ||
return true; | ||
return false; | ||
}; | ||
module.exports = isDescriptor; |
{ | ||
"name": "is-data-descriptor", | ||
"description": "Returns true if a value has the characteristics of a valid JavaScript data descriptor.", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/is-data-descriptor", | ||
@@ -21,3 +21,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=6" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
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
8707
26