An open API service indexing awesome lists of open source software.

https://github.com/imcuttle/detect-tree-changed

Detect tow tree what is updated
https://github.com/imcuttle/detect-tree-changed

Last synced: 4 months ago
JSON representation

Detect tow tree what is updated

Awesome Lists containing this project

README

          

# detect-tree-changed

[![Build status](https://img.shields.io/travis/imcuttle/detect-tree-changed/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/detect-tree-changed)
[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/detect-tree-changed.svg?style=flat-square)](https://codecov.io/github/imcuttle/detect-tree-changed?branch=master)
[![NPM version](https://img.shields.io/npm/v/detect-tree-changed.svg?style=flat-square)](https://www.npmjs.com/package/detect-tree-changed)
[![NPM Downloads](https://img.shields.io/npm/dm/detect-tree-changed.svg?style=flat-square&maxAge=43200)](https://www.npmjs.com/package/detect-tree-changed)
[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io/)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)

> Detect tow tree what is updated

## Installation

```bash
npm install detect-tree-changed
# or use yarn
yarn add detect-tree-changed
```

## Usage

```javascript
const detectTreeChanged = require('detect-tree-changed')

detectTreeChanged(
{
node: 'Root'
},
{
node: 'root'
}
)

// => Map {
{node: 'Root'}: {status: 'updated', ctx: {...}}
}
```

It's shameless of use document of [@moyuyc/visit-tree](https://github.com/imcuttle/visit-tree#context) about the `ctx` which is returned.

## API

### detectTreeChanged

[index.js:23-131](https://github.com/imcuttle/detect-tree-changed/blob/6bf6a879939a1e39ba8075d94428f8cd3e4a1d4f/index.js#L23-L131 "Source code on GitHub")

#### Parameters

- `treeA` {T}
- `treeB` {T}
- `opt` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** {{}}
- `opt.limit` The limit of changed node (optional, default `Infinity`)
- `opt.equal` The compare strategy of two node (optional, default `(a,b)=>a===b`)
- `opt.path` (optional, default `'children'`)

Returns **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)**

## Related

- [@moyuyc/visit-tree](https://github.com/imcuttle/visit-tree) - Visit tree by pre or post DFS.
- [detect-one-changed](https://github.com/imcuttle/detect-one-changed) - Detect first changed html and markdown between old text and new.

## Contributing

- Fork it!
- Create your new branch:
`git checkout -b feature-new` or `git checkout -b fix-which-bug`
- Start your magic work now
- Make sure npm test passes
- Commit your changes:
`git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`
- Push to the branch: `git push`
- Submit a pull request :)

## Authors

This library is written and maintained by imcuttle, moyuyc95@gmail.com.

## License

MIT - [imcuttle](https://github.com/imcuttle) 🐟