textConvert
    Preparing search index...

    textConvert

    textConvert logo

    textConvert

    All Contributors GitHub package version GitHub license GitHub commit activity GitHub open issues npm version npm downloads Coverage Status CI Status Docs

    textConvert is a lightweight, dependency-free TypeScript library for text conversion, validation, and analysis — including redact(), which masks PII embedded in free-form text before it hits a log or a database.

    import { redact } from 'textconvert';

    redact('Contact me at jordan@example.com or 555-123-4567');
    // 'Contact me at jo**************** or 55**********'


    npm install textconvert
    
    // ES Module
    import * as convert from 'textconvert';
    // or CommonJS
    const convert = require('textconvert');

    • PII redaction: mask emails, phone numbers, credit card numbers, and (opt-in) API keys/tokens embedded in free-form text, or partially mask a known value for display
    • Case conversion: camelCase, PascalCase, snake_case, kebab-case, slugify, capitalize, Title Case
    • Validation: email addresses, URLs, and phone numbers
    • Extraction: pull email addresses and URLs out of a block of text
    • Text analysis: word/letter/sentence/paragraph counting, reading time, etc.
    • Text utilities: truncate with word-boundary awareness
    • Language detection: English, French, Spanish, German, Italian, Portuguese, Dutch
    • Number to words: Converts numbers < 100 million to English words
    • Pure, dependency-free, and TypeScript-ready

    • PII Redaction Built In: Mask emails and phone numbers embedded in free-form text — sanitize logs and user content without reaching for a full NLP-based PII detector or a paid API.
    • Lightweight & Dependency-Free: No external dependencies, fast and easy to use.
    • Comprehensive Text Utilities: Covers case conversion, text analysis, language detection, and more.
    • TypeScript Support: Fully typed for safe and productive development.
    • Modern API: Designed for clarity, performance, and extensibility.
    • Actively Maintained: Open to contributions and new features.

    Function Description
    camelCase(text) Convert to camelCase
    pascalCase(text) Convert to PascalCase
    snakeCase(text) Convert to snake_case
    kebabCase(text) Convert to kebab-case
    slugify(text) Convert to a URL-safe slug
    capitalize(text) Capitalize only the first letter
    titleCase(text) Capitalize the first letter of every word
    clear(text) Remove punctuation from text
    count(text, countNumbers?) Count letters (optionally including numbers)
    countWords(text) Count words
    countSentences(text) Count sentences
    reverse(text) Reverse a string
    spread(text, clear?) Split a string into an array of characters
    truncate(text, maxLength, options?) Shorten text to a max length, with an ellipsis
    maskText(text, options?) Partially mask a string for display
    redact(text, options?) Mask PII/secrets embedded in text
    getTextStats(text, wordsPerMinute?) Full text statistics (counts, averages, reading time)
    detectLanguage(text, minLength?, options?) Detect the language of a piece of text
    numbersToWords(number) Convert a number under 100 million to English words
    isEmail(text) Validate an email address
    isUrl(text) Validate a URL
    isPhoneNumber(text) Validate a phone number
    extractEmails(text) Extract all email addresses found in a block of text
    extractUrls(text) Extract all URLs found in a block of text

    See docs/API.md for full parameter, return type, and edge-case details on every function, or browse the auto-generated API reference site.


    import { redact, camelCase, count, isEmail, isUrl, isPhoneNumber } from 'textconvert';

    redact('Contact me at jordan@example.com or 555-123-4567');
    // 'Contact me at jo**************** or 55**********'
    camelCase('hello world'); // 'helloWorld'
    count('Hello, world!'); // 10
    isEmail('user@example.com'); // true
    isUrl('https://example.com/path?query=123'); // true
    isPhoneNumber('+1-202-555-0173'); // true

    See more usage examples in docs/RECIPES.md.


    // Detect language with options
    import { detectLanguage, Language } from 'textconvert';
    const result = detectLanguage('Hola mundo', 4, { maxCharsToAnalyze: 300 });
    if (result.language === Language.Spanish) {
    console.log('Spanish detected!');
    }

    // Get detailed text statistics
    const stats = convert.getTextStats('Hello world. This is a test.');
    console.log(stats.wordCount, stats.readingTimeFormatted);

    // Convert numbers to words
    console.log(convert.numbersToWords(987654));
    // "nine hundred eighty-seven thousand six hundred and fifty-four"

    Contributions are welcome! Please see CONTRIBUTING.md for guidelines and workflow.

    If you are adding a new function, follow the step-by-step instructions in docs/ADDING_FUNCTION.md.


    See CHANGELOG.md for release history and updates.


    This project is licensed under the MIT License.


    Nicolas Alkhoury
    Nicolas Alkhoury

    💬 🐛 💼 💻 🔣 🎨 📖 🤔 🚇 🚧 🧑‍🏫 📦 🔌 📆 🔬 👀 ⚠️ 🔧 📓
    Madesh
    Madesh

    💻 📖 💡 ⚠️
    Kuba
    Kuba

    💻 📖 💡

    This project follows the all-contributors specification. Contributions of any kind welcome!