From b936ccdf038dbf5568ce6f38008c0aad207d3e25 Mon Sep 17 00:00:00 2001 From: Alexey Plutalov Date: Thu, 4 May 2017 22:05:15 +0300 Subject: [PATCH] Move `matches` to `traversing` namespace --- spec/{ => traversing}/matches.spec.js | 2 +- src/index.js | 24 +----------------------- src/traversing/matches.js | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 24 deletions(-) rename spec/{ => traversing}/matches.spec.js (93%) create mode 100644 src/traversing/matches.js diff --git a/spec/matches.spec.js b/spec/traversing/matches.spec.js similarity index 93% rename from spec/matches.spec.js rename to spec/traversing/matches.spec.js index 0f54824..f5668fb 100644 --- a/spec/matches.spec.js +++ b/spec/traversing/matches.spec.js @@ -1,4 +1,4 @@ -import { matches } from "../src"; +import { matches } from "../../src"; describe("matches", () => { afterEach(clearFixtures); diff --git a/src/index.js b/src/index.js index dbaa9f3..a587890 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import type { Elements, Selector } from "./types"; import { html, body } from "./aliases"; import query from "./queries/query"; import queryAll from "./queries/query-all"; +import matches from "./traversing/matches"; /* Types */ @@ -18,29 +19,6 @@ type EventType = string; type PredicateFn = (element: Element) => boolean; -/* Queries */ - -type MatchesFn = (selector: Selector) => boolean; - -function getMatchesFn(): MatchesFn { - const element = (document.createElement("div"): any); - - return ( - element.matches || - element.matchesSelector || - element.msMatchesSelector || - element.mozMatchesSelector || - element.webkitMatchesSelector || - element.oMatchesSelector - ); -} - -const matchesFn: MatchesFn = getMatchesFn(); - -function matches(element: Element, selector: Selector): boolean { - return matchesFn.call(element, selector); -} - /* Classes */ function hasClass(element: Element, cssClass: CSSClass): boolean { diff --git a/src/traversing/matches.js b/src/traversing/matches.js new file mode 100644 index 0000000..1ba55d9 --- /dev/null +++ b/src/traversing/matches.js @@ -0,0 +1,26 @@ +/* @flow */ + +import type { Selector } from "../types"; + +type Matches = (selector: Selector) => boolean; + +function getMatchesFn(): Matches { + const element = (document.createElement("div"): any); + + return ( + element.matches || + element.matchesSelector || + element.msMatchesSelector || + element.mozMatchesSelector || + element.webkitMatchesSelector || + element.oMatchesSelector + ); +} + +const matchesFn: Matches = getMatchesFn(); + +function matches(element: Element, selector: Selector): boolean { + return matchesFn.call(element, selector); +} + +export default matches;