Skip to content

Instantly share code, notes, and snippets.

@third774
Created May 31, 2018 14:29
Show Gist options
  • Save third774/5f8608d6cc5687be40d16e0e8c4d2342 to your computer and use it in GitHub Desktop.
Save third774/5f8608d6cc5687be40d16e0e8c4d2342 to your computer and use it in GitHub Desktop.
const format = (strings, ...values) => {
if (values.every(v => typeof v !== "function")) {
return strings.reduce((acc, str, i) => values[i] === undefined ? acc + str : acc + str + values[i], "")
}
return obj => strings.reduce((acc, str, i) => values[i] === undefined ? acc + str :
typeof values[i] === "function" ? acc + str + values[i](obj) : acc + str + values[i], "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment