Package Exports
- wordsninja
- wordsninja/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wordsninja) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
WordsNinja
Split an English sentence that lacks spaces and accents into separate words.
Install
npm install wordsninja --saveLoad package
const WordsNinjaPack = require('wordsninja');
const WordsNinja = new WordsNinjaPack();Load dictionary
await WordsNinja.loadDictionary(); // First load dictionaryAdd word(s)
WordsNinja.addWords('new word');Parameters
word: The word(s) (string|array)
Split sentence
let words = WordsNinja.splitSentence(string, {camelCaseSplitter, capitalizeFirstLetter, joinWords});Parameters
string: The string for splitoptionscamelCaseSplitter: Split by Camel Case, Default isfalse(optional)capitalizeFirstLetter: Capitalize First Letter, Default isfalse(optional)joinWords: Return join words as sentence, Default isfalse(optional)
Example
(async () => {
await WordsNinja.loadDictionary(); // First load dictionary
let string = 'youneedtolearnfromyourmistakes';
let words = WordsNinja.splitSentence(string);
console.log(words);
})();Result
[ 'you', 'need', 'to', 'learn', 'from', 'your', 'mistakes' ]More options
let string = 'youneedtolearnfromyourmistakes';
let words = WordsNinja.splitSentence(string,
{
camelCaseSplitter: true, // Camel case splitting
capitalizeFirstLetter: true, // Capitalize first letter of result
joinWords: true // Join words with spaces
}
);
console.log(words);Result
You Need To Learn From Your MistakesAdd Word(s)
You can add new word(s) to dictionary in runtime
WordsNinja.addWords('Parsa'); // Add one word
WordsNinja.addWords(['Parsa', 'Kafi']); // Add one or more wordsExample
let string = 'parsayouneedtolearnfromyourmistakes';
WordsNinja.addWords('Parsa');
let words = WordsNinja.splitSentence(string,
{
capitalizeFirstLetter: true, // Capitalize first letter of result
joinWords: true // Join words with spaces
}
);
console.log(words);Result
Parsa You Need To Learn From Your MistakesAcknowledgement
Algorithm from How to split text without spaces into list of words?. List of words from wordninja python package. Camel case splitter based on split-camelcase-to-words package.
