@ganuz/is-property-descriptor
v0.1.1
Published
Is Property Descriptor is package from Ganuz library
Downloads
21
Maintainers
Readme
@ganuz/is-property-descriptor
Is Property Descriptor is package from Ganuz library
Install
$ yarn add @ganuz/is-property-descriptor
Or
$ npm install --save @ganuz/is-property-descriptor
Use
Module
import {
default as isPropertyDescriptor
} from '@ganuz/is-property-descriptor';
Browser
<script src="https://unpkg.com/@ganuz/is-property-descriptor/bundle.umd.min.js"></script>
let {
isPropertyDescriptor
} = G;
Examples
isPropertyDescriptor(); // => false
isPropertyDescriptor('foo'); // => false
isPropertyDescriptor({}); // => true
isPropertyDescriptor({color: 'red'}); // => true
isPropertyDescriptor(class {}); // => true
isPropertyDescriptor({value: undefined, foo: 'bar'}); // => true
isPropertyDescriptor({get: undefined}); // => true
isPropertyDescriptor({set: Object, enumerable: [0, 1, 2]}); // => true
isPropertyDescriptor({get(){}, value: 55}); // => false
isPropertyDescriptor({get: 'foo'}); // => false
isPropertyDescriptor({get(){}, set: NaN}); // => false
isPropertyDescriptor({get(){}, writable: undefined}); // => false
isPropertyDescriptor({set(){}, value: undefined}); // => false
Note: To check the kind of the descriptor use {@link isDataDescriptor} or {@link isAccessorDescriptor}
@ganuz/is-property-descriptor/assert
Module
import {
default as assertPropertyDescriptor
} from '@ganuz/is-property-descriptor/assert';
Browser
<script src="https://unpkg.com/@ganuz/is-property-descriptor/assert/bundle.umd.min.js"></script>
let {
assertPropertyDescriptor
} = G;
Examples
assertPropertyDescriptor(null); // throw TypeError
assertPropertyDescriptor(false); // throw TypeError
assertPropertyDescriptor({set: []}); // throw TypeError
assertPropertyDescriptor({get() {}, writable: false}); // throw TypeError
assertPropertyDescriptor({set: undefined, value: 'foo'}); // throw TypeError
assertPropertyDescriptor({}); // => {}
assertPropertyDescriptor({get: undefined}); // => {get: undefined}
assertPropertyDescriptor({enumerable: true}); // => {enumerable: true}
assertPropertyDescriptor({value: NaN}); // => {value: NaN}
License
Copyright © Yisrael Eliev, Licensed under the MIT license.