Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

史上最差的 Case 转化实现 #28

Open
CyanSalt opened this issue Jul 20, 2020 · 0 comments
Open

史上最差的 Case 转化实现 #28

CyanSalt opened this issue Jul 20, 2020 · 0 comments

Comments

@CyanSalt
Copy link
Owner

CyanSalt commented Jul 20, 2020


path: worst-casing-convertion


let transformer = document.createElement('span')

function camel2kebab(name) {
  const dataset = transformer.dataset
  dataset[name] = '1'
  const key = transformer.attributes[0].name
  delete dataset[name]
  return key.substring(5)
}

function kebab2camel(name) {
  transformer.setAttribute(`data-${name}`, '1')
  const dataset = transformer.dataset
  const key = Object.keys(dataset)[0]
  delete dataset[key]
  return key
}
@CyanSalt CyanSalt transferred this issue from another repository Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant