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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@full-pack/string-pack

v0.8.0

Published

A lightweight and versatile String Utility Package for Node.js & Browser.

Downloads

90

Readme

@full-pack/string-pack

npm

jest Code Style: Prettier codecov

A lightweight and versatile String Utility Package for Node.js & Browser.

Contents

install

npm install @full-pack/string-pack

require

const { ... } = require('@full-pack/string-pack');

import

import { ... } from '@full-pack/string-pack';

API

padding

Adds padding to given string.

padStart

Pads the start of a string with a specified fill string a certain number of times.

// Basic Usage
padStart('hello', 'abc', 3) // abcabcabchello

// Limiting total length
padStart('hello', 'abc', 3, 8) // abchello
padEnd

Pads the end of a string with a specified fill string a certain number of times.

// Basic Usage
padEnd('hello', 'abc', 3); // helloabcabcabc

// Limiting total length
padEnd('hello', 'abc', 3, 8); // helloabc
padBidirectional

Pads a string with a specified fill string a certain number of times on both ends.

// Basic usage
padBidirectional('hello', '*', 2); // '**hello**'

// Limiting total length
padBidirectional('world', '-', 3, 10); // '--world---'
 
// Controlling padding distribution
padBidirectional('example', '*', 2, 10, 0); // '**example*'

merge

Merges an array of strings into a single string using a specified separator.

merge('-', 'apple', 'orange', 'banana'); // 'apple-orange-banana'

merge(true, 'apple', 'orange'); // 'apple orange'
 
merge(false, 'apple', 'orange', 'banana'); // 'appleorangebanana'

compare

Performs a strict comparison between two strings.

compare("hello", "hello"); // true

compare("abc", "ABC"); // false

looseCompare

Performs a case-insensitive loose comparison between two strings.

looseCompare("hello", "HELLO"); // true

looseCompare('abc', '123'); // false

capitalizeInitial

Capitalizes the first letter of a word in a string.

capitalizeInitial('hello'); // 'Hello'

capitalizeInitial(':> hello');  // ':> Hello'

capitalizeWords

Capitalizes the first letter of each word in a given string.

capitalizeWords('hello world'); // 'Hello World'

capitalizeWords('Sphinx of black quartz:-judge my vow'); // 'Sphinx Of Black Quartz:-Judge My Vow'

Case Conversion

snakeCase

Converts a string to snake_case format.

snakeCase('hello WorLd'); // 'hello_world'
snakeCase('from-kebab-case'); // 'from_kebab_case'
snakeCase('snake Case With Numbers123', true); // 'snake_case_with_numbers_one_two_three'

kebabCase

Converts a string to kebab-case format.

kebabCase('h3llo WoRld'); // 'h3llo-world'
kebabCase('from_snake_case'); // 'from-snake-case'
kebabCase('kebab Case With Numbers123', true); // 'kebab-case-with-numbers-one-two-three'

camelCase

Converts a string to camelCase format.

camelCase('hello WoRld'); // 'helloWorld'
camelCase('Test CaSe ExamplE'); // 'testCaseExample'
camelCase('camel Case With Numbers123'); // 'camelCaseWithNumbers'

pascalCase

Converts a string to PascalCase format.

pascalCase('hello WoRld'); // 'HelloWorld'
pascalCase('Test CaSe ExamplE'); // 'TestCaseExample'
pascalCase('pasCal Case With Numbers123'); // 'PascalCaseWithNumbers'

Case Validation

isSnakeCase

Checks if a string is in snake_case format.

// Valid
isSnakeCase('snake_case_example'); // true
isSnakeCase('hello_world'); // true
 
// Valid with alphanumeric flag
isSnakeCase('with_1234', true); // true
isSnakeCase('pi_3_14', true); // true
 
// Invalid
isSnakeCase('123at_start'); // false
isSnakeCase(' no_space_allowed'); // false
isSnakeCase('no_CAPS'); // false

isKebabCase

Checks if a string is in kebab-case format.

// Valid
isKebabCase('kebab-case-example'); // true
isKebabCase('hello-world'); // true
 
// Valid with alphanumeric flag
isKebabCase('with-1234', true); // true
isKebabCase('pi-3-14', true); // true
 
// Invalid
isKebabCase('123at-start'); // false
isKebabCase(' no-space-allowed'); // false
isKebabCase('no-CAPS'); // false

isCamelCase

Checks if a string is in camelCase format.

// Valid
isCamelCase('camelCaseExample'); // true
isCamelCase('helloWorld'); // true
 
// Invalid
isCamelCase('CAMEL'); // false
isCamelCase(' noSpaceAllowed'); // false
isCamelCase('withThe1234'); // false

isPascalCase

Checks if a string is in PascalCase format.

// Valid
isPascalCase('PascalCaseExample'); // true
isPascalCase('HelloWorld'); // true
 
// Invalid
isPascalCase('PASCAL'); // false
isPascalCase(' NoSpaceAllowed');; // false
isPascalCase('WithThe1234'); // false

regionMatch

Compares two strings or regions for equality.

// Matching identical strings
regionMatch('hello', 'hello'); // true

// Matching identical regions in strings
const str1 = { str: 'hello world', start: 0, end: 5 };
const str2 = { str: 'hello there', start: 0, end: 5 };
regionMatch(str1, str2); // true
// OR
regionMatch('hello world', 'hello there', 0, 5) // true

// Not matching regions
regionMatch('hello world', 'hello there', 6, 11); // false

looseRegionMatch

Performs a loose comparison of two strings or regions for equality.

// Loose matching identical strings
looseRegionMatch('hello', 'HeLLo'); // true

// Loose matching identical regions in strings
const str1 = { str: ' hellO world', start: 1, end: 6 };
const str2 = { str: 'HelLo there', start: 0, end: 5 };
looseRegionMatch(str1, str2); // true

isAlpha

Checks if a string contains only alphabetic characters (A-Z, a-z).

isAlpha("HelloWorld"); // true
isAlpha("Hello123"); // false

isAlphaNumeric

Checks if a string contains only alphanumeric characters (A-Z, a-z, 0-9).

isAlphaNumeric("Hello01"); // true
isAlphaNumeric("1234567890"); // false

Reverse

Reverses the sequence of characters in given string.

reverse('bad') // 'dab'

Build

npm run build

License

The MIT License. Full License is here