1.0.0 • Published 5 years ago

@cappalyst/cappalyst v1.0.0

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
5 years ago

@cappalyst/cappalyst

NPM version Greenkeeper Dependency Status Dev Dependency Status Known Vulnerabilities Build status codecov License

Install

npm i @cappalyst/cappalyst

Methods

Global Augmentation

String

capitalize()

Capitalize the first letter of a string.

const str = 'hello world!'
console.log(str.capitalize()) // Hello world!
sanitize()

Sanitize a string depending on the type of sanitization expected.

  • regexp
const str = '/hello+[world].'
console.log(str.sanitize('regexp')) // \/hello\+\[world\]\.
  • html
const str = 'unsafe <string>'
console.log(str.sanitize('html')) // unsafe%20%3Cstring%3E

i18n

translator()

Translate a string based on a memoized dictionary.

const translations = {
  hello: {
    en: 'hello world !',
    fr: 'bonjour tout le monde !',
  },
  helloName: {
    en: name => `hello ${name} !`,
    fr: name => `bonjour ${name} !`,
  },
}

const t = translator(translations)

console.log(t('hello', 'en')) // hello world !
console.log(t('helloName', 'fr')('john')) // bonjour john !

License

GPL-3.0