UNPKG

bootstrap-vue

Version:

BootstrapVue, with over 40 plugins and more than 80 custom components, custom directives, and over 300 icons, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated WAI-AR

36 lines (29 loc) 1.09 kB
import identity from './identity'; import { isArray, isObject } from './inspect'; import { clone } from './object'; /** * Copies props from one array/object to a new array/object. Prop values * are also cloned as new references to prevent possible mutation of original * prop object values. Optionally accepts a function to transform the prop name. * * @param {[]|{}} props * @param {Function} transformFn */ var copyProps = function copyProps(props) { var transformFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : identity; if (isArray(props)) { return props.map(transformFn); } // Props as an object. var copied = {}; for (var prop in props) { /* istanbul ignore else */ // eslint-disable-next-line no-prototype-builtins if (props.hasOwnProperty(prop)) { // If the prop value is an object, do a shallow clone to prevent // potential mutations to the original object. copied[transformFn(prop)] = isObject(props[prop]) ? clone(props[prop]) : props[prop]; } } return copied; }; export default copyProps;