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

mercedutils

v1.1.0

Published

---

Downloads

3

Readme

Alex Merced's Utilities


AlexMercedCoder.com

This library contain some utility functions.

installation

CDN LINK: http://www.alexmercedcoder.com/mercedutils.js

NPM

npm i @alexmerced/bettertypes

const {superArray, utils, superString} = require("mercedutils")

superArray(); //add methods to array prototype
superString(); //add methods to string prototype

const {
    randomIndex,
    randomRange,
    randomNumber,
    eliminateDupes,
    Fetcher,
    SuperSet
} = utils() // makes these utility functions available

Github

git clone https://github.com/AlexMercedCoder/JS_Utilities.git

const {superArray, utils, superString} = require("superArray.js")

superArray(); //add methods to array prototype
superString(); //add methods to string prototype

const {
    randomIndex,
    randomRange,
    randomNumber,
    eliminateDupes,
    Fetcher,
    SuperSet,
    countWords,
    highWordCount
} = utils() // makes these utility functions available

superArray


superArray() => run this function and going forward all the below methods will be available to all your arrays


Array.random() => return random element from array

Array.remove((value, index) => return boolean) => the opposite of filter, remove elements where the callback function returns true, returns a superArray

Array.undupe() => returns a superArray of the array with duplicates removed

Array.randElim() => eliminates a random element and returns it

Array.leaveOne() => Randomly eliminates all but one element from array and returns a superArray of removed elements

Array.leaveSome(number) => Randomly eliminates all but a defined number of elements from array and returns a superArray of removed elements

Array.findRemove(value) => finds and removes value from array returning the removed value

Array.addLength(length, value) => increases array to desired length and fills in additional spots with the value passed.

Array.lessLengthRight(length) => removes elements from back of the array till is desired length, returns array of removed values

Array.lessLengthRight(length) => removes elements from front of the array till is desired length, returns array of removed values

Array.someMore((value, index) => return boolean, number) => returns true if the number of iterations that return true are equal or greater to the number argument

Array.everyLess((value, index) => return boolean, number) => returns true if the number of iterations that return false are equal or less to the number argument

Array.MapToObject((value, index) => return [key, value]) => like map but returns an object, the callback function must return a two element array [key, value]

Array.MapToMap((value, index) => return [key, value]) => like map but returns an Map, the callback function must return a two element array [key, value]

Array.MapToMap((value, index) => return [key, value]) => like map but returns a Set

Array.MapToUnique((value, index) => return [key, value]) => like map but returns an Array of only unique elements

Array.squish() => removes the first and last elements of the array and return them in an array

Array.shuff() => return shuffled version of array

Array.toStrings() => return array with all elements casted as strings

Array.toNums() => return array with all elements casted as Numbers

Array.toBools() => return array with all elements casted as Booleans

Array.iPop() => immutable pop, return new version of array with last value popped

Array.iPush(value) => immutable push, return new version of array with value pushed into end of array

Array.iShift() => immutable shift, return new version of array with first value removed

Array.iUnshift(value) => immutable unshift, return new version of array with value added at beginning of array

Array.iSplice(index, amount) => immutable splice, return new version of array with the specified number of elements removed starting with the specified index.


superString


superString() => run this function and going forward all the below methods will be available to all your strings


String.words() => returns array of words in the string

String.reverseWords() => returns string with the words reversed

String.swapWord(target, replacement) => returns string where the first instance of the target word is replaced by the replacement.


Utility Functions


randomIndex(Array) => Return random number 0 - Array.length

randomRange (Low, High) => Return number between low and high

randomNumber(Number) => Return random number 0 - Number

eliminateDupes(Array) => Return Array with duplicates removed

countWords(String) => returns object of words in string and their word count

highWordCount(string) => returns array with most used word and count in a string

Fetcher


The Fetcher class can help you encapsulate your API endpoints

const get = new Fetcher('http://www.xyz/get/')
const post = new Fetcher('http://www.xyz/post/')
const delete = new Fetcher('http://www.xyz/delete/')
const update = new Fetcher('http://www.xyz/update/')

call(callback,config,extUrl)

this function will call the url passed and run the callback function when the promise resolves and has been converted into JSON. You can pass in a config object include things like, headers, body, and specify type of call (defaults to get). The extUrl parameter will be appended to the url which allows you to get more mileage out of a single instance of fetcher. The resulting data from the most recent call is saved in case you need to access it again.

get.call((json) => console.log(json))

post.call((json) => console.log(json), {
        method: 'post',
        body:    JSON.stringify(body),
        headers: { 'Content-Type': 'application/json' },
    }, "?user=SteveJones")

recall() returns the data from the most recent call


PowerSet


combines the benefits of arrays and sets but giving you access to a dataset in both forms. The constructor takes an array to generate the PowerSet from. I implemented the methods from the MDN examples for sets, cause well... they are useful.

const { PowerSet } = utils();

const pset1 = new PowerSet([1, 2, 3, 4]);
const pset2 = new PowerSet([3, 4, 5, 6]);

console.log(pset1.difference(pset2));

PowerSet Properties

this.set => the set of the array passed in

this.arr => this is the array of the array passed in without duplicates

PowerSet methods

this.arrMethod("Method", "Argument") => use any array method by passing in a string for the method you desire to use and another string with the argument you want to pass.

this.isSuperset(PowerSet) => Returns true if the PowerSet is a superset of the PowerSet passed as an argument

this.union(PowerSet) => Returns a powerset that is a combonation of this PowerSet and the PowerSet passed in as an argument.

this.intersection(PowerSet) => returns PowerSet of elements in common between two PowerSets

this.symmetricDifference(PowerSet) => returns PowerSet of elements not shared by both PowerSets

this.difference(PowerSet) => returns PowerSet of elements not shared by this array with the passed in array