0.1.1 • Published 6 years ago
@ganuz/set v0.1.1
@ganuz/set
Set is package from Ganuz library
Install
$ yarn add @ganuz/set
Or
$ npm install --save @ganuz/set
Use
Module
import {
default as set
} from '@ganuz/set';
Browser
<script src="https://unpkg.com/@ganuz/set/bundle.umd.min.js"></script>
let {
set
} = G;
Examples
set(null, 'foo', 'bar'); // throw TypeError
set({}, 'foo', 'bar'); // => true
set({color: 'blue'}, 'color', 'green'); // => true
set(v => v, Symbol('foo'), 'bar'); // => true
set({}, 'foo', 'bar', {}); // => true
set(Object.freeze({}), 'foo', 'bar', {}); // => true
set(Object.freeze({foo: 'bar'}), 'foo', 'bar'); // => false
set({}, 'foo', 'bob', {get(){}, set(v){}}); // => false
set({}, 'foo', 'bar', 69); // => false
set({get foo(){}}, 'foo', 'bar'); // => false
set({get foo(){}}, 'foo', 'bar', {}); // => false
set(Object.preventExtensions({}), 'foo', 'bar'); // => false
set(Object.preventExtensions({}), 'foo', 'bar', {}); // => false
set(Object.create(null, {foo: {value: 'bar'}}), 'foo', 'bob'); // => false
set(Object.create(null, {foo: {value: 'bar'}}), 'foo', 'bob', {}); // => false
set(Object.create(Object.create(null, {foo: {value: 'bar'}})), 'foo', 'bob'); // => false
set(Object.freeze({}), 'foo', 'bar', {}); // => true
set({}, 'foo', 'bob', Object.create(null, {foo: {value: 'bar'}})); // => false
let object = {
set name(name){ this._name = name; },
_name: 'bob'
};
let other = {_name: 'alice'};
set(object, 'name', 'john', other); // => true
console.log(object._name); // => 'bob'
console.log(other._name); // => 'john'
let object = {
set color(color){ this._color = color; },
_color: 'blue'
};
let other = Object.freeze({_color: 'red'});
set(object, 'color', 'green', other); // => true (in 'use strict' mode it will throw TypeError)
console.log(object._color); // => 'blue'
console.log(other._color); // => 'red'
let object = {num: 69}
let anther = {
get num(){
return this._num;
},
set num(num){
this._num = num;
},
_num: -1
}
set(object, 'num', 77, anther); // => false
console.log(object.num); // => 69
console.log(other.num); // => -1
@ganuz/set/polyfill
Module
import '@ganuz/set/polyfill';
Browser
<script src="https://unpkg.com/@ganuz/set/polyfill/bundle.umd.min.js"></script>
License
Copyright © Yisrael Eliev, Licensed under the MIT license.