Files
login/node_modules/object-copy/index.js
Amruta Kawade 45b10ffd19 Adding node_modules for dependabot (#67)
* Bump lodash from 4.17.15 to 4.17.19 (#52)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com>

* Bump @actions/core from 1.1.3 to 1.2.6 (#60)

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.1.3 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com>

* updating node_nodules

* updated package-lock

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-12 14:58:40 +05:30

175 lines
3.3 KiB
JavaScript

'use strict';
var typeOf = require('kind-of');
var copyDescriptor = require('copy-descriptor');
var define = require('define-property');
/**
* Copy static properties, prototype properties, and descriptors from one object to another.
*
* ```js
* function App() {}
* var proto = App.prototype;
* App.prototype.set = function() {};
* App.prototype.get = function() {};
*
* var obj = {};
* copy(obj, proto);
* ```
* @param {Object} `receiver`
* @param {Object} `provider`
* @param {String|Array} `omit` One or more properties to omit
* @return {Object}
* @api public
*/
function copy(receiver, provider, omit) {
if (!isObject(receiver)) {
throw new TypeError('expected receiving object to be an object.');
}
if (!isObject(provider)) {
throw new TypeError('expected providing object to be an object.');
}
var props = nativeKeys(provider);
var keys = Object.keys(provider);
var len = props.length;
omit = arrayify(omit);
while (len--) {
var key = props[len];
if (has(keys, key)) {
define(receiver, key, provider[key]);
} else if (!(key in receiver) && !has(omit, key)) {
copyDescriptor(receiver, provider, key);
}
}
};
/**
* Return true if the given value is an object or function
*/
function isObject(val) {
return typeOf(val) === 'object' || typeof val === 'function';
}
/**
* Returns true if an array has any of the given elements, or an
* object has any of the give keys.
*
* ```js
* has(['a', 'b', 'c'], 'c');
* //=> true
*
* has(['a', 'b', 'c'], ['c', 'z']);
* //=> true
*
* has({a: 'b', c: 'd'}, ['c', 'z']);
* //=> true
* ```
* @param {Object} `obj`
* @param {String|Array} `val`
* @return {Boolean}
*/
function has(obj, val) {
val = arrayify(val);
var len = val.length;
if (isObject(obj)) {
for (var key in obj) {
if (val.indexOf(key) > -1) {
return true;
}
}
var keys = nativeKeys(obj);
return has(keys, val);
}
if (Array.isArray(obj)) {
var arr = obj;
while (len--) {
if (arr.indexOf(val[len]) > -1) {
return true;
}
}
return false;
}
throw new TypeError('expected an array or object.');
}
/**
* Cast the given value to an array.
*
* ```js
* arrayify('foo');
* //=> ['foo']
*
* arrayify(['foo']);
* //=> ['foo']
* ```
*
* @param {String|Array} `val`
* @return {Array}
*/
function arrayify(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
}
/**
* Returns true if a value has a `contructor`
*
* ```js
* hasConstructor({});
* //=> true
*
* hasConstructor(Object.create(null));
* //=> false
* ```
* @param {Object} `value`
* @return {Boolean}
*/
function hasConstructor(val) {
return isObject(val) && typeof val.constructor !== 'undefined';
}
/**
* Get the native `ownPropertyNames` from the constructor of the
* given `object`. An empty array is returned if the object does
* not have a constructor.
*
* ```js
* nativeKeys({a: 'b', b: 'c', c: 'd'})
* //=> ['a', 'b', 'c']
*
* nativeKeys(function(){})
* //=> ['length', 'caller']
* ```
*
* @param {Object} `obj` Object that has a `constructor`.
* @return {Array} Array of keys.
*/
function nativeKeys(val) {
if (!hasConstructor(val)) return [];
return Object.getOwnPropertyNames(val);
}
/**
* Expose `copy`
*/
module.exports = copy;
/**
* Expose `copy.has` for tests
*/
module.exports.has = has;