Comparing version 1.0.0 to 1.0.1
62
index.js
@@ -1,60 +0,6 @@ | ||
module.exports = function (text) { | ||
// splits the text at \n | ||
var textToParagraphs = function(text) { | ||
var paragraphs = text.split( /[\r\n|\n|\r]+/g ); | ||
return paragraphs.map(paragraphToSentences); | ||
}; | ||
var textparse = require('./lib/text-parse'); | ||
// splits the paragraph at end of sentence punctuation | ||
var paragraphToSentences = function(paragraph) { | ||
paragraph = paragraph.trim(); | ||
var sentences = paragraph.match( /[^\.!\?]+[\.!\?(?="|')]+/g ); | ||
return { | ||
raw: paragraph, | ||
type: 'paragraph', | ||
children: sentences.map(sentenceToWords) | ||
}; | ||
}; | ||
// splits the sentence at the spaces | ||
var sentenceToWords = function(sentence) { | ||
sentence = sentence.trim(); | ||
var words = sentence.split(/\s+/); | ||
return { | ||
raw: sentence, | ||
type: 'sentence', | ||
children: words.map(wordToChars) | ||
}; | ||
}; | ||
// splits the word into characters and classifies each | ||
var wordToChars = function(word) { | ||
var chars = []; | ||
var letters = ''; | ||
var punctuation = []; | ||
for (var i = 0; i < word.length; i++) { | ||
var curChar = word[i]; | ||
// if it's not a letter then it's punctuation | ||
if (/\W/.test(curChar)) { | ||
chars.push({raw: curChar, type: 'punctuation'}); | ||
punctuation.push(curChar); | ||
} | ||
// if it's a letter than append to noPunctuation | ||
else { | ||
chars.push({raw: curChar, type: 'letter'}); | ||
letters += curChar; | ||
} | ||
} | ||
return { | ||
raw: word, | ||
noPunctuation: letters, | ||
type: 'word', | ||
children: chars | ||
}; | ||
}; | ||
return textToParagraphs(text); | ||
module.exports = function(text) { | ||
var parser = textparse(); | ||
return parser.textToParagraphs(text); | ||
}; |
{ | ||
"name": "text-parse", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Text parser", | ||
@@ -5,0 +5,0 @@ "keywords": ["text", "parser", "plaintext"], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8573
8
57