word_count library
A comprehensive multi-language word counting library for Dart.
This library provides word counting functionality for 85+ languages including CJK (Chinese, Japanese, Korean), European, South Asian, African, and Middle Eastern languages. It supports configurable punctuation handling and provides multiple output formats.
Usage
Basic word counting:
import 'package:word_count/word_count.dart';
int count = wordsCount('Hello World'); // 2
List<String> words = wordsSplit('Hello World'); // ['Hello', 'World']
WordCountResult result = wordsDetect('Hello World'); // count: 2, words: ['Hello', 'World']
With configuration:
const config = WordCountConfig(punctuationAsBreaker: true);
wordsCount("don't", config); // 2
Classes
- WordCountConfig
- Configuration options for word counting behavior.
- WordCountResult
- Result object containing both word count and word array.
Constants
-
defaultPunctuation
→ const List<
String> - Default punctuation characters from multiple languages.
- emptyResult → const WordCountResult
- Predefined empty result for null or empty text inputs.
Functions
-
wordsCount(
String? text, [WordCountConfig config = const WordCountConfig()]) → int - Counts words in text and returns the count as an integer.
-
wordsDetect(
String? text, [WordCountConfig config = const WordCountConfig()]) → WordCountResult - Detects and counts words in text, returning both count and word array.
-
wordsSplit(
String? text, [WordCountConfig config = const WordCountConfig()]) → List< String> - Splits text into words and returns them as a list of strings.