Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/GoogleChromeLabs/detect-es-version


https://github.com/GoogleChromeLabs/detect-es-version

Last synced: 4 days ago
JSON representation

Awesome Lists containing this project

README

        

# `detect-es-version`



Given a package name, filepath, or string of code, returns the [ecma version](https://developer.mozilla.org/en-US/docs/Glossary/ECMAScript). You can try out the web app version [here](https://detect-es-version.glitch.me/)!

## Usage
```javascript
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”, “[email protected]” to be pulled from npm.
- `resolverOptions` (`Object`): An options object to pass to [enhanced-resolve](https://github.com/webpack/enhanced-resolve#resolver-options). 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](https://github.com/webpack/enhanced-resolve#resolver-options). 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](https://github.com/webpack/enhanced-resolve#resolver-options). 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