source: trip-planner-front/node_modules/define-properties/index.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[6a3a178]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 origDefineProperty = Object.defineProperty;
9
10var isFunction = function (fn) {
11 return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
12};
13
14var arePropertyDescriptorsSupported = function () {
15 var obj = {};
16 try {
17 origDefineProperty(obj, 'x', { enumerable: false, value: obj });
18 // eslint-disable-next-line no-unused-vars, no-restricted-syntax
19 for (var _ in obj) { // jscs:ignore disallowUnusedVariables
20 return false;
21 }
22 return obj.x === obj;
23 } catch (e) { /* this is IE 8. */
24 return false;
25 }
26};
27var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
28
29var defineProperty = function (object, name, value, predicate) {
30 if (name in object && (!isFunction(predicate) || !predicate())) {
31 return;
32 }
33 if (supportsDescriptors) {
34 origDefineProperty(object, name, {
35 configurable: true,
36 enumerable: false,
37 value: value,
38 writable: true
39 });
40 } else {
41 object[name] = value;
42 }
43};
44
45var defineProperties = function (object, map) {
46 var predicates = arguments.length > 2 ? arguments[2] : {};
47 var props = keys(map);
48 if (hasSymbols) {
49 props = concat.call(props, Object.getOwnPropertySymbols(map));
50 }
51 for (var i = 0; i < props.length; i += 1) {
52 defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
53 }
54};
55
56defineProperties.supportsDescriptors = !!supportsDescriptors;
57
58module.exports = defineProperties;
Note: See TracBrowser for help on using the repository browser.