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

mutils_am

v1.0.2

Published

---

Downloads

2

Readme

Mutils


AlexMercedCoder.com

This library contains utility classes for working with Arrays, Sets and Random numbers

installation

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

NPM

npm i mutils_am

const {Rand, MSet, MArray} = require("mutils_am")

Script Tag

<script src="http://www.alexmercedcoder.com/mutils.js" defer></script>

Marray


A special type of array with all the methods of normal arrays plus all the additional methods below.

const myArray = new MArray(1,2,3,4,5)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

MArray.squish() => removes the first and last elements of the array and returns them in an Marray

MArray.shuff() => return shuffled version of Marray

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

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

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

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

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

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

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

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


Rand

Class with several static functions for generating random numbers


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

Rand.range (Low, High) => Return number between low and high

Rand.num (Number) => Return random number 0 - Number


MSet

A Class that is an extension of Set. Has all the features of Native sets plus the additional methods below.


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 MSet from. I implemented the methods from the MDN examples for sets, cause well... they are useful.

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

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

MSet methods

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

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

MSet.intersection(MSet) => returns MSet of elements in common between two MSets

MSet.symmetricDifference(MSet) => returns MSet of elements not shared by both MSets

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