Skip to content

Commit

Permalink
refactor(Utils): Move getRealClassNamesArray on utils module to have …
Browse files Browse the repository at this point in the history
…pure modules
  • Loading branch information
lucaperret committed Aug 12, 2017
1 parent 5fd8528 commit 4038be8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
13 changes: 1 addition & 12 deletions src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
* @module attributes
*/

import { toCamelCase } from './utils'

/**
* Filter incorrect class names.
* @private
*
* @param {string} [classNames=''] One or more space-separated classes to be filtered
* @return {Array} Valid class names array
*/
function getRealClassNamesArray (classNames = '') {
return classNames.split(' ').filter(className => !!className)
}
import { toCamelCase, getRealClassNamesArray } from './utils'

/**
* Determine whether the element is assigned the given class.
Expand Down
11 changes: 11 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ export function toCamelCase (kebabCaseString) {
return memo + token.slice(0, 1).toUpperCase() + token.slice(1)
})
}

/**
* Filter incorrect class names.
* @private
*
* @param {string} [classNames=''] One or more space-separated classes to be filtered
* @return {Array} Valid class names array
*/
export function getRealClassNamesArray (classNames = '') {
return classNames.split(' ').filter(className => !!className)
}
3 changes: 3 additions & 0 deletions test/specs/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ describe('Utils', () => {
test('Kebab to camel case', () => {
expect(utils.toCamelCase('kebab-case-string')).toBe('kebabCaseString')
})
test('Filter incorrect class names', () => {
expect(utils.getRealClassNamesArray(' class1 class2 ')).toEqual(['class1', 'class2'])
})
})

0 comments on commit 4038be8

Please sign in to comment.