npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ztextutils

v1.0.3

Published

A powerful text utility library for parsing, masking, and formatting text content. Parse URLs, hashtags, mentions, emails, markdown elements, and format phone numbers, dates, and more.

Downloads

677

Readme

TextUtils

A powerful text utility library for parsing, masking, and formatting text content. Parse URLs, hashtags, mentions, emails, markdown elements, and format phone numbers, dates, and more.

Features

  • 🔍 Parse and extract:
    • URLs (www., http:, https:, domain.com)
    • Hashtags (#example)
    • Mentions (@username)
    • Email addresses
    • Phone numbers
    • Markdown elements (links, headings, lists, emphasis)
  • 📞 Format and mask:
    • Phone numbers: (123) 456-7890
    • Dates: MM/DD/YYYY
    • Currency: $1,234.56
    • Custom masks
  • 📍 Position-aware matching
  • 🎯 Configurable parsing options
  • 🔗 Customizable URL generation
  • 📦 Zero dependencies
  • 💪 TypeScript-first

Installation

npm install ztextutils
# or
yarn add ztextutils
# or
pnpm add ztextutils

Usage

import { createTextUtils } from "ztextutils";

// Create a utils instance with specific options
const utils = createTextUtils({
  parser: {
    urls: true,
    hashtags: true,
    mentions: true,
    phones: true,
  },
});

// Process text with parsing and masking
const text = "Call 1234567890 or visit https://example.com! #support @sarah";
const result = utils.processText(text, {
  parse: {
    types: ["phones", "urls", "hashtags", "mentions"],
    baseUrls: {
      hashtags: "https://twitter.com/hashtag",
      mentions: "https://twitter.com",
    },
  },
  mask: {
    phones: true,
  },
});

console.log(result.matches);
/* Output:
[
  {
    type: 'phone',
    text: '1234567890',
    value: '(123) 456-7890',
    position: { start: 5, end: 15 },
    url: 'tel:1234567890'
  },
  {
    type: 'url',
    text: 'https://example.com',
    value: 'https://example.com',
    position: { start: 22, end: 40 },
    url: 'https://example.com'
  },
  {
    type: 'hashtag',
    text: '#support',
    value: 'support',
    position: { start: 42, end: 50 },
    url: 'https://twitter.com/hashtag/support'
  },
  {
    type: 'mention',
    text: '@sarah',
    value: 'sarah',
    position: { start: 51, end: 57 },
    url: 'https://twitter.com/sarah'
  }
]
*/

API

TextUtils

The main class combining parsing and masking functionality.

const utils = createTextUtils(options);

Options

type Options = {
  parser?: {
    urls?: boolean;
    hashtags?: boolean;
    mentions?: boolean;
    emails?: boolean;
    phones?: boolean;
    markdownLinks?: boolean;
    markdownHeadings?: boolean;
    markdownLists?: boolean;
    markdownEmphasis?: boolean;
    all?: boolean;
  };
  mask?: {
    mask?: string | string[];
    tokens?: Record<string, MaskToken>;
    placeholder?: string;
    autoClear?: boolean;
  };
};

Methods

Parsing
  • parse(text: string): Parse text and return all matches
  • parseMany(texts: string[]): Parse multiple strings
  • findLinkableElements(text: string, baseUrls?): Find all linkable elements with positions
  • extractUrls(text: string): Extract only URLs
  • extractMentions(text: string): Extract only mentions
  • extractHashtags(text: string): Extract only hashtags
  • extractPhones(text: string): Extract only phone numbers
Masking
  • mask(value: string, maskOpt: string | MaskOptions): Apply a mask to a value
  • formatPhoneNumber(phone: string): Format a phone number
  • formatDate(date: string): Format a date
  • formatCurrency(amount: string | number): Format currency
Combined
  • processText(text: string, options): Process text with both parsing and masking

Examples

Basic Parsing

const utils = createTextUtils();

// Parse URLs, hashtags, mentions, and emails
const result = utils.parse(
  "Email me@example.com or visit https://example.com #help"
);
console.log(result);

Formatting

const utils = createTextUtils();

console.log(utils.formatPhoneNumber("1234567890"));
// "(123) 456-7890"

console.log(utils.formatDate("12252023"));
// "12/25/2023"

console.log(utils.formatCurrency("1234.5"));
// "$1,234.50"

Combined Processing

const utils = createTextUtils();

const text = "Contact 1234567890 or email support@example.com";
const result = utils.processText(text, {
  parse: {
    types: ["phones", "emails"],
  },
  mask: {
    phones: true,
  },
});

console.log(result.matches);
// Includes formatted phone number and email with positions

Contributing

If you want a feature, make an issue or create a PR!

License

MIT - AKA I don't really care what you do with it, it's not anything fancy!

Changelog

  • 1.0.3: Fixed URL parsing to extract the full URL