Upload from GitHub
This commit is contained in:
106
general/configs/VSCodium/User/snippets/javascript.json
Executable file
106
general/configs/VSCodium/User/snippets/javascript.json
Executable file
@@ -0,0 +1,106 @@
|
||||
{
|
||||
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
|
||||
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
|
||||
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
|
||||
// same ids are connected.
|
||||
// Example:
|
||||
// "Print to console": {
|
||||
// "prefix": "log",
|
||||
// "body": [
|
||||
// "console.log('$1');",
|
||||
// "$2"
|
||||
// ],
|
||||
// "description": "Log output to console"
|
||||
// }
|
||||
"JS-Class": {
|
||||
"prefix": "jsSetupClass",
|
||||
"body": "class $1 { \n\tconstructor () {} \n\n \t$2 () {\n\t$3\n\t}\n}",
|
||||
"description": "Setup the basic structure of a class in JS"
|
||||
},
|
||||
"ExpressJS": {
|
||||
"prefix": "jsExpressSetup",
|
||||
"body": [
|
||||
"const express = require( 'express' );",
|
||||
"let app = express();",
|
||||
"const path = require( 'path' );",
|
||||
"const expressSession = require( 'express-session' );",
|
||||
"const fs = require( 'fs' );",
|
||||
"const bodyParser = require( 'body-parser' );",
|
||||
"const cookieParser = require( 'cookie-parser' )",
|
||||
"const favicon = require( 'serve-favicon' );",
|
||||
"\napp.use( expressSession ( {\n\tsecret: $1,\n\tresave: true,\n\tsaveUninitialized: true\n} ) );",
|
||||
"app.use( bodyParser.urlencoded( { extended: false } ) );",
|
||||
"app.use( bodyParser.json() );",
|
||||
"app.use( cookieParser() );",
|
||||
"app.use( favicon( path.join( __dirname + '$2' ) ) );\n",
|
||||
"app.use( ( request, response, next ) => {\n\tresponse.sendFile( path.join( __dirname + '$3' ) ) \n} );",
|
||||
"\n\napp.get( '/', ( request, response ) => {\n$4\n} );",
|
||||
"\n\nconst PORT = process.env.PORT || 8080;",
|
||||
"http.createServer( app ).listen( PORT );"
|
||||
]
|
||||
},
|
||||
"ExpressJS-Route": {
|
||||
"prefix": "jsEjsRoute",
|
||||
"body": "\n\napp.get( '$1', ( request, response ) => {\n$4\n} );"
|
||||
},
|
||||
"JSAsync": {
|
||||
"prefix": "jsAsync",
|
||||
"body": "(async () => {\n$1\n} ) ();"
|
||||
},
|
||||
"JSpromiseReturnFunc": {
|
||||
"prefix": "jsPromise",
|
||||
"body": "function $1 () {\n\treturn new Promise( ( resolve, reject ) => {\n\t$2\n\t} );\n}"
|
||||
},
|
||||
"fetch from other url": {
|
||||
"prefix": "remoteURL",
|
||||
"body": [
|
||||
"localStorage.getItem( 'url' ) + '/$1'",
|
||||
],
|
||||
"description": "remote URL fetching (get from base address from local storage)"
|
||||
},
|
||||
"fetch post": {
|
||||
"prefix": "fetchPost",
|
||||
"body": [
|
||||
"const fetchOptions = {",
|
||||
"\tmethod: 'post',",
|
||||
"\tbody: JSON.stringify( $1 ),",
|
||||
"\tcredentials: 'include',",
|
||||
"\theaders: {",
|
||||
"\t\t'Content-Type': 'application/json',",
|
||||
"\t\t'charset': 'utf-8'",
|
||||
"\t}",
|
||||
"};",
|
||||
"fetch( $2, fetchOptions ).then( res => {",
|
||||
"\tif ( res.status === 200 ) {",
|
||||
"\t\tres.json().then( json => {",
|
||||
"\t\t\t$3",
|
||||
"\t\t} );",
|
||||
"\t}",
|
||||
"} );",
|
||||
"$4"
|
||||
],
|
||||
"description": "POST request using fetch"
|
||||
},
|
||||
"fetch get": {
|
||||
"prefix": "fetchGet",
|
||||
"body": [
|
||||
"fetch( $2, { credentials: 'include' } ).then( res => {",
|
||||
"\tif ( res.status === 200 ) {",
|
||||
"\t\tres.json().then( json => {",
|
||||
"\t\t\t$3",
|
||||
"\t\t} );",
|
||||
"\t}",
|
||||
"} );",
|
||||
"$4"
|
||||
],
|
||||
"description": "POST request using fetch"
|
||||
},
|
||||
"promise": {
|
||||
"prefix": "promise",
|
||||
"body": [
|
||||
"return new Promise( ( resolve, reject ) => {",
|
||||
"\t",
|
||||
"} );"
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user