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

a-object

v1.0.4

Published

A Node.js module for iterating through objects asynchronously and synchronously, updating them recursivley and comparing their keys. Package moved: https://npmjs.org/package/object-analyzr

Downloads

15

Readme

AObject

A Node.js module for iterating through objects asynchronously and synchronously, updating them recursivley and comparing their keys.

License GNU GPL v3.0

Package moved

This package has been renamed to objectAnalyzr and moved to https://npmjs.org/package/object-analyzr. The newer versions will be avalible only there!

Usage

npm install a-object
var AObject = require('a-object');

Functions

AObject()

var aObject = new AObject(object object);

Creates a new instance of AObject with the given object.

Arguments

  • object object - The object to use for instance functions.

Example

var aObject = new AObject({
	key1: 'foo',
	key2: 'bla'
});

AObject#each()

aObject.each(function iterator, function callback);

Calls AObject.each() with the object given in AObject() as object.

Arguments

  • function iterator(string key, mixed value, function callback) - A function to apply to each item in object. iterator is passed a callback(error) which must be called once it has completed. If no error has occurred, the callback should be run without arguments or with an explicit null argument.
  • function callback(error) - A callback which is called when all iterator functions have finished, or an error occurs.

AObject#eachSync()

aObject.eachSync(function iterator);

Calls AObject.eachSync() with the object given in AObject() as object.

Arguments

  • function iterator(string key, mixed value) - A function to apply to each item in object.

AObject#update()

aObject.update(object newObject);

Calls AObject.update() with the object given in AObject() as newObject.

Arguments

  • object newObject - The object to be merged into currentObject.

AObject#compareKeys()

aObject.compareKeys(mixed expectedObject);

Calls AObject.compareKeys() with the object given in AObject() as object.

Arguments

  • mixed object - The object for comparision. It can be an array as well, where only the keys are given, if expectedObject is an array, the comparison isn't recursive.
  • bool strict - Wether all keys of object have to exist in expectedObject as well. Default: false

AObject#getKeys()

aObject.getKeys(array keys)

Calls AObject.getKeys() with the object given in AObject() as object.

Arguments

  • array keys - All keys of object to be returned.

AObject.each()

AObject.each(object object, function iterator, function callback);

Applies the function iterator to each item in object, in parallel. iterator is called with a key and a value from the object, and a callback for when it has finished. If the iterator passes an error to its callback, the main callback (for the each function) is immediately called with the error.

Note, that since this function applies iterator to each item in parallel, there is no guarantee that the iterator functions will complete in order.

Arguments

  • object object - An object to iterate over.
  • function iterator(string key, mixed value, function callback) - A function to apply to each item in object. iterator is passed a callback(error) which must be called once it has completed. If no error has occurred, the callback should be run without arguments or with an explicit null argument.
  • function callback(error) - A callback which is called when all iterator functions have finished, or an error occurs.

Example

// will log 'done' to console if no error occurs in the iterator function
AObject.each(
	{
		key1: 'foo',
		key2: 'bla',
	},
	function(key, value, next) {
		// Do some asynchronous stuff with key and value
		if(err) next(err); // Ooops ... error ...
		next();
	},
	function(error) {
		if(error) throw error;
		console.log('done');
	}
);

AObject.eachSync()

AObject.eachSync(object object, function iterator);

Applies the function iterator to each item in object, serial. iterator is called with a key and a value from the object.

Arguments

  • object object - An object to iterate over.
  • function iterator(string key, mixed value) - A function to apply to each item in object.

Example

// will log 2 messages to console: 'The value of key1 is foo'; 'The value of key2 is bla'
AObject.eachSync(
	{
		key1: 'foo',
		key2: 'bla'
	},
	function(key, value) {
		console.log('The value of ' + key + ' is ' + value);
	}
);

AObject.update()

AObject.update(object currentObject, object newObject);

Adds all keys of newObject and their values recursively to currentObject or overwrites existing ones.

Arguments

  • object currentObject - The object to be updated.
  • object newObject - The object to be merged into currentObject.

Example

// currentObject will be {key1: 'foo', key2: 'bla2', key3: 'foo2'}
AObject.update(
	{
		key1: 'foo',
		key2: 'bla',
	},
	{
		key2: 'bla2',
		key3: 'foo2'
	}
);

AObject.compareKeys()

AObject.compareKeys(mixed expectedObject, object object);

Compares all keys of object with the keys of expectedObject recursively. If the keys of both objects match exactly true will be returned, otherwise false.

Arguments

  • object object - The object to be compared with expectedObject.
  • mixed expectedObject - The object for comparison. It can be an array as well, where only the keys are given, if expectedObject is an array, the comparison isn't recursive.
  • bool strict - Wether all keys of object have to exist in expectedObject as well or not. Default: false

Note, that by default all keys of expectedObject have to exist in object as well to return true, but in object there can be keys not given in expectedObject.

If strict is set to true, all keys of object have to exist in expectedObject as well, so the comparison is bidirectional.

Example

// returns true
AObject.compareKeys(
	{
		key1: 'foo',
		key2: {
			key3: 'bla'
		}
	},
	{
		key1: 'foo2',
		key2: {
			key3: 'bla2'
		}
	}
);
// returns false
AObject.compareKeys(
	[
		'key1',
		'key3'
	],
	{
		key1: 'foo',
		key2: 'bla'
	}
);

AObject.getKeys()

AObject.getKeys(object object, array keys);

Returns all keys in keys of object.

Arguments

  • object object - The object the wanted values are in.
  • array keys - An array with all keys to be returned.

Example

// returns {first: 'one', third: 'four'}
AObject.getKeys(
	{
		first: 'one',
		second: 'seven',
		third: 'four'
	},
	[
		'first',
		'third'
	]
);