UNPKG

text-sentence-case

Version:

Convert into a lower case with spaces between words, then capitalize text

16 lines (15 loc) 445 B
import { noCase } from "text-no-case"; import { upperCaseFirst } from "text-upper-case-first"; export function sentenceCaseTransform(input, index) { const result = input.toLowerCase(); if (index === 0) return upperCaseFirst(result); return result; } export function sentenceCase(input, options = {}) { return noCase(input, { delimiter: " ", transform: sentenceCaseTransform, ...options, }); }