Skip to content

v2.0.0 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[{*.ts,*.md,*.html,*.json,webpack.config.js}]
end_of_line = lf
charset = utf-8
indent_style = tab
indent_size = 4

[package-lock.json]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

2 changes: 0 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
The MIT License (MIT)

Copyright (c) 2014 yeikos

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
90 changes: 58 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,84 @@
# Merge

Merge multiple objects into one, optionally creating a new cloned object.
Similar to the jQuery.extend but more flexible. Works in Node.js and the
browser.
(recursive)? merging of (cloned)? objects.

## Node.js Usage
# Install

## Node.js

```sh
npm install merge --save
npm i merge
```
```js
import merge from 'merge'
```

## Browser

```html
<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/dist/merge.browser.min.js"></script>
```
```js
var merge = require('merge'), original, cloned;
window.merge
```

console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
# API

original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;
```typescript
merge(clone: boolean, ...items: Object[])
merge(...items: Object[])
merge.recursive(clone: boolean, ...items: Object[])
merge.recursive(...items: Object[])
```

console.log(original.x.y, cloned.x.y);
// -> 1, 2
# Examples

console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }
```js

```
// Merge

## Browser Usage
{
var objectA = {}

```html
<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/merge.js"></script>
<script>
var original, cloned;
merge(objectA,
{ value: 1 },
{ str: 'hello world' }
)

console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
var objectB = merge(true, objectA,
{ value: 2 }
)

original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;
objectA // { value: 1, str: 'hello world' }
objectB // { value: 2, str: 'hello world' }
}

console.log(original.x.y, cloned.x.y);
// -> 1, 2
// Recursive merge

console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }
{
var objectA = {}

</script>
merge.recursive(objectA,
{ level: { value: 1 } },
{ level: { str: 'hello world' } }
)
var objectB = merge.recursive(true, objectA,
{ level: { value: 2 } }
)

objectA.level // { value: 1, str: 'hello world' }
objectB.level // { value: 2, str: 'hello world' }
}
```
# Test

## Tests
## Node.js

```sh
npm test
```
## Browser

```
./dist/merge.browser.test.html
```
42 changes: 21 additions & 21 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "merge",
"version": "1.2.1",
"homepage": "https://github.com/yeikos/js.merge",
"authors": [
"yeikos <[email protected]>"
],
"description": "Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.",
"main": "merge.js",
"keywords": [
"merge",
"recursive",
"extend",
"clone",
"object",
"browser"
],
"license": "MIT",
"ignore": [
"tests"
]
}
"name": "merge",
"version": "1.2.1",
"homepage": "https://github.com/yeikos/js.merge",
"authors": [
"yeikos"
],
"description": "(recursive)? merging of (cloned)? objects.",
"main": "dist/merge.browser.min.js",
"keywords": [
"merge",
"recursive",
"extend",
"clone",
"object",
"browser"
],
"license": "MIT",
"ignore": [
"tests"
]
}
1 change: 1 addition & 0 deletions dist/merge.browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions dist/merge.browser.test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script class="mocha-init">
mocha.setup('bdd');
mocha.checkLeaks();
</script>
<script src="./merge.browser.min.js"></script>
<script src="./merge.browser.test.js"></script>
<script class="mocha-exec">
mocha.run();
</script>
</body>
</html>
Loading