Skip to content

JayPaulinCodes/smush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smush

A simple function to make merging objects together a bit easier, because why not!

Installing

npm i @devjacob/smush

Examples

import smush from "../lib/index.js";

const DEFAULT_OPTIONS = {
    name: "Default Name",
    path: "./path/to/file.txt",
    data: {
        apple: 1,
        banana: 20
    }
}

function buildOptions(options) {
    return smush(DEFAULT_OPTIONS, options);
}

const MY_OPTIONS = buildOptions({
    path: "./my/special/dir/file.txt",
    data: {
        apple: 10,
        pear: 72
    }
});

console.log(MY_OPTIONS); // Output: { name: 'Default Name', path: './my/special/dir/file.txt', data: { apple: 10, banana: 20, pear: 72 } }
import smush from "../lib/index.js";

const obj1 = {
    foo: "bar",
    buzz: {
        apple: 1,
        banana: 2,
    }
}

const obj2 = {
    foo: "fiz",
    buzz: {
        pear: 5
    }
}

console.log(smush(undefined, obj1)); // Expected Output: { foo: 'bar', buzz: { apple: 1, banana: 2 } }
console.log(smush(undefined, obj2)); // Expected Output: { foo: 'fiz', buzz: { pear: 5 } }
console.log(smush(obj1, obj2)); // Expected Output: { foo: 'fiz', buzz: { apple: 1, banana: 2, pear: 5 } }
console.log(smush(obj2, obj1)); // Expected Output: { foo: 'bar', buzz: { pear: 5, apple: 1, banana: 2 } }

Note

Because recursion is used to make this happen, there is some limitations to object size, see examples/example-callStack.js

License

This project uses the Mozilla Public License 2.0
Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license (or in certain cases, one of the GNU licenses). Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work may be distributed under different terms and without source code for files added in the larger work.

The license can be read here

The following table provides a breif overview of the license. Hovering each point will provide a more detailed description.

Permissions Conditions Limitations
Commercial use
Distribution
Modification
Patent use
Private use
Disclose source
License and copyright notice
Same license (file)
Liability
Trademark use
Warranty

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published