Giter Site home page Giter Site logo

amandeepmittal / atom-nodejs-snippets Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 29 KB

Collection of Nodejs and Javascript snippets

Home Page: https://atom.io/packages/atom-nodejs-snippets

License: MIT License

JavaScript 95.32% CSS 4.68%
atom atom-package atom-plugin atom-editor snippets nodejs-snippets javascript-snippets apm nodejs es6-javascript

atom-nodejs-snippets's Introduction

Nodejs Snippets for Atom

apm apm apm

A collection of Nodejs, JavaScript snippets.

This package also support some of the ES6 syntax half-heartedly.

Install

Go to Settings > Install & then search for atom-nodejs-snippets under Packages. After installation, restart Atom.

Snippets

These snippets are for daily use to avoid writing as much as it could the boilerplate code. If you like, to add yours, feel free to contribute.

To use, please press tab after shortkeys expressed as following.

Nodejs Commonly used entities:

  • req require
  • me module.exports
  • ex exports
  • cb callback()

path Module

  • pjoin path.join()
  • pdir path.dirname()
  • pres path.resolve()
  • pbase path.basename()
  • pext path.extname()

fs Module

  • fsread fs.readFile()
  • fsreadstream fs.createReadStream()
  • fswrite fs.writeFile()

event Module

  • on event handler | emitter.on('event',() => {})

stream Module

  • rstream readable stream
  • wstream writable stream
  • pipe rs.pipe(ws);

Process & Global Variables

  • process.env
  • process.pid
  • process.cwd
  • process.stdin
  • process.stdout
  • process.stderr
  • process.version
  • process.argv
  • process.exit
  • process.kill
  • process.uptime
  • dirn dirname

boilerplate code for importing core modules

For ES6:

Eg: const util = require('util');

  • util
  • http
  • fs
  • path
  • zlib
  • stream
  • qstring
  • assert
  • url
  • string_decoder

Consoles Shorthand

  • clog console.log()
  • cw console.warn()
  • cd console.dir()
  • ci console.info()
  • ce console.error()
  • cg console.group()
  • cge console.groupEnd()

assert Module

  • assert.equal
  • assert.notEqual
  • assert.deepEqual
  • assert.ok
  • assert.ifError

Promise

  • p new Promise(function(resolve, reject) {});
  • pthen promise.then(function (){});
  • pcatch promise.catch(function (err) {});

timer functions

  • si setInterval()
  • st setTimeout()
  • sim setImmediate()

BDD Testing

  • desc describe
  • it it in synchronous
  • itasync it in asynchronous
  • itpending it pending
  • bef before()
  • aft after()
  • befe beforeEach()
  • afte afterEach()

BDD Chai expect Library

  • expect const expect = chai.expect;
  • expecte expect equal
  • expectde expect deep equal
  • expectne expect not equal
  • expectnde expect not deep equal

Common JS Syntax

  • kv key:value pair (object)
  • fnm method (object)
  • fn anonymous function
  • fno anonymous function without parameter
  • fnn named function
  • fne function expression
  • iife immediately invoked function expression
  • r return
  • rt return true
  • rf return false
  • rp return promise
  • al alert
  • us; strict mode

ES6 Syntax

  • imp import X from module
  • ar arrow function with parameters
  • aro arrow function without parameters
  • arn named arrow function
  • cb6 Nodejs callback in ES6
  • meth Method (object)
  • get getter
  • set setter

process.nextTick()

  • nexttick

JSON

  • jparse JSON.parse()
  • jstr JSON.stringify()

TODO

  • Add more ES6 snippets
  • Convert BDD & BDD Chai Library snippets to ES6

Contribute

Pull requests for more snippets are welcome.

License

MIT Copyright (c) 2016 Aman Mittal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.