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

@mfonabasiudobia/str-func

v1.0.1

Published

Better javascript string functions similar to php

Downloads

6

Readme

@mfonabasiudobia/str-func

Better javascript string functions similar to php

Installation

npm install @mfonabasiudobia/str-func

Usage

import { strtoupper, str_shuffle, strtolower, trim, strlen, ucwords, ucfirst, lcfirst, rand, rtrim, ltrim, explode, implode  } from "@mfonabasiudobia/str-func"

strtoupper

The strtoupper() function converts a string to uppercase

const str = strtoupper('hello world!');
// returns 'HELLO WORLD!'

strtolower

The strtolower() function converts a string to lowercase

const str = strtolower('HELLO WORLD!');
// returns 'hello world!'

trim

The trim() function removes whitespace or other predefined characters from both sides of a string

const str = trim('   alpha   ');
// returns 'alpha'

// OR

const str = trim('   alpha   ', 'a'); //the second parameter is optional, it specifies which character to remove from the string
// returns 'lph'

// OR 

const str = trim('   Alpha   ', 'a', false); //the third parameter set to false indicates case insensitivity
// returns 'lph'

// OR 

const str = trim('   Alpha   ', 'a', true); or trim('   Alpha   ', 'a'); 
// returns 'Alph'

//by default third parameter is set to true

rtrim

The rtrim() function removes whitespace or other predefined characters from right sides of a string

const str = rtrim('   alpha   ');
// returns '   alpha'

// OR

const str = rtrim('   alpha   ', 'a'); //the second parameter is optional, it specifies which character to remove from the string
// returns '   alph'

// OR 

const str = rtrim('   Alpha   ', 'A', false); //the third parameter set to false indicates case insensitivity
// returns '   Alph'

// OR 

const str = rtrim('   Alpha   ', 'a', true); or rtrim('   Alpha   ', 'a'); 
// returns '   Alpha'


//by default third parameter is set to true

ltrim

The ltrim() function removes whitespace or other predefined characters from left sides of a string

const str = ltrim('   alpha   ');
// returns 'alpha   '

// OR

const str = ltrim('   alpha   ', 'a'); //the second parameter is optional, it specifies which character to remove from the string
// returns 'lpha   '

// OR 

const str = ltrim('   Alpha   ', 'a', false); //the third parameter set to false indicates case insensitivity
// returns 'lpha   '

// OR 

const str = ltrim('   Alpha   ', 'a', true); or ltrim('   Alpha   ', 'a'); 
// returns 'Alpha   '

//by default third parameter is set to true

strlen

The strlen() function returns the length of a string

const str = strlen('HELLO WORLD!');
// returns 12

rand

The rand() function generates a random integer

const str = rand();
// returns 127929382383
Example tip

If you want a random integer between 10 and 100 (inclusive), use rand(10, 100)

rand();

//or

rand(min, max);

str_shuffle

The str_shuffle() function randomly shuffles all the characters of a string

const str = str_shuffle('hello world!');
// returns oldlre loWH

ucwords

The ucwords() function converts the first character of each word in a string to uppercase

const str = ucwords('hello world!');
// returns Hello World!

//or

const str = ucwords('he|llo world!',"|"); //the second parameter is optional, it specifies the word separator character
//returns He|Llo world!

ucfirst

The ucfirst() function converts the first character of a string to uppercase

const str = ucfirst('hello world!');
// returns Hello world!

lcfirst

The lcfirst() function converts the first character of a string to lowercase

const str = lcfirst('Hello world!');
// returns hello world!

explode

The explode() function breaks a string into an array

const str = explode('hello,world',",");
// returns ['hello','world']

implode

The implode() function returns a string from the elements of an array

const str = implode(['hello','world'],"#");
// returns hello#world