Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
190 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb/eslint-config/node/6", | ||
|
||
"overrides": [ | ||
{ | ||
"files": "test/**/*.js", | ||
"env": { | ||
"mocha": true, | ||
}, | ||
"rules": { | ||
"max-lines-per-function": "warn", | ||
"max-nested-callbacks": "warn", | ||
}, | ||
}, | ||
], | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
'use strict'; | ||
|
||
const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key); | ||
const isObject = val => { | ||
return val !== null && typeof val === 'object' && !Array.isArray(val); | ||
}; | ||
const isObject = (val) => 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; | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
const desc = key ? Object.getOwnPropertyDescriptor(obj, key) : obj; | ||
if (isObject(desc)) { | ||
const booleans = [ | ||
'configurable', 'enumerable', 'writable', | ||
]; | ||
if (!hasOwn(desc, 'value') || hasOwn(desc, 'get') || hasOwn(desc, 'set')) { | ||
return false; | ||
} | ||
for (const descKey of Object.keys(desc)) { | ||
if (booleans.includes(descKey) && typeof desc[descKey] !== 'boolean') { | ||
return false; | ||
} | ||
if (!booleans.includes(descKey) && descKey !== 'value') { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
module.exports = isDescriptor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,73 @@ | ||
{ | ||
"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" | ||
}, | ||
"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", | ||
"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": { | ||
"lint": "eslint --ext=js,mjs .", | ||
"pretest": "npm run lint", | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.1", | ||
"eslint": "=8.8.0", | ||
"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 | ||
} | ||
} | ||
} |
Oops, something went wrong.