Skip to content

Commit

Permalink
Update development dependencies and revise documentation
Browse files Browse the repository at this point in the history
The development dependency on `mock-fs` has been updated since it now supports all of its functionalities for `node >= 10`.
Modifications have been made to the documentation to clear off `typedoc` warnings and to improve legibility, as well as to document generic types.
  • Loading branch information
MartyO256 committed Feb 4, 2019
1 parent 6d69b52 commit 1791401
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 191 deletions.
97 changes: 80 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ npm install find-files-by-patterns
Assuming this file system, where the current working directory is
`/Documents/project`:

```txt
```plaintext
/
└── Documents
├── data.csv
Expand Down Expand Up @@ -151,14 +151,18 @@ If no directory is supplied, then the current working directory is read.
```ts
type Filter<T> = (element: T) => Promise<boolean>;
type FilterSync<T> = (element: T) => boolean;
findFile(...tests: Array<Filter<string> | FilterSync<string>>): Promise<
string | null
>;

findFile(
...tests: Array<Filter<string> | FilterSync<string>>
): Promise<string | null>;

findFile(
directories: string | AsyncIterable<string> | Iterable<string>,
...tests: Array<Filter<string> | FilterSync<string>>
): Promise<string | null>;

findFileSync(...tests: Array<FilterSync<string>>): string | null;

findFileSync(
directories: string | Iterable<string>,
...tests: Array<FilterSync<string>>
Expand All @@ -176,13 +180,18 @@ If no directory is supplied, then the current working directory is read.
```ts
type Filter<T> = (element: T) => Promise<boolean>;
type FilterSync<T> = (element: T) => boolean;
findAllFiles(...tests: Array<Filter<string>
| FilterSync<string>>): Promise<string[]>;

findAllFiles(
...tests: Array<Filter<string> | FilterSync<string>>
): Promise<string[]>;

findAllFiles(
directories: string | AsyncIterable<string> | Iterable<string>,
...tests: Array<Filter<string> | FilterSync<string>>
): Promise<string[]>;

findAllFilesSync(...tests: Array<FilterSync<string>>): string[];

