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

test-over

v0.2.3

Published

run useful tests on your arrays or hashes of arrays or hashes

Downloads

16

Readme

Test-Over

run useful tests on your arrays or hashes of arrays or hashes

var test = require('testover');

test.max('length').over(someArray); //run your tests inline

var samelength = test.equals('length'); //or set up a testing function to call later
samelength(someArray);

Iterate over whatever property

triplets: [
    {name: 'Joe', age: 20}
 ,  {name: 'Josie', age: 20}
 ,  {name: 'Johnny', age: 20}
]

test.consistent('age').over(triplets);
test.equals('age', 20).over(triplets);

and over associative arrays

assoc_triplets: {
    first: {name: 'Joe', age: 20}
 ,  second: {name: 'Josie', age: 20}
 ,  third: {name: 'Johnny', age: 20}
}

test.consistent('age').over(assoc_triplets);
test.equals('age', 20).over(assoc_triplets);

Included tests

  • max: biggest numerical value
  • min: smallest numerical value
  • equals: if all values equal a specified value
  • consistent: if all values equal an unspecified value
  • exists: if a property exists (but might be null)
  • assigned: if a property actually exists
  • unique: if all values are unique

Add your own tests

The underlying process is essentially a fancy reduce function. With this in mind you can add your own reductions to do even more testing.

Usage

tests.add(* *<field name>, * *<reduction function>, * *<options object>)

Reduction functions

Reductions take the form r(property, row, reduced, opts) where property is the property passed to the new test row is the object or array currently being tested reduced is the variable being reduced (the variable that will be returned) opts is an object with extra goodies you can pass between iterations of your reduction

You can assign an initial value by assigning opts.init when you add the new reduction, otherwise opts.init and opts.first are assigned to the first list item's value.

Example

test.add('noConsecutiveRepeats', function(prop, row, repeats, opts) {
	var current = row[prop];
	if (current === opts.previous) {
		return false
	} else {
		opts.previous = current;
		return repeats;
	}
}, {init: true, previous: null});

test.noConsecutiveRepeats('property').over(array);

License

MIT