Created
November 18, 2019 22:30
-
-
Save jfolds/ac36276c0ef340f43d73797286c197e7 to your computer and use it in GitHub Desktop.
Some utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {object} obj data object to parse columns from | |
* parses columns from an object's keys | |
*/ | |
export function parseColumns(obj) { | |
if (!obj) { | |
return null; | |
} | |
return Object.keys(obj).map(key => ({ title: key, data: key })); | |
} | |
/** | |
* | |
* @param {array} ids array of integers | |
* gets next sequential value of provided integers | |
*/ | |
export function getNextId(ids) { | |
let nextId = 0; | |
ids.forEach(id => { | |
if (id >= nextId) { | |
nextId = id + 1; | |
} | |
}); | |
return nextId; | |
} | |
/** | |
* | |
* @param {string} email email to validate | |
* validates an email to be of _@_._ format | |
*/ | |
export function emailIsValid(email) { | |
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment