# 安装

  • npm
npm install @babel/helper-validator-identifier
  • yarn
yarn add @babel/helper-validator-identifier

  • pnpm
pnpm add @babel/helper-validator-identifier

# 用法

要在代码中使用包,请从 @babel/helper-validator-identifier:

my-babel-plugin.js

import {
  isIdentifierName,
  isIdentifierStart,
  isIdentifierChar,
  isReservedWord,
  isStrictBindOnlyReservedWord,
  isStrictBindReservedWord,
  isStrictReservedWord,
  isKeyword,
} from "@babel/helper-validator-identifier";

# isIdentifierName

function isIdentifierName(name: string): boolean

isIdentifierName函数检查给定的字符串是否可以是有效的标识符名称。注意,它不处理unicode转义序列。例如,isIdentifierName("\u0061")返回false,而\u0061可能是JavaScript标识符名称(a)。

# import { named as _hintedName } from "source" (opens new window)

# isIdentifierStart

function isIdentifierStart(codepoint: number): boolean

isIdentifierStart函数检查给定的Unicode码点是否可以启动标识符,如IdentifierStartChar所定义的。

# isIdentifierChar

function isIdentifierChar(codepoint: number): boolean

isIdentifierChar函数检查给定的Unicode码位是否可以作为标识符的一部分,如IdentifierPartChar所定义的。

# 关键字和保留字

这些帮助程序检测关键字和保留字。有关更多信息,请参阅实现。

function isReservedWord(word: string, inModule: boolean): boolean
function isStrictReservedWord(word: string, inModule: boolean): boolean
function isStrictBindOnlyReservedWord(word: string): boolean
function isStrictBindReservedWord(word: string, inModule: boolean): boolean
function isKeyword(word: string): boolean

Last Updated: 6/7/2023, 9:06:23 AM