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 🙏

© 2025 – Pkg Stats / Ryan Hefner

x-common

v1.0.0

Published

utilities used by x-x.io x-components

Downloads

24

Readme

x-common

Build Status](https://travis-ci.org/x-component/x-common)

./common.js

undefined.extend(target:, source_1...source_n:)

extend( target, source_1...source_n )

Extends a target object with properties from multiple source objects. Properties from source objects are added in the given order. Existing properties are overwritten. Note: Property values like objects and arrays are not cloned or copied.

example:

  t={a:1,b:2};
  s1={c:{y:'z'}};
  s2={d:3};
  r=extend(t,s1,s2,{e:4}); // => r is now { a:1,b:2,c:{y:'z'},d:3,e:4}
  r.a=5; // => t.a====5  is now also 5, as t i target
  r.d=6; // => s2.d====3, number is not an object and copied
  r.c.y='zz'; // ==> s1.y===='zz' is now also 'zz', as both point to the same object

when using

  extend(t,s1,s2,{e:4},true);

then

  r.c.y='zz'; // s1.y===='z'

you can use this to add properties to any object like functions or to an options object

merge

merge( target, source_1...source_n )

Merges multiple nested object structures into a single target object structure. It handles all enumaratable properties recursively.

  • Arrays/objects from the sources are copied by a deep copy.
  • null as a source property sets target obect/array/function property to null.
  • Array like objects like arguments and dom lists are transformed into real arrays
  • Arrays of sources are concatenated to target arrays
  • Primitives and functions are added to arrays
  • Object properties are merged as properties added to arrays.
So you can not add an object directly into an array, you have to use [] arround it
For the same reason you can not add null direclty into an array you must use [null]
  • Functions from sources can define or replace target functions

  • Functions from sources can not be merged/copied into a target objects,array, or primitives, they switch roles with the target.

  • Thus merging for functions has side effects!

  • Source objects properties can be merged into functions

  • Arrays and primitives can not be merged into function, the source becomes an object with a single value before merging.

  • Arrays and objects can not be merged into target primitives,

the target becomes an array or obect with a single value before merging.

To delete a property in a merge you can use a sepcial object as source: merge.remove

undefined.isNaN()

isNaN(value)

replacement for Number.isNaN as long as not all support this

undefined.flatten(object:)

flatten( object )

Flattens a nested object hierarchy to an single object with just non object values

example:

  flatten({a:{n:1,m:2},b:['x',{'y':'z'}],c:3})

result:

  {'a.n':1,'a.m':2,'b[0]':'x','b[1].y':'z',c:3}

recursive structures can not be flattened because paths would be endless