Skip to content

Commit

Permalink
fix: merge array also use values from b
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jun 28, 2019
1 parent 696946c commit 586a5c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ const configuration await expand("${include('" + '/path/to/the/config.json' + "'
- [Parameters](#parameters-9)
- [merge](#merge)
- [Parameters](#parameters-10)
- [removeSensibleValues](#removesensiblevalues)
- [Parameters](#parameters-11)

## defaultConstants

Expand Down Expand Up @@ -277,17 +275,6 @@ When a and b are arrays of values only the none duplaces are appendend to a

Returns **any** merged b into a

## removeSensibleValues

genereates a new object tree by removing sensible values like credentials from it

### Parameters

- `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `toBeRemoved` (optional, default `key=>key.match(/pass|auth|key|user|secret/)`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object tree free of sensible data

# install

With [npm](http://npmjs.org) do:
Expand Down
2 changes: 1 addition & 1 deletion src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function merge(a, b) {

if (Array.isArray(a)) {
if (Array.isArray(b)) {
return [...a, ...a.filter(x => !b.find(e => equal(e, x)))];
return [...a, ...b.filter(x => !a.find(e => equal(e, x)))];
}
return [...a, b];
}
Expand Down
36 changes: 31 additions & 5 deletions tests/merge-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ test("merge complex array", async t =>
[{ a: 1 }, { b: 2 }]
));

test("merge complex array 2", async t =>
t.deepEqual(
await expand([
{
"type": "github-repository-provider"
},
{
"type": "gitea-repository-provider"
}
], {
default: [
{
"type": "github-repository-provider"
}
]
}),
[
{
"type": "github-repository-provider"
},
{
"type": "gitea-repository-provider"
}
]
));

test("merge array", async t =>
t.deepEqual(
await expand(
Expand Down Expand Up @@ -51,9 +77,9 @@ test("merge array", async t =>
));


test("eq1",t =>{
t.true(equal(1,1));
t.true(equal([1],[1]));
t.true(equal([{a:1}],[{a:1}]));
t.false(equal([{a:1}],[{b:1}]));
test("eq1", t => {
t.true(equal(1, 1));
t.true(equal([1], [1]));
t.true(equal([{ a: 1 }], [{ a: 1 }]));
t.false(equal([{ a: 1 }], [{ b: 1 }]));
});

0 comments on commit 586a5c5

Please sign in to comment.