Skip to content

Commit 4b1fa38

Browse files
committed
Updated README, added LICENSE, added index.js, added package.json
1 parent 0cb6591 commit 4b1fa38

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 NOALVO
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# javascript-unwind
2-
A very simple native function for unwinding a collection by a property, like MongoDB's $unwind function.
2+
A very simple native function for unwinding a collection by a property, like MongoDB's [`$unwind`](https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/) function.
3+
4+
# Features
5+
* **This function is immutable.** Your original collection doesn't change.
6+
* **It works for both primitives and complex values**.
7+
8+
# Installation
9+
10+
```
11+
$ npm i javascript-unwind --save
12+
```
13+
14+
# How to use
15+
16+
```javascript
17+
const unwind = require('javascript-unwind');
18+
19+
const collection = [
20+
{ a: [{ x: 1 }, { x: 2 }], b: 123 },
21+
{ a: [{ x: 3 }, { x: 4 }], b: 785, c: 368 },
22+
];
23+
24+
console.log(unwind(collection, 'a'));
25+
```
26+
27+
Output:
28+
29+
```javascript
30+
[
31+
{ a: [{ x: 1 }, { x: 2 }], b: 123 },
32+
{ a: [{ x: 3 }, { x: 4 }], b: 785, c: 368 },
33+
]
34+
```

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = unwind;
2+
3+
function unwind(array, prop) {
4+
return array
5+
.reduce((acc, curr) => [...acc, ...curr[prop]
6+
.map(x => Object
7+
.assign({}, curr, { [prop]: x }),
8+
)],
9+
[]);
10+
}

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "javascript-unwind",
3+
"version": "1.0.1",
4+
"description": "A very simple native function for unwinding a collection by a property, like MongoDB's $unwind function.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/NOALVO/javascript-unwind.git"
12+
},
13+
"keywords": [
14+
"unwind",
15+
"native",
16+
"array",
17+
"javascript",
18+
"object",
19+
"collection"
20+
],
21+
"author": "NOALVO",
22+
"license": "MIT",
23+
"bugs": {
24+
"url": "https://github.com/NOALVO/javascript-unwind/issues"
25+
},
26+
"homepage": "https://github.com/NOALVO/javascript-unwind#readme"
27+
}

0 commit comments

Comments
 (0)