Skip to content

Instantly share code, notes, and snippets.

@zhjgithub
Created November 15, 2017 07:35
Show Gist options
  • Save zhjgithub/a2b3e32813571b2e896f73f134ed4ba1 to your computer and use it in GitHub Desktop.
Save zhjgithub/a2b3e32813571b2e896f73f134ed4ba1 to your computer and use it in GitHub Desktop.
const compose = (...fns) => data =>
fns.reduceRight((value, fn) => fn(value), data)
const trim = str => str.trim()
const split = separator => str => str.split(separator)
const notEmpty = str => str.length > 0
const removeEmpty = parts => parts.filter(notEmpty)
const words = compose(removeEmpty, split(' '), trim)
const upperCapital = str => str.charAt(0).toUpperCase() + str.substr(1)
const capitalize = filtered => filtered.map(upperCapital)
const join = separator => arr => arr.join(separator)
const titleCase = compose(join(' '), capitalize, words)
titleCase('this is a test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment