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

only-shallow

v1.2.0

Published

like `deeper` and `deepest`, but less strict, and with 90s flavor

Downloads

44,548

Readme

only-shallow on npm Build Status Coverage Status "standard" style

only-shallow

If deeper and deepest are assert.deepEqual()'s strict East Coast siblings with engineering backgrounds, only-shallow is their laid-back California cousin. only-shallow is a library for structurally comparing JavaScript objects. It supports recursive / cyclical data structures, is written to avoid try / catch / throw (for speed), and has no dependencies. It's not particularly strict about matching types. It's more of a duck squeezer.

It has some optimizations but stresses correctness over raw speed. Unlike deepest, it has no native dependencies, so you can use it, like, wherever.

If you install Ben Noordhuis's buffertools into a project using only-shallow, it will use that to speed up comparison of Buffers.

The core algorithm is based on those used by Node's assertion library and the implementation of cycle detection in isEqual in Underscore.js.

I like to think the documentation is pretty OK.

only-shallow has this name because I'm old.

installation

npm install only-shallow

usage

var deepEqual = require('only-shallow')

if (!deepEqual(obj1, obj2)) console.log("yay! diversity!");

details

Copied from the source, here are the details of only-shallow's algorithm:

  1. Use loose equality (==) only for value types (non-objects). This is the biggest difference between only-shallow and deeper / deepest. only-shallow cares more about shape and contents than type. This step will also catch functions, with the useful (default) property that only references to the same function are considered equal. 'Ware the halting problem!
  2. null is an object – a singleton value object, in fact – so if either is null, return a == b. For the purposes of only-shallow, loose testing of emptiness makes sense.
  3. Since the only way to make it this far is for a or b to be an object, if a or b is not an object, they're clearly not the same.
  4. It's much faster to compare dates by numeric value (.getTime()) than by lexical value.
  5. Compare RegExps by their components, not the objects themselves.
  6. The parts of an arguments list most people care about are the arguments themselves, not the callee, which you shouldn't be looking at anyway.
  7. Objects are more complex:
    1. Return true if a and b both have no properties.
    2. Ensure that a and b have the same number of own properties (which is what Object.keys() returns).
    3. Ensure that cyclical references don't blow up the stack.
    4. Ensure that all the key names match (faster).
    5. Ensure that all of the associated values match, recursively (slower).

license

ISC. Go nuts.