Giter Site home page Giter Site logo

boraseoksoon / cljs-merge Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 113 KB

Merge jsons into a single one.

Home Page: https://www.npmjs.com/package/cljs-merge

License: MIT License

JavaScript 11.77% Clojure 69.08% HTML 19.15%
nodejs clojure clojurescript javascript merge deep-merge json objects replace two

cljs-merge's Introduction

cljs-merge

'cljs-merge' recursively merges two jsons into a unified one, excluding null or undefined in the same order.

NPM Version

const { merge } = require('cljs-merge')

const js1 = { k1: "v1", k2: "v2", k3: "v3" }
const js2 = { k1: "v1", k2: undefined, k4: "v4", k5: "v5", k6: null }

const res = merge({ src:js1, target: js2 })
console.log("res ==> ", res);
// res ==> { k1: 'v1', k2: 'v2', k3: 'v3', k4: 'v4', k5: 'v5' }
const { merge } = require("cljs-merge")

const src = {	
	key1: "1",
	key2: "2",
	key3: "3",
	key4: "4",
	key5: {
		key22: null,
		key11: "10",
		key33: "30"
	},
	special: "BORA"
}

const target = {	
	key1: "10",
	key3: null,
	key4: "40",
	key5: {
		key11: null,
		key22: "200",
		key33: null
	}, 
	key6: "6", 
	quit: -1
}

const res = merge({ src, target })

console.log("res ==> ", res);
// res ==> 
// {	
// 	key1: "10",
// 	key2: "2",
// 	key3: "3",
// 	key4: "40"
//  key5: {
// 		key11: "10", 
// 		key22: "200", 
// 		key33: "30", 
// 	}
// 	key6: "6", 
// 	special: "BORA"
//  quit: -1
// }

Installation for Node.js

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm install cljs-merge

Installation for Web Browser

CDN

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<script src="https://cdn.jsdelivr.net/npm/[email protected]/cljs_dist/core/web/cljs.js"></script>
	<script>
		const { merge } = cljs.merge.core
		
		const src = {
			k1: "v1",
			k2: "v2",
			k3: "v3"
		}
	
		const target = {
			k1: "v1",
			k2: undefined,
			k4: "v4",
			k5: "v5",
			k6: null
		}
	
		const res = merge({ src, target })
		
		console.log("res ==> ", res);
		// res ==> { k1: 'v1', k2: 'v2', k3: 'v3', k4: 'v4', k5: 'v5' }
	</script>
</head>
<body>
	
</body>
</html>
	<script src="https://cdn.jsdelivr.net/npm/[email protected]/cljs_dist/core/web/cljs.js"></script>
	<script>
		const { merge } = cljs.merge.core
		
		const src = {
			k1: "v1",
			k2: "v2",
			k3: "v3"
		}
	
		const target = {
			k1: "v1",
			k2: undefined,
			k4: "v4",
			k5: "v5",
			k6: null
		}
	
		const res = merge({ src, target })
		
		console.log("res ==> ", res);
		// res ==> { k1: 'v1', k2: 'v2', k3: 'v3', k4: 'v4', k5: 'v5' }
	</script>

Contributing

Contributing Guide

License

MIT

cljs-merge's People

Contributors

boraseoksoon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.