Created
June 17, 2025 11:53
-
-
Save frontsideair/9111a177cd36385efa606ff668653940 to your computer and use it in GitHub Desktop.
cnx.js
This file contains hidden or 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
function cnx(strings, ...keys) { | |
const ret = [] | |
for (let i = 0; i < strings.length + keys.length; i++) { | |
if (i % 2 === 0) { | |
const index = i / 2 | |
ret.push(strings[index].trim()) | |
} else { | |
const index = (i - 1) / 2 | |
const key = keys[index] | |
if (typeof key === 'string') { | |
ret.push(key) | |
} | |
} | |
} | |
return ret.join(' ') | |
} | |
const a = null | |
const b = 'test' | |
console.log(cnx`hello ${a} world`) | |
console.log(cnx`hello ${b} world ${a} hi`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment