String utility functions such as titleize, capitalize, pluralize etc
npm install help-my-strings
!logo
returns a string with only the first letter capitalized
``javascript`
capitalize("hello world") // => Hello world
capitalize("HellO WOrLd") // => Hello world
capitalize("HELLOWORLD") // => Helloworld
returns a string suitable for human consumption
`javascript
humanize("hello_world") // => hello world
humanize("RenderHtml") // => Render Html
humanize("HTMLRender") // => HTML Render
`
returns a string in title format
`javascript
titalize("hello world") // => Hello World
titalize("hello_world") // => Hello World
titalize("HelloWorld") // => Hello World
`
returns a truncated string
truncate(string, {omission?, length?, separator?})
| Option | Purpose | default |
| ------------- | ------------- | ------- |
| omission | Replaces the truncated content | ... |
| length | The total length of the truncated content, including omission characters | 20 |
| separator | Defines the separator between words. Will stop at the last seperator if a word is broken by truncation | undefined |
`javascript
truncate("Hello my name is James") // => Hello my name is ...
truncate("hello my name is James", { omission: "???", length: 10 }) // => Hello m???
truncate("hello my name is James", { length: 10, separator: " " }) // => Hello...
truncate("hello my name is James", { length: 11, separator: " " }) // => Hello my...
`
returns a string in camel case with option to capitalise first letter
`javascript`
camelCase("hello_world") // => helloWorld
camelCase("hello-world") // => helloWorld
camelCase("hello.world-bear") // => helloWorldBear
camelCase("hello_world", true) // => HelloWorld
returns the singular of the word
`javascript`
singularize("words") // => word
singularize("people") // => person
singularize("car") // => car
returns a pluralised word
`javascript
pluralize("cat") // => cats
pluraliz("person") // => people
pluralize(0, "thing") // => 0 things
pluralize(1, "thing") // => 1 thing
pluralize(2, "thing") // => 2 things
pluralize(1, "thing" undefined, { noCount: true }) // => thing
pluralize(2, "thing" undefined, { noCount: true }) // => things
`
returns a string in snake case
`javascript`
snakeCase("words are cool") // => words_are_cool
snakeCase("Words-Are-Cool") // => words_are_cool
returns a string in a parameterized form, suitable for URL slugs
`javascript``
parameterize("hello world") // => hello-world
parameterize("hello.world") // => helloworld
parameterize("hello world.bear") // => hello-worldbear