What is humanize-string?
The humanize-string npm package is used to convert a string to a human-readable format. It transforms strings with various delimiters (like dashes, underscores, or camelCase) into a more readable format with spaces and capitalized words.
What are humanize-string's main functionalities?
Basic String Humanization
This feature converts camelCase strings into a human-readable format with spaces and capitalized words.
const humanizeString = require('humanize-string');
console.log(humanizeString('helloWorld')); // 'Hello world'
Handling Strings with Dashes
This feature converts strings with dashes into a human-readable format with spaces and capitalized words.
const humanizeString = require('humanize-string');
console.log(humanizeString('hello-world')); // 'Hello world'
Handling Strings with Underscores
This feature converts strings with underscores into a human-readable format with spaces and capitalized words.
const humanizeString = require('humanize-string');
console.log(humanizeString('hello_world')); // 'Hello world'
Other packages similar to humanize-string
titleize
The titleize package converts a string to title case, where the first letter of each word is capitalized. Unlike humanize-string, it focuses on title casing rather than just making the string more readable.
decamelize
The decamelize package converts camelCase strings to a format with a specified delimiter, usually an underscore. It is more focused on converting camelCase to other formats rather than making the string human-readable.
lodash.startcase
The lodash.startcase function from the lodash library converts a string to start case, where the first letter of each word is capitalized and words are separated by spaces. It provides similar functionality to humanize-string but is part of the larger lodash utility library.
humanize-string
Converts a camelized/dasherized/underscored string into a humanized one
Example: fooBar-Baz_Faz
→ Foo bar baz faz
Install
$ npm install --save humanize-string
Usage
var humanizeString = require('humanize-string');
humanizeString('fooBar');
humanizeString('foo-bar');
humanizeString('foo_bar');
License
MIT © Sindre Sorhus