You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

26 lines
693 B

/**
* function to convert array to string and string to array
* @param {*} input
* @param {String} separator
* @returns {*}
*/
function convertArrayAndString(input, separator = ', ') {
// If the separator is just a comma without a space, change it to ", "
if (separator === ',') {
separator = ', '
}
if (Array.isArray(input)) {
// Convert array to string with the correct separator
return input.join(separator)
} else if (typeof input === 'string') {
// Convert string to array using the separator
return input.split(separator)
} else {
throw new Error('Input must be either an array or a string.')
}
}
module.exports = {
convertArrayAndString
}