npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coffeescript-styleguide

v0.1.1

Published

Style guide for CoffeeScript

Downloads

4

Readme

CoffeeScript

The main aim of this style-guide is to get the best possible readability (and not writability).

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Naming Conventions

  • Names SHOULD be descriptive
  • camelCase MUST be used for naming objects, functions, and instances
  • PascalCase MUST be used for classes and constructor names

Whitespace

  • Tabs MUST be used for indentation
  • It's RECOMMENDED to equal the indentation of a tab to 4 spaces
  • You MAY use, however, a different number while working on the code to match your style preferences. Other common numbers of spaces are 2 and 8.
  • There MUST be no trailing whitespace characters
  • An empty newline MUST be placed at the end of a file
  • Invisibles SHOULD be displayed during coding to reduce the likelihood of whitespace mistakes
  • Tabs and spaces MUST NOT be mixed

Multi-line Statements

  • Lines MUST not be longer than 80 characters (counting tabs as 4 spaces)
  • When a statement is too long to fit on one line, line breaks MUST occur after an operator

Commas

  • Commas SHOULD be omitted were possible

    foo =
    	bar: 1
    	baz: 2

    instead of

    foo =
    	bar: 1,
    	baz: 2

    and

    fruits = [
    		apple
    		melon
    		pear
    	]

    instead of

    fruits = [
    		apple,
    		melon,
    		pear
    	]
  • Inline commas MUST be followed by one space character

    colors = ['green', 'yellow', 'red']

    instead of

    colors = ['green','yellow','red']

Relational Operators

  • is MUST be used over ==
  • not MUST be used over !
  • isnt MUST be used over !=
  • or MUST be used over ||
  • and MUST be used over &&

Comments

  • There MUST be a space between # and the first character of the comment
  • The first character of the comment MUST be uppercase
  • Single line comments MUST be placed on a newline above the subject of the comment
  • One empty line SHOULD be put before a single line comment
  • Obscure code SHOULD be commented but not obvious things
  • # FIXME: MAY be used to annotate problems
  • # TODO: MAY be used to capture issues which need to get solved

Strings

  • Single Quotes MUST be used for simple strings except the string contains an interpolation (e.g. "#{name}")

    test = 'foo'

    instead of

    test = "foo"

Objects

  • Objects MUST be split up over several lines

    vector =
    	x: 10
    	y: 20
    	z: 30

    instead of

    vector = x: 10, y: 20, z: 30
  • Shorthand assignments with braces MUST be used in single-line assignments

    test = { name }

    instead of

    test = name: name
  • Objects with braces MUST be indented

    return {
    	x: 1
    	y: 2
    }

    instead of

    return {
    x: 1
    y: 2
    }

Functions

  • Parentheses for an empty argument list MUST be omitted

    logTest = ->
    	console.log 'test'

    instead of

    logTest = () ->
    	console.log 'test'
  • Fat arrows MUST only be used when necessary

    logTest = ->
    	console.log 'test'

    instead of

    logTest = =>
    	console.log 'test'
  • Implicit returns SHOULD NOT be used

    add = (a, b) ->
    	return a + b

    instead of

    add = (a, b) -> a + b
  • Function calls with more than 2 arguments SHOULD be split over several lines

    doSomething(
    	'with'
    	'those'
    	'strings'
    )

    instead of

    doSomething 'with', 'those', 'strings'

Chaining

  • Method chains with more than 2 method calls MUST be wrapped and indented.

    $('#items')
    	.find('.selected')
    	.highlight()

    instead of

    $('#items').find('.selected').highlight()
  • Sub-properties MUST not be wrapped

    person.address.country
    	.toUpperCase()
    	.split('')

    instead of

    person
    	.address
    	.country
    	.toUpperCase()
    	.split('')
  • Methods SHOULD return @ to enable method chaining

Conditionals

  • Newlines SHOULD be insterted after if and else blocks

    if isTest
    	doSomething()
    	doSomethingElse()
    
    else
    	doNothing()
    	jumpAround()

    instead of

    if isTest
    	doSomething()
    	doSomethingElse()
    else
    	doNothing()
    	jumpAround()

Type Casting

  • To string: String(123)
  • To number: Number('123')
  • To boolean: Boolean(1)

General

You MAY (when it's absolutely necessary) differ from any rules of this guide to increase the performance. You MUST, however, explain the reasons for not sticking to a rule in a comment.

Framework specific

jQuery

  • jQuery object variables MUST be prefixed with a $

    $form = $ '#myForm'

    instead of

    form = $ '#myForm'
  • Lookups MUST be cached

    $form = $ '#form'
    
    $form.css {
    	'background-color': 'pink'
    }
    
    # …
    
    $form.hide()

    instead of

    $('#form').css {
    	'background-color': 'pink'
    }
    
    # …
    
    $('#form').hide()