@putout/operate
Advanced tools
Comparing version 6.1.4 to 6.2.0
@@ -8,2 +8,4 @@ 'use strict'; | ||
isImportDeclaration, | ||
isLiteral, | ||
isIdentifier, | ||
} = require('@babel/types'); | ||
@@ -136,1 +138,11 @@ | ||
module.exports.extract = (node) => { | ||
if (isIdentifier(node)) | ||
return node.name; | ||
if (isLiteral(node)) | ||
return node.value; | ||
throw Error('"operator.extract(node)" understands only Literals and Identifiers 🤷'); | ||
}; | ||
{ | ||
"name": "@putout/operate", | ||
"version": "6.1.4", | ||
"version": "6.2.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -5,0 +5,0 @@ "description": "operate on ast", |
@@ -24,2 +24,9 @@ # Operate [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL] | ||
### extract(path) | ||
- checks the node by type, | ||
- if it is `Identifier` return `name`, | ||
- if it is any type of `Literal` return `value` | ||
- `throw` in other cases | ||
### replaceWith(path, node) | ||
@@ -26,0 +33,0 @@ |
7988
104
89