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

es5-validator

v1.3.1

Published

Validate JS source code against ES5 to avoid breaking you App by shipping ES6+ code to production silently

Downloads

1,768

Readme

es5-validator

Validate JS source code against ES5 and report possible syntax errors before shipping to production to make your code safe on iOS 9, iOS 10 or other ES6+ incompatible platforms.

The earlier you find ES5 incompatibility errors, the earlier you can fix them.

Use

npx es5-validator FILE_TO_VALIDATE1.js [FILE_TO_VALIDATE2.js] [https://some-cdn/es.min.js]

Or Use as Script

npm i es5-validator --save-dev

package.json

{
  "scripts": {
    "lint:es5": "es5-validator es6.js"
  }
}

es6.js

function func(foo = '') {}
const bar = 1;
npm run lint:es5

Result:

[es5-validator] Your code is not ES5 Compatible. It's not ready to ship to production, otherwise it will break you App on iOS 9 or iOS 10.

Error: ECMAScript 5 validate failed when parsing es6.js.formatted (1, 18)


> 1 | function func(foo = '') {}
    |                  ^ Invalid ECMAScript 5 syntax
  2 | const bar = 1;

es5-validator-demo

Demo repo.

Why it exits

To avoid breaking you App by shipping ES6+ code to production silently.

How it works

Detect syntax error by parsing source code aganest ES5 using acorn. For more details, you can read the code.

When encountering a syntax error, the parser will raise a SyntaxError object with a meaningful message. The error object will have a pos property that indicates the string offset at which the error occurred, and a loc object that contains a {line, column} object referring to that same position.

  • https://www.npmjs.com/package/acorn
acorn.parse(source, {
  ecmaVersion: 5,
});

💡 Notice: Only the syntax can be detected. Methods introduced by ES6+ wont be reported. For example Object.assign will not be reported but spread operator will.

Features

  • [x] Validate local JS file.
  • [x] Validate remote JS file. For example: npx es5-validator https://cdn.jsdelivr.net/npm/js-pinyin/index.js.
  • [x] Validate multiple JS files concurrently. For example: npx es5-validator es6-1.js es6-2.js.
  • [x] Validate inline source code directly. For example: npx es5-validator --inline "const bar = 1;".

Todo

  • [x] Validate remote js. npx es5-validator https://cdn.jsdelivr.net/npm/js-pinyin/index.js.

Give a star ❤️ if it helped you https://github.com/legend80s/es5-validator.