From aec1d0cdfe081ef79e8331a5d6ca3a2169b0d804 Mon Sep 17 00:00:00 2001 From: James Messinger Date: Mon, 19 Aug 2019 08:43:07 -0500 Subject: [PATCH] Separated internal and public-facing types --- src/file-path-filter.ts | 4 ++-- src/index.ts | 2 +- src/normalize.ts | 3 ++- src/types.ts | 26 -------------------------- src/util.ts | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/util.ts diff --git a/src/file-path-filter.ts b/src/file-path-filter.ts index 51d63dc..435043c 100644 --- a/src/file-path-filter.ts +++ b/src/file-path-filter.ts @@ -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. diff --git a/src/index.ts b/src/index.ts index 2730432..e3c2647 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 diff --git a/src/normalize.ts b/src/normalize.ts index 3246e44..d7de868 100644 --- a/src/normalize.ts +++ b/src/normalize.ts @@ -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"; diff --git a/src/types.ts b/src/types.ts index 1ee3d75..da9f5c7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,34 +34,8 @@ export interface Filters { export type AnyFilter = FilterCriteria | Partial; /** - * 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; -} - -/** - * 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"; -} diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..b54a6d3 --- /dev/null +++ b/src/util.ts @@ -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; +} + +/** + * 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"; +}