All files utils.js

100% Statements 1/1
100% Branches 0/0
100% Functions 1/1
100% Lines 1/1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                              5x    
 
export function convertToArray (value) {
	if (typeof value === 'string') {
		value = value.split(' ')
	}
	return value
}
 
/**
 * Add classes to an element.
 * This method checks to ensure that the classes don't already exist before adding them.
 * It uses el.className rather than classList in order to be IE friendly.
 * @param {object} el - The element to add the classes to.
 * @param {classes} string - List of space separated classes to be added to the element.
 */
export function addClasses (el, classes) {
	const newClasses = convertToArray(classes)
	const classList = convertToArray(el.className)
	newClasses.forEach((newClass) => {
		if (classList.indexOf(newClass) === -1) {
			classList.push(newClass)
		}
	})
	el.className = classList.join(' ')
}