File tree 8 files changed +1264
-4606
lines changed
8 files changed +1264
-4606
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ preset : 'ts-jest' ,
3
+ testEnvironment : 'node' ,
4
+ } ;
Original file line number Diff line number Diff line change 15
15
" src"
16
16
],
17
17
"scripts" : {
18
- "build" : " tsdx build" ,
19
- "coverage" : " tsdx test --coverage" ,
20
- "lint" : " tsdx lint src tests" ,
21
- "prepare" : " tsdx build" ,
22
- "start" : " tsdx watch" ,
23
- "test" : " tsdx test"
18
+ "build" : " tsc" ,
19
+ "coverage" : " jest --coverage" ,
20
+ "lint" : " tsc && prettier -list-different --write src tests" ,
21
+ "test" : " jest"
24
22
},
25
23
"repository" : {
26
24
"type" : " git" ,
35
33
" environment variable" ,
36
34
" validation"
37
35
],
36
+ "dependencies" : {},
38
37
"devDependencies" : {
38
+ "@types/jest" : " 26.0.24" ,
39
+ "@types/node" : " 16.4.0" ,
39
40
"husky" : " 4.3.6" ,
40
- "tsdx" : " ^0.14.1" ,
41
- "typescript" : " ^4.1.3"
41
+ "jest" : " 27.0.6" ,
42
+ "prettier" : " 2.3.2" ,
43
+ "ts-jest" : " 27.0.4" ,
44
+ "tslib" : " 2.3.0" ,
45
+ "typescript" : " 4.3.5"
42
46
},
43
47
"author" : " Aaron Franks" ,
44
48
"license" : " MIT" ,
45
- "dependencies" : {},
46
49
"prettier" : {
47
50
"printWidth" : 100 ,
48
51
"semi" : false ,
51
54
},
52
55
"husky" : {
53
56
"hooks" : {
54
- "pre-commit" : " yarn lint --fix " ,
57
+ "pre-commit" : " yarn lint" ,
55
58
"pre-push" : " yarn test"
56
59
}
57
60
}
Original file line number Diff line number Diff line change @@ -45,5 +45,5 @@ export function customCleanEnv<T, MW>(
45
45
* For more context, see https://github.com/af/envalid/issues/32
46
46
*/
47
47
export const testOnly = < T > ( defaultValueForTests : T ) => {
48
- return process . env . NODE_ENV === 'test' ? defaultValueForTests : ( ( testOnlySymbol as unknown ) as T ) // T is not strictly correct, but prevents type errors during usage
48
+ return process . env . NODE_ENV === 'test' ? defaultValueForTests : ( testOnlySymbol as unknown as T ) // T is not strictly correct, but prevents type errors during usage
49
49
}
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ export const defaultReporter = <T = any>(
56
56
colors . yellow ( '\n Exiting with error code 1' ) ,
57
57
RULE ,
58
58
]
59
- . filter ( x => ! ! x )
59
+ . filter ( ( x ) => ! ! x )
60
60
. join ( '\n' )
61
61
62
62
logger ( output )
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ const isFQDN = (input: string) => {
17
17
// "best effort" regex-based IP address check
18
18
// If you want a more exhaustive check, create your own custom validator, perhaps wrapping this
19
19
// implementation (the source of the ipv4 regex below): https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
20
- const ipv4Regex = / ^ ( ( [ 0 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] | 1 [ 0 - 9 ] { 2 } | 2 [ 0 - 4 ] [ 0 - 9 ] | 2 5 [ 0 - 5 ] ) \. ) { 3 } ( [ 0 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] | 1 [ 0 - 9 ] { 2 } | 2 [ 0 - 4 ] [ 0 - 9 ] | 2 5 [ 0 - 5 ] ) $ /
20
+ const ipv4Regex =
21
+ / ^ ( ( [ 0 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] | 1 [ 0 - 9 ] { 2 } | 2 [ 0 - 4 ] [ 0 - 9 ] | 2 5 [ 0 - 5 ] ) \. ) { 3 } ( [ 0 - 9 ] | [ 1 - 9 ] [ 0 - 9 ] | 1 [ 0 - 9 ] { 2 } | 2 [ 0 - 4 ] [ 0 - 9 ] | 2 5 [ 0 - 5 ] ) $ /
21
22
const ipv6Regex = / ( [ a - f 0 - 9 ] + : + ) + [ a - f 0 - 9 ] + /
22
23
const isIP = ( input : string ) => {
23
24
if ( ! input . length ) return false
@@ -27,7 +28,7 @@ const isIP = (input: string) => {
27
28
const EMAIL_REGEX = / ^ [ ^ @ \s ] + @ [ ^ @ \s ] + \. [ ^ @ \s ] + $ / // intentionally non-exhaustive
28
29
29
30
export const makeValidator = < T > ( parseFn : ( input : string ) => T ) => {
30
- return function ( spec ?: Spec < T > ) : ValidatorSpec < T > {
31
+ return function ( spec ?: Spec < T > ) : ValidatorSpec < T > {
31
32
return { ...spec , _parse : parseFn }
32
33
}
33
34
}
@@ -104,6 +105,7 @@ export function port<T extends number = number>(spec?: Spec<T>) {
104
105
export function url < T extends string = string > ( spec ?: Spec < T > ) {
105
106
return makeValidator ( ( x : string ) => {
106
107
try {
108
+ // @ts -expect-error TS doesn't acknowledge this API by default yet
107
109
new URL ( x )
108
110
return x
109
111
} catch ( e ) {
Original file line number Diff line number Diff line change @@ -114,12 +114,12 @@ test('str()', () => {
114
114
} )
115
115
116
116
test ( 'custom types' , ( ) => {
117
- const alwaysFoo = makeValidator ( _x => 'foo' )
117
+ const alwaysFoo = makeValidator ( ( _x ) => 'foo' )
118
118
119
119
const fooEnv = cleanEnv ( { FOO : 'asdf' } , { FOO : alwaysFoo ( ) } )
120
120
expect ( fooEnv ) . toEqual ( { FOO : 'foo' } )
121
121
122
- const hex10 = makeValidator ( x => {
122
+ const hex10 = makeValidator ( ( x ) => {
123
123
if ( / ^ [ a - f 0 - 9 ] { 10 } $ / . test ( x ) ) return x
124
124
throw new Error ( 'need 10 hex chars' )
125
125
} )
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
+ "outDir" : " ./dist" ,
3
4
"rootDir" : " ./src" ,
4
5
"strict" : true ,
5
- "module" : " esnext " ,
6
+ "module" : " commonjs " ,
6
7
"moduleResolution" : " node" ,
7
8
"esModuleInterop" : true ,
8
9
"importHelpers" : true ,
9
10
"declaration" : true ,
10
11
"sourceMap" : true ,
11
12
"noUnusedLocals" : true ,
12
13
"noUnusedParameters" : true ,
13
- "noImplicitReturns" : true
14
+ "noImplicitReturns" : true ,
15
+ "lib" : [" es2019" ]
14
16
},
15
17
"include" : [" src" ],
16
18
"exclude" : [
You can’t perform that action at this time.
0 commit comments