8d74bc9ba71c238410e539e41dd4d429588a2b597d0e509a99878f49a39d1c17574f997f29694cf05998768c3c7d9a9ef349e64d742c1b071db231020fa89b 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. RegExp.prototype.flags <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![Build Status][travis-svg]][travis-url]
  3. [![dependency status][deps-svg]][deps-url]
  4. [![dev dependency status][dev-deps-svg]][dev-deps-url]
  5. [![License][license-image]][license-url]
  6. [![Downloads][downloads-image]][downloads-url]
  7. [![npm badge][npm-badge-png]][package-url]
  8. [![browser support][testling-svg]][testling-url]
  9. An ES6 spec-compliant `RegExp.prototype.flags` shim. Invoke its "shim" method to shim RegExp.prototype.flags if it is unavailable.
  10. *Note*: `RegExp#flags` requires a true ES5 environment - specifically, one with ES5 getters.
  11. 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).
  12. Most common usage:
  13. ```js
  14. var flags = require('regexp.prototype.flags');
  15. var assert = require('assert');
  16. assert(flags(/a/) === '');
  17. assert(flags(new RegExp('a')) === '');
  18. assert(flags(/a/mig) === 'gim');
  19. assert(flags(new RegExp('a', 'mig')) === 'gim');
  20. if (!RegExp.prototype.flags) {
  21. flags.shim();
  22. }
  23. assert(flags(/a/) === /a/.flags);
  24. assert(flags(new RegExp('a')) === new RegExp('a').flags);
  25. assert(flags(/a/mig) === /a/mig.flags);
  26. assert(flags(new RegExp('a', 'mig')) === new RegExp('a', 'mig').flags);
  27. ```
  28. ## Tests
  29. Simply clone the repo, `npm install`, and run `npm test`
  30. [package-url]: https://npmjs.com/package/regexp.prototype.flags
  31. [npm-version-svg]: http://versionbadg.es/es-shims/RegExp.prototype.flags.svg
  32. [travis-svg]: https://travis-ci.org/es-shims/RegExp.prototype.flags.svg
  33. [travis-url]: https://travis-ci.org/es-shims/RegExp.prototype.flags
  34. [deps-svg]: https://david-dm.org/es-shims/RegExp.prototype.flags.svg
  35. [deps-url]: https://david-dm.org/es-shims/RegExp.prototype.flags
  36. [dev-deps-svg]: https://david-dm.org/es-shims/RegExp.prototype.flags/dev-status.svg
  37. [dev-deps-url]: https://david-dm.org/es-shims/RegExp.prototype.flags#info=devDependencies
  38. [testling-svg]: https://ci.testling.com/es-shims/RegExp.prototype.flags.png
  39. [testling-url]: https://ci.testling.com/es-shims/RegExp.prototype.flags
  40. [npm-badge-png]: https://nodei.co/npm/regexp.prototype.flags.png?downloads=true&stars=true
  41. [license-image]: http://img.shields.io/npm/l/regexp.prototype.flags.svg
  42. [license-url]: LICENSE
  43. [downloads-image]: http://img.shields.io/npm/dm/regexp.prototype.flags.svg
  44. [downloads-url]: http://npm-stat.com/charts.html?package=regexp.prototype.flags