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

@motiro/string

v0.1.3

Published

Fast, tree-shakeable string helpers — case conversion, trimming, padding, slugify, templating and more. Part of the Motiro utility toolkit.

Downloads

422

Readme

@motiro/string

Fast, tree-shakeable string helpers — case conversion, trimming, padding, slugify, templating and more. Part of the Motiro utility toolkit.

npm version license

A focused set of string utilities: seventeen case converters, HTML-aware truncation, plain-text excerpts, {{ template }} interpolation, URL slugify with locale support, human-readable duration formatting, and more. Everything is ESM-only, side-effect free, and fully tree-shakeable.

Features

  • 🔤 Rich case conversion — camel, pascal, kebab, snake, constant, title, sentence, train, cobol, ada, path, dot-notation, and more.
  • ✂️ Smart truncationtruncate preserves and re-closes HTML tags; excerpt strips them for plain text.
  • 🧬 Templatinginterpolate resolves {{ nested.keys }} with escaping and custom delimiters.
  • 🔗 Slugify — transliterates non-ASCII to URL-safe slugs, with per-locale overrides and an extendable charset.
  • ⏱️ Durations — parse and format between milliseconds/seconds and human strings ('1h', '1 hour').
  • 🌳 Tree-shakeable — import only what you use; zero dependencies.

Installation

# bun
bun add @motiro/string

# npm
npm install @motiro/string

# pnpm
pnpm add @motiro/string

# yarn
yarn add @motiro/string

Usage

import { toCamelCase, slug, truncate, interpolate, fromMilliseconds } from '@motiro/string';

toCamelCase('hello world'); // => 'helloWorld'

slug('Olá, coração', { locale: 'pt' }); // => 'ola-coracao'

truncate('<p>Hello <em>friend</em></p>', 10);
// => '<p>Hello <em>frie...</em></p>'

interpolate('hello {{ user.name }}', { user: { name: 'John' } });
// => 'hello John'

fromMilliseconds(3600000, true); // => '1 hour'

API

Capitalization

| Function | Description | | --- | --- | | capitalize(input) | Uppercases the first character, leaving the rest unchanged. Preserves the literal type as Capitalize<T>. |

Case conversion

All converters accept an optional CaseOptions ({ keep?: string[]; strict?: boolean }) unless noted.

| Function | Example ('hello world') | | --- | --- | | toCamelCase | helloWorld | | toPascalCase | HelloWorld | | toKebabCase | hello-world | | toSnakeCase | hello_world | | toSpaceCase | hello world | | toDotNotationCase | hello.world | | toConstantCase | HELLO_WORLD | | toTrainCase | Hello-World | | toAdaCase | Hello_World | | toCobolCase | HELLO-WORLD | | toPathCase | hello/world | | toCapitalCase | Hello World | | toLowerCase | hello world | | toUpperCase | HELLO WORLD | | toTitleCase | Hello World (English title rules; no options) | | toSentenceCase | Hello world (no options) | | toNoCase | hello world (no options) |

Truncation & excerpts

| Function | Description | | --- | --- | | truncate(input, length, options?) | Truncates to length visible characters, preserving HTML tags and re-closing any left open. | | excerpt(input, length, options?) | Strips HTML first, then cuts by characters (or words with { words: true }). |

TruncateOptions: { strict?: boolean; ellipsis?: string } — defaults strict: true, ellipsis: '...'. ExcerptOptions: { strict?: boolean; ellipsis?: string; words?: boolean } — defaults strict: false, ellipsis: '...', words: false.

Templating

| Function | Description | | --- | --- | | interpolate(input, data, options?) | Replaces {{ key }} placeholders with values from data. Supports nested dot paths ({{ user.name }}, {{ items.0 }}), \{{ escaped }} placeholders, and custom delimiters. |

InterpolateOptions: { fallback?: (key: string) => string; delimiters?: [open, close] } — defaults to an empty-string fallback and ['{{', '}}'].

Slugify

| Member | Description | | --- | --- | | slug(input, options?) | Converts a string to a URL-friendly slug, transliterating non-ASCII characters. | | slug.create(options?) | Returns a new slug function pre-configured with default options. | | slug.extend(charset) | Extends the shared transliteration charset with custom entries. |

SlugOptions: { trim?: boolean; lower?: boolean; strict?: boolean; remove?: RegExp; locale?: Locale; separator?: string }. Supported locales: bg, es, fr, it, de, nl, pt, sv, uk, vi, da, nb.

slug('Hello, World!'); // => 'hello-world!'
slug('Hello, World!', { strict: true }); // => 'hello-world'

const upperSlug = slug.create({ lower: false, separator: '_' });
upperSlug('Hello World'); // => 'Hello_World'

Durations

| Function | Description | | --- | --- | | fromMilliseconds(input, long?) | Formats milliseconds as '1h' (or '1 hour' when long is true). | | fromSeconds(input, long?) | Formats seconds as a human-readable duration. | | toMilliseconds(input) | Parses a duration (number or string like '1h' / '2 hours') into milliseconds. Throws TypeError on invalid strings. | | toSeconds(input) | Parses a duration into whole seconds (floored). Throws TypeError on invalid strings. |

Miscellaneous

| Function | Description | | --- | --- | | random(length, alphabet?) | Generates a random string. Not cryptographically secure — uses Math.random(); use for non-sensitive values only. | | sentence(input, options?) | Joins an array into a human-readable, Oxford-comma sentence ('a, b, and c'). |

SentenceOptions: { separator?: string; pairSeparator?: string; lastSeparator?: string }.

Exported types

import type {
  CaseOptions,
  DurationUnit,
  DurationUnitAnyCase,
  PrettyDuration,
  ExcerptOptions,
  InterpolateOptions,
  SentenceOptions,
  Slug,
  SlugBuilder,
  SlugOptions,
  TruncateOptions,
} from '@motiro/string';

License

MIT © meluiz