json 有意思:Snippets javascript.json

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json 有意思:Snippets javascript.json相关的知识,希望对你有一定的参考价值。

{

/**
* Templates for coding learned at Thinkful
**/

// Express Snippets

"router.get":{
  "prefix": "routeGet",
  "body":[
    "router.get('${1}', (req, res)=>{",
    "\t${2}",
    "});"
  ],
  "description":"Create an Express Router GET"
},
"router.getById":{
  "prefix": "routerGetById",
  "body":[
    "router.get('${1}/:id', (req, res)=>{",
    "\t${2}",
    "});"
  ],
  "description":"Create an Express Router GET"
},
"router.post":{
  "prefix": "routerPost",
  "body":[
    "router.post('${1}', (req, res)=>{",
    "\t${2}",
    "});"
  ],
  "description":"Create an Express Router POST"
},
"router.put":{
  "prefix": "routerPut",
  "body":[
    "router.put('${1}/:id', (req, res)=>{",
    "\t${2}",
    "});"
  ],
  "description":"Create an Express Router PUT"
},

"router.DELETE":{
  "prefix": "routerDelete",
  "body":[
    "router.delete('${1}/:id', (req, res)=>{",
    "\t${2}",
    "});"
  ],
  "description":"Create an Express Router DELETE"
},
"router.all":{
  "prefix":"routerAll",
  "body":[
    "router.get('${1}', (req, res)=>{",
    "\t",
    "});",
    "",
    "router.get('${1}/:id', (req, res)=>{",
    "\t",
    "});",
    "",
    "router.post('${1}', (req, res)=>{",
    "\t",
    "});",
    "",    
    "router.put('${1}/:id', (req, res)=>{",
    "\t",
    "});",
    "", 
    "router.delete('${1}/:id', (req, res)=>{",
    "\t",
    "});",
    "",
  ],
  "description": "Create all Express Routes (GET, POST, PUT, DELETE)"
},

"routerjs":{
"prefix": "routerjs",
"body":[
  "'use strict';",
  "const express = require('express');",
  "router = express.Router();",
  "",
  "router.get('${1}', (req, res)=>{",
  "\t",
  "});",
  "",
  "router.get('${1}/:id', (req, res)=>{",
  "\t",
  "});",
  "",
  "router.post('${1}', (req, res)=>{",
  "\t",
  "});",
  "",    
  "router.put('${1}/:id', (req, res)=>{",
  "\t",
  "});",
  "", 
  "router.delete('${1}/:id', (req, res)=>{",
  "\t",
  "});",
  "",
],
"description": "Create a router.js template"
},

"then()":{
  "prefix":"then",
    "body":[
    ".then((${1})=>{",
    "\t${2}",
    "});"
  ], 
  "description":"Promise .then() method"
},


"catch()":{
  "prefix":"catch",
    "body":[
    ".catch(err => {",
    "\t${1}",
    "});"
  ], 
  "description":"Promise .catch() method"
},


"then().catch()":{
  "prefix":"thenCatch",
    "body":[
    ".then((${1})=>{",
    "\t${2}",
    "})",
    ".catch(err => {",
      "\t${3}",
      "});"
  ], 
  "description":"Promise .then() method"
},

"Express Server.js":{
"prefix": "serverjs",
"body": [
  "'use strict';",
  "require('dotenv').config();",
  "const express = require('express');",
  "const path = require('path');",
  "const morgan = require('morgan');",
  "const bodyParser = require('body-parser');",
  "const cors = require('cors');",
  "const passport = require('passport');",
  "",
  "const {PORT} = require('./config');",
  "const app = express();",
  "app.use(cors({origin: 'http://localhost:3000'}));",
  "",
  "if(process.env.ENV === 'development') app.use(morgan('dev'));",
  "else app.use(morgan('common'));",
  "app.use(express.static(path.join(__dirname, 'public')));",
  "",
  "app.use('*', (req, res) => {",
  "\treturn res.status(404).json({message: 'Not Found'});",
  "});",
  "if (app.get('env') === 'development' || app.get('env' === 'testing')) {",
  "  app.use(function(err, req, res, next) {",
  "    res.status(err.status || 500).json({",
  "      message: err.message,",
  "      error: err",
  "    });",
  "  });",
  "}",
  "",
  "app.use(function(err, req, res, next) {",
  "  res.status(err.status || 500).json({",
  "    message: err.message,",
  "    error: {}",
  "  });",
  "});",
  "",
  "let server;",
  "function runServer(){",
  "\treturn new Promise((resolve, reject)=>{",
  "\t\tserver.app.listen(PORT, () =>{",
  "\t\t\tconsole.info(`Your app is listening on ${PORT}`);",
  "\t\t\tresolve();",
  "\t\t})",
  "\t.on('error', err=>{",
  "\t\treject(err);",
  "\t});",
  "});",
  "}",
  "",
  "function closeServer(){",
  "return new Promise((resolve, reject) =>{",
  "\tserver.close(err => {",
  "\t\tif (err){",
  "\t\t\treturn reject(err);",
  "\t\t}",
  "\tresolve();",
  "});",
  "});",
  "}",
  "",
  "if (require.main === module){",
  "\trunServer().catch(err => console.error(err));",
  "}",
  "",
  "module.exports = {app, runServer, closeServer};"
],
"description": "Create a server.js template"
},


"testsExpress":{
  "prefix": "testjs",
  "body": [
    "'use strict';",
    "process.env.ENV  = process.env.NODE_ENV = 'testing';",
    "const chai = require('chai');",
    "const chaiHttp = require('chai-http');",
    "const should = chai.should();",
    "const faker = require('faker');",
    "const {app, runServer, closeServer } = require('../server');",
    "",
    "chai.use(chaiHttp);",
    "describe('', () =>{",
    "\tbefore(() =>{",
    "\t});",
    "",
    "\tbeforeEach('', () => {",
    "\t});",
    "\tafter('', () =>{",
    "\t});",
    "\tafterEach('', () => {",
    "\t});",
    "",
    "\tdescribe('', ()=>{",
    "\t\tit('should ', () =>{",
    "\t\t});",
    "\t});",
    "});"
  ],
  "description": "Create mocha test template"
},
/*
"describe":{

},

"it":{

},

"describeit":{

},
*/
// React Snippets

"React Stateful Component":{
  "prefix":"StatefulReactComponent",
    "body":[
      "'use strict';",
      "import React from 'react'\n",
      "export default class ${1:name} extends React.Component{",
      "\tconstructor(props){",
      "\t\tsuper(props)",
      "\t\tthis.state= {",
      "\t\t}",
      "\t}",
      "render(){",
      "\treturn(${2});",
      "\t}",
      "}"

    ],
    "description": "Creates a React Stateful Component"
},

"React Statelss Component":{
  "prefix":"statelessReactComponenet",
  "body":[
    "'use strict';",
    "import React from 'react';",
    "",
    "export default function ${1:name}(props){",
    "return ();",
    "}"
  ],
  "description": "Create a Stateless React Component"
},

"reactSetupTestjs":{
  "prefix": "setupTestjs",
  "body":[
    "import {configure} from 'enzyme';",
    "import Adapter from 'enzyme-adapter-react-16';",
    "configure ({adapter: new Adapter()});"
  ],
  "description": "Create a setupTest.js for React testing with Enzyme"
},

"reactTestwithEnzyme":{
"prefix":"reactTest",
"body":[
  "import  React from 'react';",
  "import {shallow, mount} from 'enzyme';",
  "import '../setupTest.js';",
  "",
  "describe('', () =>{",
  "\tit('', ()=>{",
  "\t\tconst wrapper = shallow(${1:component});",
  "\t\tshallow(${1:component});",
  "\t});",
  "});",
],
"description": "Create a react component test with enzyme"

}

/*

import { composeWithDevTools } from 'redux-devtools-extension';
*/

}

以上是关于json 有意思:Snippets javascript.json的主要内容,如果未能解决你的问题,请参考以下文章

json 用于VSCode的Velocity Snippets。

json VSCode_markdown_snippets

json MongoDB Snippets

json VS Code html Snippets

json VS Code php Snippets

json 用于托架的Jasmine Snippets