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

js-extends

v1.0.9

Published

Extends for some js types: Date, Array, Object, Function.

Downloads

17

Readme

js-extends

  • Extends for some js types.
  • 'Type' enum.

Extends:

Date:

  • equals(date)
let d1 = new Date("2000-01-01"),    
let d2 = new Date(2000, 0, 1);
d1.equals(d2); // true

Array:

  • notNullItems()
let o1 = {a: 1, b: null, c: "str"};
let o2 = o.notNullItems(); // {a: 1, c: "str"}
  • string() instead of toString()
  • sortBoolean()
let arr = [null, true, false, true, undefined, false];
let arr2 = arr.sortBoolean(); // [null, null, false, false, true, true]
  • equals(arr)
let a1 = [1, "s", true, {a:1, b:() => {return 15}}];
let a2 = [1, "s", true, {a:1, b:() => {return 15}}];
let a3 = [1, "s", true, {a:1, b:() => {return 16}}];
a1.equals(a2); // true
a1.equals(a3); // false
  • contains(item)
let arr = [1, "s", true, {a:1, b:() => {return 15}}];
let o = {a:1, b:() => {return 15}};
arr.contains(o); // true. (while 'arr.includes(o)' is false)
  • groupBy()
let arr = [1, 2, 3, 2, 2, 1];
let arr2 = arr.group(); // [{'1': 2}, {'2': 3}, {'3': 1}]
  • groupObjectsBy(key, countOnly)
let arr = [
    { make: 'audi', model: 'r8' },
    { make: 'ford', model: 'fusion' },
    { make: 'audi', model: 'rs5' },
    { make: 'kia', model: 'optima' },
    { make: 'ford', model: 'mustang' },
];
let arr2 = arr.groupObjectsBy("make", false); // [{ 'audi': [{ 'model': 'r8' }, { 'model': 'rs5' }]}, { 'ford': [{ 'model': 'fusion' }, { 'model': 'mustang' }]}, { 'kia': [{ 'model': 'optima' }]}]
let arr3 = arr.groupObjectsBy("make", true); // [{ 'audi': 2 }, { 'ford': 2 }, { 'kia': 1 }]

Object:

  • notNullItems()
let a1 = [1, "s", null, true, {a:1,}];
let a2 = a1.notNullItems(); // [1, "s", true, {a:1,}];
  • isAnyNullOrUndefined(props)
let o = {prop_a: 1, prop_b: null, prop_c: "str"};
o.isAnyNullOrUndefined(); // true
o.isAnyNullOrUndefined(["prop_a", "prop_c"]); // false
o.isAnyNullOrUndefined(["prop_a", "prop_d"]); // true
  • string() instead of toString()
  • equals(obj)
let o1 = {a:1, b: "str", c: true, d: (p) => {return p * p}};
let o2 = {a:1, b: "str", c: true, d: (p) => {return p * p}};
let o2 = {a:1, b: "str", c: true, d: (p) => {return p + p}};
o1.equals(o2); // true
o1.equals(o3); // false

Function

  • body()
// Returns the function's body
  • string() Returns func.toString() without newlines and spaces.
  • equals(func)
function f1(a) { return a + a; }
function f2(a) { 
    return a + a;
}
f1.equals(f2); // true;

'Type' Enum:

let t1 = Type.GetType(new Date()); // Type.Date (while 'typeof new Date()' is "object")
t1 == Type.Date; // true
let t2 = Type.GetType([]); // Type.Array (while 'typeof []' is "object")
t2 == Type.Array; // true
// Supported: Type.Undefine, Type.Number, Type.String, Type.Boolean, Type.Array, Type.Date, Type.Function, Type.Object.