├── README.md ├── gitlab-pages.snp ├── js ├── csl.snp ├── hapi:route.snp ├── iife.snp ├── next:api.snp ├── next:init.snp └── rq.snp ├── md └── huya:badge.snp ├── my-snippet.code-snippets ├── react ├── fc.snp ├── impr.snp ├── tag.snp └── ust.snp └── snp.snp /README.md: -------------------------------------------------------------------------------- 1 | ## My personal code snippets 2 | 3 | Install [snp](https://github.com/djyde/snp): 4 | 5 | ``` 6 | $ curl -sf https://gobinaries.com/djyde/snp | sh 7 | ``` 8 | 9 | Automatically update to VS Code: 10 | 11 | ``` 12 | $ snp -u 13 | ``` 14 | 15 | Save as `.code-snippets` file: 16 | 17 | ``` 18 | $ snp -p > my-snippet.code-snippets 19 | ``` 20 | -------------------------------------------------------------------------------- /gitlab-pages.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: yaml 3 | --- 4 | 5 | image: node:12.16.1 6 | 7 | cache: 8 | paths: 9 | - node_modules/ 10 | 11 | before_script: 12 | - npm config set @huyafed:registry https://nexus.huya.com/repository/npm-public/ 13 | - npm i 14 | 15 | pages: 16 | tags: 17 | - pages 18 | stage: deploy 19 | script: 20 | - npm run doc 21 | artifacts: 22 | paths: 23 | - public 24 | only: 25 | - master 26 | -------------------------------------------------------------------------------- /js/csl.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: console.log 4 | --- 5 | 6 | console.log($0) -------------------------------------------------------------------------------- /js/hapi:route.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: typescript,javascript 3 | description: hapi route 4 | --- 5 | 6 | server.route({ 7 | path: '$1', 8 | method: '${2|GET,POST,PUT,DELETE|}', 9 | async handler(req, h) { 10 | $0 11 | } 12 | }) 13 | -------------------------------------------------------------------------------- /js/iife.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: typescript,javascript,typescriptreact 3 | --- 4 | 5 | ;(() => { 6 | $0 7 | })() 8 | -------------------------------------------------------------------------------- /js/next:api.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: Next.js API handler 4 | --- 5 | 6 | import { NextApiRequest, NextApiResponse } from "next"; 7 | 8 | export default async function handler(req: NextApiRequest, res: NextApiResponse) { 9 | if (req.method === '$1') { 10 | $0 11 | } 12 | } -------------------------------------------------------------------------------- /js/next:init.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: Next.js Page 4 | --- 5 | 6 | function ${1:pageName}() { 7 | return ( 8 | <> 9 | $2 10 | 11 | ) 12 | } 13 | 14 | export async function getServerSideProps(ctx) { 15 | return { 16 | props: { 17 | 18 | } 19 | } 20 | } 21 | 22 | export default ${1} 23 | -------------------------------------------------------------------------------- /js/rq.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: Require 4 | --- 5 | 6 | const $1 = require('$1')$0 -------------------------------------------------------------------------------- /md/huya:badge.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: markdown 3 | description: huya npm badge 4 | --- 5 | 6 | [![${1:package}](http://shields.huya.info/npm/v/$1?registry_uri=https://nexus.huya.com/repository/npm-public)](https://npmjs.huya.info/package/$1) 7 | -------------------------------------------------------------------------------- /my-snippet.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "csl": { 3 | "scope": "javascript,typescript,typescriptreact", 4 | "description": "console.log", 5 | "body": [ 6 | "console.log($0)" 7 | ], 8 | "prefix": "csl" 9 | }, 10 | "fc": { 11 | "scope": "javascript,typescript,typescriptreact", 12 | "description": "React Function Component", 13 | "body": [ 14 | "function ${componentName} () {", 15 | " return (", 16 | " <>", 17 | " $0", 18 | " ", 19 | " )", 20 | "}", 21 | "", 22 | "export default ${componentName}" 23 | ], 24 | "prefix": "fc" 25 | }, 26 | "gitlab-pages": { 27 | "scope": "yaml", 28 | "description": "", 29 | "body": [ 30 | "image: node:12.16.1", 31 | "", 32 | "cache:", 33 | " paths:", 34 | " - node_modules/", 35 | "", 36 | "before_script:", 37 | " - npm config set @huyafed:registry https://nexus.huya.com/repository/npm-public/", 38 | " - npm i", 39 | "", 40 | "pages:", 41 | " tags: ", 42 | " - pages", 43 | " stage: deploy", 44 | " script:", 45 | " - npm run doc", 46 | " artifacts:", 47 | " paths:", 48 | " - public", 49 | " only:", 50 | " - master" 51 | ], 52 | "prefix": "gitlab-pages" 53 | }, 54 | "hapi:route": { 55 | "scope": "typescript,javascript", 56 | "description": "hapi route", 57 | "body": [ 58 | "server.route({", 59 | " path: '$1',", 60 | " method: '${2|GET,POST,PUT,DELETE|}',", 61 | " async handler(req, h) {", 62 | " $0", 63 | " }", 64 | "})" 65 | ], 66 | "prefix": "hapi:route" 67 | }, 68 | "iife": { 69 | "scope": "typescript,javascript,typescriptreact", 70 | "description": "", 71 | "body": [ 72 | ";(() => {", 73 | " $0", 74 | "})()" 75 | ], 76 | "prefix": "iife" 77 | }, 78 | "impr": { 79 | "scope": "javascript,typescript,typescriptreact", 80 | "description": "import react", 81 | "body": [ 82 | "import * as React from 'react'" 83 | ], 84 | "prefix": "impr" 85 | }, 86 | "next:init": { 87 | "scope": "javascript,typescript,typescriptreact", 88 | "description": "import react", 89 | "body": [ 90 | "function ${pageName}() {", 91 | " return (", 92 | " <>", 93 | " ", 94 | " )", 95 | "}", 96 | "", 97 | "export async function getServerSideProps(ctx) {", 98 | " return {", 99 | " props: {", 100 | "", 101 | " }", 102 | " }", 103 | "}", 104 | "", 105 | "export default ${pageName}" 106 | ], 107 | "prefix": "next:init" 108 | }, 109 | "ust": { 110 | "scope": "javascript,typescript,typescriptreact", 111 | "description": "useState", 112 | "body": [ 113 | "const [ $2, $3 ] = React.useState($1)$0" 114 | ], 115 | "prefix": "ust" 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /react/fc.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: React Function Component 4 | --- 5 | 6 | function ${componentName} () { 7 | return ( 8 | <> 9 | $0 10 | 11 | ) 12 | } 13 | 14 | export default ${componentName} 15 | -------------------------------------------------------------------------------- /react/impr.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: import react 4 | --- 5 | 6 | import * as React from 'react' -------------------------------------------------------------------------------- /react/tag.snp: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | <${1:tagName}>$0 5 | -------------------------------------------------------------------------------- /react/ust.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: javascript,typescript,typescriptreact 3 | description: useState 4 | --- 5 | 6 | const [$1, set${1/(.*)/${1:/capitalize}/}] = useState($2) -------------------------------------------------------------------------------- /snp.snp: -------------------------------------------------------------------------------- 1 | --- 2 | scope: plaintext 3 | description: snp sytax 4 | --- 5 | 6 | --- 7 | scope: $1 8 | description: $2 9 | --- 10 | 11 | $0 12 | --------------------------------------------------------------------------------