Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

text-parse

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

text-parse - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/text-parse.js

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc