# regexp.prototype.flags

> ES6 spec-compliant RegExp.prototype.flags shim.

Latest version **1.5.4** (published 2025-01-03) · MIT license · 0 weekly downloads

> **Native alternative:** RegExp.prototype.flags (e.g. "/foo/g.flags") — Use native JavaScript (Node 6.0.0+) (https://developer.mozilla.orgGlobal_Objects/RegExp/flags)

## Install

```sh
npm install regexp.prototype.flags
pnpm add regexp.prototype.flags
yarn add regexp.prototype.flags
bun add regexp.prototype.flags
```

## Health

**Score 43/100 (D)** — status: stable.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.5.4 |
| Published | 2025-01-03 |
| First published | 2014-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/regexp.prototype.flags) |
| Module format | CommonJS |
| Node | >= 0.4 |
| Dependencies | 6 |
| Unpacked size | 43.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | RegExp.prototype.flags, regex, regular expression, ES6, shim, flag, flags, regexp, RegExp#flags, polyfill, es-shim API |

## Links

- npm: https://www.npmjs.com/package/regexp.prototype.flags
- Repository: https://github.com/es-shims/RegExp.prototype.flags
- Homepage: https://github.com/es-shims/RegExp.prototype.flags#readme
- Issues: https://github.com/es-shims/RegExp.prototype.flags/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/regexp.prototype.flags

## Dependencies (6)

- [gopd](https://npm.io/package/gopd.md) ^1.2.0
- [call-bind](https://npm.io/package/call-bind.md) ^1.0.8
- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0
- [get-proto](https://npm.io/package/get-proto.md) ^1.0.1
- [define-properties](https://npm.io/package/define-properties.md) ^1.2.1
- [set-function-name](https://npm.io/package/set-function-name.md) ^2.0.2

## Recent versions

- 1.5.4 (latest) — 2025-01-03
- 1.5.3 — 2024-10-03
- 1.5.2 — 2024-02-11
- 1.5.1 — 2023-09-13
- 1.5.0 — 2023-04-19
- 1.4.3 — 2022-04-15
- 1.4.2 — 2022-04-13
- 1.4.1 — 2022-01-14
- 1.4.0 — 2022-01-14
- 1.3.2 — 2022-01-13
- 1.3.1 — 2021-01-15
- 1.3.0 — 2019-12-15
- 1.2.0 — 2017-10-25
- 1.1.1 — 2015-08-16
- 1.1.0 — 2015-08-16
- … 2 more at https://npm.io/package/regexp.prototype.flags/versions

## README

RegExp.prototype.flags <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![Build Status][travis-svg]][travis-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

[![browser support][testling-svg]][testling-url]

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](https://github.com/es-shims/api) interface. It works in an ES5-supported environment and complies with the [spec](http://www.ecma-international.org/ecma-262/6.0/#sec-get-regexp.prototype.flags).

Most common usage:
```js
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`

[package-url]: https://npmjs.com/package/regexp.prototype.flags
[npm-version-svg]: http://versionbadg.es/es-shims/RegExp.prototype.flags.svg
[travis-svg]: https://travis-ci.org/es-shims/RegExp.prototype.flags.svg
[travis-url]: https://travis-ci.org/es-shims/RegExp.prototype.flags
[deps-svg]: https://david-dm.org/es-shims/RegExp.prototype.flags.svg
[deps-url]: https://david-dm.org/es-shims/RegExp.prototype.flags
[dev-deps-svg]: https://david-dm.org/es-shims/RegExp.prototype.flags/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/RegExp.prototype.flags#info=devDependencies
[testling-svg]: https://ci.testling.com/es-shims/RegExp.prototype.flags.png
[testling-url]: https://ci.testling.com/es-shims/RegExp.prototype.flags
[npm-badge-png]: https://nodei.co/npm/regexp.prototype.flags.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/regexp.prototype.flags.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/regexp.prototype.flags.svg
[downloads-url]: http://npm-stat.com/charts.html?package=regexp.prototype.flags

---
_Source: https://npm.io/package/regexp.prototype.flags · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
