Skip to content

🧐 Precisely count words

License

Notifications You must be signed in to change notification settings

UltiRequiem/count_words

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Count Words

Code Coverage Deno Doc

A lightweight JavaScript/TypeScript library to count words in a string. It handles multiple consecutive spaces correctly and is Unicode-aware.

Features

  • ✨ Simple and intuitive API
  • πŸš€ Fast and efficient word counting
  • πŸ”§ Handles multiple consecutive spaces
  • 🌍 Unicode-aware
  • πŸ“¦ Works with Deno, Node.js, and browsers
  • 🎯 Zero dependencies

Quick Start

import { countWords } from "https://deno.land/x/count_words/mod.ts";

console.log(countWords("Hello World")); // 2
console.log(countWords("The quick brown fox")); // 4
import { countWords } from "count-n-words";

console.log(countWords("Hello World")); // 2
console.log(countWords("The quick brown fox")); // 4

You can use any CDN πŸ”₯

<script type="module">
  import { countWords } from "https://cdn.skypack.dev/count-n-words";

  console.log(countWords("Hello World")); // 2
</script>

Other CDN options:

API Reference

countWords(text: string, separator?: string): number

Counts the number of words in a string.

Parameters

  • text (string): The text to count words in
  • separator (string, optional): The separator between words. Defaults to " " (space)

Returns

  • (number): The number of words found in the text

Examples

// Basic usage
countWords("Hello World"); // 2
countWords("Hey, my name is Eliaz."); // 5

// Handles multiple spaces
countWords("Hello        World"); // 2
countWords("  Hey  "); // 1

// Empty strings
countWords(""); // 0
countWords("   "); // 0

// Custom separator
countWords("apple,banana,orange", ","); // 3

Documentation

Full API documentation is hosted on Deno Doc πŸ“„

Support

Open an Issue, I will check it a soon as possible πŸ‘€

If you want to hurry me up a bit send me a tweet πŸ˜†

Consider supporting me on Patreon if you like my work πŸ™

Don't forget to start the repo ⭐

Authors

Eliaz Bobadilla - Creator and Maintainer πŸ’ͺ

See also the full list of contributors who participated in this project ✨

Versioning

We use Semantic Versioning. For the versions available, see the tags 🏷️

Licence

Licensed under the MIT License πŸ“„

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •