Skip to main content

Built and signed on GitHub Actions

string utilities such as Utf8StringBuilder, StringBuilder, case insensitive comparisons, trim methods that allow other characters, whitespace check.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
76%
Published
6 months ago (0.3.0)

@gnome/strings

logo Work less. Do more.

Overview

The strings module provides case insenstive methods like equalsIgnoreCase, includesIgnoreCase, indexOfIgnoreCase, startsWithIgnoreCase, and endsWithIgnoreCase to avoid using string allocation by using comparisons with toLowerCase/toUpperCase.

A Utf8StringBuilder and StringBuilder classes are included to avoid uness unnecessary allocations for building text.

Trim methods that take other characters than whitespace for trimming a string.

Basic Usage

import * from str from '@gnome/strings'

console.log(str.equalIgnoreCase("left", "LeFT")); // true
console.log(str.trimEnd("my random text...", ".")); // my random text
console.log(str.underscore("first-place")); // first_place

// useful for FFI
var sb = new str.Utf8StringBuilder()
sb.append("test")
   .append(new TextEncoder().encode(": another test"));

// faster
sb.appendString("test")
  .appendUtf8Array(new TextEncoder().encode(": another test"))

console.log(sb.toString())

LICENSE

MIT License and additional MIT License for the inflection code, see License for details.

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@gnome/strings

Import symbol

import * as strings from "@gnome/strings";

---- OR ----

Import directly with a jsr specifier

import * as strings from "jsr:@gnome/strings";

Add Package

npx jsr add @gnome/strings

Import symbol

import * as strings from "@gnome/strings";

Add Package

yarn dlx jsr add @gnome/strings

Import symbol

import * as strings from "@gnome/strings";

Add Package

pnpm dlx jsr add @gnome/strings

Import symbol

import * as strings from "@gnome/strings";

Add Package

bunx jsr add @gnome/strings

Import symbol

import * as strings from "@gnome/strings";