| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 'use strict';
- let isObject = function (value) {
- return value !== null && typeof value === 'object';
- }
- let isArray = function (value) {
- return Array.isArray(value);
- }
- let isNumber = function (value) {
- return typeof value === 'number';
- }
- let copyObjectTo = function (from, to) {
- if (!to) {
- return from;
- }
- for (const name in from) {
- if (!from.hasOwnProperty(name)) {
- continue;
- }
- const fromValue = from[name];
- const toValue = to[name];
- if (isObject(fromValue) || isArray(fromValue)) {
- to[name] = copyObjectTo(from[name], to[name]);
- } else {
- if (fromValue !== toValue) {
- to[name] = fromValue;
- }
- }
- }
- return to;
- }
- module.exports = {
- isObject: isObject,
- isArray: isArray,
- isNumber: isNumber,
- copyObjectTo: copyObjectTo
- }
|