Skip to content

Commit

Permalink
Separated internal and public-facing types
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMessinger committed Aug 19, 2019
1 parent b2725ba commit aec1d0c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/file-path-filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalize } from "./normalize";
import { _filters, AnyFilter, FilterCriterion, FilterFunction, Filters, PathFilter } from "./types";
import { createFilter } from "./create-filter";
import { AnyFilter, FilterCriterion, FilterFunction, Filters } from "./types";

/**
* Creates a `FilterFunction` that matches file paths based on the specified criteria.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { filePathFilter } from "./file-path-filter";

export { AnyFilter, FilterCriteria, FilterCriterion, FilterFunction, Filters } from "./types";
export * from "./types";
export { filePathFilter };

// Export `filePathFilter` as a named export and the default export
Expand Down
3 changes: 2 additions & 1 deletion src/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as GlobToRegExp from "glob-to-regexp";
import { _filters, AnyFilter, Filter, FilterCriterion, FilterFunction, Filters, isFilterCriterion, isPathFilter } from "./types";
import { AnyFilter, Filter, FilterCriterion, FilterFunction, Filters, Options } from "./types";
import { _filters, isFilterCriterion, isPathFilter } from "./util";

const isWindows = process.platform === "win32";

Expand Down
26 changes: 0 additions & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,8 @@ export interface Filters<T = FilterCriteria> {
export type AnyFilter = FilterCriteria | Partial<Filters>;

/**
* 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";
}
34 changes: 34 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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";
}

0 comments on commit aec1d0c

Please sign in to comment.