Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 8, 2021
1 parent 9007bc7 commit faa9e4a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
18 changes: 7 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
declare namespace execall {
interface Match {
match: string;
subMatches: string[];
index: number;
}
export interface Match {
match: string;
subMatches: string[];
index: number;
}

/**
Expand All @@ -14,9 +12,9 @@ Find multiple RegExp matches in a string.
@example
```
import execall = require('execall');
import execAll from 'execall';
execall(/(\d+)/g, '$200 and $400');
execAll(/(\d+)/g, '$200 and $400');
// [
// {
// match: '200',
Expand All @@ -31,6 +29,4 @@ execall(/(\d+)/g, '$200 and $400');
// ]
```
*/
declare function execall(regexp: RegExp, string: string): execall.Match[];

export = execall;
export default function execAll(regexp: RegExp, string: string): Match[];
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const cloneRegexp = require('clone-regexp');
import cloneRegexp from 'clone-regexp';

module.exports = (regexp, string) => {
export default function execAll(regexp, string) {
let match;
const matches = [];
const clonedRegexp = cloneRegexp(regexp, {lastIndex: 0});
Expand All @@ -21,4 +20,4 @@ module.exports = (regexp, string) => {
}

return matches;
};
}
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import execall = require('.');
import execAll, {Match} from './index.js';

expectType<execall.Match[]>(execall(/(\d+)/g, '$200 and $400'));
expectType<Match[]>(execAll(/(\d+)/g, '$200 and $400'));
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Find multiple RegExp matches in a string",
"license": "MIT",
"repository": "sindresorhus/execall",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -38,11 +41,11 @@
"global"
],
"dependencies": {
"clone-regexp": "^2.1.0"
"clone-regexp": "^3.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
15 changes: 3 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
Instead of having to iterate over `RegExp#exec`, immutable, and with a nicer result format.


## Install

```
$ npm install execall
```


## Usage

```js
const execall = require('execall');
import execAll from 'execall';

execall(/(\d+)/g, '$200 and $400');
execAll(/(\d+)/g, '$200 and $400');
/*
[
{
Expand All @@ -34,10 +32,9 @@ execall(/(\d+)/g, '$200 and $400');
*/
```


## API

### execall(regexp, string)
### execAll(regexp, string)

Returns an `object[]` with a match, sub-matches, and index.

Expand All @@ -51,12 +48,6 @@ Regular expression to match against the `string`.

Type: `string`


## Related

- [replace-string](https://github.com/sindresorhus/replace-string) - Replace all substring matches in a string


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava';
import execall from '.';
import execAll from './index.js';

test('main', t => {
const result = execall(/(\d+)/, '$200 and $400')[0];
const result = execAll(/(\d+)/, '$200 and $400')[0];
t.is(result.match, '200');
t.is(result.subMatches[0], '200');
t.is(result.index, 1);
t.is(execall(/\d+/g, '$200 and $400')[1].match, '400');
t.is(execall(/\d+/g, 'unicorn').length, 0);
t.is(execAll(/\d+/g, '$200 and $400')[1].match, '400');
t.is(execAll(/\d+/g, 'unicorn').length, 0);
});

0 comments on commit faa9e4a

Please sign in to comment.