@xylabs/jest-helpers 5.0.79 → 5.0.81

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.
package/README.md CHANGED
@@ -21,130 +21,6 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
21
21
 
22
22
  ***
23
23
 
24
- ## Functions
25
-
26
- - [describeIf](#functions/describeIf)
27
- - [itIf](#functions/itIf)
28
- - [tags](#functions/tags)
29
- - [testIf](#functions/testIf)
30
-
31
- ### functions
32
-
33
- ### <a id="describeIf"></a>describeIf
34
-
35
- [**@xylabs/jest-helpers**](#../README)
36
-
37
- ***
38
-
39
- ```ts
40
- function describeIf<T>(expr?): any;
41
- ```
42
-
43
- Conditionally runs or skips the describe
44
-
45
- ## Type Parameters
46
-
47
- ### T
48
-
49
- `T`
50
-
51
- ## Parameters
52
-
53
- ### expr?
54
-
55
- The condition to evaluate
56
-
57
- `null` | `T`
58
-
59
- ## Returns
60
-
61
- `any`
62
-
63
- If the condition is true, describe, otherwise skips
64
-
65
- ### <a id="itIf"></a>itIf
66
-
67
- [**@xylabs/jest-helpers**](#../README)
68
-
69
- ***
70
-
71
- ```ts
72
- function itIf<T>(expr?): any;
73
- ```
74
-
75
- Conditionally runs or skips the it
76
-
77
- ## Type Parameters
78
-
79
- ### T
80
-
81
- `T`
82
-
83
- ## Parameters
84
-
85
- ### expr?
86
-
87
- The condition to evaluate
88
-
89
- `null` | `T`
90
-
91
- ## Returns
92
-
93
- `any`
94
-
95
- If the condition is true, it, otherwise skips
96
-
97
- ### <a id="tags"></a>tags
98
-
99
- [**@xylabs/jest-helpers**](#../README)
100
-
101
- ***
102
-
103
- ```ts
104
- function tags(...tagLabels): Record<string, any>;
105
- ```
106
-
107
- ## Parameters
108
-
109
- ### tagLabels
110
-
111
- ...`string`[]
112
-
113
- ## Returns
114
-
115
- `Record`\<`string`, `any`\>
116
-
117
- ### <a id="testIf"></a>testIf
118
-
119
- [**@xylabs/jest-helpers**](#../README)
120
-
121
- ***
122
-
123
- ```ts
124
- function testIf<T>(expr?): any;
125
- ```
126
-
127
- Conditionally runs or skips the test
128
-
129
- ## Type Parameters
130
-
131
- ### T
132
-
133
- `T`
134
-
135
- ## Parameters
136
-
137
- ### expr?
138
-
139
- The condition to evaluate
140
-
141
- `null` | `T`
142
-
143
- ## Returns
144
-
145
- `any`
146
-
147
- If the condition is true, test, otherwise skips
148
24
 
149
25
 
150
26
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
@@ -1,5 +1,2 @@
1
- export * from './describeIf.ts';
2
- export * from './itIf.ts';
3
- export * from './tags/index.ts';
4
- export * from './testIf.ts';
1
+ export {};
5
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
@@ -1,80 +1 @@
1
- // src/describeIf.ts
2
- var describeIf = (expr) => expr ? describe : describe.skip;
3
-
4
- // src/itIf.ts
5
- var itIf = (expr) => expr ? it : it.skip;
6
-
7
- // src/testIf.ts
8
- var testIf = (expr) => expr ? test : test.skip;
9
-
10
- // src/tags/config.ts
11
- var NOT_SYMBOL = "!";
12
- var AND_SYMBOL = "&&";
13
- var OR_SYMBOL = "||";
14
-
15
- // src/tags/regexps.ts
16
- var AND_REGX = /\s*&&\s*/;
17
- var OR_REGX = /\s*\|\|\s*/;
18
- var PLAIN_REGX = /\s+`/;
19
- var BAD_REGX = /^!.*$/;
20
- var GOOD_REGX = /^[^!].*$/;
21
-
22
- // src/tags/filter.ts
23
- var matchFilter = (strParam = "") => (tags2) => {
24
- const str = strParam.trim();
25
- if (typeof tags2 === "string") {
26
- tags2 = [tags2];
27
- }
28
- if (str.includes(OR_SYMBOL)) {
29
- const include2 = goodTags(str.split(OR_REGX));
30
- const exclude2 = badTags(str.split(OR_REGX));
31
- if (exclude2.length === 0) {
32
- return include2.length === 0 || include2.some((s) => tags2.includes(s));
33
- }
34
- if (include2.length === 0 && exclude2.length > 0) {
35
- return exclude2.some((s) => !tags2.includes(s));
36
- }
37
- return include2.length === 0 || include2.some((s) => tags2.includes(s)) || exclude2.some((s) => !tags2.includes(s));
38
- }
39
- if (str.includes(AND_SYMBOL)) {
40
- const include2 = goodTags(str.split(AND_REGX));
41
- const exclude2 = badTags(str.split(AND_REGX));
42
- return include2.every((s) => tags2.includes(s)) && !exclude2.some((s) => tags2.includes(s));
43
- }
44
- const include = goodTags(str.split(PLAIN_REGX));
45
- const exclude = badTags(str.split(PLAIN_REGX));
46
- return (include.length === 0 || include.some((s) => tags2.includes(s))) && !exclude.some((s) => tags2.includes(s));
47
- };
48
- var goodTags = (arr) => {
49
- return arr.filter((s) => RegExp(GOOD_REGX).exec(s));
50
- };
51
- var badTags = (arr) => {
52
- return arr.filter((s) => RegExp(BAD_REGX).exec(s)).map((s) => s.replace(NOT_SYMBOL, ""));
53
- };
54
-
55
- // src/tags/index.ts
56
- function tags(...tagLabels) {
57
- const tagsParam = process.argv.indexOf("--tags");
58
- const passedTags = tagsParam > 0 ? process.argv[tagsParam + 1] : void 0;
59
- const filter = matchFilter(passedTags);
60
- const chain = {};
61
- const filterMatch = filter(tagLabels);
62
- chain.describeIf = filterMatch ? describeIf : (_param) => describe.skip;
63
- chain.itIf = filterMatch ? itIf : (_param) => it.skip;
64
- chain.testIf = filterMatch ? testIf : (_param) => test.skip;
65
- chain.describe = filterMatch ? globalThis.describe : globalThis.xdescribe;
66
- chain.it = filterMatch ? globalThis.it : globalThis.xit;
67
- chain.test = filterMatch ? globalThis.test : globalThis.xtest;
68
- chain.test.only = globalThis.test.only;
69
- chain.test.skip = globalThis.test.skip;
70
- chain.xtest = globalThis.xtest;
71
- chain.xit = globalThis.xit;
72
- return chain;
73
- }
74
- export {
75
- describeIf,
76
- itIf,
77
- tags,
78
- testIf
79
- };
80
1
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/describeIf.ts","../../src/itIf.ts","../../src/testIf.ts","../../src/tags/config.ts","../../src/tags/regexps.ts","../../src/tags/filter.ts","../../src/tags/index.ts"],"sourcesContent":["/**\n * Conditionally runs or skips the describe\n * @param expr The condition to evaluate\n * @returns If the condition is true, describe, otherwise skips\n */\n// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\nexport const describeIf = <T>(expr?: T | null) => (expr ? describe : describe.skip)\n","/**\n * Conditionally runs or skips the it\n * @param expr The condition to evaluate\n * @returns If the condition is true, it, otherwise skips\n */\n// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\nexport const itIf = <T>(expr?: T | null) => (expr ? it : it.skip)\n","/**\n * Conditionally runs or skips the test\n * @param expr The condition to evaluate\n * @returns If the condition is true, test, otherwise skips\n */\n// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\nexport const testIf = <T>(expr?: T | null) => (expr ? test : test.skip)\n","export const NOT_SYMBOL = '!'\n\nexport const AND_SYMBOL = '&&'\n\nexport const OR_SYMBOL = '||'\n","export const AND_REGX = /\\s*&&\\s*/\n\nexport const OR_REGX = /\\s*\\|\\|\\s*/\n\nexport const PLAIN_REGX = /\\s+`/\n\nexport const BAD_REGX = /^!.*$/\n\nexport const GOOD_REGX = /^[^!].*$/\n","import {\n AND_SYMBOL, NOT_SYMBOL, OR_SYMBOL,\n} from './config.ts'\nimport {\n AND_REGX, BAD_REGX, GOOD_REGX, OR_REGX, PLAIN_REGX,\n} from './regexps.ts'\n\n// f.e. tag1 !tag2\n// tag1 && tag2 && !tag3\n// tag1 || tag2 || !tag3\n\n// ATTENTION!!: cases with () not handled: f.e. (tag1 && tag2) || tag3 won`t work\n\nexport const matchFilter\n = (strParam = '') =>\n (tags: string[]) => {\n const str = strParam.trim()\n if (typeof tags === 'string') {\n tags = [tags]\n }\n if (str.includes(OR_SYMBOL)) {\n const include = goodTags(str.split(OR_REGX))\n const exclude = badTags(str.split(OR_REGX))\n if (exclude.length === 0) {\n return include.length === 0 || include.some(s => tags.includes(s))\n }\n if (include.length === 0 && exclude.length > 0) {\n return exclude.some(s => !tags.includes(s))\n }\n return include.length === 0 || include.some(s => tags.includes(s)) || exclude.some(s => !tags.includes(s))\n }\n if (str.includes(AND_SYMBOL)) {\n const include = goodTags(str.split(AND_REGX))\n const exclude = badTags(str.split(AND_REGX))\n\n return include.every(s => tags.includes(s)) && !exclude.some(s => tags.includes(s))\n }\n const include = goodTags(str.split(PLAIN_REGX))\n const exclude = badTags(str.split(PLAIN_REGX))\n\n return (include.length === 0 || include.some(s => tags.includes(s))) && !exclude.some(s => tags.includes(s))\n }\n\nconst goodTags = (arr: string[]) => {\n return arr.filter(s => RegExp(GOOD_REGX).exec(s))\n}\n\nconst badTags = (arr: string[]) => {\n return arr.filter(s => RegExp(BAD_REGX).exec(s)).map(s => s.replace(NOT_SYMBOL, ''))\n}\n","import { describeIf } from '../describeIf.ts'\nimport { itIf } from '../itIf.ts'\nimport { testIf } from '../testIf.ts'\nimport { matchFilter } from './filter.ts'\n\n// Based on https://www.npmjs.com/package/jest-tags/v/1.0.1\n\nexport function tags(...tagLabels: string[]) {\n const tagsParam = process.argv.indexOf('--tags')\n const passedTags = tagsParam > 0 ? process.argv[tagsParam + 1] : undefined\n const filter = matchFilter(passedTags)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const chain: Record<string, any> = {}\n\n const filterMatch = filter(tagLabels)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chain.describeIf = filterMatch ? describeIf : (_param: any) => describe.skip\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chain.itIf = filterMatch ? itIf : (_param: any) => it.skip\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chain.testIf = filterMatch ? testIf : (_param: any) => test.skip\n chain.describe = filterMatch ? globalThis.describe : globalThis.xdescribe\n chain.it = filterMatch ? globalThis.it : globalThis.xit\n chain.test = filterMatch ? globalThis.test : globalThis.xtest\n chain.test.only = globalThis.test.only\n chain.test.skip = globalThis.test.skip\n chain.xtest = globalThis.xtest\n chain.xit = globalThis.xit\n\n return chain\n}\n"],"mappings":"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","names":["tags","include","exclude"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/jest-helpers",
3
- "version": "5.0.79",
3
+ "version": "5.0.81",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "jest",
@@ -29,31 +29,23 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/neutral/index.d.ts",
32
- "source": "./src/index.ts",
33
32
  "default": "./dist/neutral/index.mjs"
34
33
  },
35
34
  "./package.json": "./package.json"
36
35
  },
37
36
  "module": "./dist/neutral/index.mjs",
38
- "source": "./src/index.ts",
39
37
  "types": "./dist/neutral/index.d.ts",
40
38
  "files": [
41
39
  "dist",
42
- "src",
43
40
  "!**/*.bench.*",
44
41
  "!**/*.spec.*",
45
42
  "!**/*.test.*"
46
43
  ],
47
44
  "devDependencies": {
48
- "@types/jest": "~30.0.0",
49
- "@types/node": "~25.2.3",
50
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
51
- "@xylabs/tsconfig": "~7.3.2",
45
+ "@xylabs/ts-scripts-yarn3": "~7.4.11",
46
+ "@xylabs/tsconfig": "~7.4.11",
52
47
  "typescript": "~5.9.3"
53
48
  },
54
- "peerDependencies": {
55
- "jest": "*"
56
- },
57
49
  "engines": {
58
50
  "node": ">=18"
59
51
  },
@@ -1,7 +0,0 @@
1
- /**
2
- * Conditionally runs or skips the describe
3
- * @param expr The condition to evaluate
4
- * @returns If the condition is true, describe, otherwise skips
5
- */
6
- export declare const describeIf: <T>(expr?: T | null) => jest.Describe;
7
- //# sourceMappingURL=describeIf.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"describeIf.d.ts","sourceRoot":"","sources":["../../src/describeIf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,kBAAsC,CAAA"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Conditionally runs or skips the it
3
- * @param expr The condition to evaluate
4
- * @returns If the condition is true, it, otherwise skips
5
- */
6
- export declare const itIf: <T>(expr?: T | null) => jest.It;
7
- //# sourceMappingURL=itIf.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"itIf.d.ts","sourceRoot":"","sources":["../../src/itIf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,YAA0B,CAAA"}
@@ -1,4 +0,0 @@
1
- export declare const NOT_SYMBOL = "!";
2
- export declare const AND_SYMBOL = "&&";
3
- export declare const OR_SYMBOL = "||";
4
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/tags/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,MAAM,CAAA;AAE7B,eAAO,MAAM,UAAU,OAAO,CAAA;AAE9B,eAAO,MAAM,SAAS,OAAO,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare const matchFilter: (strParam?: string) => (tags: string[]) => boolean;
2
- //# sourceMappingURL=filter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../src/tags/filter.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,WAAW,GACnB,iBAAa,MACb,MAAM,MAAM,EAAE,YA0Bd,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare function tags(...tagLabels: string[]): Record<string, any>;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":"AAOA,wBAAgB,IAAI,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,uBAyB1C"}
@@ -1,6 +0,0 @@
1
- export declare const AND_REGX: RegExp;
2
- export declare const OR_REGX: RegExp;
3
- export declare const PLAIN_REGX: RegExp;
4
- export declare const BAD_REGX: RegExp;
5
- export declare const GOOD_REGX: RegExp;
6
- //# sourceMappingURL=regexps.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"regexps.d.ts","sourceRoot":"","sources":["../../../src/tags/regexps.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,QAAa,CAAA;AAElC,eAAO,MAAM,OAAO,QAAe,CAAA;AAEnC,eAAO,MAAM,UAAU,QAAS,CAAA;AAEhC,eAAO,MAAM,QAAQ,QAAU,CAAA;AAE/B,eAAO,MAAM,SAAS,QAAa,CAAA"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Conditionally runs or skips the test
3
- * @param expr The condition to evaluate
4
- * @returns If the condition is true, test, otherwise skips
5
- */
6
- export declare const testIf: <T>(expr?: T | null) => jest.It;
7
- //# sourceMappingURL=testIf.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testIf.d.ts","sourceRoot":"","sources":["../../src/testIf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,YAA8B,CAAA"}
package/src/describeIf.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Conditionally runs or skips the describe
3
- * @param expr The condition to evaluate
4
- * @returns If the condition is true, describe, otherwise skips
5
- */
6
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
7
- export const describeIf = <T>(expr?: T | null) => (expr ? describe : describe.skip)
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './describeIf.ts'
2
- export * from './itIf.ts'
3
- export * from './tags/index.ts'
4
- export * from './testIf.ts'
package/src/itIf.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Conditionally runs or skips the it
3
- * @param expr The condition to evaluate
4
- * @returns If the condition is true, it, otherwise skips
5
- */
6
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
7
- export const itIf = <T>(expr?: T | null) => (expr ? it : it.skip)
@@ -1,5 +0,0 @@
1
- export const NOT_SYMBOL = '!'
2
-
3
- export const AND_SYMBOL = '&&'
4
-
5
- export const OR_SYMBOL = '||'
@@ -1,50 +0,0 @@
1
- import {
2
- AND_SYMBOL, NOT_SYMBOL, OR_SYMBOL,
3
- } from './config.ts'
4
- import {
5
- AND_REGX, BAD_REGX, GOOD_REGX, OR_REGX, PLAIN_REGX,
6
- } from './regexps.ts'
7
-
8
- // f.e. tag1 !tag2
9
- // tag1 && tag2 && !tag3
10
- // tag1 || tag2 || !tag3
11
-
12
- // ATTENTION!!: cases with () not handled: f.e. (tag1 && tag2) || tag3 won`t work
13
-
14
- export const matchFilter
15
- = (strParam = '') =>
16
- (tags: string[]) => {
17
- const str = strParam.trim()
18
- if (typeof tags === 'string') {
19
- tags = [tags]
20
- }
21
- if (str.includes(OR_SYMBOL)) {
22
- const include = goodTags(str.split(OR_REGX))
23
- const exclude = badTags(str.split(OR_REGX))
24
- if (exclude.length === 0) {
25
- return include.length === 0 || include.some(s => tags.includes(s))
26
- }
27
- if (include.length === 0 && exclude.length > 0) {
28
- return exclude.some(s => !tags.includes(s))
29
- }
30
- return include.length === 0 || include.some(s => tags.includes(s)) || exclude.some(s => !tags.includes(s))
31
- }
32
- if (str.includes(AND_SYMBOL)) {
33
- const include = goodTags(str.split(AND_REGX))
34
- const exclude = badTags(str.split(AND_REGX))
35
-
36
- return include.every(s => tags.includes(s)) && !exclude.some(s => tags.includes(s))
37
- }
38
- const include = goodTags(str.split(PLAIN_REGX))
39
- const exclude = badTags(str.split(PLAIN_REGX))
40
-
41
- return (include.length === 0 || include.some(s => tags.includes(s))) && !exclude.some(s => tags.includes(s))
42
- }
43
-
44
- const goodTags = (arr: string[]) => {
45
- return arr.filter(s => RegExp(GOOD_REGX).exec(s))
46
- }
47
-
48
- const badTags = (arr: string[]) => {
49
- return arr.filter(s => RegExp(BAD_REGX).exec(s)).map(s => s.replace(NOT_SYMBOL, ''))
50
- }
package/src/tags/index.ts DELETED
@@ -1,33 +0,0 @@
1
- import { describeIf } from '../describeIf.ts'
2
- import { itIf } from '../itIf.ts'
3
- import { testIf } from '../testIf.ts'
4
- import { matchFilter } from './filter.ts'
5
-
6
- // Based on https://www.npmjs.com/package/jest-tags/v/1.0.1
7
-
8
- export function tags(...tagLabels: string[]) {
9
- const tagsParam = process.argv.indexOf('--tags')
10
- const passedTags = tagsParam > 0 ? process.argv[tagsParam + 1] : undefined
11
- const filter = matchFilter(passedTags)
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- const chain: Record<string, any> = {}
15
-
16
- const filterMatch = filter(tagLabels)
17
-
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- chain.describeIf = filterMatch ? describeIf : (_param: any) => describe.skip
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- chain.itIf = filterMatch ? itIf : (_param: any) => it.skip
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- chain.testIf = filterMatch ? testIf : (_param: any) => test.skip
24
- chain.describe = filterMatch ? globalThis.describe : globalThis.xdescribe
25
- chain.it = filterMatch ? globalThis.it : globalThis.xit
26
- chain.test = filterMatch ? globalThis.test : globalThis.xtest
27
- chain.test.only = globalThis.test.only
28
- chain.test.skip = globalThis.test.skip
29
- chain.xtest = globalThis.xtest
30
- chain.xit = globalThis.xit
31
-
32
- return chain
33
- }
@@ -1,9 +0,0 @@
1
- export const AND_REGX = /\s*&&\s*/
2
-
3
- export const OR_REGX = /\s*\|\|\s*/
4
-
5
- export const PLAIN_REGX = /\s+`/
6
-
7
- export const BAD_REGX = /^!.*$/
8
-
9
- export const GOOD_REGX = /^[^!].*$/
package/src/testIf.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Conditionally runs or skips the test
3
- * @param expr The condition to evaluate
4
- * @returns If the condition is true, test, otherwise skips
5
- */
6
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
7
- export const testIf = <T>(expr?: T | null) => (expr ? test : test.skip)