regexp.prototype.flags

中文文档
1.5.4发布于 2025/01/03MITCommonJS近 30 天下载 3.9亿

ES6 spec-compliant RegExp.prototype.flags shim.

原始使用文档

RegExp.prototype.flags Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

An ES6 spec-compliant RegExp.prototype.flags shim. Invoke its "shim" method to shim RegExp.prototype.flags if it is unavailable. Note: RegExp#flags requires a true ES5 environment - specifically, one with ES5 getters.

This package implements the es-shim API interface. It works in an ES5-supported environment and complies with the spec.

Most common usage:

var flags = require('regexp.prototype.flags');
var assert = require('assert');

assert(flags(/a/) === '');
assert(flags(new RegExp('a')) === '');
assert(flags(/a/mig) === 'gim');
assert(flags(new RegExp('a', 'mig')) === 'gim');

if (!RegExp.prototype.flags) {
    flags.shim();
}

assert(flags(/a/) === /a/.flags);
assert(flags(new RegExp('a')) === new RegExp('a').flags);
assert(flags(/a/mig) === /a/mig.flags);
assert(flags(new RegExp('a', 'mig')) === new RegExp('a', 'mig').flags);

Tests

Simply clone the repo, npm install, and run npm test

版本与发布记录

regexp.prototype.flags 共发布 17 个版本,首次发布于 2014/12/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.4latest2025/01/031.8 年前
1.5.32024/10/032 年前
1.5.22024/02/122 年前
1.5.12023/09/133 年前
1.5.02023/04/193 年前
1.4.32022/04/154 年前

关于 regexp.prototype.flags 的常见问题

regexp.prototype.flags 是什么?

ES6 spec-compliant RegExp.prototype.flags shim.

如何安装 regexp.prototype.flags?

在项目目录运行 npm install regexp.prototype.flags,或使用 pnpm add / yarn add / bun add。

regexp.prototype.flags 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/regexp.prototype.flags 是否存在。

regexp.prototype.flags 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

regexp.prototype.flags 需要什么版本的 Node.js?

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

regexp.prototype.flags 可以商用吗?

regexp.prototype.flags 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

regexp.prototype.flags 的下载量有多少?

根据 npm 官方下载统计,regexp.prototype.flags 在 2026/10/05 – 2026/11/03 这 30 天内被下载 386,447,823 次,日均约 12,881,594 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

regexp.prototype.flags 还在维护吗?

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