Skip to content

Commit 444bb36

Browse files
committed
init
0 parents  commit 444bb36

17 files changed

+771
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Set default behavior to automatically normalize line endings.
2+
* text=auto
3+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
*.vsix

.vscode/launch.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A launch configuration that launches the extension inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
]
15+
}
16+
]
17+
}

.vscodeignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vscode/**
2+
.vscode-test/**
3+
.gitignore
4+
vsc-extension-quickstart.md
5+
src

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 jwy
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.

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# JavaScript Snippets
2+
3+
> JavaScript Snippets for MDN
4+
5+
<p align="center">
6+
<img src="https://images.cnblogs.com/cnblogs_com/jwyblogs/1576071/o_220312063215_javascript.png" alt="icon">
7+
</p>
8+
<p align="center">
9+
<a href="https://marketplace.visualstudio.com/items?itemName=jwy.javascript-snippets-self">
10+
<img src="https://img.shields.io/visual-studio-marketplace/i/jwy.javascript-snippets-self?style=square" alt="">
11+
</a>
12+
<a href="https://marketplace.visualstudio.com/items?itemName=jwy.javascript-snippets-self">
13+
<img src="https://img.shields.io/visual-studio-marketplace/d/jwy.javascript-snippets-self?style=square" alt="">
14+
</a>
15+
<a href="https://marketplace.visualstudio.com/items?itemName=jwy.javascript-snippets-self">
16+
<img src="https://img.shields.io/visual-studio-marketplace/stars/jwy.javascript-snippets-self?style=square" alt="">
17+
</a>
18+
<a href="https://github.com/jwyGithub/JavaScript-Snippets/blob/main/LICENSE">
19+
<img src="https://img.shields.io/github/license/jwyGithub/JavaScript-Snippets?style=square" alt="">
20+
21+
</a>
22+
</p>
23+
24+
## Snippets
25+
26+
> React.js
27+
28+
<table border>
29+
<tr style="font-weight: bold">
30+
<td width="200">Snippet prefix</td>
31+
<td width="200">Specification</td>
32+
<td>Description</td>
33+
</tr>
34+
<tr style="color: #1296db">
35+
<td>edc</td>
36+
<td></td>
37+
<td></td>
38+
</tr>
39+
<tr style="color: #1296db">
40+
<td>edcc</td>
41+
<td></td>
42+
<td></td>
43+
</tr>
44+
</table>
45+
<br />
46+
47+
### Supported languages
48+
49+
- javascript (.js)
50+
- typescript (.ts)
51+
- javascriptreact (.jsx)
52+
- typescripereact (.tsx)

icon/React.png

8.17 KB
Loading

package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "react-snippets",
3+
"displayName": "React-Snippets",
4+
"description": "react snippets for smiple",
5+
"version": "0.0.1",
6+
"scripts": {
7+
"build": "node src/index.js && node src/output/markdown.js"
8+
},
9+
"icon": "icon/React.png",
10+
"engines": {
11+
"vscode": "^1.65.0"
12+
},
13+
"categories": [
14+
"Snippets"
15+
],
16+
"galleryBanner": {
17+
"color": "#0273D4",
18+
"theme": "dark"
19+
},
20+
"publisher": "jwy",
21+
"contributes": {
22+
"snippets": [
23+
{
24+
"language": "javascript",
25+
"path": "./snippets/snippets.code-snippets"
26+
},
27+
{
28+
"language": "typescript",
29+
"path": "./snippets/snippets.code-snippets"
30+
},
31+
{
32+
"language": "javascriptreact",
33+
"path": "./snippets/snippets.code-snippets"
34+
},
35+
{
36+
"language": "typescriptreact",
37+
"path": "./snippets/snippets.code-snippets"
38+
}
39+
]
40+
},
41+
"repository": "https://github.com/jwyGithub/JavaScript-Snippets.git",
42+
"homepage": "https://github.com/jwyGithub/JavaScript-Snippets/readme",
43+
"license": "SEE LICENSE IN LICENSE",
44+
"devDependencies": {
45+
"@types/node": "^17.0.21",
46+
"prettier": "^2.5.1"
47+
}
48+
}
49+

pnpm-lock.yaml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snippets/snippets.code-snippets

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"export default component": {
3+
"prefix": "edc",
4+
"body": "const $1 = () => {\r\n return <div>$1</div>;\r\n};\r\nexport default $1;\r\n",
5+
"description": ""
6+
},
7+
"export default connect component": {
8+
"prefix": "edcc",
9+
"body": "import { connect } from 'react-redux';\r\nimport { bindActionCreators } from 'redux';\r\n\r\nconst App = ({ user, actions }) => {\r\n return (\r\n <div>\r\n <h1>{{ user }}</h1>\r\n </div>\r\n );\r\n};\r\n\r\nconst mapStateToProps = (state, props) => {\r\n return {\r\n user: state.user ?? 'test'\r\n };\r\n};\r\n\r\nconst mapDispatchToProps = (dispatch, props) => {\r\n return {\r\n actions: bindActionCreators(\r\n {\r\n writeComment: comment => ({\r\n comment,\r\n type: 'WRITE_COMMENT'\r\n })\r\n },\r\n dispatch\r\n )\r\n };\r\n};\r\nexport default connect(mapStateToProps, mapDispatchToProps)(App);\r\n",
10+
"description": ""
11+
}
12+
}

src/index.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require('fs');
2+
const { resolve } = require('path');
3+
const prettier = require('./lib/prettier.js');
4+
5+
const snippetsJSONRoot = resolve(__dirname, '../snippets/snippets.code-snippets');
6+
const snippetsRoot = resolve(__dirname, './snippets');
7+
8+
const format = ({ key, prefix, body, description }) => {
9+
return {
10+
[key]: {
11+
prefix,
12+
body: prettier(body),
13+
description
14+
}
15+
};
16+
};
17+
18+
const generator = () => {
19+
try {
20+
let snippets = fs.readdirSync(snippetsRoot, { withFileTypes: true }).reduce((pre, item) => {
21+
const path = resolve(__dirname, snippetsRoot, item.name);
22+
require(path).forEach(item => {
23+
const _snippet = format(item);
24+
pre = { ...pre, ..._snippet };
25+
});
26+
return pre;
27+
}, {});
28+
29+
fs.writeFileSync(snippetsJSONRoot, JSON.stringify(snippets, null, 4));
30+
} catch (error) {
31+
console.log(error);
32+
}
33+
};
34+
35+
generator();

src/lib/block-code.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
exports.tableStr = content => {
2+
return `<table border>
3+
<tr style="font-weight:bold">
4+
<td width="200">Snippet prefix</td>
5+
<td width="200">Specification</td>
6+
<td>Description</td>
7+
</tr>
8+
${content}
9+
</table><br/>`;
10+
};
11+
12+
exports.trStr = content => {
13+
return `<tr style="color: #1296db">${content}</tr>`;
14+
};
15+
16+
exports.tdStr = arrContent => {
17+
return arrContent.reduce((pre, cur, index, array) => {
18+
return pre + `<td>${cur}</td>`;
19+
}, '');
20+
};
21+
22+
exports.htmlMd = (snippets, type) => {
23+
return (
24+
'\n' +
25+
`> ${type}` +
26+
'\n' +
27+
this.tableStr(
28+
snippets.reduce((pre, item, index, array) => {
29+
return pre + this.trStr(this.tdStr([item.prefix, item.specification || '', item.description]));
30+
}, '')
31+
)
32+
);
33+
};

src/lib/prettier.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const prettier = require('prettier');
2+
3+
module.exports = (html, parser = 'babel') =>
4+
prettier.format(html, {
5+
arrowParens: 'avoid',
6+
bracketSpacing: true,
7+
endOfLine: 'crlf',
8+
htmlWhitespaceSensitivity: 'css',
9+
insertPragma: false,
10+
jsxSingleQuote: true,
11+
printWidth: 200,
12+
proseWrap: 'never',
13+
quoteProps: 'as-needed',
14+
requirePragma: false,
15+
semi: true,
16+
singleQuote: true,
17+
tabWidth: 4,
18+
trailingComma: 'none',
19+
useTabs: false,
20+
parser: parser
21+
});

0 commit comments

Comments
 (0)