Created
May 31, 2018 14:29
-
-
Save third774/5f8608d6cc5687be40d16e0e8c4d2342 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 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