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 🙏

© 2026 – Pkg Stats / Ryan Hefner

decorated-merger

v1.4.1

Published

Small utility to merge your object, respecting class decoration if any exist

Readme

Build Status Coverage Status

Decorated Merged

A very simple package to merge to object respecting decoration if any.

Features

  • Exclude/Include all class properties with decoractors
  • Define group of decorators to have different option at runtime
  • Define Equatable function with decorator to properly merge arrays

Usage

Install

Yarn:

yarn add decorated-merger

npm:

npm i decorated-merger

Merger

Merger function will merge all newObject properties into the source object merging arrays and sub-objects, respecting all the decorators below.

   merger(newObject, object); // will merge properties of newObject in object

Decorators

  • @Exclude at class level it will exclude all the class properties by default. The one yo want to merge will need to be set with the @Include decorator. Ex:
@Exclude()
export class Person {
   id: string;
   firstname: string;
   lastname: string;
   @Include()
   status: string;
   constructor(id: string, lastname: string, firstname: string, status: string) {
       this.id = id;
       this.firstname = firstname;
       this.lastname = lastname;
       this.status = status;
   }
}

Only status from the new object will be merged into the source object

  • @Exclude at property level it will exclude only this property. Ex:
export class Person {
   @Exclude()
   id: string;
   firstname: string;
   lastname: string;
   status: string;
   constructor(id: string, lastname: string, firstname: string, status: string) {
       this.id = id;
       this.firstname = firstname;
       this.lastname = lastname;
       this.status = status;
   }
}

All properties except ID of the new object will be merged into the source object

  • Groups You can specify a group at the decorater level and in the merger to specify different behaviours. Ex:
@Exclude()
export class Person {
   id: string;
   @Include({group: 'admin'}))
   firstname: string;
   @Include({group: 'admin'}))
   lastname: string;
   @Include()
   status: string;
   constructor(id: string, lastname: string, firstname: string, status: string) {
       this.id = id;
       this.firstname = firstname;
       this.lastname = lastname;
       this.status = status;
   }
}

If you call without group option:

merger(newObject, object);

only status will be merged in object If you call with group admin option:

merger(newObject, object, {group: 'admin'});

lastname, firstame and status will be merged in new object

  • Equatable Allow you to specify if new object should be merged with an existing object in the array or if the object should be appended to the array. Ex:
@Equatable<Car>({equal: (a, b) => a.id === b.id})
export class Car {
   id: string
   model: string;
}
export class Person {
   @Exclude()
   id: string;
   firstname: string;
   lastname: string;
   cars: Car[];
   constructor(id: string, lastname: string, firstname: string, cars?: Car[]) {
       this.id = id;
       this.firstname = firstname;
       this.lastname = lastname;
       this.status = status;
   }
}

TODO

  • override equatable a array property level.

Exemple use cases (from tests)

@Exclude()
@Equatable<Car>({equal: (a, b) => a.id === b.id})
export class Car {
    id: string
    @Include({group: 'garage'})
    model: string;
    creator: string;
    @Include()
    notfilled: string;
    @Include()
    price: number;
    options: string[];
    @Include()
    canUse: Person[];
    buyer: Person;
}

@Equatable<Person>({equal: (a, b) => a.id === b.id})
export class Person {
    @Exclude()
    id: string;
    fixing: Car[];   
    @Exclude()
    middlename: string;
    constructor(id: string, public lastname: string, public firstname: string, middlename: string) {
        this.id = id;
        this.middlename = middlename;
    }
}

export const getTestCar = () => {
  const car = new Car()
  car.id = 'test'
  car.model = 'Model 3'
  car.creator = 'Elon'
  car.price = 30000
  return car
}

export const getElecticCar = () => {
  const car = new ElectricCar()
  car.id = 'electric'
  car.model = 'Model 3'
  car.creator = 'Elon'
  car.price = 30000
  car.percent = 50
  return car
}
export const getTransformerCar = () => {
  const car = new TransformerCar()
  car.id = 'transformer'
  car.creator = 'Elon'
  car.model = 'Model 3'
  car.price = 30000
  car.surename = 'billy'
  return car
}

export const getPersonA = () => new Person('a', 'A', 'toto', 'middlea')
export const getPersonB = () => new Person('b', 'B', 'toto', 'middleb')


it("Two simple class should merge", () => {
    const car = getTestCar();
    const carNew = getTestCar();
    carNew.notfilled = 'test';
    carNew.creator = 'toto';
    carNew.model = 'Model X';
    expect(car.notfilled).toBeUndefined();
    expect(car.creator).toEqual('Elon');
    expect(car.model).toEqual('Model 3');
    merger(carNew, car);
    expect(car.notfilled).toBeDefined();
    expect(car.creator).toEqual('Elon');
    expect(car.model).toEqual('Model 3');
  })

  it("Two simple class with group should merge", () => {
    const car = getTestCar();
    const carNew = getTestCar();
    carNew.notfilled = 'test';
    carNew.creator = 'toto';
    carNew.model = 'Model X';
    expect(car.notfilled).toBeUndefined();
    expect(car.creator).toEqual('Elon');
    expect(car.model).toEqual('Model 3');
    merger(carNew, car, {group: 'garage'});
    expect(car.notfilled).toBeDefined();
    expect(car.creator).toEqual('Elon');
    expect(car.model).toEqual('Model X');
  })

  it("Two simple class with new array should merge", () => {
    const car = getTestCar();
    const carNew = getTestCar();
    const personA = getPersonA();
    carNew.canUse = [personA];
    expect(car.canUse).toBeUndefined();
    merger(carNew, car);
    expect(car.canUse).toBeDefined();
    expect(car.canUse[0]).toEqual(personA);
  })

  it("Two simple class with exsiting array should merge", () => {
    const car = getTestCar();
    const carNew = getTestCar();
    const personA = getPersonA();
    const personB = getPersonB();
    car.canUse = [personA];
    carNew.canUse = [personB]
    merger(carNew, car);
    expect(car.canUse.length).toEqual(2);
    expect(car.canUse[0]).toEqual(personA);
    expect(car.canUse[1]).toEqual(personB);
  })

  it("Two simple class with exsiting array with equals should merge", () => {
    const car = getTestCar();
    const carNew = getTestCar();
    const personA = getPersonA();
    const personB = getPersonA();
    personB.lastname = 'Ab';
    personB.middlename = 'cecile';
    car.canUse = [personA];
    carNew.canUse = [personB]
    expect(personA.middlename).toEqual('middlea');
    merger(carNew, car);
    expect(car.canUse.length).toEqual(1);
    expect(car.canUse[0].lastname).toEqual('Ab');
    expect(car.canUse[0].middlename).toEqual('middlea');
  })