Custom-Capitalization is a JavaScript library that provides functions for capitalizing words in a sentence with customizable excluded words. It offers an easy-to-use interface for developers to capitalize sentences while excluding specific words from capitalization.
- Sentence Capitalization: Capitalize words in a sentence while preserving the capitalization of specific words.
- Customizable Exclusion: Set default excluded words and add custom excluded words to control which words should not be capitalized.
- Dynamic Exclusion Management: Easily add, remove, and move words between default and custom excluded word lists.
- Flexible Usage: Use individual functions for setting excluded words, or directly capitalize sentences with customizable exclusion rules.
- Corrected version number from 1.0.2 to 1.1.0.
- Updated import syntax for easier usage:
- Previously:
import { setDefault, setCustom, delDefault, delCustom, moveDefaultToCustom, moveCustomToDefault, capitalize, capitalizeAllWords, defaultExcludedWords, customExcludedWords } from 'custom-capitalization';
- Now:
import customCapitalization from 'custom-capitalization';
- Previously:
- Corrected the path to the main file in package.json
- Initial release of Custom-Capitalization.
To install Custom-Capitalization, you can use npm:
npm install custom-capitalization
import customCapitalization from 'custom-capitalization';
console.log(customCapitalization.capitalize('that quick brown fox jumps over the lazy dog in the park', true, true)); // Output: That Quick Brown Fox Jumps Over the Lazy Dog in the Park
console.log(customCapitalization.capitalizeAllWords('that quick brown fox jumps over the lazy dog in the park')); // Output: THAT QUICK BROWN FOX JUMPS OVER THE LAZY DOG IN THE PARK
import customCapitalization from 'custom-capitalization';
customCapitalization.setDefault('that', 'over');
customCapitalization.setCustom('dog','fox');
console.log(customCapitalization.capitalize('that quick brown fox jumps over the lazy dog in the park', true, true)); // Output: That Quick Brown fox Jumps over the Lazy dog in the Park
import customCapitalization from 'custom-capitalization';
customCapitalization.setCustom('dog','fox');
customCapitalization.delDefault('in', 'the');
customCapitalization.delCustom('fox');
customCapitalization.moveDefaultToCustom('that');
customCapitalization.moveCustomToDefault('dog');
console.log(customCapitalization.capitalize('That quick brown fox jumps over the lazy dog in the park with joy', true, true)); // Output: That Quick Brown Fox Jumps Over The Lazy dog In The Park With Joy
The defaultExcludedWords
variable contains a set of words that are excluded from capitalization by default. These words are commonly used as articles, conjunctions, and prepositions that are typically not capitalized in sentences.
- a, an, the, and, but, or, for, nor, on, at, to, by, in, of
These words can be removed from the default excluded list using the delDefault
function provided by the library.
This project is licensed under the ISC License - see the LICENSE.md file for details.