source: imaps-frontend/node_modules/define-properties/index.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[d565449]1'use strict';
2
3var keys = require('object-keys');
4var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
5
6var toStr = Object.prototype.toString;
7var concat = Array.prototype.concat;
8var defineDataProperty = require('define-data-property');
9
10var isFunction = function (fn) {
11 return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
12};
13
14var supportsDescriptors = require('has-property-descriptors')();
15
16var defineProperty = function (object, name, value, predicate) {
17 if (name in object) {
18 if (predicate === true) {
19 if (object[name] === value) {
20 return;
21 }
22 } else if (!isFunction(predicate) || !predicate()) {
23 return;
24 }
25 }
26
27 if (supportsDescriptors) {
28 defineDataProperty(object, name, value, true);
29 } else {
30 defineDataProperty(object, name, value);
31 }
32};
33
34var defineProperties = function (object, map) {
35 var predicates = arguments.length > 2 ? arguments[2] : {};
36 var props = keys(map);
37 if (hasSymbols) {
38 props = concat.call(props, Object.getOwnPropertySymbols(map));
39 }
40 for (var i = 0; i < props.length; i += 1) {
41 defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
42 }
43};
44
45defineProperties.supportsDescriptors = !!supportsDescriptors;
46
47module.exports = defineProperties;
Note: See TracBrowser for help on using the repository browser.