handleExternalClasses.js 537 B

123456789101112131415161718192021222324
  1. function handleExternalClasses(opts = {}) {
  2. const externalClasses = opts.externalClasses
  3. const arr = Array.isArray(externalClasses) ? externalClasses : []
  4. const _class = []
  5. arr.forEach((a) => {
  6. _class.push(_transform(a) || '')
  7. })
  8. opts.data = opts.data || {}
  9. opts.data.__classNames = _class
  10. opts.data.__classes = ''
  11. function _transform(str = '') {
  12. str = str.replace(/-(\w)/g, (...$) => {
  13. return $[1].toUpperCase()
  14. })
  15. return str || ''
  16. }
  17. return opts
  18. }
  19. module.exports = handleExternalClasses