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

prototypeextender

v0.0.1

Published

Extends the prototypes of Strings, Arrays

Downloads

1

Readme

#Prototype Extender

A small collection of extensions to the prototypes of String, Array, and Number. Kind of like underscore, but simpler and it directly affects the prototype.

#Methods

##String prototype

####Reverse

Takes a string and reverses the order of characters.

'abc'.reverse(); //cba

####replaceLast

Replaces the last occurrence of a substring

'abca'.replaceLast('a');  //abc

####replaceAll

Replaces all occurrences of a substring

'abca'.replaceLast('a');  //bc

####findOcc

Finds the amount of times a substing occurs. Takes an optional allow overlapping argument that defaults to true.

'sss'.findOcc('ss'); //1
'sss'.findOcc('ss', true); //2

####contains

Returns true if a string has a substring.

'abca'.contains('a');  //true
'abca'.contains('f');  //false

####splitFirst

Splits a string at the first occurence of a word.

'dabcad'.splitFirst('a');  //['d', 'bcad']

####splitLast

Splits a string at the last occurence of a word.

'dabcad'.splitLast('a');  //['dabc', 'd']

####is

Takes a list and checks if the string is an item of that list.

'b'.is(['a', 'b', 'c']);  //true
'd'.is(['a', 'b', 'c']);  //false

####firstWord

Returns the first word of a string.

'once upon a time there was a very small cat named steve'.firstWord(); //once

####cut

Cuts a string between substrings.

'abcdef'.cut('c'); //def
'abcdef'.cut('b', 'd'); //c

####loop

Loops over a string. Provides the letter, index of letter, and persistent variable that defaults to an empty string.

console.log(
    'abcdef'.loop(function(item, i, persist){
        return persist + item.toUpperCase() + i;
    });
}  //A1B2C3D4E5F6

##Array prototype

####invPop

Pop returns the last item of string. invPop returns everything but the last item.

['a','b','c'].invPop(); //['a', 'b']

####invShift

Returns everything but the first item.

['a','b','c'].invShift(); //['b', 'c']

####replace

Replaces all occurences of a string in every item of the list.

['ab','b','cd'].replace('b'); //['a','','cd']

####invPop

Splits a list.

['aba','b','c'].split('b'); //['a', 'a', '', '','c']

####clean

Removes falsy values.

['a', 'a', '', false, 1, undefined, null, '','c'].clean(); //['a', 'a', 'c']

####replaceItem

Compares every item and replaces it.

['ab','b','c'].replaceItem('b', 12); //['ab', 12, 'c']

####whereIs

indexOf for lists.

['a','b','c'].whereIs('b'); //1

####loop

Loop for lists.

console.log(
    'abcdef'.split('').loop(function(item, i, persist){
        return persist + item.toUpperCase() + i;
    });
}  //A1B2C3D4E5F6

##Number Prototype

####loop

I think you get the idea by now. Gives the nmber and persistent, but no index for this one.

console.log(
    7.0.loop(function(i, persist){
        return persist + i.toString();
    });
}  //1234567