Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active May 3, 2019 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/46515b002853367e1054e176ad386736 to your computer and use it in GitHub Desktop.
Save tomhodgins/46515b002853367e1054e176ad386736 to your computer and use it in GitHub Desktop.
run with -> $deno map-test.js | prettier --parser css > output.css
const listMapper = (list, template) => list.map(template).join('\n')
const objectMapper = (object, template) => Object.entries(object).map(template).join('\n')
console.log(
listMapper(
[
'red',
'blue',
'green'
],
value => `
.list-${value} {
color: ${value};
}
`
)
+ objectMapper(
{
red: '#c00',
green: '#0c0',
blue: '#00c'
},
([name, value]) => `
.object-${name} {
color: ${value};
}
`
)
)
.list-red {
color: red;
}
.list-blue {
color: blue;
}
.list-green {
color: green;
}
.object-red {
color: #c00;
}
.object-green {
color: #0c0;
}
.object-blue {
color: #00c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment