@putout/compare
Advanced tools
Comparing version 8.6.0 to 8.7.0
@@ -67,3 +67,5 @@ 'use strict'; | ||
function compare(path, template) { | ||
function compare(path, template, options = {}) { | ||
const {findUp = true} = options; | ||
if (!path && !template) | ||
@@ -99,3 +101,3 @@ return true; | ||
if (isPath(path) && !isEqualType(node, templateNode)) { | ||
if (findUp && isPath(path) && !isEqualType(node, templateNode)) { | ||
const {type} = templateNode; | ||
@@ -110,7 +112,7 @@ const newPathNode = findParent(path, type); | ||
module.exports.compareAny = (path, templateNodes) => { | ||
module.exports.compareAny = (path, templateNodes, options) => { | ||
templateNodes = maybeArray(templateNodes); | ||
for (const template of templateNodes) { | ||
if (compare(path, template)) | ||
if (compare(path, template, options)) | ||
return true; | ||
@@ -122,7 +124,7 @@ } | ||
module.exports.compareAll = (path, templateNodes) => { | ||
module.exports.compareAll = (path, templateNodes, options) => { | ||
templateNodes = maybeArray(templateNodes); | ||
for (const template of templateNodes) { | ||
if (!compare(path, template)) | ||
if (!compare(path, template, options)) | ||
return false; | ||
@@ -129,0 +131,0 @@ } |
{ | ||
"name": "@putout/compare", | ||
"version": "8.6.0", | ||
"version": "8.7.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
@@ -36,9 +36,23 @@ # @putout/compare [![NPM version][NPMIMGURL]][NPMURL] | ||
### compare(node: Node, baseNode: Node) | ||
### compare(node: string | Node, template: string | Node [, options: Options]) | ||
- `node` - `AST-node` or `code` that will be generated; | ||
- `baseNode` `AST-node` with support of `template variables`. | ||
- `template` - `AST-node` with support of `template variables`. | ||
- `options` - (optional) - object with properties: | ||
- `findUp` (default: `true`) - find up template node; | ||
### compareAll(node: Node, baseNodes: Node|Nodes[]) | ||
### compareAll(node: string | Node, templates: string[] | Node|Nodes[], [, options: Options]) | ||
Compare nodes feets `templates`. | ||
### compareAny(node: string | Node, templates: string[] | Node|Nodes[], [, options: Options]) | ||
Compare any nodes that feets one of `templates ` | ||
```js | ||
compareAny(path, 'const __a = __b', { | ||
findUp: false, | ||
}); | ||
``` | ||
#### Supported template variables: | ||
@@ -45,0 +59,0 @@ |
21986
539
199