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

atom-nodejs-snippets's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jayallen

atom-nodejs-snippets's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

How to disable shortcuts?

Hi,

From your docs:

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

Does it possible to turn this off? I'm the person that doesn't like to type and remember shortcuts or alias. But I want to see and use auto-complete suggestions when they are appear.

Please help.

Thank you.

Error Reading Snippet File

Package has an error reading the snippet file. This appears to be due to a duplicate entry for process.nextTick() on lines 83 and 431.

If you require the stack trace for more information, I have put the output below.

<embedded>:15911 Error reading snippets file 'C:\Users\user\.atom\packages\atom-nodejs-snippets\snippets\nodejs-snippet.cson': Error: C:\Users\user\.atom\packages\atom-nodejs-snippets\snippets\nodejs-snippet.cson: Duplicate key 'process.nextTick()'
    at Object.detectDuplicateKeys (<embedded>:39452:19)
    at addProperty (<embedded>:170885:42)
    at Array.reduce (native)
    at Obj (<embedded>:170877:34)
    at transformNode (<embedded>:170953:18)
    at Value (<embedded>:170834:18)
    at transformNode (<embedded>:170953:18)
    at addProperty (<embedded>:170884:21)
    at Array.reduce (native)
    at Obj (<embedded>:170877:34)
    at transformNode (<embedded>:170953:18)
    at Value (<embedded>:170834:18)
    at transformNode (<embedded>:170953:18)
    at Block (<embedded>:170831:18)
    at transformNode (<embedded>:170953:18)
    at Object.parse (<embedded>:170959:22)
    at parseObject (<embedded>:39201:29)
    at parseContents (<embedded>:39261:22)
    at <embedded>:39381:30
    at FSReqWrap.oncomplete (fs.js:114:15)

Unable to make edits to nodejs-snippet.cson become active.

This addon is a lifesaver. I love it.

I'm having an issue however. When I edit nodejs-snippet.cson to change it to my needs, the changes don't take effect.

For example, I added the following under #node- require core modules ES6

    'const express':
      'prefix': 'exprs'
      'body': "const express = require('express');"

and saved the file. But when I type exprs and hit tab, nothing happens. exprs also doesn't show up in the hints as I'm typing

What am I doing wrong?

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.