Giter Club home page Giter Club logo

words-count's Introduction

Words Count

Words count for multi-languages paragraph mixed with numbers and punctuation.
One rule apply to all.

See Test Case

Install

npm i words-count

Example

import wordsCount from 'words-count';
// const wordsCount = require('words-count').default;  

console.log(wordsCount('Hello World'));  

Why use this

words_to_be_count = 'Hello “世界”';
words-count.js -> 3

words_to_be_count.length -> 10
words_to_be_count.split(' ').length -> 2
Countable.js -> 2
PHP str_word_count(words_to_be_count) -> 1
PHP mb_strlen(words_to_be_count) -> 10
Office Word -> 5

Special Rule

Numbers count as 1 word

Configs

const words = "Some words ...";

// Treat punctuation as word breaker
const total = wordsCount(words, {    
  punctuationAsBreaker: true
});

// Treat more characters as punctuation
const total = wordsCount(words, {    
  punctuation: ['-', 'a', 'b']
});

// Disable default built-in punctuation list
const total = wordsCount(words, {    
  disableDefaultPunctuation: true
});

Words Split

const words = "Some words ...";
const { wordsSplit, wordsDetect } = require('words-count');  

const splittedWords = wordsSplit(words);
const { words, count } = wordsDetect(words);

Test Case

Test cases are based on best assumption.
Original Content:
Google's free service instantly translates words, phrases, and web pages between English and over 100 other languages.
Basic Test Content:
Translate original content into target language by Google Translate.
Test Case Coverage:
English, Chinese, Chinese-Traditional, Japanese, Korean, French, German,
Italian, Spanish, Portuguese, Russian, Ukrainian, Arabic, Hebrew, Afrikaans,
Albanian, Amharic, Armenian, Azerbaijani, Basque, Belarusian, Bengali,
Bulgarian, Bosnian, Catalan, Cebuano, Croatian, Chichewa, Corsican, Czech,
Danish, Dutch, Esperanto, Estonian, Filipino, Finnish, Frisian, Greek, Galician,
Georgian, Gujarati, Haitian Creole, Hausa, Hindi, Hmong, Hungarian, Icelandic,
Igbo, Indonesian, Irish, Javanese, Kannada, Kazakh, Kurdish, Kyrgyz, Latin,
Latvian, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam,
Nepali, Norwegian, Polish, Romanian, Serbian, Slovenian, Swedish, Turkish, Welsh
Zulu, Maori, Marathi, Mongolian, Pashto, Persian, Punjabi, Scots Gaelic, Sesotho,
Shona, Sindhi, Sinhala, Slovak, Somali, Sundanese, Swahili, Tajik, Turkish,
Urdu, uzbek, Vietnamese, Xhosa, Yiddish, Yoruba
Failed/Unknown: Hawalian, Khmer, Lao, Maltese, Myanmar, Tamil, Thai

Reference

http://php.net/manual/en/function.str-word-count.php#109733
https://www.key-shortcut.com/en/writing-systems/%E6%96%87%E5%AD%97-chinese-cjk/cjk-characters-1/ http://jrgraphix.net/r/Unicode/0D00-0D7F

words-count's People

Contributors

adam1658 avatar byn9826 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

words-count's Issues

Combined numbers and words should not be count as 2 words

For cases like "word1" or "Should be2words" they are showing count that's not following my instincts (I know my instincts doesn't mean anything, but I really found it strange)

"word1" should consider 1 word only, but it returns me 2.

"Should be2words" should be consider 2 words, but it returns me 4.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.