re2 1.17.8 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,3 +34,4 @@ jobs:
34
34
  npm i
35
35
  npm run build --if-present
36
36
  npm test
37
+ npm run ts-test
package/README.md CHANGED
@@ -352,6 +352,7 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
352
352
 
353
353
  ## Release history
354
354
 
355
+ - 1.18.0 *Modified TS bindings, added a type test (thx, [Kenichi Kamiya](https://github.com/kachick) and [Jamie Magee](https://github.com/JamieMagee)).*
355
356
  - 1.17.8 *Updated deps, added Node 19 as a pre-compilation target.*
356
357
  - 1.17.7 *Added support for a cross-platform fetching of a pre-compiled version by updating [install-artifact-from-github](https://github.com/uhop/install-artifact-from-github).*
357
358
  - 1.17.6 *Implemented `dotAll`. Thx [Michael Kriese](https://github.com/viceice).*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "re2",
3
- "version": "1.17.8",
3
+ "version": "1.18.0",
4
4
  "description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
5
5
  "homepage": "https://github.com/uhop/node-re2",
6
6
  "bugs": "https://github.com/uhop/node-re2/issues",
@@ -16,10 +16,13 @@
16
16
  "node-gyp": "^9.3.0"
17
17
  },
18
18
  "devDependencies": {
19
- "heya-unit": "^0.3.0"
19
+ "@types/node": "^18.11.12",
20
+ "heya-unit": "^0.3.0",
21
+ "typescript": "^4.9.4"
20
22
  },
21
23
  "scripts": {
22
24
  "test": "node tests/tests.js",
25
+ "ts-test": "tsc",
23
26
  "save-to-github": "save-to-github-cache --artifact build/Release/re2.node",
24
27
  "install": "install-from-cache --artifact build/Release/re2.node --host-var RE2_DOWNLOAD_MIRROR --skip-path-var RE2_DOWNLOAD_SKIP_PATH --skip-ver-var RE2_DOWNLOAD_SKIP_VER || npm run rebuild",
25
28
  "verify-build": "node scripts/verify-build.js",
package/re2.d.ts CHANGED
@@ -1,27 +1,31 @@
1
1
  declare module 're2' {
2
2
 
3
- interface RE2MatchArray<K> extends Array<K> {
4
- index?: number;
5
- input?: K;
3
+ interface RE2BufferExecArray {
4
+ index: number;
5
+ input: Buffer;
6
+ 0: Buffer;
6
7
  groups?: {
7
- [key: string]: string
8
+ [key: string]: Buffer
8
9
  }
9
10
  }
10
11
 
11
- interface RE2ExecArray<K> extends Array<K> {
12
- index: number;
13
- input: K;
12
+ interface RE2BufferMatchArray {
13
+ index?: number;
14
+ input?: Buffer;
15
+ 0: Buffer;
14
16
  groups?: {
15
- [key: string]: string
17
+ [key: string]: Buffer
16
18
  }
17
19
  }
18
20
 
19
21
  interface RE2 extends RegExp {
20
- exec<K extends String | Buffer>(str: K): RE2ExecArray<K> | null;
22
+ exec(str: string): RegExpExecArray | null;
23
+ exec(str: Buffer): RE2BufferExecArray | null;
21
24
 
22
- test(str: string | Buffer): boolean;
25
+ match(str: string): RegExpMatchArray | null;
26
+ match(str: Buffer): RE2BufferMatchArray | null;
23
27
 
24
- match<K extends String | Buffer>(str: K): RE2MatchArray<K> | null;
28
+ test(str: string | Buffer): boolean;
25
29
 
26
30
  replace<K extends String | Buffer>(str: K, replaceValue: string | Buffer): K;
27
31
  replace<K extends String | Buffer>(str: K, replacer: (substring: string, ...args: any[]) => string | Buffer): K;
@@ -32,10 +36,10 @@ declare module 're2' {
32
36
  }
33
37
 
34
38
  interface RE2Constructor extends RegExpConstructor {
35
- new(pattern: Buffer | RegExp | string): RE2;
36
- new(pattern: Buffer | string, flags?: string): RE2;
37
- (pattern: Buffer | RegExp | string): RE2;
38
- (pattern: Buffer | string, flags?: string): RE2;
39
+ new(pattern: Buffer | RegExp | RE2 | string): RE2;
40
+ new(pattern: Buffer | string, flags?: string | Buffer): RE2;
41
+ (pattern: Buffer | RegExp | RE2 | string): RE2;
42
+ (pattern: Buffer | string, flags?: string | Buffer): RE2;
39
43
  readonly prototype: RE2;
40
44
 
41
45
  unicodeWarningLevel: 'nothing' | 'warnOnce' | 'warn' | 'throw';
@@ -0,0 +1,28 @@
1
+ import RE2 from 're2';
2
+
3
+ function assertType<T>(_val: T) {}
4
+
5
+ function test_execTypes() {
6
+ const re = new RE2('quick\\s(brown).+?(?<verb>jumps)', 'ig');
7
+ const result = re.exec('The Quick Brown Fox Jumps Over The Lazy Dog')
8
+ if (!(result && result.groups)) {
9
+ throw 'Unexpected Result'
10
+ }
11
+ assertType<number>(result.index)
12
+ assertType<string>(result.input)
13
+ assertType<string | undefined>(result.groups['verb'])
14
+ }
15
+
16
+ function test_matchTypes() {
17
+ const re = new RE2('quick\\s(brown).+?(?<verb>jumps)', 'ig');
18
+ const result = re.match('The Quick Brown Fox Jumps Over The Lazy Dog')
19
+ if (!(result && result.index && result.input && result.groups)) {
20
+ throw 'Unexpected Result'
21
+ }
22
+ assertType<number>(result.index)
23
+ assertType<string>(result.input)
24
+ assertType<string | undefined>(result.groups['verb'])
25
+ }
26
+
27
+ test_execTypes()
28
+ test_matchTypes()
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "noEmit": true,
4
+ "declaration": true,
5
+ "esModuleInterop": true,
6
+ "strict": true,
7
+ "allowUnusedLabels": false,
8
+ "allowUnreachableCode": false,
9
+ "exactOptionalPropertyTypes": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "noImplicitOverride": true,
12
+ "noImplicitReturns": true,
13
+ "noPropertyAccessFromIndexSignature": true,
14
+ "noUncheckedIndexedAccess": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+
18
+ },
19
+ "include": ["**/*.ts"]
20
+ }