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

json-artisan

v0.1.3

Published

A JSON deep extend library

Downloads

5

Readme

JSON Artisan

A JSON deep extend library

JSON Artisan

Install the module from npm

npm i json-artisan --save

Usage

In its basic form JSON Artisan extends objects.

const artisan = require('json-artisan');

artisan({
    name: 'ruddiger',
    age: 37,
    pets: {
        dogs: ['murphey'],
        cats: ['tammy', 'jupiter']
    }
}, {
    age: 27,
    pets: {
        cats: ['jupiter', 'felix']
    }
}, {
    age: 28,
    canDraw: true
});
#=> {
    name: 'ruddiger',
    age: 28,
    pets: {
        dogs: ['murphey'],
        cats: ['jupiter', 'felix'],
    },
    canDraw: true
}

Unset keys by providing a value of undefined.

const target = {
    name: 'ruddiger',
    age: 37,
    income: 3000
};

artisan(target, {
    income: undefined
});
#=> {
    name: 'ruddiger',
    age: 37
}

Extensions

JSON Artisan accepts functions as properties, enabling you to do things like this:

const target = {
    age: 37,
    cats: ['tammy', 'jupiter']
};

artisan(target, {
    cats: (cats) => cats.map(cat => cat + '-cat')
});
#=> {
    age: 37,
    cats: ['tammy-cat', 'jupiter-cat']
}

The library comes with a useful set of extensions available via the $ object.

const $ = require('json-artisan').$;

$.Array.Concat

Adds provided values to the end of the array.

artisan({
    dogs: ['rex']
}, {
    dogs: $.Array.Concat('jacob', 'murphey')
});
#=> {
    dogs: ['rex', 'jacob', 'murphey']
}

$.Array.AddToSet

Adds provided values to the end of the array only if they do not already exist.

artisan({
    dogs: ['rex']
}, {
    dogs: $.Array.AddToSet('murphey', 'rex')
});
#=> {
    dogs: ['rex', 'murphey']
}

$.Array.Splice

Splice the array.

artisan({
    dogs: ['jacob', 'murphey', 'rex']
}, {
    dogs: $.Array.Splice(1, 1, 'alex', 'fredrick')
});
#=> {
    dogs: ['jacob', 'alex', 'fredrick', 'rex']
}

$.Array.Map

Performs the provided method on every item in the array.

artisan({
    dogs: ['rex', 'catalina']
}, {
    dogs: $.Array.Map(dog => dog + '-dog')
});
#=> {
    dogs: ['rex-dog', 'catalina-dog']
}

$.Boolean.Toggle

Reverses the value of the boolean (default: true).

artisan({
    isParent: true
}, {
    isParent: $.Boolean.Toggle()
});
#=> {
    isParent: false
}

$.Number.Inc $.Number.Dec

Increments or decrements the number by the provided amount (default: 1).

artisan({
    foundTreasuresCount: 10
}, {
    foundTreasuresCount: $.Number.Inc()
});
#=> {
    foundTreasuresCount: 11
}

$.Number.Mul $.Number.Div

Multiplies or divides the number by the provided amount (default: 1).

artisan({
    awesomeness: 5
}, {
    awesomeness: $.Number.Mul(3)
});
#=> {
    awesomeness: 15
}

$.Number.Max $.Number.Min

Sets the number to the highest or lowest number (default: 0).

artisan({
    health: 120
}, {
    health: $.Number.Min(100)
});
#=> {
    health: 100
}

$.Object.Set

Replaces the object rather than extending it (default: {}).

artisan({
    toys: { racers: 3, stuffedAnimals: 1 }
}, {
    toys: $.Object.Set({ racers: 5, baseballs: 2 })
});
#=> {
    toys: { racers: 5, baseballs: 2 }
}

$.String.Append $.String.Prepend

Appends or prepends a string with an optional separator (default: '').

artisan({
    fullName: 'kangaroo'
}, {
    fullName: $.String.Append('rodrigo', ', ')
});
#=> {
    fullName: 'kangaroo, rodrigo'
}

Contribute

If you like what you see please feel encouraged to get involved report problems and submit pull requests! As of the time of this writing the project is new with one maintainer.