@putout/compare
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -10,2 +10,4 @@ 'use strict'; | ||
const isStr = (a) => typeof a === 'string'; | ||
const ANY_OBJECT = '__object'; | ||
@@ -17,3 +19,30 @@ const ANY_ARRAY = '__array'; | ||
const BODY = '__body'; | ||
const ANY = '__'; | ||
const ALL = [ | ||
ANY_OBJECT, | ||
ANY_ARRAY, | ||
ARGS, | ||
LINKED_NODE, | ||
IMPORTS, | ||
BODY, | ||
ANY, | ||
]; | ||
module.exports.is = (str, array = ALL) => { | ||
for (const item of array) { | ||
if (check(str, item)) | ||
return true; | ||
} | ||
return false; | ||
}; | ||
function check(str, item) { | ||
if (isStr(item)) | ||
return str === item; | ||
return item.test(str); | ||
} | ||
module.exports.isNameStr = (a) => LINKED_NODE.test(a); | ||
@@ -23,2 +52,4 @@ module.exports.isImportsStr = (a) => a === IMPORTS; | ||
module.exports.isObjectStr = (a) => a === ANY_OBJECT; | ||
module.exports.isArrayStr = (a) => a === ANY_ARRAY; | ||
module.exports.isAnyStr = (a) => a === ANY; | ||
@@ -42,4 +73,4 @@ const isBody = (a) => isIdentifier(a, { | ||
module.exports.isStr = (a) => typeof a === 'string'; | ||
module.exports.isAny = (a) => isIdentifier(a, {name: '__'}); | ||
module.exports.isAnyLiteral = (a, b) => isLiteral(b, {value: '__'}) && isEqualType(a, b); | ||
module.exports.isAny = (a) => isIdentifier(a, {name: ANY}); | ||
module.exports.isAnyLiteral = (a, b) => isLiteral(b, {value: ANY}) && isEqualType(a, b); | ||
module.exports.isArgs = (a) => { | ||
@@ -46,0 +77,0 @@ const b = !isArray(a) ? a : a[0]; |
@@ -11,6 +11,6 @@ 'use strict'; | ||
const { | ||
is, | ||
isNameStr, | ||
isArgsStr, | ||
isImportsStr, | ||
isArgsStr, | ||
isObjectStr, | ||
} = require('./is'); | ||
@@ -50,3 +50,3 @@ | ||
if (!isNameStr(name) && !isImportsStr(name) && !isArgsStr(name) && !isObjectStr(name)) | ||
if (!is(name)) | ||
return; | ||
@@ -117,1 +117,2 @@ | ||
} | ||
{ | ||
"name": "@putout/compare", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -5,0 +5,0 @@ "description": "compare ast-nodes", |
@@ -19,5 +19,24 @@ # putout-compare [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] | ||
### Compare (node, baseNode) | ||
### getTemplateValues(node, template) | ||
- `node` - `AST-node` or `code` that will be generated; | ||
- `template` - template string with template variables; | ||
```js | ||
const {operator} = require('putout'); | ||
const {template} = operator; | ||
const node = template.ast('const [] = a'); | ||
getTemplateValues(node, 'const __array = array'); | ||
// returns | ||
{ | ||
__array: { | ||
type: 'ArrayPattern', | ||
...etc | ||
} | ||
} | ||
``` | ||
### compare (node, baseNode) | ||
- `node` - `AST-node` or `code` that will be generated; | ||
- `baseNode` `AST-node` with support of `template variables`. | ||
@@ -24,0 +43,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16780
391
138