-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation, tests, readme
- Loading branch information
Showing
17 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
|
||
"rules": { | ||
"prefer-regex-literals": "off", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [ljharb] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: npm/has-named-captures | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Tests: node.js < 10' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '< 10' | ||
type: minors | ||
command: npm run tests-only | ||
|
||
node: | ||
name: 'node < 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'Tests: pretest/posttest' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/pretest.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Tests: node.js >= 10' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '>= 10' | ||
type: minors | ||
command: npm run tests-only | ||
|
||
node: | ||
name: 'node >= 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Automatic Rebase | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
uses: ljharb/actions/.github/workflows/rebase.yml@main | ||
secrets: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Require “Allow Edits” | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
name: "Require “Allow Edits”" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: ljharb/require-allow-edits@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,5 @@ dist | |
npm-shrinkwrap.json | ||
package-lock.json | ||
yarn.lock | ||
|
||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
package-lock=false | ||
allow-same-version=true | ||
message=v%s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"all": true, | ||
"check-coverage": false, | ||
"reporter": ["text-summary", "text", "html", "json"], | ||
"lines": 86, | ||
"statements": 85.93, | ||
"functions": 82.43, | ||
"branches": 76.06, | ||
"exclude": [ | ||
"coverage", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Changelog | ||
|
||
All notable changes to this project will be documented in this file. Dates are displayed in UTC. | ||
|
||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,40 @@ | ||
# has-named-captures | ||
# has-named-captures <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
|
||
[![github actions][actions-image]][actions-url] | ||
[![coverage][codecov-image]][codecov-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
|
||
[![npm badge][npm-badge-png]][package-url] | ||
|
||
Does the JS environment support named capture groups in regexes? | ||
|
||
Returns `true` in node 10+, and equivalent engines. | ||
|
||
## Example | ||
|
||
```js | ||
var hasNamedCaptures = require('has-named-captures'); | ||
var assert = require('assert'); | ||
|
||
assert.equal(typeof hasNamedCaptures(), 'boolean', 'returns true or false'); | ||
``` | ||
|
||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
|
||
[package-url]: https://npmjs.org/package/has-named-captures | ||
[npm-version-svg]: https://versionbadg.es/inspect-js/has-named-captures.svg | ||
[deps-svg]: https://david-dm.org/inspect-js/has-named-captures.svg | ||
[deps-url]: https://david-dm.org/inspect-js/has-named-captures | ||
[dev-deps-svg]: https://david-dm.org/inspect-js/has-named-captures/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/inspect-js/has-named-captures#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/has-named-captures.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/has-named-captures.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/has-named-captures.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=has-named-captures | ||
[codecov-image]: https://codecov.io/gh/inspect-js/has-named-captures/branch/main/graphs/badge.svg | ||
[codecov-url]: https://app.codecov.io/gh/inspect-js/has-named-captures/ | ||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/has-named-captures | ||
[actions-url]: https://github.com/inspect-js/has-named-captures/actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare function hasNamedCaptures(): boolean; | ||
|
||
export = hasNamedCaptures; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
/** @type {import('.')} */ | ||
module.exports = function hasNamedCaptures() { | ||
try { | ||
return !!new RegExp('(?<x>.)'); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
var test = require('tape'); | ||
var hasNamedCaptures = require('../'); | ||
|
||
test('hasNamedCaptures', function (t) { | ||
t.equal(typeof hasNamedCaptures, 'function', 'is a function'); | ||
t.equal(typeof hasNamedCaptures(), 'boolean', 'returns a boolean'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('has named captures', { skip: !hasNamedCaptures() }, function (t) { | ||
var re = new RegExp('(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})'); | ||
var groups = /** @type {RegExpExecArray} */ (re.exec('2024-01-29')).groups; // eslint-disable-line no-extra-parens | ||
|
||
t.deepEqual(groups, { __proto__: null, year: '2024', month: '01', day: '29' }, 'returns named captures'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('no named captures', { skip: hasNamedCaptures() }, function (t) { | ||
t['throws'](function () { | ||
return new RegExp('(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})'); | ||
}); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig to read more about this file */ | ||
|
||
/* Projects */ | ||
|
||
/* Language and Environment */ | ||
"target": "es2018", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ | ||
"useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ | ||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ | ||
|
||
/* Modules */ | ||
"module": "commonjs", /* Specify what module code is generated. */ | ||
// "rootDir": "./", /* Specify the root folder within your source files. */ | ||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ | ||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ | ||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ | ||
"typeRoots": ["types"], /* Specify multiple folders that act like './node_modules/@types'. */ | ||
"resolveJsonModule": true, /* Enable importing .json files. */ | ||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ | ||
|
||
/* JavaScript Support */ | ||
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ | ||
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ | ||
"maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ | ||
|
||
/* Emit */ | ||
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ | ||
"declarationMap": true, /* Create sourcemaps for d.ts files. */ | ||
"noEmit": true, /* Disable emitting files from a compilation. */ | ||
|
||
/* Interop Constraints */ | ||
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ | ||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ | ||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ | ||
|
||
/* Type Checking */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
|
||
/* Completeness */ | ||
//"skipLibCheck": true /* Skip type checking all .d.ts files. */ | ||
}, | ||
"exclude": [ | ||
"coverage" | ||
] | ||
} |