Skip to content

Commit a149577

Browse files
committed
feature: @putout/operator-regexp: add
1 parent f854ea8 commit a149577

File tree

12 files changed

+206
-0
lines changed

12 files changed

+206
-0
lines changed

packages/operator-jsx/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea

packages/operator-jsx/.madrun.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'prepublishOnly': () => run(['lint', 'test']),
5+
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
6+
'watch:test': async () => `nodemon -w lib -x "${await run('test')}"`,
7+
'lint': () => 'putout .',
8+
'fresh:lint': () => run('lint', '--fresh'),
9+
'lint:fresh': () => run('lint', '--fresh'),
10+
'fix:lint': () => run('lint', '--fix'),
11+
'coverage': async () => `c8 ${await run('test')}`,
12+
'report': () => 'c8 report --reporter=lcov',
13+
};

packages/operator-jsx/.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.*
2+
*.spec.js
3+
test
4+
fixture
5+
yarn-error.log
6+
7+
coverage
8+
*.config.*

packages/operator-jsx/.nycrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"**/*.config.*"
10+
],
11+
"branches": 100,
12+
"lines": 100,
13+
"functions": 100,
14+
"statements": 100
15+
}

packages/operator-jsx/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/operator-jsx/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# @putout/operator-regexp [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/operator-regexp.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/operator-regexp "npm"
5+
6+
🐊[**Putout**](https://github.com/coderaiser/putout) operator operator adds methods that simplifies JSX transformations.
7+
8+
## Install
9+
10+
```
11+
npm i putout @putout/operator-regexp
12+
```
13+
14+
## API
15+
16+
### hasTagName(path: Path)
17+
18+
```js
19+
// for next jsx:
20+
<li>hello</li>;
21+
// check
22+
hasTagName(path, 'li');
23+
// returns
24+
true;
25+
```
26+
27+
## License
28+
29+
MIT
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {safeAlign} from 'eslint-plugin-putout';
2+
3+
export default safeAlign;

packages/operator-jsx/lib/jsx.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const {types} = require('@putout/babel');
4+
const {isJSXElement} = types;
5+
6+
module.exports.hasTagName = (path, name) => {
7+
const node = path.node || path;
8+
9+
if (!isJSXElement(path))
10+
return false;
11+
12+
return node.openingElement.name.name === name;
13+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const {test} = require('supertape');
4+
5+
const {template, operator} = require('putout');
6+
7+
const {hasTagName} = require('./jsx.js');
8+
const {traverse} = operator;
9+
10+
test('putout: operator: jsx: hasTagName', (t) => {
11+
let result = false;
12+
const ast = template.ast('<hello><world/></hello>');
13+
14+
traverse(ast, {
15+
JSXElement(path) {
16+
result = hasTagName(path, 'world');
17+
},
18+
});
19+
20+
t.ok(result);
21+
t.end();
22+
});
23+
24+
test('putout: operator: jsx: hasTagName: no', (t) => {
25+
let result = false;
26+
const ast = template.ast('<hello><world/></hello>');
27+
28+
result = hasTagName(ast, 'world');
29+
30+
t.notOk(result);
31+
t.end();
32+
});
33+
34+
test('putout: operator: jsx: hasTagName: wrong node', (t) => {
35+
const ast = template.ast('a = 3');
36+
const result = hasTagName(ast, 'world');
37+
38+
t.notOk(result);
39+
t.end();
40+
});

packages/operator-jsx/package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@putout/operator-jsx",
3+
"version": "1.0.2",
4+
"type": "commonjs",
5+
"author": "coderaiser <[email protected]> (https://github.com/coderaiser)",
6+
"description": "🐊Putout operator adds methods that simplifies JSX transformations",
7+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-jsx#readme",
8+
"main": "lib/jsx.js",
9+
"release": false,
10+
"tag": false,
11+
"changelog": false,
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/coderaiser/putout.git"
15+
},
16+
"scripts": {
17+
"test": "madrun test",
18+
"watch:test": "madrun watch:test",
19+
"lint": "madrun lint",
20+
"fresh:lint": "madrun fresh:lint",
21+
"lint:fresh": "madrun lint:fresh",
22+
"fix:lint": "madrun fix:lint",
23+
"coverage": "madrun coverage",
24+
"report": "madrun report"
25+
},
26+
"dependencies": {
27+
"@putout/babel": "^4.2.0"
28+
},
29+
"keywords": [
30+
"putout",
31+
"putout-operator",
32+
"operator",
33+
"jsx"
34+
],
35+
"devDependencies": {
36+
"@putout/test": "^14.0.0",
37+
"c8": "^10.0.0",
38+
"eslint": "^9.0.0",
39+
"eslint-plugin-n": "^17.0.0",
40+
"eslint-plugin-putout": "^28.0.0",
41+
"madrun": "^11.0.0",
42+
"montag": "^1.2.1",
43+
"nodemon": "^3.0.1",
44+
"supertape": "^11.0.3"
45+
},
46+
"peerDependencies": {
47+
"putout": ">=40"
48+
},
49+
"license": "MIT",
50+
"engines": {
51+
"node": ">=20"
52+
},
53+
"publishConfig": {
54+
"access": "public"
55+
}
56+
}

0 commit comments

Comments
 (0)