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

@yuhere/js-strings

v1.0.5

Published

utility library aimed at providing common helper functions for strings in JavaScript/TypeScript projects.

Readme

String Utilities

A utility library aimed at providing common language-level helper functions (strings, dates, vars, etc.) in JavaScript/TypeScript projects.

Installation

Install the package via npm:

npm install @yuhere/js-strings

Usage

Import the functions you need from the library:

import {
    s_pad,
    s_left,
    s_right,
    s_ellipsis,
    s_ellipsis_o,
    s_xprint_extract_fmt,
    s_xprint_fmts,
    s_xprint,
    s_glob
} from '@yuhere/js-strings';

String Utilities

s_pad

Pad a string to a fixed width.

  • which: padding direction, supports 'l', 'r', 'c'
  • padchar: padding character, default is space
  • is_trunc: when true, truncates the string if it exceeds width
import { s_pad } from '@yuhere/js-strings';

console.log(s_pad('hello', 10, 'l', '-')); // '-----hello'
console.log(s_pad('hello', 10, 'r', '-')); // 'hello-----'
console.log(s_pad('hello', 10, 'c')); // '  hello   '
console.log(s_pad('hello world', 5, 'r', ' ', true)); // 'hello'

s_left

Get the leftmost characters of a string.

import { s_left } from '@yuhere/js-strings';

console.log(s_left('hello world', 5)); // 'hello'
console.log(s_left('hello', 0)); // ''

s_right

Get the rightmost characters of a string.

import { s_right } from '@yuhere/js-strings';

console.log(s_right('hello world', 5)); // 'world'
console.log(s_right('hello', 0)); // ''

s_ellipsis

Pad or truncate a string to a fixed width. When truncation happens, ... is inserted according to the alignment.

  • 'l': keep the left part and put ... at the end
  • 'r': keep the right part and put ... at the beginning
  • 'c': keep both ends and put ... in the middle
import { s_ellipsis } from '@yuhere/js-strings';

console.log(s_ellipsis('hello', 8)); // 'hello   '
console.log(s_ellipsis('abcdefghijklmnopqrstuvwxyz', 10, 'l')); // 'abcdefg...'
console.log(s_ellipsis('abcdefghijklmnopqrstuvwxyz', 10, 'r')); // '...tuvwxyz'
console.log(s_ellipsis('abcdefghijklmnopqrstuvwxyz', 10, 'c')); // 'abcd...xyz'

s_ellipsis_o

Options-object form of s_ellipsis, suitable when parameters come from configuration.

import { s_ellipsis_o } from '@yuhere/js-strings';

console.log(s_ellipsis_o('hello', { width: 8 })); // 'hello   '
console.log(s_ellipsis_o('abcdefghijklmnopqrstuvwxyz', { width: 10, align: 'r' })); // '...tuvwxyz'

s_xprint_extract_fmt

Parse a column format definition used by s_xprint.

  • string form: "<width>[<align><padchar>]"
  • object form: { width, align, padchar }
import { s_xprint_extract_fmt } from '@yuhere/js-strings';

console.log(s_xprint_extract_fmt('8')); // { width: 8, align: 'l', padchar: undefined }
console.log(s_xprint_extract_fmt('8r0')); // { width: 8, align: 'r', padchar: '0' }
console.log(s_xprint_extract_fmt({ width: 12, align: 'l', padchar: '_' }));
// { width: 12, align: 'l', padchar: '_' }

s_xprint_fmts

Batch-convert multiple format definitions into normalized format objects.

import { s_xprint_fmts } from '@yuhere/js-strings';

console.log(s_xprint_fmts(['8', '6r0', { width: 10, align: 'l', padchar: '_' }]));
// [
//   { width: 8, align: 'l', padchar: undefined },
//   { width: 6, align: 'r', padchar: '0' },
//   { width: 10, align: 'l', padchar: '_' }
// ]

s_xprint

Format multiple columns into one line of fixed-width text. This is useful for CLI table rows, aligned logs, and report output.

  • columns: values to output
  • formats: per-column format definitions
  • sep: separator inserted between columns
  • ellipsisEnd: whether the last column should also be padded/truncated
import { s_xprint } from '@yuhere/js-strings';

console.log(
    s_xprint({
        columns: ['id', 7, 'abcdefghijklmnopqrstuvwxyz'],
        formats: ['6l ', '4r0', '10l '],
        sep: ' | '
    })
);
// 'id     | 0007 | abcdefg...'

console.log(
    s_xprint({
        columns: ['INFO', 'startup ok', 'this part is not truncated'],
        formats: ['6l ', '12l ', '8l '],
        sep: ' ',
        ellipsisEnd: false
    })
);
// 'INFO   startup ok   this part is not truncated'

s_glob

Match a string against a simple glob pattern.

Current public wrapper behavior uses the default glob conversion rules, which are suitable for common * pattern matching.

import { s_glob } from '@yuhere/js-strings';

console.log(s_glob('*.ts', 'index.ts')); // true
console.log(s_glob('*.ts', 'index.js')); // false
console.log(s_glob('src/*', 'src/strings.ts')); // true

License

MIT