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

object-decorator

v1.0.1

Published

Methods that would be nice to have in Object.prototype. But since adding to Object.prototype isn't safe, I created a Decorator for Object.

Downloads

6

Readme

These are methods that would be nice to have in Object.prototype. Since they can't be added safely, I created a Decorator for Object.


var decorate = require("../../index").decorate;
...
var obj = {id: 3};
var obj2 = {author: "Philip Ford"};
decorate(obj).extend(obj2);
        

API Documentation

extend(varargs)

Mixes the properties of the arguments into the component. Takes an arbitrary number of objects as parameters.

augment(that)

Mixes the properties of the specified object into the component, but only properties that do not already exist in the component. In other words, existing properties are not overridden in the component. This is the method I find most useful.

override(that)

Adds the properties of the specified object to the component if and only if the component already has properties of the same name.

has(varargs)

Checks whether all of the arguments are properties of the component.

size()

Returns the number of key/value pairs in the object.

forEach(function)

Performs an operation for each item in the specified object.

map(function)

Creates a new object by performing a transformation on each value in the specified object.

filter(function)

Returns an object of component key/value pairs that passed the filter. The filter requires a callback function that takes the following parameters: (1) the value of the current property, the name of the current property, and the component. That function must return true/false.

difference(that)

Returns an object containing the differences between the component and the specified object--differences being different properties, or properties with the same name but different values.

intersection(that)

Returns an object containing the properties that match (same name and value) between the component and the specified object.

values()

Returns an array of the values in the component.

getSpec()

Returns a "Specification" object that can be used to compare the spec for the component to the spec for another object. Used for duck-typing.

Methods of Specification

like(that)

Returns true/false for whether the specified object has all of the properties in the component. and whether the types of the corresponding properties match.

equals(that)

Returns true/false for whether the specs of the component and the specified object match exactly, sharing all of the same properties, and whether the types of the corresponding properties match.

contains(value)

Returns true/false for whether the specified value is contained in the object.

add(k, v)

remove(k)

constant(k, v)

Creates a constant in the component's scope. If the key is not uppercase, it will be converted.

getPrototypeOf()

Cross-browser function for returning an object's prototype.