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

x-object

v1.0.10

Published

JsDK of the Class of Classes Object Class

Downloads

218

Readme

Build Status Coverage Status

Overview :

JsDK (JS dev kit) of Object Class.

How to use :

1. Extend Object Class :

require(`x-object`);
// import 'x-object';

//then :
var object ={a:1, b:2, c:3};
var whitelist = ['a', 'b']
Object.filter(object, whitelist);
// {a:1, b:2}

//-----------Opposite of filter (blacklist)
var blacklist = ['a', 'b']
Object.filter(object, (k, v) => !blacklist.includes(k))
// {c:3}
//........

2. Import safe :

const XObject = require('x-object/safe');
// import XObject from 'x-object/safe';
//then :
XObject.filter(object,['a', 'b']);
//........

Methods :

1. Object.map( object, (k, v)=>)

  • return another object with the same keys , but this same/different values according to the second argument which is callback accepts two arguments.

Object.map({f:"ab",l:"abc" }, (k, v) => v.length );
// {f:2, l:3}
//-------------------
 let students = {
   sami : [80,70],
   ahmed: [90,100]
 };
 let average = (k, v) => v.reduce((a, b) => a+b , 0) / v.length ;
 Object.map(students,average);
  //{sami:75, ahmed: 95}  

2.Object.filter(object, String|Array|RegExp|function)

  • Retrieve a sub-object of a current object.

  • Examples :

 Object.filter({firstname:'Rami', age:23, parent:'Ahmed'}, 'age' );
  // {age:23}

 Object.filter({firstname:'Rami', age:23, parent:'Ahmed'}, ['age','parent'] );
  // {age:23, parent:'Ahmed'}

  Object.filter({firstname:'Rami', lastname:'Toumi', parent:'Ahmed'}, /name$/ );
   // {firstname:'Rami', lastname:'Toumi'}

   Object.filter({fn:'Rami', ln:'Toumi', p:'Ahmed'}, ((k, v) => k == 'fn' || v == 'Ahmed' ));
    // {f:'Rami', parent:'Ahmed'}      

3.Object.vals(object) :

  • As Object.keys however it returns the values of keys in arraym not the keys itself.

4. Object.belongsTo(childObject, parentObject) :

  • It checks if the 1st argument is a sub-object of the 2nd argument.

5. Object.equals

  • check quality of any two objects even if they are complex.

Unit tests :

Coverage X-object

Filter Class
  ✓ contains 4 non-static methods
  ✓ runs "byKey" method prefectly
  ✓ runs "byKeys" method prefectly
  ✓ runs "byRegExp" method prefectly by matching all keys ends with "name"
  ✓ runs "byCallback" method prefectly

Fitler#execute Method
  ✓ must forwards call to "byKey" whenever the argument is instance of "String class"
  ✓ must forwards call to "byKeys" whenever the argument is instance of "Array Class"
  ✓ must forwards call to "byRegExp" whenever the argument is regular expression
  ✓ must forwards call to "byCallback" whenever the argument is callback
  ✓ must return the same object if no argument is given
  ✓ must throw exception whenever the argument is not belong to one of  the previous classes (String, Array, RegExp, Function)

Object.map
  ✓ returns an object with the same keys of target object
  ✓ calls the callback for each keys' iteration

Object.filter
  ✓ returns an object with 1 key whenever the 2nd arg is string & this key is belongs to keys of the target object
  ✓ returns an object with 2 key whenever the 2nd arg is string & keys  belong to keys of the target object

Object.vals
  ✓ works fine
  ✓ returns an array of object values with a size equals to keys size

Object.belongsTo
  ✓ check if the 1st argument is SUB-OBJECT of the 2nd argument

Object.equals
  ✓ checks the equality of two strings
  ✓ checks the equality of two arrays
  ✓ checks the equality of two literal objects
  ✓ checks the equality of two dates
  ✓ checks the equality of two complex objects

Safe Import
  ✓ prevents the Object class from extension
  ✓ extends the Object class whenever "x-object" is imported


25 passing (24ms)