Skip to content

Commit

Permalink
📝 (README/main function DOC) Changed the commonjs import method instr…
Browse files Browse the repository at this point in the history
…uctions
  • Loading branch information
rxluz committed Feb 12, 2019
1 parent 7e95fd8 commit 5448b9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ console.log(preventObjectRecursion(a));
### Example (commonjs)

```js
var preventObjectRecursion = require('@rxluz/prevent-object-recursion');
var preventObjectRecursion = require('@rxluz/prevent-object-recursion').default;

const a = { hello: 'world' };
const b = { hey: 'hey', hello: a };
Expand Down
11 changes: 5 additions & 6 deletions src/lib/preventObjectRecursion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* ### Example (commonjs)
* ```js
* const preventObjectRecursion = require('@rxluz/prevent-object-recursion');
* const preventObjectRecursion = require('@rxluz/prevent-object-recursion').default;
*
* const a = { hello: 'world' }
* const b = { hey: 'hey', hello: a }
Expand All @@ -30,10 +30,9 @@
* @anotherNote Works in the browser as well as node.
*/

export default function preventObjectRecursion(
root: any,
list: any = []
): object {
// tslint:disable-next-line:export-just-namespace

export default function preventObjectRecursion(root: any, list: any = []): any {
// keys with null data or with string/function/boolean data couldn't create recursive data, in this case we simply return this data
const rootIsNullOrNotAObject = !root || typeof root !== 'object';

Expand All @@ -58,7 +57,7 @@ export default function preventObjectRecursion(
? Object.keys(root).reduce(
(accumulator: object, key: string) => ({
...accumulator,

// tslint:disable-next-line
[key]: preventObjectRecursion(root[key], [...list])
}),
{}
Expand Down

0 comments on commit 5448b9a

Please sign in to comment.