Skip to content

Instantly share code, notes, and snippets.

@elrikdante
Last active February 16, 2018 06:51
Show Gist options
  • Save elrikdante/ceddfc67c220351a76b2a3fed88ae0ba to your computer and use it in GitHub Desktop.
Save elrikdante/ceddfc67c220351a76b2a3fed88ae0ba to your computer and use it in GitHub Desktop.
const attributes = (settings) => {
let attributeString = ""
for (const key in settings) {
if (settings.hasOwnProperty(key)) {
const element = settings[key]
if (element != null) {
attributeString += ` ${key}="${element}"`
}
}
}
return attributeString
}
const replaceAll = (s,find,replace) => s.split(find).join(replace)
const attributes2 = (s) => {
return replaceAll (
replaceAll(
JSON.stringify(s).slice(1,-1)
,","
," ")
,":"
,"=")
}
console.log(attributes({a: 1,b: 2}))
console.log(attributes2({a: 1,b: 2}))
⚙ elrikdante@elrikgroup-labbook  ~/apps/inbizzz/lib/render-react-native-to-image   master  node test.js
a="1" b="2"
a"=1 "b"=2
⚙ elrikdante@elrikgroup-labbook  ~/apps/inbizzz/lib/render-react-native-to-image   master  node test.js
a="1" b="2"
"a"=1 "b"=2
⚙ elrikdante@elrikgroup-labbook  ~/apps/inbizzz/lib/render-react-native-to-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment