From faa9e4afcab47c46ef140504e285133020c78954 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 8 Apr 2021 21:18:10 +0700 Subject: [PATCH] Require Node.js 12 and move to ESM --- .github/workflows/main.yml | 4 +--- index.d.ts | 18 +++++++----------- index.js | 7 +++---- index.test-d.ts | 4 ++-- license | 2 +- package.json | 15 +++++++++------ readme.md | 15 +++------------ test.js | 8 ++++---- 8 files changed, 30 insertions(+), 43 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..d36e1a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/index.d.ts b/index.d.ts index 6a97259..54d9278 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,9 +1,7 @@ -declare namespace execall { - interface Match { - match: string; - subMatches: string[]; - index: number; - } +export interface Match { + match: string; + subMatches: string[]; + index: number; } /** @@ -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', @@ -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[]; diff --git a/index.js b/index.js index ea1f111..8d217e9 100644 --- a/index.js +++ b/index.js @@ -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}); @@ -21,4 +20,4 @@ module.exports = (regexp, string) => { } return matches; -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index 3b7f337..bd67108 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ import {expectType} from 'tsd'; -import execall = require('.'); +import execAll, {Match} from './index.js'; -expectType(execall(/(\d+)/g, '$200 and $400')); +expectType(execAll(/(\d+)/g, '$200 and $400')); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (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: diff --git a/package.json b/package.json index be5eda6..ea48078 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" } } diff --git a/readme.md b/readme.md index 38291f2..c7af1d8 100644 --- a/readme.md +++ b/readme.md @@ -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'); /* [ { @@ -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. @@ -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) diff --git a/test.js b/test.js index 98813c1..42d6617 100644 --- a/test.js +++ b/test.js @@ -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); });