help-my-strings
v2.0.3
Published
String utility functions such as titleize, capitalize, pluralize etc
Downloads
40
Readme
Capitalize
returns a string with only the first letter capitalized
capitalize("hello world") // => Hello world
capitalize("HellO WOrLd") // => Hello world
capitalize("HELLOWORLD") // => Helloworld
Humanize
returns a string suitable for human consumption
humanize("hello_world") // => hello world
humanize("RenderHtml") // => Render Html
humanize("HTMLRender") // => HTML Render
Titalize
returns a string in title format
titalize("hello world") // => Hello World
titalize("hello_world") // => Hello World
titalize("HelloWorld") // => Hello World
Truncate
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 |
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...
CamelCase
returns a string in camel case with option to capitalise first letter
camelCase("hello_world") // => helloWorld
camelCase("hello-world") // => helloWorld
camelCase("hello.world-bear") // => helloWorldBear
camelCase("hello_world", true) // => HelloWorld
Singularize
returns the singular of the word
singularize("words") // => word
singularize("people") // => person
singularize("car") // => car
Pluralize
returns a pluralised word
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
SnakeCase
returns a string in snake case
snakeCase("words are cool") // => words_are_cool
snakeCase("Words-Are-Cool") // => words_are_cool
Parameterize
returns a string in a parameterized form, suitable for URL slugs
parameterize("hello world") // => hello-world
parameterize("hello.world") // => helloworld
parameterize("hello world.bear") // => hello-worldbear