generated from JS-DevTools/template-node-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.ts
34 lines (30 loc) · 945 Bytes
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { FilterCriterion, FilterFunction, Filters } from "./types";
/**
* Symbol used to store the underlying filters of a `pathFilter()` function.
*/
export const _filters = Symbol("_filters");
/**
* A `pathFilter()` function that was created by `filePathFilter()`.
*/
export interface PathFilter extends FilterFunction {
[_filters]: Filters<FilterFunction[]>;
}
/**
* Determines whether the given value is a `FilterCriterion`.
*/
export function isFilterCriterion(value: unknown): value is FilterCriterion {
let type = typeof value;
return type === "string" ||
type === "boolean" ||
type === "function" ||
value instanceof RegExp;
}
/**
* Determines whether the given value is one of our internal `pathFilter()` functions.
*/
export function isPathFilter(value: unknown): value is PathFilter {
let fn = value as PathFilter;
return fn &&
typeof fn === "function" &&
typeof fn[_filters] === "object";
}