Skip to main content

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

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
3 weeks ago (0.1.0)

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 class is included to avoid allocations for building text.

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

Inflections are included from github.com/dreamerslab/node.inflection under the MIT.

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())
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @gnome/strings

Import symbol

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

Add Package

npx jsr add @gnome/strings

Import symbol

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

Add Package

yarn dlx jsr add @gnome/strings

Import symbol

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

Add Package

pnpm dlx jsr add @gnome/strings

Import symbol

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

Add Package

bunx jsr add @gnome/strings

Import symbol

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