14
14
15
15
const path = require ( 'path' ) ;
16
16
const fs = require ( 'fs' ) ;
17
+ const isArraySorted = require ( 'is-array-sorted' ) ;
17
18
const runner = require ( '../lib/runner' ) ;
18
19
19
- const arrayHas = parts => part => parts . indexOf ( part ) > - 1 ;
20
+ const arrayHas = parts => part => parts . indexOf ( part ) !== - 1 ;
20
21
21
22
const base = fs . readFileSync ( path . join ( __dirname , 'base.d.ts' ) , 'utf8' ) ;
22
23
@@ -35,13 +36,13 @@ function generatePrefixed(prefix) {
35
36
for ( const part of allParts ) {
36
37
const parts = prefix . concat ( [ part ] ) ;
37
38
38
- if ( prefix . indexOf ( part ) > - 1 || ! verify ( parts , true ) ) {
39
+ if ( prefix . indexOf ( part ) !== - 1 || ! verify ( parts , true ) ) {
39
40
// Function already in prefix or not allowed here
40
41
continue ;
41
42
}
42
43
43
44
// If `parts` is not sorted, we alias it to the sorted chain
44
- if ( ! isSorted ( parts ) ) {
45
+ if ( ! isArraySorted ( parts ) ) {
45
46
const chain = parts . sort ( ) . join ( '.' ) ;
46
47
47
48
if ( exists ( parts ) ) {
@@ -55,7 +56,7 @@ function generatePrefixed(prefix) {
55
56
// `always` is a valid prefix, for instance of `always.after`,
56
57
// but not a valid function name.
57
58
if ( verify ( parts , false ) ) {
58
- if ( parts . indexOf ( 'todo' ) > - 1 ) {
59
+ if ( parts . indexOf ( 'todo' ) !== - 1 ) { // eslint-disable-line no-negated-condition
59
60
output += '\t' + writeFunction ( part , 'name: string' , 'void' ) ;
60
61
} else {
61
62
const type = testType ( parts ) ;
@@ -147,17 +148,6 @@ function exists(parts) {
147
148
return false ;
148
149
}
149
150
150
- // Checks that an array is sorted
151
- function isSorted ( a ) {
152
- for ( let i = 1 ; i < a . length ; i ++ ) {
153
- if ( a [ i - 1 ] >= a [ i ] ) {
154
- return false ;
155
- }
156
- }
157
-
158
- return true ;
159
- }
160
-
161
151
// Returns the type name of for the test implementation
162
152
function testType ( parts ) {
163
153
const has = arrayHas ( parts ) ;
0 commit comments