@ganuz/define-property
v0.1.1
Published
Define Property is package from Ganuz library
Downloads
21
Maintainers
Readme
@ganuz/define-property
Define Property is package from Ganuz library
Install
$ yarn add @ganuz/define-property
Or
$ npm install --save @ganuz/define-property
Use
Module
import {
default as defineProperty
} from '@ganuz/define-property';
Browser
<script src="https://unpkg.com/@ganuz/define-property/bundle.umd.min.js"></script>
let {
defineProperty
} = G;
Examples
defineProperty(null, 'foo', {value: 'bar'}); // throw TypeError
defineProperty({}, 'foo', {value: 'bar', get: () => 'bar'}); // throw TypeError
defineProperty({}, 'foo', {value: 'bar'}); // => true
defineProperty(Object.freeze({}), 'foo', {value: 'bar'}); // => false
defineProperty(Object.freeze({car: true}), 'foo', {car: true, enumerable: true}); // => true
defineProperty(Object.create(null, {drink: {value: 'tea', writable: true}}), 'drink', {value: 'beer'}); // => true
defineProperty(Object.create({}, {name: {value: 'bob', writable: true}}), 'name', {value: 'alice', configurable: false}); // => true
defineProperty(Object.create(null, {color: {value: 'red'}}), 'color', {value: 'blue'}); // => false
defineProperty(Object.create({}, {foo: {value: 'bar'}}), 'foo', {configurable: false}); // => true
let object = {color: 'red', get foo (){ return 'bar'; }};
defineProperty(object, 'name', {value: 'bob'}); // => true
defineProperty(object, 'color', {value: 'yellow', writable: false}); // => true
defineProperty(object, 'foo', {value: 'bar', configurable: false}); // => true
Object.getOwnPropertyDescriptors(object);
// => {
// color: {value: 'yellow', configurable: true, enumerable: true, writable: false},
// foo: {value: 'bar', configurable: false, enumerable: true, writable: false},
// name: {value: 'bob', configurable: false, enumerable: false, writable: false}
// }
@ganuz/define-property/polyfill
Module
import '@ganuz/define-property/polyfill';
Browser
<script src="https://unpkg.com/@ganuz/define-property/polyfill/bundle.umd.min.js"></script>
License
Copyright © Yisrael Eliev, Licensed under the MIT license.