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 🙏

© 2026 – Pkg Stats / Ryan Hefner

string-range-tokens

v1.0.0

Published

Turn strings into per-letter token arrays and rebuild words, paths and URLs from index ranges. JS and TypeScript, zero dependencies.

Readme

srTokens

npm package: string-range-tokens

Turn any string into a letter-per-index token array, then rebuild words, paths or URLs from index ranges.

Zero dependencies, plain ESM, works in Node 18+ and the browser. Ships a JavaScript implementation, a TypeScript implementation and type definitions.

Install

npm i string-range-tokens

Or copy src/index.js (or src/index.ts) into your project. No build step.

JavaScript and TypeScript

// JavaScript (types come for free via index.d.ts)
import { toTokens, sub } from 'string-range-tokens';
// TypeScript
import { toTokens, sub, type Range } from 'string-range-tokens';

const ranges: Range[] = [[26, 31]];
sub(toTokens('https://api.example.com/v1/users'), 23, 25, ...ranges);

The TypeScript source lives in src/index.ts and is also exported as string-range-tokens/ts for runtimes that run TS directly (Deno, Bun, Node with type stripping).

CDN: jsdelivr

  import { toTokens, sub, build, plan, scatter, gather } from 'https://cdn.jsdelivr.net/npm/[email protected]/src/index.js';

Usage

import { toTokens, sub, build, plan, scatter, gather } from 'string-range-tokens';

const t = toTokens('https://api.example.com/v1/users');

sub(t, 0, 4);                 // "https"
sub(t, 23, 25, [26, 31]);     // "/v1/users"
sub(t, -5, -1);               // "users"
build(t, [0, 4], [23, 25]);   // "https/v1"

API

| Function | What it does | | --- | --- | | toTokens(str) | String to array of single characters (unicode safe) | | sub(tokens, start, end, ...[s, e]) | Join inclusive ranges. Negative indexes count from the end. [i] picks one token | | build(tokens, ...[s, e]) | Same, ranges only. No ranges returns the whole string | | plan(tokens, target) | Finds ranges that rebuild target from the tokens | | scatter(str, seed) | Seeded shuffle, returns { pool, key } | | gather(pool, key) | Rebuilds the string from scatter output |

Build a word from a pool of letters

const pool = toTokens('the quick brown fox');
const ranges = plan(pool, 'brew');
build(pool, ...ranges); // "brew"

Scatter and gather

const { pool, key } = scatter('/api/orders', 7);
gather(pool, key); // "/api/orders"

Use cases

  • Assemble API paths and keys from shared token pools
  • Pick substrings by position without regex
  • Tiny string templating from a fixed alphabet
  • Teaching and puzzles around indexing and recursion

Security note

This is string assembly, not encryption. Anything shipped to a browser can be read by the user. Never hide real secrets or API keys with it. Keep them server side (Netlify Functions, Workers, etc).

Test

npm test

Contributing

See CONTRIBUTING.md.

License

MIT, see LICENSE.