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

txt-util

v0.0.1

Published

A text utility library

Downloads

74

Readme

Text Util

A utility library for various text and HTML document processing tasks.

Installation

To install the library, use npm:

npm install text-util

API

analyzeText(text)

Analyzes the given text and returns various statistics about it.

Parameters:

  • text (string): The text to analyze.

Returns:

  • An object containing the following properties:
    • spaceCount
    • fullStopCount
    • semicolonCount
    • squareBracketCount
    • colonCount
    • doubleQuoteCount
    • curlyBracketCount
    • otherPunctuationCount
    • spaceToFullStopRatio
    • spaceToParenthesesRatio
    • fullStopSpaceToFullStopRatio
    • squareBracketToCharactersRatio
    • curlyBracketToCharactersRatio
    • colonToCharactersRatio
    • doubleQuoteToSpaceRatio

simple_ratio_analyse_text(text)

Alias for analyzeText.

indicate_is_computer_language(text)

Determines if the given text is likely to be computer code.

Parameters:

  • text (string): The text to analyze.

Returns:

  • true if the text is likely to be computer code, false otherwise.

get_html_document_text_nodes(html, downloaded_url_id, filter, do_trim_white_space = true)

Extracts text nodes from an HTML document.

Parameters:

  • html (string): The HTML document.
  • downloaded_url_id (number): The ID of the downloaded URL.
  • filter (function): A filter function to apply to the nodes.
  • do_trim_white_space (boolean): Whether to trim white space from the text nodes.

Returns:

  • An array of text nodes.

get_html_document_a_elements(html_document, downloaded_url_id)

Extracts <a> elements from an HTML document.

Parameters:

  • html_document (string): The HTML document.
  • downloaded_url_id (number): The ID of the downloaded URL.

Returns:

  • An array of <a> elements.

iterate_html_document_nodes(html)

Iterates over the nodes of an HTML document.

Parameters:

  • html (string): The HTML document.

Yields:

  • Each node in the document.

join_url_parts(...a)

Joins URL parts into a single URL.

Parameters:

  • ...a (string[]): The URL parts to join.

Returns:

  • The joined URL.

normalise_linked_url(page_url, linked_url, archive_url)

Normalizes a linked URL based on the page URL and archive URL.

Parameters:

  • page_url (string): The page URL.
  • linked_url (string): The linked URL.
  • archive_url (string): The archive URL.

Returns:

  • The normalized URL.

get_scheme_based_authority(url)

Gets the scheme-based authority of a URL.

Parameters:

  • url (string): The URL.

Returns:

  • The scheme-based authority.

is_simple_url(url)

Determines if a URL is simple.

Parameters:

  • url (string): The URL to check.

Returns:

  • true if the URL is simple, false otherwise.

get_string_byte_length(str)

Gets the byte length of a string.

Parameters:

  • str (string): The string.

Returns:

  • The byte length of the string.

compress_sync(inputString, level = 10)

Compresses a string using Brotli compression.

Parameters:

  • inputString (string): The string to compress.
  • level (number): The compression level (default is 10).

Returns:

  • The compressed buffer.

decompress_sync(buf)

Decompresses a Brotli-compressed buffer.

Parameters:

  • buf (Buffer): The compressed buffer.

Returns:

  • The decompressed string.

calc_hash_256bit(value)

Calculates a 256-bit hash of a value.

Parameters:

  • value (string): The value to hash.

Returns:

  • The hash as a buffer.

count_whitespace(str)

Counts the number of whitespace characters in a string.

Parameters:

  • str (string): The string.

Returns:

  • The number of whitespace characters.

get_char_info(str)

Gets information about the first character in a string.

Parameters:

  • str (string): The string.

Returns:

  • An object containing information about the character.

lazy_lookup_get_char_info(character)

Gets information about a Unicode character using lazy lookup.

Parameters:

  • character (string): The Unicode character.

Returns:

  • An object containing information about the character.

fn_tn_filter(tn)

Filters text nodes based on their parent element.

Parameters:

  • tn (object): The text node.

Returns:

  • true if the text node passes the filter, false otherwise.

get_url_domain(url)

Gets the domain of a URL.

Parameters:

  • url (string): The URL.

Returns:

  • The domain of the URL.

remake_html(str_html)

Remakes an HTML document.

Parameters:

  • str_html (string): The HTML document.

Returns:

  • The remade HTML document.

remake_trim_html(str_html)

Remakes an HTML document by trimming text nodes.

Parameters:

  • str_html (string): The HTML document.

Returns:

  • The remade HTML document.

remake_html_to_els_structure(str_html)

Remakes an HTML document to an elements structure.

Parameters:

  • str_html (string): The HTML document.

Returns:

  • The remade HTML document.

count_character_types(str)

Counts the types of characters in a string.

Parameters:

  • str (string): The string.

Returns:

  • An object containing the counts of different character types.

iterate_chars(str)

Iterates over the characters of a string.

Parameters:

  • str (string): The string.

Yields:

  • Each character in the string.

iterate_string_chars_info(text)

Iterates over the characters of a string and provides information about each character.

Parameters:

  • text (string): The string.

Yields:

  • An object containing information about each character.

iterate_char_type_groups_tokenize_string(str)

Iterates over character type groups and tokenizes a string.

Parameters:

  • str (string): The string.

Yields:

  • An object representing each token.