Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

feat: support hyphenation attribute for React in Vue #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/resolvers/Vue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactWrapper } from '../'
import { camelCaseKeys } from '../utils/camelCase'

export default function VueResolver (component) {
return {
Expand All @@ -13,7 +14,7 @@ export default function VueResolver (component) {
component,
passedProps: this.$props.passedProps,
},
attrs: this.$attrs,
attrs: camelCaseKeys(this.$attrs),
on: this.$listeners,
},
this.$slots.default
Expand Down
30 changes: 30 additions & 0 deletions src/utils/camelCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export function camelCase (string) {
if (typeof string !== 'string') {
return string
}

const divider = /[_-\s]/

string.toLowerCase()
return string
.split(divider)
.map((word, index) => {
if (word && index) {
const [capital, ...rest] = word
return `${capital.toUpperCase()}${rest.join('')}`
}
return word
})
.join('')
}

export function camelCaseKeys (obj) {
let newObj = {}

for (key in obj) {
const camelCaseKey = camelCase(key)
newObj[camelCaseKey] = obj[key]
}

return newObj
}