What is sentence-case?
The sentence-case npm package is designed to convert strings to sentence case, where the first letter of the sentence is capitalized and all other letters are in lower case. This is useful for formatting text to adhere to grammatical rules in English and other languages that follow similar capitalization rules.
What are sentence-case's main functionalities?
Convert string to sentence case
This feature allows you to convert any given string to sentence case. It also supports locale-based transformations, which can be useful for languages with specific casing rules.
const sentenceCase = require('sentence-case');
const result = sentenceCase('string'); // 'String'
const resultWithLocale = sentenceCase('STRING', 'tr'); // 'Strıng' with Turkish locale
Other packages similar to sentence-case
change-case
A comprehensive toolkit for converting text between different case formats. It includes functionality similar to sentence-case but also supports camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, snakeCase, and more. This makes it more versatile if you need to handle various text transformations.
title-case
Converts a string into title case, where the first letter of each word is capitalized. It is similar to sentence-case in that it deals with capitalization, but it applies the capitalization to each word rather than just the first word of the sentence.
Sentence Case
Sentence case a string. Explicitly adds a single underscore between groups of numbers to maintain readability and reversibility (E.g. 1.20.5
becomes 1_20_5
, not 1205
), by default.
Supports Unicode (non-ASCII characters) and non-string entities, such as objects with a toString
property, numbers and booleans. Empty values (null
and undefined
) will result in an empty string.
Installation
Node
npm install sentence-case --save
Usage
var sentenceCase = require('sentence-case')
sentenceCase('string')
sentenceCase('dot.case')
sentenceCase('PascalCase')
sentenceCase('version 1.2.10')
sentenceCase('STRING 1.2', 'tr')
Typings
Includes a TypeScript definition.
License
MIT