"use strict"; const assign = require('lodash/assign'); const clone = require('lodash/clone'); const cloneDeepWith = require('lodash/cloneDeepWith'); const isArray = require('lodash/isArray'); const isEmpty = require('lodash/isEmpty'); const isFunction = require('lodash/isFunction'); const isNaN = require('lodash/isNaN'); const isNil = require('lodash/isNil'); const isNumber = require('lodash/isNumber'); const isNull = require('lodash/isNull'); const isObject = require('lodash/isObject'); const isString = require('lodash/isString'); const isUndefined = require('lodash/isUndefined'); const capitalize = require('lodash/capitalize'); const reduce = require('lodash/reduce'); const filter = require('lodash/filter'); const reject = require('lodash/reject'); const has = require('lodash/has'); const map = require('lodash/map'); const forEach = require('lodash/forEach'); const includes = require('lodash/includes'); const size = require('lodash/size'); const join = require('lodash/join'); const trimEnd = require('lodash/trimEnd'); const findIndex = require('lodash/findIndex'); const get = require('lodash/get'); const every = require('lodash/every'); const keys = require('lodash/keys'); const mapKeys = require('lodash/mapKeys'); const pickBy = require('lodash/pickBy'); const value = require('lodash/value'); const unset = require('lodash/unset'); const transform = require('lodash/transform'); const startsWith = require('lodash/startsWith'); const endsWith = require('lodash/endsWith'); /* istanbul ignore next */ module.exports = { /** * Creates an inheritance relation between the child and the parent, adding a 'super_' attribute to the * child, and setting up the child prototype. * * @param {Function} child - The target object to create parent references for,. * @param {Function} base - The parent association to assign to the provided child definition. * @returns {*} */ inherit: function (child, base) { Object.defineProperty(child, 'super_', { value: isFunction(base) ? base : _.noop, configurable: false, enumerable: false, writable: false }); child.prototype = Object.create((isFunction(base) ? base.prototype : base), { constructor: { value: child, enumerable: false, writable: true, configurable: true } }); return child; }, /** * Creates a hidden property on an object, which can be changed, but is not enumerable. * * @param {Object} obj * @param {String} name * @param {*} prop * @returns {*} */ assignHidden: function (obj, name, prop) { Object.defineProperty(obj, name, { value: prop, configurable: true, enumerable: false, writable: true }); return obj; }, /** * Creates a property on an object, with the given type. * * @param {Object} obj * @param {String} name * @param {Property} Prop * @param {*} [fallback] * @returns {Prop|undefined} */ createDefined: function (obj, name, Prop, fallback) { return has(obj, name) ? (new Prop(obj[name])) : fallback; }, /** * Merges defined keys from the target object onto the source object. * * @param {Object} target * @param {Object} source * @returns {Object} */ mergeDefined: function (target, source) { var key; for (key in source) { if (source.hasOwnProperty(key) && !isUndefined(source[key])) { target[key] = source[key]; } } return target; }, /** * Returns the value of a property if defined in object, else the default * * @param {Object} obj * @param {String} prop * @param {*=} def * * @returns {*} */ getOwn: function (obj, prop, def) { return has(obj, prop) ? obj[prop] : def; }, /** * Creates a clone of an object, but uses the toJSON method if available. * * @param {Object} obj * @returns {*} */ cloneElement: function (obj) { return cloneDeepWith(obj, function (value) { // falls back to default deepclone if object does not have explicit toJSON(). if (value && isFunction(value.toJSON)) { return value.toJSON(); } }); }, isNumeric: function (n) { return !isNaN(n) && isFinite(n); }, assign, clone, isArray, isEmpty, isFunction, isNaN, isNil, isNumber, isNull, isObject, isString, isUndefined, capitalize, reduce, filter, reject, has, map, forEach, includes, size, join, trimEnd, findIndex, get, every, keys, mapKeys, pickBy, value, unset, transform, startsWith, endsWith, };