Some refactoring

This commit is contained in:
jos 2016-08-14 14:00:14 +02:00
parent ebca411384
commit 422315dba2
4 changed files with 17 additions and 52 deletions

View File

@ -4,7 +4,7 @@ import { cloneDeep } from './utils/objectUtils'
import { setIn, updateIn, getIn, deleteIn } from './utils/immutabilityHelpers'
import { compareAsc, compareDesc } from './utils/arrayUtils'
import { stringConvert } from './utils/typeUtils'
import { isObject } from './utils/typeUtils'
import { isObject } from './utils/objectUtils'
import bindMethods from './utils/bindMethods'
import JSONNode from './JSONNode'

View File

@ -1,5 +1,7 @@
'use strict';
import { isObject, clone } from './objectUtils'
/**
* Immutability helpers
*
@ -138,40 +140,3 @@ export function deleteIn (object, path) {
return object
}
}
/**
* Flat clone the properties of an object or array
* @param {Object | Array} value
* @return {Object | Array} Returns a flat clone of the object or Array
*/
export function clone (value) {
if (Array.isArray(value)) {
return value.slice(0)
}
else if (isObject(value)) {
const cloned = {}
Object.keys(value).forEach(key => {
cloned[key] = value[key]
})
return cloned
}
else {
// a primitive value
return value
}
}
/**
* Test whether a value is an object (and not an Array or Date or primitive value)
*
* @param {*} value
* @return {boolean}
*/
export function isObject (value) {
return typeof value === 'object' &&
value !== null &&
!Array.isArray(value) &&
value.toString() === '[object Object]'
}

View File

@ -1,5 +1,18 @@
import { isObject } from './typeUtils'
// TODO: unit test isObject
/**
* Test whether a value is an object (and not an Array or Date or primitive value)
*
* @param {*} value
* @return {boolean}
*/
export function isObject (value) {
return typeof value === 'object' &&
value !== null &&
!Array.isArray(value) &&
value.toString() === '[object Object]'
}
// TODO: unit test clone

View File

@ -30,19 +30,6 @@ export function valueType(value) {
return 'object'
}
/**
* Test whether a value is an object (and not an Array or Date or primitive value)
*
* @param {*} value
* @return {boolean}
*/
export function isObject (value) {
return typeof value === 'object' &&
value && // not null
!Array.isArray(value) &&
value.toString() === '[object Object]'
}
/**
* Test whether a text contains a url (matches when a string starts
* with 'http://*' or 'https://*' and has no whitespace characters)