findAllFilesSync(
directories: string | Iterable<string>,
...tests: Array<FilterSync<string>>
Expand All @@ -200,14 +209,18 @@ If no directory is supplied, then the current working directory is read.
```ts
type Filter<T> = (element: T) => Promise<boolean>;
type FilterSync<T> = (element: T) => boolean;
findOnlyFile(...tests: Array<Filter<string> | FilterSync<string>>): Promise<
string | null
>;

findOnlyFile(
...tests: Array<Filter<string> | FilterSync<string>>
): Promise<string | null>;

findOnlyFile(
directories: string | AsyncIterable<string> | Iterable<string>,
...tests: Array<Filter<string> | FilterSync<string>>
): Promise<string | null>;

findOnlyFileSync(...tests: Array<FilterSync<string>>): string | null;

findOnlyFileSync(
directories: string | Iterable<string>,
...tests: Array<FilterSync<string>>
Expand All @@ -216,20 +229,27 @@ findOnlyFileSync(

### `downwardDirectories` and `downwardDirectoriesSync`

Returns an iterable ocer the existing downward files from a start path. Symbolic
Returns an iterable over the existing downward files from a start path. Symbolic
links are followed and handled such that no directory is traversed twice.

> Specifications
```ts
downwardDirectories(): AsyncIterable<string>;

downwardDirectories(maximumDepth: number): AsyncIterable<string>;

downwardDirectories(startDirectory: string): AsyncIterable<string>;

downwardDirectories(startDirectory: string,
maximumDepth: number): AsyncIterable<string>;

downwardDirectoriesSync(): Iterable<string>;

downwardDirectoriesSync(maximumDepth: number): Iterable<string>;

downwardDirectoriesSync(startDirectory: string): Iterable<string>;

downwardDirectoriesSync(startDirectory: string,
maximumDepth: number): Iterable<string>;
```
Expand All @@ -238,7 +258,7 @@ downwardDirectoriesSync(startDirectory: string,
Assuming this file system, where the current working directory is `/Documents`:

```txt
```plaintext
/
└── Documents
├── Images
Expand Down Expand Up @@ -274,14 +294,21 @@ Returns an iterable over the existing directories upwards from a start path.
```ts
upwardDirectories(): AsyncIterable<string>;

upwardDirectories(startPath: string): AsyncIterable<string>;

upwardDirectories(startPath: string,
maximumHeight: number): AsyncIterable<string>;

upwardDirectories(startPath: string, endPath: string): AsyncIterable<string>;

upwardDirectoriesSync(): Iterable<string>;

upwardDirectoriesSync(startPath: string): Iterable<string>;

upwardDirectoriesSync(startPath: string,
maximumHeight: number): Iterable<string>;

upwardDirectoriesSync(startPath: string, endPath: string): Iterable<string>;
```

Expand All @@ -290,7 +317,7 @@ upwardDirectoriesSync(startPath: string, endPath: string): Iterable<string>;
Assuming this file system, where the current working directory is
`/Documents/project`:

```txt
```plaintext
/
└── Documents
├── Images
Expand Down Expand Up @@ -325,13 +352,20 @@ Returns and iterable over the files in each downward directory yielded by
```ts
downwardFiles(): AsyncIterable<string>;

downwardFiles(maximumDepth: number): AsyncIterable<string>;

downwardFiles(startDirectory: string): AsyncIterable<string>;

downwardFiles(startDirectory: string,
maximumDepth: number): AsyncIterable<string>;

downwardFilesSync(): Iterable<string>;

downwardFilesSync(maximumDepth: number): Iterable<string>;

downwardFilesSync(startDirectory: string): Iterable<string>;

downwardFilesSync(startDirectory: string,
maximumDepth: number): Iterable<string>;
```
Expand All @@ -345,12 +379,19 @@ Returns and iterable over the files in each upward directory yielded by
```ts
upwardFiles(): AsyncIterable<string>;

upwardFiles(startPath: string): AsyncIterable<string>;

upwardFiles(startPath: string, maximumHeight: number): AsyncIterable<string>;

upwardFiles(startPath: string, endPath: string): AsyncIterable<string>;

upwardFilesSync(): Iterable<string>;

upwardFilesSync(startPath: string): Iterable<string>;

upwardFilesSync(startPath: string, maximumHeight: number): Iterable<string>;

upwardFilesSync(startPath: string, endPath: string): Iterable<string>;
```

Expand All @@ -371,9 +412,13 @@ A segment tester can be a string, a regular expression or a function.
```ts
type SegmentTester = string | RegExp | ((segment: string) => boolean);

ofBasename(...tests: SegmentTester[]): FilterSync<string>;

ofName(...tests: SegmentTester[]): FilterSync<string>;

ofDirname(...tests: SegmentTester[]): FilterSync<string>;

ofExtname(...tests: SegmentTester[]): FilterSync<string>;
```

Expand Down Expand Up @@ -414,6 +459,7 @@ A segment tester can be a string, a regular expression or a function.
```ts
type SegmentTester = string | RegExp | ((segment: string) => boolean);

hasPathSegments(...tests: SegmentTester[]): FilterSync<string>;
```

Expand All @@ -422,10 +468,13 @@ hasPathSegments(...tests: SegmentTester[]): FilterSync<string>;
```js
const { hasPathSegments } = require("find-files-by-patterns");

const isNotIgnored = hasPathSegments(segment => !segment.startsWith("_"));
isNotIgnored("project/src/_ignored.json"); //=> `false`
isNotIgnored("project/_ignored/data.json"); //=> `false`
isNotIgnored("project/src/data.yaml"); //=> `true`
const isIgnored = hasPathSegments(segment => segment.startsWith("_"));

isIgnored("project/src/_ignored.json"); //=> `true`

isIgnored("project/_ignored/data.json"); //=> `true`

isIgnored("project/src/data.yaml"); //=> `false`
```

### `isFile` and `isFileSync`
Expand All @@ -436,6 +485,7 @@ Determines whether or not a path exists on the file system and is a file.
```ts
isFile(path: string): Promise<boolean>;

isFileSync(path: string): boolean;
```

Expand All @@ -447,6 +497,7 @@ Determines whether or not a path exists on the file system and is a directory.
```ts
isDirectory(path: string): Promise<boolean>;

isDirectorySync(path: string): boolean;
```

Expand All @@ -459,6 +510,7 @@ a file which matches a filter.
```ts
hasFile(test: Filter<string> | FilterSync<string>): Filter<string>;

hasFileSync(test: FilterSync<string>): FilterSync<string>;
```

Expand All @@ -467,7 +519,7 @@ hasFileSync(test: FilterSync<string>): FilterSync<string>;
Assuming this file system, where the current working directory is
`/Documents/project`:

```txt
```plaintext
/
└── Documents
├── Images
Expand Down Expand Up @@ -495,6 +547,7 @@ Returns an iterable over the fully qualified file names in the given directory.
```ts
readdir(directory: string): AsyncIterable<string>;

readdirSync(directory: string): Iterable<string>;
```

Expand All @@ -507,6 +560,7 @@ directories.
```ts
readdirs(directory: string): AsyncIterable<string>;

readdirsSync(directory: string): Iterable<string>;
```

Expand All @@ -521,8 +575,10 @@ This is analogous to the array filter method.
```ts
type Filter<T> = (element: T) => Promise<boolean>;
type FilterSync<T> = (element: T) => boolean;

filter<T>(iterable: Iterable<T> | AsyncIterable<T>,
filter: Filter<T> | FilterSync<T>): AsyncIterable<T>;

filterSync<T>(iterable: Iterable<T>,
filter: FilterSync<T>): Iterable<T>;
```
Expand Down Expand Up @@ -551,7 +607,9 @@ Compounds a sequence of filters using logical conjunction.
```ts
type Filter<T> = (element: T) => Promise<boolean>;
type FilterSync<T> = (element: T) => boolean;

conjunction<T>(filters: Array<Filter<T> | FilterSync<T>>): Filter<T>;

conjunctionSync<T>(filters: Array<FilterSync<T>>): FilterSync<T>;
```

Expand Down Expand Up @@ -581,7 +639,9 @@ Compounds a sequence of filters using logical disjunction.
```ts
type Filter<T> = (element: T) => Promise<boolean>;
type FilterSync<T> = (element: T) => boolean;

disjunction<T>(filters: Array<Filter<T> | FilterSync<T>>): Filter<T>;

disjunctionSync<T>(filters: Array<FilterSync<T>>): FilterSync<T>;
```

Expand All @@ -608,6 +668,7 @@ Converts an iterable to an array.
```ts
allElements<T>(iterable: AsyncIterable<T>): Promise<T[]>;

allElementsSync<T>(iterable: Iterable<T>): T[];
```

Expand All @@ -619,6 +680,7 @@ Returns the first element of an iterable.
```ts
firstElement<T>(iterable: AsyncIterable<T>): Promise<T | null>;

firstElementSync<T>(iterable: Iterable<T>): T | null;
```

Expand All @@ -632,6 +694,7 @@ thrown.
```ts
onlyElement<T>(iterable: AsyncIterable<T>): Promise<T | null>;

onlyElementSync<T>(iterable: Iterable<T>): T | null;
```

Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "find-files-by-patterns",
"version": "1.1.0",
"version": "1.1.1",
"description": "Find files by patterns in directories, upwards or downwards from other paths.",
"license": "MIT",
"author": "Marc-Antoine Ouimet <ouimetmarcantoine@gmail.com>",
Expand All @@ -19,7 +19,7 @@
"main": "./lib/index.js",
"engineStrict": true,
"engines": {
"node": ">=10.0.0 || ~10.13.0"
"node": ">=10.0.0 || ^10.15.1"
},
"scripts": {
"format": "prettier --write \"./{src,test}/**/*.ts\"",
Expand Down Expand Up @@ -63,22 +63,22 @@
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/mock-fs": "^3.6.30",
"@types/node": "^10.12.18",
"@types/node": "^10.12.21",
"chai": "^4.2.0",
"coveralls": "^3.0.2",
"husky": "^1.2.1",
"lint-staged": "^8.1.0",
"husky": "^1.3.1",
"lint-staged": "^8.1.3",
"markdown-toc": "^1.2.0",
"markdownlint-cli": "^0.13.0",
"mocha": "^5.2.0",
"mock-fs": "^4.7.0",
"mock-fs": "^4.8.0",
"nyc": "^13.1.0",
"prettier": "^1.15.3",
"source-map-support": "^0.5.9",
"ts-node": "^7.0.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"typedoc": "^0.13.0",
"typescript": "^3.2.2"
"prettier": "^1.16.4",
"source-map-support": "^0.5.10",
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"tslint-config-prettier": "^1.18.0",
"typedoc": "^0.14.2",
"typescript": "^3.3.1"
}
}
Loading

0 comments on commit 1791401

Please sign in to comment.