Last active
February 16, 2018 06:51
-
-
Save elrikdante/ceddfc67c220351a76b2a3fed88ae0ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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