Skip to content

Commit

Permalink
docs: updated to v4 + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriGor committed Apr 25, 2019
1 parent 558ca4c commit 145e88c
Show file tree
Hide file tree
Showing 23 changed files with 296 additions and 148 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*(unreleased)*

**Breaking Changes**
- in the browser deepdash doesn't try to patch existing global `_` variable. It now exposes global `deepdash` function and the user should pass a lodash instance to this function manually.
- source object/array (root) passed to the iteratee/predicate too, as a very first value with undefined key/path/parent
- `indexate` renamed to [index](/#index).
- in case of completely rejected object [filterDeep](/#filterdeep) returns null instead of empty {}/[]
Expand All @@ -14,6 +15,9 @@
- `tree` sub-object option deprecated, `tree.children` renamed to `childrenPath`, `tree.rootIsChildren` renamed to `rootIsChildren`

**Features added**
- cherry-pick separate methods now available as standalone functions or as a lodash mixins.
- standalone version now available
- `deepdash-es` package created for importing as es6 module. It's just a content of `es` folder from main repo.
- `includeRoot` option added to [eachDeep](/#eachdeep-foreachdeep), [index](/#index), [paths (keysDeep)](/#paths-keysdeep) and [filterDeep](/#filterdeep) methods.
- leavesOnly implemented for tree mode. eachDeep now also has leavesOnly option.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018
Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
68 changes: 57 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,74 @@ Looking for eachDeep, filterDeep, omitDeep, keysDeep etc? Tree traversal extensi
[![NPM](https://nodei.co/npm/deepdash.png?compact=true)](https://nodei.co/npm/deepdash/)

### Installation
In a browser load [script](https://cdn.jsdelivr.net/npm/deepdash/deepdash.min.js) after Lodash:
#### In a browser
Load [script](https://cdn.jsdelivr.net/npm/deepdash/browser/deepdash.min.js) after Lodash, then pass a lodash instanced to the deepdash function:

```html
<script src="https://cdn.jsdelivr.net/npm/lodash/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/deepdash/deepdash.min.js"></script>
<script>
deepdash(_);
console.log(_.eachDeep); // --> new methods mixed into Lodash
</script>
```
Using npm:

If you don't use Lodash - there is a standalone version:
```html
<script src="https://cdn.jsdelivr.net/npm/deepdash/deepdash.standalone.min.js"></script>
<script>
console.log(deepdash.eachDeep); // --> all the methods just work
</script>
```
Standalone Deepdash weigh more then "dry" version, because it includes some of cherry-picked Lodash methods it depends on.
But it's better to use Standalone version, than include full Lodash just as dependency.


####Using npm:
```
npm i --save deepdash
```
In Node.js (same for the Angular component):
In Node.js:
```js
//mixin new methods into Lodash object
const _ = require('deepdash')(require('lodash'));
// load Lodash if you need it
const _ = require('lodash');
//mixin all the methods into Lodash object
require('deepdash')(_);
// or cherry-pick method you only need and mix it into lodash
require('deepdash/addFilterDeep')(_);
// or cherry-pick method separately if you don't want to mutate Lodash instantne
const filterDeep = require('deepdash/getFilterDeep')(_);
// If you don't need Lodash - there is standalone version
const deepdash = require('deepdash/standalone')(_); // full
const filterDeep = require('deepdash/filterDeep')(_); // or separate standalone methods
```

There is also deepdash as ES6 module
```
npm i --save deepdash-es
```
Or as [ECMAScript Module](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
```js
import lodash from "lodash";
import deepdash from "deepdash";
import lodash from 'lodash-es';
import deepdash from 'deepdash-es';
const _ = deepdash(lodash);
```
## Demo
in the ES package there are same cherry-pick and/or standalone methods as in the main package.
```js
import filterDeep from 'deepdash-es/filterDeep';
```
or
```js
import { filterDeep } from 'deepdash-es/standalone';
```
or
```js
import _ from 'lodash-es';
import getFilterDeep from 'deepdash-es/getFilterDeep';
const filterDeep = getFilterDeep(_);
```

## Demo
(not updated to v4 yet)
[Example react+redux app](https://kw0zox7r.codesandbox.io/) with nested comments filtered by Deepdash.([play with code here](https://codesandbox.io/s/kw0zox7r))

## Methods
Expand Down Expand Up @@ -59,7 +105,7 @@ const _ = deepdash(lodash);

console.log('\n = Iterate over tree (each child object) = \n');

_.eachDeep(children, displayField, { tree: true });
_.eachDeep(children, displayField, { childrenPath: 'children' });

console.log('\n = Iterate over object (each field) = \n');

Expand Down Expand Up @@ -178,7 +224,7 @@ Console:
console.log('\n = Filter tree (good children) = \n');

console.log(
_.filterDeep(children, 'good', { tree: true })
_.filterDeep(children, 'good', { childrenPath: 'children' })
);

console.log('\n = Filter object (names of good children) = \n');
Expand Down
10 changes: 5 additions & 5 deletions browser/deepdash.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion browser/deepdash.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 145e88c

Please sign in to comment.