Clean multiline TypeScript string literals by removing leading/trailing blank lines and stripping pipe prefixes.
npm install cleanstring-tsimport 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"const cleanstring = require('cleanstring-ts');The cleanstring() function processes multiline strings by:
- Removing leading blank lines - Any whitespace-only lines at the start are stripped
- Stripping prefixes - Lines with whitespace followed by a prefix character (default
|) have the prefix removed, preserving all content after the prefix - Removing trailing blank lines - Any whitespace-only lines at the end are stripped
- 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: '>' }).
import cleanstring from 'cleanstring-ts';
const sql = cleanstring(`
|SELECT *
|FROM users
|WHERE active = true
`);
// Result: "SELECT *\nFROM users\nWHERE active = true"// Markdown quotes with > prefix
const quote = cleanstring(`
>This is a quote
>from someone famous
`, { prefix: '>' });
// Result: "This is a quote\nfrom someone famous"// 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"const script = cleanstring(`
|#!/bin/bash
|
|echo "Hello World"
|exit 0
`);
// Result: "#!/bin/bash\n\necho \"Hello World\"\nexit 0"Note that leading/trailing blank lines are still stripped.
const text = cleanstring(`
This is a multiline string
with some content
`);
// Result: " This is a multiline string\n with some content"Instructions for working on the library...
# Run tests
npm test
# Run linting and formatting checks
npm run ci
# Build the project
npm run build
# Format code
npm run formatReleases are automated via GitHub Actions. Only the repository owner can create releases.
-
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)
- Generate SSH key pair:
-
Add Repository Secrets:
- Go to repository → Settings → Secrets and variables → Actions
- Add
DEPLOY_KEYwith contents of private key file (release_key) - Add
NPM_TOKENwith your npm automation token
- Go to your repository on GitHub
- Navigate to Actions tab
- Click on "Release" workflow in the left sidebar
- Click "Run workflow" button
- 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)
- Click "Run workflow" to start the release process
The automated release process:
- Runs all CI checks (lint, test, build)
- Updates package.json version
- Commits and pushes to main (bypasses branch protection)
- Creates and pushes git tag
- Creates GitHub release
- Automatically publishes to npm (triggered by release creation)
MIT License - see LICENSE file for details.