Skip to content

Commit bab26dd

Browse files
authored
nodenext compatibility (#22)
1 parent 013b1a3 commit bab26dd

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ jobs:
1515
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
1616
with:
1717
license-check: true
18+
lint: true

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const parse = require('ret')
44
const types = parse.types
55

6-
module.exports = function (re, opts) {
6+
function safeRegex (re, opts) {
77
if (!opts) opts = {}
88
const replimit = opts.limit === undefined ? 25 : opts.limit
99

@@ -46,3 +46,7 @@ module.exports = function (re, opts) {
4646
function isRegExp (x) {
4747
return {}.toString.call(x) === '[object RegExp]'
4848
}
49+
50+
module.exports = safeRegex
51+
module.exports.default = safeRegex
52+
module.exports.safeRegex = safeRegex

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
"version": "3.0.0",
44
"description": "detect possibly catastrophic, exponential-time regular expressions",
55
"main": "index.js",
6+
"types": "types/index.d.ts",
67
"dependencies": {
78
"ret": "~0.4.0"
89
},
910
"devDependencies": {
1011
"standard": "^17.0.0",
11-
"tape": "^5.0.0"
12+
"tape": "^5.0.0",
13+
"tsd": "^0.25.0"
1214
},
1315
"scripts": {
14-
"test": "standard && tape test/*.js"
16+
"lint": "standard",
17+
"test": "npm run test:unit",
18+
"test:typescript": "tsd",
19+
"test:unit": "tape test/*.js"
1520
},
1621
"repository": {
1722
"type": "git",

types/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type SafeRegex2 = (re: string | RegExp, opts?: { limit?: number }) => boolean
2+
3+
declare namespace safeRegex {
4+
export const safeRegex: SafeRegex2
5+
export { safeRegex as default }
6+
}
7+
8+
declare function safeRegex(...params: Parameters<SafeRegex2>): ReturnType<SafeRegex2>
9+
export = safeRegex

types/index.test-d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import safeRegex, { safeRegex as safeRegexNamed } from '..'
2+
import { expectType } from 'tsd'
3+
4+
expectType<boolean>(safeRegex('regex'))
5+
expectType<boolean>(safeRegex(/regex/))
6+
expectType<boolean>(safeRegex('^([a-zA-Z0-9]+\\s?)+$'))
7+
expectType<boolean>(safeRegex(/^([a-zA-Z0-9]+\s?)+$/g))
8+
9+
expectType<boolean>(safeRegexNamed('regex'))
10+
expectType<boolean>(safeRegexNamed(/regex/))
11+
expectType<boolean>(safeRegexNamed('^([a-zA-Z0-9]+\\s?)+$'))
12+
expectType<boolean>(safeRegexNamed(/^([a-zA-Z0-9]+\s?)+$/g))

0 commit comments

Comments
 (0)