2018-02-02 20:07:51 +03:00
|
|
|
import cloneDeep from 'clone-deep'
|
|
|
|
|
2018-01-31 01:21:21 +03:00
|
|
|
/**
|
|
|
|
* Compare the equality of two arrays.
|
|
|
|
* @param {Array} arr1
|
|
|
|
* @param {Array} arr2
|
|
|
|
*/
|
|
|
|
export function equals (arr1, arr2) {
|
|
|
|
var length = arr1.length
|
|
|
|
if (length !== arr2.length) return false
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
if (arr1[i] !== arr2[i]) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to map over an object.
|
|
|
|
* @param {Object} obj An object to map over
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
export function map (original, callback) {
|
2018-02-02 20:07:51 +03:00
|
|
|
let obj = cloneDeep(original)
|
2018-01-31 01:21:21 +03:00
|
|
|
for (let key in obj) {
|
|
|
|
obj[key] = callback(key, obj[key])
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to filter an object's properties
|
|
|
|
* @param {Object} original
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
export function filter (original, callback) {
|
|
|
|
let obj = {}
|
|
|
|
for (let key in original) {
|
|
|
|
if (callback(key, original[key])) {
|
|
|
|
obj[key] = original[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to reduce an object's properties
|
|
|
|
* @param {Object} original
|
|
|
|
* @param {Function} callback
|
|
|
|
* @param {*} accumulator
|
|
|
|
*/
|
|
|
|
export function reduce (original, callback, accumulator) {
|
|
|
|
for (let key in original) {
|
|
|
|
accumulator = callback(accumulator, key, original[key])
|
|
|
|
}
|
|
|
|
return accumulator
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comprehensive list of input types supported.
|
|
|
|
*/
|
|
|
|
export const inputTypes = {
|
|
|
|
text: [
|
|
|
|
'text',
|
|
|
|
'email',
|
|
|
|
'number',
|
|
|
|
'color',
|
|
|
|
'date',
|
|
|
|
'datetime-local',
|
|
|
|
'hidden',
|
|
|
|
'month',
|
|
|
|
'password',
|
|
|
|
'range',
|
|
|
|
'search',
|
|
|
|
'tel',
|
|
|
|
'time',
|
|
|
|
'url',
|
|
|
|
'week'
|
|
|
|
],
|
|
|
|
button: [
|
|
|
|
'submit',
|
|
|
|
'button'
|
|
|
|
],
|
2018-02-01 01:20:29 +03:00
|
|
|
select: [
|
2018-01-31 01:21:21 +03:00
|
|
|
'select'
|
2018-02-01 01:20:29 +03:00
|
|
|
],
|
|
|
|
box: [
|
|
|
|
'radio',
|
|
|
|
'checkbox'
|
2018-01-31 01:21:21 +03:00
|
|
|
]
|
|
|
|
}
|