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

es-check-format

v1.0.6

Published

es-check formatting output

Downloads

28

Readme

es-check-format

参考es-check,出于以下两个原因做了一些改造:

  1. es-check 只支持 cli 使用方式,不能很方便地在某个工具库或自动化流程中直接使用,所以将 核心逻辑 抽离,提供 apicli 两种方式;
  2. es-check 输出的错误日志格式,在使用了 webpack 打包有 sourcemap 的情况下,很难定位到源代码,所以这里使用 source-map 进行了溯源,输出更友好的错误日志;

使用方式

CLI

使用方式跟参数跟 es-check 保持一致,但是为了避免冲突,对名称进行了修改

npm install es-check-format -g
es-check-format es5 './dist/**/*.js'

or

npx es-check-format es5 './dist/**/*.js'

API

Install

npm install es-check-format -save-dev

Example

const esCheck = require('es-check-format')

...
const errors = await esCheck({
	context: process.cwd(),
	files: './dist/**/*.js',
	ecmaVersion: 'es5'
})

if (errors.length) {
	console.log(errors)
	/* [{
		file: 'xxx', // 扫描出错的文件
		source: 'xxx', // sourcemap存在时,溯源到的源文件
		location: { line: 1, column: 100 }, // sourcemap存在时是源文件位置,不存在时是出错文件位置
		code: 'xxx' // sourcemap存在时,源文件位置代码
	}]*/
}

esCheck(options)

  • context: The base directory, an absolute path, default process.cwd()
  • files: Array of glob pattern
  • ecmaVersion: Indicates the ECMAScript version to parse. Default is es5.
  • module: use ES modules, default false
  • allowHashBang: supports files that start with hash bang, default false
  • not: folderName1,folderName2 An array of file/folder names that you would like to ignore. Defaults to []

注意

  • 项目中使用 webpack 打包时,主要解析不到的文件是外部依赖包(参考why-es-check),而一般外部依赖包会被统一打包到 common-chunk 中,由于 acorn 只要解析失败就会退出,所以不管是 es-check-format 还是 es-check 都没法遍历到一个文件所有的问题,暂时只能查到一个解决后再继续查。(如果哪个同学有好的办法,烦请在 issue 中留言)