1.0.0 • Published 5 years ago
@cappalyst/cappalyst v1.0.0
@cappalyst/cappalyst
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
1.0.0
5 years ago
1.0.0-beta.6
5 years ago
1.0.0-beta.5
5 years ago
1.0.0-beta.4
5 years ago
1.0.0-beta.1
5 years ago
1.0.0-beta.0
5 years ago