Skip to content

Instantly share code, notes, and snippets.

@frontsideair
Created June 17, 2025 11:53
Show Gist options
  • Save frontsideair/9111a177cd36385efa606ff668653940 to your computer and use it in GitHub Desktop.
Save frontsideair/9111a177cd36385efa606ff668653940 to your computer and use it in GitHub Desktop.
cnx.js
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