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

semi

v4.0.5

Published

To semicolon or not to semicolon; that is the question

Downloads

11,750

Readme

Semi npm version Build Status

To semicolon or not to semicolon; that is the question

Add/remove semicolons from your JavaScript. Supports full ES6!

Why???

Because style.

On a more serious note, some people (including me) feel more comfortable and productive when writing JavaScript without semicolons. (If you disagree, read this) However, this is often not viable in a team environment, or when working on a project with established code style requirements.

As a solution to this problem, Semi can add semicolons to files written in a semicolon-less style, and can also remove semicolons from those written with semicolons. This allows you to write code in the style you like and just auto convert it before committing your code.

It was originally implemented by hacking jshint and now by using a custom rule for ESLint. Semi 100% preserves your original code formatting (other than semicolons). It even takes care of special cases where a newline semicolon is needed (see below).

Usage

CLI

npm install -g semi

Usage: semi [add|rm] [files...] [--out dir] [--leading] [--silent]

Options:

  --out      Output directory. If not specified, will overwrite original.
  --leading  Always add leading semicolons for lines that start with +-[(/.
  --silent   Suppress output messages.

API

var semi = require('semi')

// handle errors
semi.on('error', function (err) { /* ... */ })

// semi.add(<String>)
var jsWithSemicolons = semi.add(jsWithoutSemicolons)
// semi.remove(<String>)
var jsWithoutSemicolons = semi.remove(jsWithSemicolons, {
  leading: true
})

There's also Semi for SublimeText3!

It doesn't work!

If it doesn't seem to do anything, it's most likely because your code contains syntax errors.

Special Cases

Semi will automatically convert between the following two cases (also for newlines that start with [, +, - or a regex literal):

// A
var a = b;
(function () {
  /* ... */
})()
// B
var a = b
;(function () {
  /* ... */
})()

When leading option is true, it will add a leading semicolon for all newlines that start with one of those special tokens, even if the code is valid without the semicolon:

var a = 123;
++a;
// converts to:
var a = 123
;++a

However, it will not do anything to the following, because it is valid JavaScript and Semi cannot safely assume you wanted a semicolon there.

var a = b
(function () {
  /* ... */
})()

But Semicolons Are REQUIRED!!!

Semicolons in JavaScript are indeed optional. Now before you start to talk about how semicolons improve readibility simply because you also write other C-style languages, try to realize that JavaScript is not C, nor is it Java. Its semicolons are designed to be optional and dropping them can be a productivity boon for some people, including me. In fact, languages like Go and Groovy also have optional semicolons and the convention is not using them. You can even use semicolons in Ruby and Python, but obviously nobody does that because it's actually very easy to identify EOL as the end of a statement where it makes sense.

Now, if you are adding semicolons everywhere because you fear dropping them can cause mysterious bugs in some weird browsers, break minifiers, or the rules are simply too hard to remember, you are doing it wrong. The correct way to deal with FUD is to confront them and understand the root cause. You should read these following articles: