Aerostack
edit

text-word-count Edge Function — Content

Content

Counts words, unique words, characters, and sentences in a text string. Handles edge cases like empty text, whitespace, and punctuation.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function text-word-count Counts words, unique words, characters, and sentences in a text string. Handles edge cases like empty text, whitespace, and punctuation.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/text-word-count
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "text-word-count",
  args: {
    "text": "example_text",
    "countUnique": true
  }
})

text-word-count

Counts words, unique words, characters, and sentences in a text string. Handles edge cases like empty text, whitespace-only input, and punctuation-only tokens. Zero external dependencies.

Install

aerostack function add text-word-count

Usage

import { wordCount } from './functions/text-word-count';

// Basic word count
const result = wordCount({ text: 'Hello world. How are you?' });
// { success: true, data: { words: 5, unique: 5, characters: 25, charactersNoSpaces: 21, sentences: 2 } }

// Disable unique word counting
const simple = wordCount({ text: 'Hello hello world', countUnique: false });
// { success: true, data: { words: 3, unique: 0, ... } }

API

POST /api/text-word-count

Request

{
  "text": "The quick brown fox jumps over the lazy dog.",
  "countUnique": true
}

Response

{
  "success": true,
  "data": {
    "words": 9,
    "unique": 8,
    "characters": 44,
    "charactersNoSpaces": 35,
    "sentences": 1
  }
}
Field Type Required Default
text string Yes --
countUnique boolean No true

Output Fields

Field Description
words Total number of words
unique Unique words (case-insensitive). 0 if countUnique is false
characters Total characters including spaces
charactersNoSpaces Total characters excluding spaces
sentences Sentences delimited by . ! ?

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

text
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Content Functions

Browse Content Functions →

Frequently asked questions

What does the text-word-count function do? +

text-word-count is a serverless edge function for content automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the text-word-count function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/text-word-count ``` It will be live on Cloudflare Workers in seconds.

What runtime does text-word-count use? +

text-word-count runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the text-word-count function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.