Comparing version 1.1.0 to 1.2.1
24
index.js
@@ -23,2 +23,3 @@ 'use strict' | ||
let wordsPerSent = 0 | ||
let spacedOutBody = ''; | ||
let dict = { ';': 0 | ||
@@ -39,12 +40,13 @@ , ':': 0 | ||
ReadFile(filePath, options.encoding) | ||
.pipe(removeCarriageReturn()) | ||
.pipe(removeDoubleSpaces()) | ||
.pipe(removeAndReplace(/\r/g, '')) | ||
.pipe(removeAndReplace(/\s\s+/g, ' ')) | ||
.pipe(findAndCount(dict, punctuationStore)) | ||
.pipe(findWordsPerSentence(count => wordsPerSent = count)) | ||
.pipe(findAndCount(dict, punctuationStore)) | ||
.pipe(removeAndReplace(/[a-zA-Z\d]+/g, ' ', spaced => spacedOutBody = spaced)) | ||
.on('data', _ => _) | ||
.on('end', _ => { | ||
console.log('end count:', wordsPerSent) | ||
return resolve({ body: punctuationStore.join('') | ||
, count: dict | ||
, wordsPerSentence: wordsPerSent | ||
, spaced: spacedOutBody | ||
}) | ||
@@ -56,14 +58,8 @@ }) | ||
function removeCarriageReturn () { | ||
function removeAndReplace (regex, replace, dest) { | ||
return Through2.obj(function(chunk, _, callback) { | ||
chunk = chunk.replace(/\r/g, '') | ||
chunk = chunk.replace(regex, replace) | ||
callback(null, chunk) | ||
}) | ||
} | ||
if (dest) dest(chunk) | ||
function removeDoubleSpaces () { | ||
return Through2.obj(function(chunk, _, callback) { | ||
chunk = chunk.replace(/\s\s+/g, ' ') | ||
callback(null, chunk) | ||
@@ -91,3 +87,3 @@ }) | ||
}) | ||
callback() | ||
callback(null, chunk) | ||
}) | ||
@@ -94,0 +90,0 @@ } |
{ | ||
"name": "punc", | ||
"version": "1.1.0", | ||
"version": "1.2.1", | ||
"description": "Ever wonder what your favorite books look like without words?", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,3 @@ # Punc | ||
## Example Usage | ||
## Example Usage #1 | ||
@@ -28,2 +28,3 @@ ```javascript | ||
``` | ||
Output found: [here][EXAMPLE_OUTPUT] | ||
@@ -34,2 +35,8 @@ | ||
### Features | ||
1. removes words and numbers from a file leaving only punctuations. | ||
1. counts each punctuation seen. | ||
1. words per sentence average. | ||
1. same as (#1) but instead replaces each character found with an empty space. | ||
## Notes | ||
@@ -36,0 +43,0 @@ - Punctuations to keep when removing words: |
@@ -10,3 +10,3 @@ 'use strict' | ||
let aliceStub = new Buffer('-;alice,in.wonder\'land(-;-.,""') | ||
let word_count_stub = new Buffer(`one. | ||
let wordCountStub = new Buffer(`one. | ||
two two! | ||
@@ -17,3 +17,3 @@ three three three? | ||
Mock({ 'books': { 'alice.txt': aliceStub | ||
, 'word_count.txt': word_count_stub | ||
, 'word_count.txt': wordCountStub | ||
} | ||
@@ -93,2 +93,11 @@ }) | ||
.catch(err => t.fail(err)) | ||
}) | ||
Test('Punc: spaced out text', t => { | ||
t.plan(2) | ||
Punc('books/word_count.txt') | ||
.then(book => { | ||
t.ok(book.spaced, 'spaced property exists on returned object') | ||
t.equals(book.spaced, ' . ! ? .') | ||
}) | ||
}) |
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
7770
163
66