Skip to content

Commit

Permalink
Merge pull request #32 from yeikos/develop
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
yeikos authored Jul 31, 2019
2 parents b31e67f + 43ffa43 commit ece8885
Show file tree
Hide file tree
Showing 294 changed files with 5,873 additions and 29,946 deletions.
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 <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"
]
}
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

0 comments on commit ece8885

Please sign in to comment.