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

cleanstring-ts

v1.1.7

Published

Clean multiline TypeScript string literals

Downloads

3,616

Readme

cleanstring-ts

npm version

Clean multiline TypeScript string literals by removing leading/trailing blank lines and stripping pipe prefixes.

Installation

npm install cleanstring-ts

Usage

import cleanstring from 'cleanstring-ts';

const result = cleanstring(`
    |Any literal
    |which needs to be split
    |on multiple lines for readability.
`);
// Result: "Any literal\nwhich needs to be split\non multiple lines for readability."

// Custom prefix example
const markdown = cleanstring(
  `
    >This is a markdown quote
    >with multiple lines
`,
  { prefix: '>' },
);
// Result: "This is a markdown quote\nwith multiple lines"

// Custom prefix with trailing space example (note the prefix contains a space)
const markdown = cleanstring(
  `
    > This is a markdown quote
    > with multiple lines
`,
  { prefix: '> ' },
);
// Result: "This is a markdown quote\nwith multiple lines"

CommonJS

const cleanstring = require('cleanstring-ts');

How it works

The cleanstring() function processes multiline strings by:

  1. Removing leading blank lines - Any whitespace-only lines at the start are stripped
  2. Stripping prefixes - Lines with whitespace followed by a prefix character (default |) have the prefix removed, preserving all content after the prefix
  3. Removing trailing blank lines - Any whitespace-only lines at the end are stripped
  4. Preserving internal structure - Whitespace lines between content are maintained

Important: Content after the prefix is preserved exactly as-is. If you want to strip a space after the prefix, include the space as part of the prefix (e.g., { prefix: '> ' } instead of { prefix: '>' }).

Examples

Basic usage with pipe prefix (default)

import cleanstring from 'cleanstring-ts';

const sql = cleanstring(`
    |SELECT *
    |FROM users
    |WHERE active = true
`);
// Result: "SELECT *\nFROM users\nWHERE active = true"

Custom prefix characters

// Markdown quotes with > prefix
const quote = cleanstring(
  `
    > This is a quote
    > from someone famous
`,
  { prefix: '>' },
);
// Result: " This is a quote\n from someone famous"

// Shell comments with # prefix
const script = cleanstring(
  `
    # This is a shell script
    # with multiple comment lines
`,
  { prefix: '#' },
);
// Result: " This is a shell script\n with multiple comment lines"

// List items with * prefix
const list = cleanstring(
  `
    * First item
    * Second item
    * Third item
`,
  { prefix: '*' },
);
// Result: " First item\n Second item\n Third item"

Multi-character prefixes for space stripping

If you want to strip a space after the prefix (reproducing the old behavior), include the space as part of the prefix:

// Using "> " (greater than + space) strips the space after >
const cleanQuote = cleanstring(
  `
    > This is a quote
    > with multiple lines
`,
  { prefix: '> ' },
);
// Result: "This is a quote\nwith multiple lines"

// Using "| " (pipe + space) strips the space after |
const cleanCode = cleanstring(
  `
    | function example() {
    |   return 'hello world';
    | }
`,
  { prefix: '| ' },
);
// Result: "function example() {\n  return 'hello world';\n}"

Mixed content with prefix

const script = cleanstring(`
    |#!/bin/bash
    |
    |echo "Hello World"
    |exit 0
`);
// Result: "#!/bin/bash\n\necho \"Hello World\"\nexit 0"

Without prefixes

const text = cleanstring(`

    This is a multiline string
    with some content

`);
// Result: "    This is a multiline string\n    with some content"

Development

Common commands

# Run tests
npm test

# Run linting and formatting checks
npm run ci

# Build the project
npm run build

# Format code
npm run format

Releases

Releases are automated via GitHub Actions. Only the repository owner can create releases.

Prerequisites (one-time setup)

  1. Create Deploy Key with Write Access:

    • Generate SSH key pair: ssh-keygen -t ed25519 -f release_key -N ""
    • Go to repository → Settings → Deploy keys
    • Click "Add deploy key"
    • Title: "Release Automation"
    • Key: Contents of release_key.pub
    • ✅ Check "Allow write access"
    • Configure to bypass repository rules (Settings → Rules)
  2. Add Repository Secrets:

    • Go to repository → Settings → Secrets and variables → Actions
    • Add DEPLOY_KEY with contents of private key file (release_key)
    • Add NPM_TOKEN with your npm automation token

Creating a Release

  1. Go to your repository on GitHub
  2. Navigate to Actions tab
  3. Click on "Release" workflow in the left sidebar
  4. Click "Run workflow" button
  5. Select the version bump type from the dropdown:
    • patch: 1.0.0 → 1.0.1 (bug fixes)
    • minor: 1.0.0 → 1.1.0 (new features)
    • major: 1.0.0 → 2.0.0 (breaking changes)
  6. Click "Run workflow" to start the release process

The automated release process:

  1. Runs all CI checks (lint, test, build)
  2. Updates package.json version
  3. Commits and pushes to main (bypasses branch protection)
  4. Creates and pushes git tag
  5. Creates GitHub release
  6. Automatically publishes to npm (triggered by release creation)

License

MIT License - see LICENSE file for details.