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

@mitevpi/algos

v0.2.0

Published

Low-level algorithms for data processing and manipulation.

Downloads

50

Readme

Algos

Generic badge Generic badge Generic badge

npm npm bundle size npm npm2

Azure DevOps builds Azure DevOps Tests GitHub issues David GitHub last commit

Low-level JavaScript algorithms as shorthand for everyday use in frontend & backend code.

Usage

To use this module, install locally using the command below, or clone this repository and import the .js files directly from source. Full documentation can be found on the GitHub Pages Site for this project.

npm i @mitevpi/algos

Imports

Imports can be done through the aggregating index.js file or via individual members.

Full Import

// es5
const algos = require('./index.js'); // from source
const algos = require('@mitevpi/algos') // from npm

// es6
import * as Algos from "../src"; // from source
import * as Algos from from "@mitevpi/algos"; // from npm

Individual Import

// from source
const Arrays = require("./Arrays");
const Numbers = require("./Numbers");

// from npm
const { Arrays } = require("@mitevpi/algos");
const { Numbers } = require("@mitevpi/algos");
import { Arrays, Numbers } from "@mitevpi/algos"; // es6

CDN

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <!-- import minified script from CDN or copy it locally -->
    <script src="../dist/algos.umd.min.js"></script>
  </head>

  <body>
    <script>
      var arr = [1, 2, 3, 4, 5]; // create array
      var result = algos.Arrays.sum(arr); // sum the array
      console.log("LIBRARY", algos); // imported lib object: classes, functions
      console.log("RESULT", result); // 15
    </script>
  </body>
</html>

Sample Usage

For full examples of usage, please refer to the test and samples folder which have a wide variety of use and test cases to learn from.

Arrays

This is a suite of functions to be used on Arrays of any kind and data type.

Considering the following input:

import { Arrays } from "@mitevpi/algos";
Flatten
// any level of nesting as an input
const array01 = [
  [1, 2, 3],
  [4, 5, 7]
];
const array02 = [[[1, 2, 3]], [4, 5, 7]];
const array03 = [[[1, 2, 3]], [[4, 5, 7]]];
const array04 = [1, [0, [[1, [2, 3], 0]]], [[4, 5, 7]]];

const flat01 = Arrays.flatten(array01); // uniform nesting like array02/array03
// [1, 2, 3, 4, 5, 7] <- Expected Result

const flat04 = Arrays.flatten(array04); // non-uniform nesting
// [1, 0, 1, 2, 3, 0, 4, 5, 7] <- Expected Result

Summarize

const array2 = ["tom", "peter", "mary", "tom", "mary", "mary", "jeremy"];
const res = Arrays.summarize(array2); // get a summary of the array contents
// {tom: 2, peter: 1, mary: 3, jeremy: 1} <- Expected Result

Object Arrays

This is a suite of functions to be used on Arrays which contain Objects.

Considering the following input:

import { ArraysObjective } from "@mitevpi/algos";
const states = [
  { population: 10, size: 13, state: "OH", near: "KY" },
  { population: 20, size: 20, state: "KY", near: "TN" },
  { population: 60, size: 20, state: "IN", near: "PA" },
  { population: 40, size: 13, state: "PA", near: "NY" }
];
Auto Normalize
// Auto Normalize all values between 0 to 1 on objects
// which have keys containing numerical value
const res = ArraysObjective.normalizeAuto(states);

// We expect the return object to look like this:
console.log(res);
0:Object {population: 0, size: 0, state: "OH", …}
1:Object {population: 0.2, size: 1, state: "KY", …}
2:Object {population: 1, size: 1, state: "IN", …}
3:Object {population: 0.6, size: 0, state: "PA", …}
Normalize By Key
// Normalize all values between 0 to 1 on values of objects in the array
// which correspond to the input key
const res = ArraysObjective.normalizeByKey(states, "population");

// We expect the return object to look like this:
console.log(res);
0:Object {population: 0, size: 13, state: "OH", …}
1:Object {population: 0.2, size: 20, state: "KY", …}
2:Object {population: 1, size: 20, state: "IN", …}
3:Object {population: 0.6, size: 13, state: "PA", …}
Group By Key
// reformat the array to be grouped by unique same values in a corresponding key
const res = ArraysObjective.groupBy(states, "size");

// We expect that the return object will be reformatted and grouped
// by the two unique values in the "size" key
console.log(res);
13:Array(2) [Object, Object]
0:Object {population: 10, size: 13, state: "OH", …}
1:Object {population: 40, size: 13, state: "PA", …}
20:Array(2) [Object, Object]
0:Object {population: 20, size: 20, state: "KY", …}
1:Object {population: 60, size: 20, state: "IN", …}

Development

Building

The module can be built by running npm run build in the root directory of this repository. Documentation is built using the Documentation module from npm, and by running npm run docs in the root directory of this repository. This will create markdown and HTML documentaion.

Testing

Testing is handled using jest and code coverage is evaluated using nyc. Tests can be initiated by running npm test in the root directory of this repository (be sure to first set your required env variables such as GMAPS_KEY).

Commands

The following commands are available during development.

npm test # run tests with Jest
npm run coverage # run tests with coverage and open it on browser
npm run lint # lint code
npm run docs # generate docs
npm run build # transpile code