├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.swo 2 | *.swp 3 | /node_modules 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.10 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Mic Network, Inc 2 | 3 | This software is released under the MIT license: 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## SYNOPSIS 2 | Counts words in HTML body. 3 | 4 | [![Build Status](https://travis-ci.org/micnews/html-word-count.svg)](https://travis-ci.org/micnews/html-word-count) 5 | 6 | ## USAGE 7 | 8 | ```js 9 | var wordCount = require('html-word-count'); 10 | wordCount('

Hello world!

'); // 2 11 | ``` 12 | 13 | ##LICENSE 14 | 15 | MIT 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var htmlToText = require('html-to-text'); 2 | var wordCount = require('wordcount'); 3 | 4 | module.exports = function (body) { 5 | var text = htmlToText.fromString(body, { 6 | wordwrap: false, 7 | ignoreImage: true, 8 | ignoreHref: true 9 | }); 10 | 11 | return wordCount(text); 12 | }; 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "html-word-count", 3 | "version": "2.0.0", 4 | "description": "Count words in HTML document", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "tape test.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/micnews/html-word-count.git" 12 | }, 13 | "author": "Mic Network, Inc", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/micnews/html-word-count/issues" 17 | }, 18 | "homepage": "https://github.com/micnews/html-word-count", 19 | "devDependencies": { 20 | "tape": "^4.0.0" 21 | }, 22 | "dependencies": { 23 | "html-to-text": "^3.2.0", 24 | "wordcount": "^1.1.1" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var wordCount = require('./'); 3 | 4 | test('simple', function (t) { 5 | t.equal(wordCount('

Hello world!

'), 2); 6 | t.end(); 7 | }); 8 | 9 | test('should include link text', function (t) { 10 | t.equal(wordCount('

Hello world!

'), 2); 11 | t.end(); 12 | }); 13 | 14 | test('should ignore attributes', function (t) { 15 | t.equal(wordCount('Text 1 2 3'), 4); 16 | t.end(); 17 | }); 18 | 19 | test('should ignore images', function (t) { 20 | t.equal(wordCount('Some textHello'), 1); 21 | t.end(); 22 | }); 23 | 24 | test('should correctly count words', function (t) { 25 | t.equal(wordCount('Hello!!!! Comma, question?!'), 3); 26 | t.end(); 27 | }); 28 | --------------------------------------------------------------------------------