UNPKG

@magic/log

Version:

enhanced console.log

42 lines (34 loc) 765 B
import is from '@magic/types' /** * @param {any} a * @returns {string} */ export const stringifyByType = a => { if (is.array(a) && a.length === 1) { return stringifyByType(a[0]) } if (is.string(a)) { return a } else if (is.number(a)) { return `${a}` } else if (is.array(a)) { return stringify(...a) } else if (is.object(a)) { if (is.function(a) || is.date(a) || is.regexp(a)) { return a.toString() } return JSON.stringify(a) } return '' + a } /** * @param {any} t * @returns {boolean} */ export const byEmptyString = t => t !== '' /** * @param {...any} str * @returns {string} */ export const stringify = (...str) => str.map(stringifyByType).filter(byEmptyString).join(' ') export default stringify