Skip to content

GoogleChromeLabs/detect-es-version

Repository files navigation

detect-es-version

Given a package name, filepath, or string of code, returns the ecma version. You can try out the web app version here!

Usage

const { getEcmaVersion } = require('detect-es-version');
const ecmaVersion = getEcmaVersion('const foo = 123;');
console.log(ecmaVersion); // prints 2015

API

getPackageEcmaVersion(packageString, resolverOptions)

  • packageString (String): A string representing a package. e.g. “react”, “react@16.13.1” to be pulled from npm.
  • resolverOptions (Object): An options object to pass to enhanced-resolve. This can be used to control which entry points are analyzed.
  • Returns (Number): The ecma version of the package. e.g. 2017.

getLocalPackageEcmaVersion(packagePath, resolverOptions)

  • packagePath (String): An absolute path to a package’s directory. The directory must contain an index file or package.json.
  • resolverOptions (Object): An options object to pass to enhanced-resolve. This can be used to control which entry points are analyzed.
  • Returns (Number): The ecma version of the package. e.g. 2017.

getEntryPointEcmaVersion(entryPoint, resolverOptions)

  • entryPoint (String): An absolute path to an entry point.
  • resolverOptions (Object): An options object to pass to enhanced-resolve. This can be used to control which entry points are analyzed.
  • Returns (Number): The ecma version of the package. e.g. 2017.

getEcmaVersion(content)

  • code (String|Object): The source code or AST to inspect
  • Returns (Number): The ecma version of the source code or AST. e.g. 2017.

isEcmaVersionModern(ecmaVersion)

  • ecmaVersion (Number): A number representing an ECMA version. e.g. 5, 2015, or 2016
  • Returns (Boolean): True if the ECMA version is considered modern; False otherwise

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published