Getting Started

@ppabari/strio is two things in one zero-dependency package:

  1. Secure generation โ€” cryptographically secure tokens, IDs, passphrases, and secrets (the main @ppabari/strio export).
  2. A string toolkit โ€” 60+ general-purpose string utilities (the @ppabari/strio/str subpath).

Install

npm install @ppabari/strio
# or
pnpm add @ppabari/strio
# or
yarn add @ppabari/strio

Secure generation

import {
  generateRandomString,
  generateId,
  generateExpiringToken,
  generatePassphrase,
  PRESETS,
} from '@ppabari/strio';

generateRandomString({ length: 32 });        // 32-char token
generateRandomString(PRESETS.TOKEN);          // named preset
generateId({ prefix: 'usr' });                 // โ†’ 'usr_K3xP9mQr2L4Xc'
generatePassphrase({ words: 4 });              // โ†’ 'stone-river-proud-flame'
const { token, expiresAt } = generateExpiringToken({ ttlSeconds: 900 });

See the Secure Generation reference for the full API.

String toolkit

Everything in the toolkit is a pure, tree-shakeable named export on the /str subpath:

import { slugify, camelize, truncate, pluralize } from '@ppabari/strio/str';

slugify('Hรฉllo, World!');   // โ†’ 'hello-world'
camelize('foo-bar_baz');    // โ†’ 'fooBarBaz'
truncate('The quick brown fox', 12); // โ†’ 'The quick bโ€ฆ'
pluralize('child');         // โ†’ 'children'

Because they are individual exports, bundlers only include the functions you actually use.

๐Ÿ”

The random, randomAlpha, randomNumeric, and randomAlphanumeric helpers in the toolkit are backed by the same secure Web-Crypto engine as the core library โ€” they are not Math.random.

Browse the toolkit by category starting at the API Overview.

CLI

npx @ppabari/strio --length 32
npx @ppabari/strio --preset TOKEN --count 5
npx @ppabari/strio --passphrase --words 5
npx @ppabari/strio --check          # runtime compatibility report
npx @ppabari/strio --help