From 4f178907caeed86d5bd880b46dfbf9ccf7e7958a Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Fri, 23 Aug 2013 12:24:49 -0700 Subject: [PATCH] Export string-pattern as stringPattern for JS compatibility --- src/cljx/frak.cljx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cljx/frak.cljx b/src/cljx/frak.cljx index 61988f0..6989efc 100644 --- a/src/cljx/frak.cljx +++ b/src/cljx/frak.cljx @@ -184,19 +184,24 @@ (string/replace #"\(\?:?(\[[^\]]+\])([^\|\)]+[^\?]?)\)([^\?])" "$1$2$3"))) -;; TODO: This needs to be `:export`ed and work with regular -;; JavaScript. (defn string-pattern "Construct a regular expression as a string from a collection of strings." - [strs opts] - (let [pattern (binding [*capture* (:capture? opts)] - (-> (build-trie strs) - render-trie - remove-unecessary-grouping))] - (if (:exact? opts) - (str "^" pattern "$") - pattern))) + ([strs] + (string-pattern strs {:capture? false, :exact? false})) + ([strs opts] + (let [#+cljs opts #+cljs (js->clj opts) + pattern (binding [*capture* (or (:capture? opts) + (opts "capture?"))] + (-> (build-trie strs) + render-trie + remove-unecessary-grouping))] + (if (or (:exact? opts) (opts "exact?")) + (str "^" pattern "$") + pattern)))) + +#+cljs +(def ^:export stringPattern string-pattern) (defn ^:export pattern "Construct a regular expression from a collection of strings." -- 2.25.1