aboutsummaryrefslogtreecommitdiff
path: root/node_modules/copy-descriptor/index.js
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/copy-descriptor/index.js
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/copy-descriptor/index.js')
-rw-r--r--node_modules/copy-descriptor/index.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/node_modules/copy-descriptor/index.js b/node_modules/copy-descriptor/index.js
new file mode 100644
index 0000000..6da21b1
--- /dev/null
+++ b/node_modules/copy-descriptor/index.js
@@ -0,0 +1,81 @@
+/*!
+ * copy-descriptor <https://github.com/jonschlinkert/copy-descriptor>
+ *
+ * Copyright (c) 2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+/**
+ * Copy a descriptor from one object to another.
+ *
+ * ```js
+ * function App() {
+ * this.cache = {};
+ * }
+ * App.prototype.set = function(key, val) {
+ * this.cache[key] = val;
+ * return this;
+ * };
+ * Object.defineProperty(App.prototype, 'count', {
+ * get: function() {
+ * return Object.keys(this.cache).length;
+ * }
+ * });
+ *
+ * copy(App.prototype, 'count', 'len');
+ *
+ * // create an instance
+ * var app = new App();
+ *
+ * app.set('a', true);
+ * app.set('b', true);
+ * app.set('c', true);
+ *
+ * console.log(app.count);
+ * //=> 3
+ * console.log(app.len);
+ * //=> 3
+ * ```
+ * @name copy
+ * @param {Object} `receiver` The target object
+ * @param {Object} `provider` The provider object
+ * @param {String} `from` The key to copy on provider.
+ * @param {String} `to` Optionally specify a new key name to use.
+ * @return {Object}
+ * @api public
+ */
+
+module.exports = function copyDescriptor(receiver, provider, from, to) {
+ if (!isObject(provider) && typeof provider !== 'function') {
+ to = from;
+ from = provider;
+ provider = receiver;
+ }
+ if (!isObject(receiver) && typeof receiver !== 'function') {
+ throw new TypeError('expected the first argument to be an object');
+ }
+ if (!isObject(provider) && typeof provider !== 'function') {
+ throw new TypeError('expected provider to be an object');
+ }
+
+ if (typeof to !== 'string') {
+ to = from;
+ }
+ if (typeof from !== 'string') {
+ throw new TypeError('expected key to be a string');
+ }
+
+ if (!(from in provider)) {
+ throw new Error('property "' + from + '" does not exist');
+ }
+
+ var val = Object.getOwnPropertyDescriptor(provider, from);
+ if (val) Object.defineProperty(receiver, to, val);
+};
+
+function isObject(val) {
+ return {}.toString.call(val) === '[object Object]';
+}
+