Skip to content

Commit

Permalink
[New] add hasIndices/d flag
Browse files Browse the repository at this point in the history
ljharb committed Jan 13, 2022

Verified

This commit was signed with the committer’s verified signature.
ljharb Jordan Harband
1 parent 45b78d5 commit 89959ca
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions implementation.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ module.exports = function flags() {
throw new $TypeError('RegExp.prototype.flags getter called on non-object');
}
var result = '';
if (this.hasIndices) {
result += 'd';
}
if (this.global) {
result += 'g';
}
6 changes: 6 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -39,6 +39,12 @@ module.exports = function runTests(flags, t) {
st.end();
});

t.test('hasIndices flag', { skip: !has(RegExp.prototype, 'hasIndices') }, function (st) {
st.equal(flags(getRegexLiteral('/a/d')), 'd', 'flags(/a/d) !== "d"');
st.equal(flags(new RegExp('a', 'd')), 'd', 'flags(new RegExp("a", "d")) !== "d"');
st.end();
});

t.test('sorting', function (st) {
st.equal(flags(/a/gim), 'gim', 'flags(/a/gim) !== "gim"');
st.equal(flags(/a/mig), 'gim', 'flags(/a/mig) !== "gim"');

0 comments on commit 89959ca

Please sign in to comment.