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

@bearz/slices

v0.1.1

Published

Cross runtime module for slices and char slices which creates views over arrays without allocating a new array. Char slices is useful for transforming text without allocating a new string for every change.

Readme

@bearz/slices

Overview

Slices enable working with slices of an array without resizing or creating new arrays in most cases. Instead, new slices are created that that allows one to work with a segment of the array.

They are not as effecient as go's slice or .NET's Span<T>, but they do provide some benefits for dealing with smaller segments of arrays or character slices.

The CharSlice and ReadOnlyCharSlice are specialized slice types for working with string characters in their uint32 codepoint format and provide string like methods such as trim, indexof, toUpper, toLower, includes, and more without the need to convert them back into strings to perform those operations.

The CharSlice and ReadOnlyCharSlice allow you to work with strings without allocating multiple copies of immuatable strings and allow you to make multiple transforms before converting back to a string.

The case insensitive formats of methods end with "Fold" which are based upon go's SimpleFold and EqualFold methods. For example: equalFold, startsWithFold, endsWithFold, indexOfFold perform case insensitive comparisons over strings or CharSliceLike objects such as CharSlice or Uint32Arrays.

logo

JSR npm version GitHub version

Documentation

Documentation is available on jsr.io

A list of other modules can be found at github.com/bearz-io/js

Usage

import * from slices from '@bearz/slices'

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


var sb = new slices.CharArrayBuilder()
sb.append("test")
   .append(new TextEncoder().encode(": another test"));

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

console.log(sb.toString())

const slice = new slices.Slice([0, 3, 4], 1);
console.log(slice.at(0)); // 3
console.log(slice.length); // 2

Classes

  • CharArrayBuilder - A builder for character arrays.
  • CharSlice - A slice of characters.
  • ReadOnlySlice - A readonly slice of characters.
  • Slice - A slice of an array, which doesn't create a new array but acts as a view over the array.
  • `ReadOnlySlice - A readonly slice of an array.

Functions

  • camelize - converts a word to camel case.
  • capitalize - capitalizes a word.
  • dasherize - converts a word to hyphen/dash case.
  • endsWith - determines if a string or char array ends with characters.
  • endsWithFold - determines if a string or char array ends with characters using case insensitivity.
  • equalFold - determines if a string or char array with characeters.
  • equal - determines if a string or char array with characters.
  • indexOfFold - determines the index of a character or char array using case insensitivity.
  • indexOf - determines the index of of a character or char array.
  • lastIndexOfFolder - determines the last index of a character or char array using case insensitivity.
  • lastIndex - determines the last index of a character or char array.
  • ordinalize - converts word/number to the ordinal case.
  • pascalize - converts a word to pascal case.
  • startsWith - determines if a string or char array starts with another char array.
  • startsWithFold - determines if a string or char array starts with another char array using case insensitivity.
  • titleize - converts characters into title case.
  • trim - trims the specified characters from the start and end of a char array. defaults to whitespace.
  • trimStart - trims the specified characters from the start of a char array. defaults to whitespace.
  • trimEnd - trims the specified characters from the end of a char array. defaults to whitespace.
  • toCharArray - converts a string to in array of characters/runes represented by a number.
  • toString - converts an array of characters into a string.

License

MIT License