-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from yeikos/develop
v2.0.0
- Loading branch information
Showing
294 changed files
with
5,873 additions
and
29,946 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <yeikos@gmail.com>" | ||
], | ||
"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" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.