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

@shah-a/string-lib

v1.2.0

Published

A library for string manipulation.

Downloads

10

Readme

FEW 2.1 Assignment 1: String Library

npm (scoped) npm

Description

A library for string manipulation.

Installation

Local installation to any node project:

$ npm install @shah-a/string-lib

Usage

Require the package in your script and call any of the available functions.

Examples:

const s = require('@shah-a/string-lib');

console.log(s.makeHashtag('Amazing bongo drums for sale'));
// Output: ['#Amazing', '#Bongo', '#Drums']

console.log(s.shift('Shift me right by 3', 3));
// Output: 'y 3Shift me right b'

console.log(s.shift('Shift me left by 3', -3));
// Output: 'ft me left by 3Shi'

That's it! 😃

API

Reference list of available functions (sorted by the assignment's corresponding challenge number):

Functions

Challenge 1

Challenge 2

Challenge 3

Challenge 4

Challenge 5

Challenge 6

Challenge 7

Challenge 8

Challenge 9

Challenge 10

Reference

capFirst(s: string)

Uppercases the first character in a string.

s.capFirst('salaam');
// returns 'Salaam'

lowerFirst(s: string)

Lowercases the first character in a string.

s.lowerFirst('Salaam');
// returns 'salaam'

capWords(s: string)

Uppercases the first letter of each word in a string.

s.capWords('salaam world');
// returns 'Salaam World'

capTitle(s: string)

Uppercases the first letter of each word in a string except for the following words:

'the', 'in', 'a', 'an', 'and', 'but', 'for', 'at', 'by', 'from'

The first word is always uppercased, even if it's on the exception list.

s.capTitle('the most foo in bar');
// returns 'The Most Foo in Bar'

allCaps(s: string)

Uppercases all characters in a string.

Note: This function is an alias for the built-in String.prototype.toUpperCase function.

s.allCaps('salaam world');
// returns 'SALAAM WORLD'

removeExtraSpaces(s: string)

Removes all spaces from the beginning and end of a string along with any extra spaces in the middle.

If more than one space appears in the middle of a string, it is replaced by a single space.

s.removeExtraSpaces('   Salaam   world!   ');
// returns 'Salaam world!'

kebobCase(s: string)

Removes extra spaces and replaces spaces with a hyphen "-". Also makes all characters lowercase.

s.kebobCase(' Kebob Case! ');
// returns 'kebob-case!'

kebobCaseNoSpecial(s: string)

Removes extra spaces and replaces spaces with a hyphen "-". Also makes all characters lowercase and removes special characters.

s.kebobCaseNoSpecial(' Kebob Case! ');
// returns 'kebob-case'

snakeCase(s: string)

Removes extra spaces and replaces spaces with an underscore "_". Also makes all characters lowercase.

s.snakeCase(' Snake Case! ');
// returns 'snake_case!'

snakeCaseNoSpecial(s: string)

Removes extra spaces and replaces spaces with an underscore "_". Also makes all characters lowercase and removes special characters.

s.snakeCaseNoSpecial(' Snake Case! ');
// returns 'snake_case'

customSeparator(s: string, separator?: string)

Removes extra spaces and replaces spaces with a custom separator. Also makes all characters lowercase.

s.customSeparator(' Custom Case! ', '🐒');
// returns 'custom🐒case!'

If no separator is provided, the default separator is ' ' (one space).

s.customSeparator(' Custom Case! ');
// returns 'custom case!'

customSeparatorNoSpecial(s: string, separator?: string)

Removes extra spaces and replaces spaces with a custom separator. Also makes all characters lowercase and removes special characters.

s.customSeparatorNoSpecial(' Custom Case! ', '🐒');
// returns 'custom🐒case'

If no separator is provided, the default separator is ' ' (one space).

s.customSeparatorNoSpecial(' Custom Case! ');
// returns 'custom case'

camelCase(s: string)

Lowercases the first character of the first word. Then uppercases the first character of all other words. Also removes all spaces.

s.camelCase('Camel Case!');
// returns 'camelCase!'

camelCaseNoSpecial(s: string)

Lowercases the first character of the first word. Then uppercases the first character of all other words. Also removes all spaces and removes special characters.

s.camelCaseNoSpecial('Camel Case!');
// returns 'camelCase'

shift(s: string, step?: number)

Shifts the characters of a string to the right or left. If the step parameter is positive, characters will be shifted to the right. If the step parameter is negative, the characters will be shifted to the left.

s.shift('Shift me right by 3', 3);
// returns 'y 3Shift me right b'
s.shift('Shift me left by 3', -3);
// returns 'ft me left by 3Shi'

If no step is provided, the default step is 1.

s.shift('Shift me right by 1');
// returns '1Shift me right by '

makeHashtag(s: string)

Converts a string to a list of hashtags. A hashtag begins with '#' and has no spaces. Also uppercases the hashtagged words.

If the string has more than three words, picks the three longest and returns hashtags from those.

s.makeHashtag('Salaam world');
// returns ['#Salaam', '#World']
s.makeHashtag('Amazing bongo drums for sale');
// returns ['#Amazing', '#Bongo', '#Drums']

isEmpty(s: string)

Returns true if a string is empty or contains only whitespace. Whitespace includes: spaces, line returns, and tabs. These characters can be represented with: '\n' (new line), '\r' (carriage return), and '\t' (tab).

s.isEmpty('Abc def');
// returns false
s.isEmpty('  \n  \n\r\t');
// returns true
s.isEmpty(`

			`);
// returns true