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

objectifyjs

v1.0.0

Published

A utility package to play around with objects

Downloads

5

Readme

Objectifyjs

Static Badge GitHub Actions Jest TypeScript codecov Pivotal Tracker npm License

Overview

Objectifyjs is an npm package that provides a collection of utility functions to work with objects in JavaScript. It includes functions for deep cloning, merging, extracting differences, and more. This package aims to simplify common object manipulations and enhance productivity.

Installation

You can install Objectifyjs via npm:

npm install objectifyjs

Or via yarn:

yarn add objectifyjs

Features

  • Deep Clone: Create a deep copy of an object.
  • Merge: Merge two objects, including nested objects.
  • Extract Differences: Extract differences between two objects.
  • TypeScript Support: Fully typed with TypeScript.
  • Unit Tested: Thoroughly tested with Jest.

Usage

Deep Clone

import { deepClone } from 'objectifyjs';

const original = { a: 1, b: { c: 2 } };
const clone = deepClone(original);

console.log(clone); // { a: 1, b: { c: 2 } }

Merge

import { merge } from 'objectifyjs';

const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { d: 3 } };

merge(obj1, obj2);
console.log(obj1); // { a: 1, b: { c: 2, d: 3 } }

Extract Differences

import { getDifference } from 'objectifyjs';

const obj1 = { a: 1, b: 2, c: { d: 3 } };
const obj2 = { a: 1, b: 3, c: { d: 4 } };

// Extract differences from obj1 to obj2
const diff1 = getDifference(obj1, obj2, 1);
console.log(diff1); // { b: 2, c: { d: 3 } }

// Extract differences from obj2 to obj1
const diff2 = getDifference(obj2, obj1, -1);
console.log(diff2); // { b: 3, c: { d: 4 } }

// Extract combined differences
const diff3 = getDifference(obj1, obj2, 0);
console.log(diff3); // { b: 2, c: { d: 3 }, b: 3, c: { d: 4 } }

API

deepClone(obj: T): T

Creates a deep copy of the provided object.

Parameters:

  • obj (T) - The object to clone.

Returns: A deep copy of the object.

merge(target: T, source: Partial): void

Merges the source object into the target object, including nested objects.

Parameters:

  • target (T) - The target object to merge into.
  • source (Partial) - The source object to merge from.

extractDifferences(obj1: T, obj2: T, flag: number): Partial

Extracts differences between two objects based on the flag value.

Parameters:

  • obj1 (T) - The first object to compare.
  • obj2 (T) - The second object to compare.
  • flag (number) - The flag to determine the direction of the difference extraction:
    • -1: Extract differences from obj2 to obj1.
    • 1: Extract differences from obj1 to obj2.
    • 0: Extract differences from both objects, excluding common properties with different values.

Returns: An object containing the differences.

Contributing

We welcome contributions! Please read our Contributing Guide to learn how you can help.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • TypeScript
  • Jest
  • Pivotal Tracker
  • GitHub Actions