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

deep6

v1.1.4

Published

No dependency mini-library: unification, deep equivalence, deep cloning.

Downloads

16

Readme

deep6 NPM version

deep6 is a no-dependency ES6 mini-library:

  • Advanced deep equivalency for JavaScript structures.
    • Extensible to accommodate custom objects.
  • Traversing objects.
    • Extensible deep cloning.
  • Written in ES6:
    • Use it in Node or browsers without transpiling.
    • Natively supports Map, Set, typed arrays.
    • Natively supports symbols and property descriptors.
    • Presented as ES6 modules, yet provides CommonJS modules for convenience.
  • Efficient non-recursive algorithms.
    • ~500 tests to ensure correctness.
    • Support for circular dependencies.
    • Support for "loose" comparisons.
  • Unification.
    • Identifying and capturing object fragments.

Intro

import equal, {match, clone, any} from 'deep6';

const x = {a: 1, b: 2, c: ['hi!', 42, null, {}]};

// deep equality
equal(x, {b: 2, a: 1, c: ['hi!', 42, null, {}]});     // true
equal(x, {b: 2, a: 1, c: ['hi!', 42, null, {z: 1}]}); // false

// pattern matching
match(x, {a: 1});         // true
match(x, {z: 1});         // false
match(x, {a: 1, c: any}); // true
match(x, {a: 1, c: []});  // false
match(x, {a: 1, d: any}); // false

// deep cloning
const y = clone(x);
equal(x, y);              // true

// circular dependencies are fine
const z = {},
  w = {};
z.z = z;
w.z = w;
const p = clone(w);
equal(z, w);              // true
equal(z, p);              // true

// more standard types
const m = {a: new Map(), b: Buffer.from([99, 98, 97])};
m.a.set('a', [Symbol(), new Set([1, 2, 3])]);
m.a.set('b', [/^abc/i, new Date()]);
const n = clone(m);
equal(m, n);              // true

// advanced: symbols
const s = Symbol(),
  t = {[s]: 42, [Symbol.for('deep6')]: 33},
  u = {[s]: 42, [Symbol.for('deep6')]: 33},
  v = clone(u, {symbols: true});
equal(t, u, {symbols: true}); // true
equal(t, v, {symbols: true}); // true

// advanced: clone non-enumerable properties
const r = {a: 1};
Object.defineProperty(r, 'b', {value: 2, enumerable: false});
const q = clone(r, {allProps: true});
r === q;                  // false
equal(r, {a: 1});         // true
equal(r, {a: 1, b: 2});   // false
r.a === q.a;              // true
r.b === q.b;              // true

Docs

All pertinent information is in the wiki.

Installation and use

npm install --save deep6
// ES6 modules
import equal, {clone} from 'deep6';
import matchString from 'deep6/unifiers/matchString';
// CommonJS modules
const {equal, clone} = require('deep6/cjs');
const matchString = require('deep6/cjs/unifiers/matchString').default;

License

BSD-3-Clause

Release History

  • 1.1.4 updated dev deps.
  • 1.1.3 updated dev deps.
  • 1.1.2 updated dev deps.
  • 1.1.1 reformulated any as a well-known symbol.
  • 1.1.0 separated from yopl, extensive refactoring.
  • 1.0.1 added the exports statement.
  • 1.0.0 the first 1.0 release.