@es-joy/esutils

中文文档
3.0.0发布于 2026/08/21BSD-2-ClauseTypeScriptES Module近 30 天下载 17.2万

utility box for ECMAScript language tools

原始使用文档
文档目录27 节
  1. API
  2. ast
  3. ast.isExpression(node)
  4. ast.isStatement(node)
  5. ast.isIterationStatement(node)
  6. ast.isSourceElement(node)
  7. ast.trailingStatement(node)
  8. ast.isProblematicIfStatement(node)
  9. code
  10. code.isDecimalDigit(code)
  11. code.isHexDigit(code)
  12. code.isOctalDigit(code)
  13. code.isWhiteSpace(code)
  14. code.isLineTerminator(code)
  15. code.isIdentifierStart(code)
  16. code.isIdentifierPart(code)
  17. keyword
  18. keyword.isKeywordES5(id, strict)
  19. keyword.isKeywordES6(id, strict)
  20. keyword.isReservedWordES5(id, strict)
  21. keyword.isReservedWordES6(id, strict)
  22. keyword.isRestrictedWord(id)
  23. keyword.isIdentifierNameES5(id)
  24. keyword.isIdentifierNameES6(id)
  25. keyword.isIdentifierES5(id, strict)
  26. keyword.isIdentifierES6(id, strict)
  27. License

@es-joy/esutils

@es-joy/esutils is a utility box for ECMAScript language tools.

API

ast

ast.isExpression(node)

Returns true if node is an Expression as defined in ECMA262 edition 5.1 section 11.

ast.isStatement(node)

Returns true if node is a Statement as defined in ECMA262 edition 5.1 section 12.

ast.isIterationStatement(node)

Returns true if node is an IterationStatement as defined in ECMA262 edition 5.1 section 12.6.

ast.isSourceElement(node)

Returns true if node is a SourceElement as defined in ECMA262 edition 5.1 section 14.

ast.trailingStatement(node)

Returns Statement? if node has trailing Statement.

if (cond) {
  consequent;
}

When taking this IfStatement, returns consequent; statement.

ast.isProblematicIfStatement(node)

Returns true if node is a problematic IfStatement. If node is a problematic IfStatement, node cannot be represented as an one-to-one JavaScript code.

const ast = {
  type: 'IfStatement',
  consequent: {
    type: 'WithStatement',
    body: {
      type: 'IfStatement',
      consequent: {type: 'EmptyStatement'}
    }
  },
  alternate: {type: 'EmptyStatement'}
};

The above node cannot be represented as a JavaScript code, since the top level else alternate belongs to an inner IfStatement.

code

code.isDecimalDigit(code)

Return true if provided code is decimal digit.

code.isHexDigit(code)

Return true if provided code is hexadecimal digit.

code.isOctalDigit(code)

Return true if provided code is octal digit.

code.isWhiteSpace(code)

Return true if provided code is white space. White space characters are formally defined in ECMA262.

code.isLineTerminator(code)

Return true if provided code is line terminator. Line terminator characters are formally defined in ECMA262.

code.isIdentifierStart(code)

Return true if provided code can be the first character of ECMA262 Identifier. They are formally defined in ECMA262.

code.isIdentifierPart(code)

Return true if provided code can be the trailing character of ECMA262 Identifier. They are formally defined in ECMA262.

keyword

keyword.isKeywordES5(id, strict)

Returns true if provided identifier string is a Keyword or Future Reserved Word in ECMA262 edition 5.1. They are formally defined in ECMA262 sections 7.6.1.1 and 7.6.1.2, respectively. If the strict flag is truthy, this function additionally checks whether id is a Keyword or FutureReservedWord under strict mode.

keyword.isKeywordES6(id, strict)

Returns true if provided identifier string is a Keyword or FutureReservedWord in ECMA262 edition 6. They are formally defined in ECMA262 sections 11.6.2.1 and 11.6.2.2, respectively. If the strict flag is truthy, this function additionally checks whether id is a Keyword or FutureReservedWord under strict mode.

keyword.isReservedWordES5(id, strict)

Returns true if provided identifier string is a ReservedWord in ECMA262 edition 5.1. They are formally defined in ECMA262 section 7.6.1. If the strict flag is truthy, this function additionally checks whether id is a ReservedWord under strict mode.

keyword.isReservedWordES6(id, strict)

Returns true if provided identifier string is a ReservedWord in ECMA262 edition 6. They are formally defined in ECMA262 section 11.6.2. If the strict flag is truthy, this function additionally checks whether id is a ReservedWord under strict mode.

keyword.isRestrictedWord(id)

Returns true if provided identifier string is one of eval or arguments. They are restricted in strict mode code throughout ECMA262 edition 5.1 and in ECMA262 edition 6 section 12.1.1.

keyword.isIdentifierNameES5(id)

Return true if provided identifier string is an IdentifierName as specified in ECMA262 edition 5.1 section 7.6.

keyword.isIdentifierNameES6(id)

Return true if provided identifier string is an IdentifierName as specified in ECMA262 edition 6 section 11.6.

keyword.isIdentifierES5(id, strict)

Return true if provided identifier string is an Identifier as specified in ECMA262 edition 5.1 section 7.6. If the strict flag is truthy, this function additionally checks whether id is an Identifier under strict mode.

keyword.isIdentifierES6(id, strict)

Return true if provided identifier string is an Identifier as specified in ECMA262 edition 6 section 12.1. If the strict flag is truthy, this function additionally checks whether id is an Identifier under strict mode.

License

Copyright (C) 2013 Yusuke Suzuki (twitter: @Constellation) and other contributors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

版本与发布记录

@es-joy/esutils 共发布 1 个版本,首次发布于 2026/08/21;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.0.0latest2026/08/212 个月前

关于 @es-joy/esutils 的常见问题

@es-joy/esutils 是什么?

utility box for ECMAScript language tools

如何安装 @es-joy/esutils?

在项目目录运行 npm install @es-joy/esutils,或使用 pnpm add / yarn add / bun add。

@es-joy/esutils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@es-joy/esutils 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@es-joy/esutils 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.16.0 || >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@es-joy/esutils 可以商用吗?

@es-joy/esutils 使用 BSD-2-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@es-joy/esutils 的下载量有多少?

根据 npm 官方下载统计,@es-joy/esutils 在 2026/10/14 – 2026/11/12 这 30 天内被下载 172,116 次,日均约 5,737 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@es-joy/esutils 还在维护吗?

最新版本 3.0.0 发布于 2026/08/21(2 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2026/08/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。