Working production build in docs subdirectory.

This commit is contained in:
Simon Brooke 2020-02-27 09:35:17 +00:00
parent bb7be028e6
commit a5204c66b9
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
644 changed files with 134256 additions and 53616 deletions

View file

@ -0,0 +1,152 @@
;; Copyright (c) Rich Hickey. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns clojure.browser.dom
(:require [goog.dom :as gdom]
[goog.object :as gobject]))
(defn append [parent & children]
(apply gdom/append parent children)
parent)
(defprotocol DOMBuilder
(-element [this] [this attrs-or-children] [this attrs children]))
(defn log [& args]
(.log js/console (apply pr-str args)))
(defn log-obj [obj]
(.log js/console obj))
(extend-protocol DOMBuilder
string
(-element
([this]
(log "string (-element " this ")")
(cond (keyword? this) (gdom/createElement (name this))
:else (gdom/createTextNode (name this))))
([this attrs-or-children]
(log "string (-element " this " " attrs-or-children ")")
(let [attrs (first attrs-or-children)]
(if (map? attrs)
(-element this attrs (rest attrs-or-children))
(-element this nil attrs-or-children))))
([this attrs children]
(log "string (-element " this " " attrs " " children ")")
(let [str-attrs (if (and (map? attrs) (seq attrs))
(reduce (fn [o [k v]]
(let [o (if (nil? o) (js-obj) o)]
(log "o = " o)
(log "k = " k)
(log "v = " v)
(when (or (keyword? k)
(string? k))
(doto o (gobject/set (name k) v)))))
(js-obj)
attrs)
nil)]
(log-obj str-attrs)
(if (seq children)
(apply gdom/createDom
(name this)
str-attrs
(map -element children))
(gdom/createDom (name this)
str-attrs)))))
PersistentVector
(-element
[this]
(log "PersistentVector (-element " this ")")
(let [tag (first this)
attrs (second this)
children (drop 2 this)]
(if (map? attrs)
(-element tag attrs children)
(-element tag nil (rest this)))))
js/Element
(-element [this]
(log "js/Element (-element " this ")")
this))
(defn element
([tag-or-text]
(log "(element " tag-or-text ")")
(-element tag-or-text))
([tag & children]
(log "(element " tag " " children ")")
(let [attrs (first children)]
(if (map? attrs)
(-element tag attrs (rest children))
(-element tag nil children)))))
(defn remove-children
"Remove all children from the element with the passed id."
[id]
(let [parent (gdom/getElement (name id))]
(do (gdom/removeChildren parent))))
(defn get-element [id]
(gdom/getElement (name id)))
(defn html->dom [s]
(gdom/htmlToDocumentFragment s))
(defn insert-at [parent child index]
(gdom/insertChildAt parent child index))
(defn ensure-element
"Coerce the argument to a dom element if possible."
[e]
(cond (keyword? e) (get-element e)
(string? e) (html->dom e)
:else e))
(defn replace-node
"Replace old-node with new-node. old-node can be an element or a
keyword which is the id of the node to replace. new-node can be an
element or an html string."
[old-node new-node]
(let [old-node (ensure-element old-node)
new-node (ensure-element new-node)]
(gdom/replaceNode new-node old-node)
new-node))
(defn set-text
"Set the text content for the passed element returning the
element. If a keyword is passed in the place of e, the element with
that id will be used and returned."
[e s]
(gdom/setTextContent (ensure-element e) s))
(defn get-value
"Get the value of an element."
[e]
(.-value (ensure-element e)))
(defn set-properties
"Set properties on an element"
[e m]
(gdom/setProperties (ensure-element e)
(apply gobject/create (interleave (keys m) (vals m)))))
(defn set-value
"Set the value property for an element."
[e v]
(set-properties e {"value" v}))
(defn click-element
[e]
(.click (ensure-element e) ()))
;; TODO CSS class manipulation
;; TODO Query syntax

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,390 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('clojure.browser.dom');
goog.require('cljs.core');
goog.require('goog.dom');
goog.require('goog.object');
clojure.browser.dom.append = (function clojure$browser$dom$append(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25653 = arguments.length;
var i__4731__auto___25654 = (0);
while(true){
if((i__4731__auto___25654 < len__4730__auto___25653)){
args__4736__auto__.push((arguments[i__4731__auto___25654]));
var G__25655 = (i__4731__auto___25654 + (1));
i__4731__auto___25654 = G__25655;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return clojure.browser.dom.append.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
clojure.browser.dom.append.cljs$core$IFn$_invoke$arity$variadic = (function (parent,children){
cljs.core.apply.call(null,goog.dom.append,parent,children);
return parent;
});
clojure.browser.dom.append.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
clojure.browser.dom.append.cljs$lang$applyTo = (function (seq25651){
var G__25652 = cljs.core.first.call(null,seq25651);
var seq25651__$1 = cljs.core.next.call(null,seq25651);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25652,seq25651__$1);
});
/**
* @interface
*/
clojure.browser.dom.DOMBuilder = function(){};
clojure.browser.dom._element = (function clojure$browser$dom$_element(var_args){
var G__25657 = arguments.length;
switch (G__25657) {
case 1:
return clojure.browser.dom._element.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
break;
case 2:
return clojure.browser.dom._element.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return clojure.browser.dom._element.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));
}
});
clojure.browser.dom._element.cljs$core$IFn$_invoke$arity$1 = (function (this$){
if((((!((this$ == null)))) && ((!((this$.clojure$browser$dom$DOMBuilder$_element$arity$1 == null)))))){
return this$.clojure$browser$dom$DOMBuilder$_element$arity$1(this$);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (clojure.browser.dom._element[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$);
} else {
var m__4431__auto__ = (clojure.browser.dom._element["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$);
} else {
throw cljs.core.missing_protocol.call(null,"DOMBuilder.-element",this$);
}
}
}
});
clojure.browser.dom._element.cljs$core$IFn$_invoke$arity$2 = (function (this$,attrs_or_children){
if((((!((this$ == null)))) && ((!((this$.clojure$browser$dom$DOMBuilder$_element$arity$2 == null)))))){
return this$.clojure$browser$dom$DOMBuilder$_element$arity$2(this$,attrs_or_children);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (clojure.browser.dom._element[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,attrs_or_children);
} else {
var m__4431__auto__ = (clojure.browser.dom._element["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,attrs_or_children);
} else {
throw cljs.core.missing_protocol.call(null,"DOMBuilder.-element",this$);
}
}
}
});
clojure.browser.dom._element.cljs$core$IFn$_invoke$arity$3 = (function (this$,attrs,children){
if((((!((this$ == null)))) && ((!((this$.clojure$browser$dom$DOMBuilder$_element$arity$3 == null)))))){
return this$.clojure$browser$dom$DOMBuilder$_element$arity$3(this$,attrs,children);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (clojure.browser.dom._element[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,attrs,children);
} else {
var m__4431__auto__ = (clojure.browser.dom._element["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,attrs,children);
} else {
throw cljs.core.missing_protocol.call(null,"DOMBuilder.-element",this$);
}
}
}
});
clojure.browser.dom._element.cljs$lang$maxFixedArity = 3;
clojure.browser.dom.log = (function clojure$browser$dom$log(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25660 = arguments.length;
var i__4731__auto___25661 = (0);
while(true){
if((i__4731__auto___25661 < len__4730__auto___25660)){
args__4736__auto__.push((arguments[i__4731__auto___25661]));
var G__25662 = (i__4731__auto___25661 + (1));
i__4731__auto___25661 = G__25662;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null);
return clojure.browser.dom.log.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__);
});
clojure.browser.dom.log.cljs$core$IFn$_invoke$arity$variadic = (function (args){
return console.log(cljs.core.apply.call(null,cljs.core.pr_str,args));
});
clojure.browser.dom.log.cljs$lang$maxFixedArity = (0);
/** @this {Function} */
clojure.browser.dom.log.cljs$lang$applyTo = (function (seq25659){
var self__4718__auto__ = this;
return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq25659));
});
clojure.browser.dom.log_obj = (function clojure$browser$dom$log_obj(obj){
return console.log(obj);
});
goog.object.set(clojure.browser.dom.DOMBuilder,"string",true);
goog.object.set(clojure.browser.dom._element,"string",(function() {
var G__25672 = null;
var G__25672__1 = (function (this$){
clojure.browser.dom.log.call(null,"string (-element ",this$,")");
if((this$ instanceof cljs.core.Keyword)){
return goog.dom.createElement(cljs.core.name.call(null,this$));
} else {
return goog.dom.createTextNode(cljs.core.name.call(null,this$));
}
});
var G__25672__2 = (function (this$,attrs_or_children){
clojure.browser.dom.log.call(null,"string (-element ",this$," ",attrs_or_children,")");
var attrs = cljs.core.first.call(null,attrs_or_children);
if(cljs.core.map_QMARK_.call(null,attrs)){
return clojure.browser.dom._element.call(null,this$,attrs,cljs.core.rest.call(null,attrs_or_children));
} else {
return clojure.browser.dom._element.call(null,this$,null,attrs_or_children);
}
});
var G__25672__3 = (function (this$,attrs,children){
clojure.browser.dom.log.call(null,"string (-element ",this$," ",attrs," ",children,")");
var str_attrs = ((((cljs.core.map_QMARK_.call(null,attrs)) && (cljs.core.seq.call(null,attrs))))?cljs.core.reduce.call(null,(function (o,p__25663){
var vec__25664 = p__25663;
var k = cljs.core.nth.call(null,vec__25664,(0),null);
var v = cljs.core.nth.call(null,vec__25664,(1),null);
var o__$1 = (((o == null))?({}):o);
clojure.browser.dom.log.call(null,"o = ",o__$1);
clojure.browser.dom.log.call(null,"k = ",k);
clojure.browser.dom.log.call(null,"v = ",v);
if((((k instanceof cljs.core.Keyword)) || (typeof k === 'string'))){
var G__25669 = o__$1;
goog.object.set(G__25669,cljs.core.name.call(null,k),v);
return G__25669;
} else {
return null;
}
}),({}),attrs):null);
clojure.browser.dom.log_obj.call(null,str_attrs);
if(cljs.core.seq.call(null,children)){
return cljs.core.apply.call(null,goog.dom.createDom,cljs.core.name.call(null,this$),str_attrs,cljs.core.map.call(null,clojure.browser.dom._element,children));
} else {
return goog.dom.createDom(cljs.core.name.call(null,this$),str_attrs);
}
});
G__25672 = function(this$,attrs,children){
switch(arguments.length){
case 1:
return G__25672__1.call(this,this$);
case 2:
return G__25672__2.call(this,this$,attrs);
case 3:
return G__25672__3.call(this,this$,attrs,children);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
G__25672.cljs$core$IFn$_invoke$arity$1 = G__25672__1;
G__25672.cljs$core$IFn$_invoke$arity$2 = G__25672__2;
G__25672.cljs$core$IFn$_invoke$arity$3 = G__25672__3;
return G__25672;
})()
);
cljs.core.PersistentVector.prototype.clojure$browser$dom$DOMBuilder$ = cljs.core.PROTOCOL_SENTINEL;
cljs.core.PersistentVector.prototype.clojure$browser$dom$DOMBuilder$_element$arity$1 = (function (this$){
var this$__$1 = this;
clojure.browser.dom.log.call(null,"PersistentVector (-element ",this$__$1,")");
var tag = cljs.core.first.call(null,this$__$1);
var attrs = cljs.core.second.call(null,this$__$1);
var children = cljs.core.drop.call(null,(2),this$__$1);
if(cljs.core.map_QMARK_.call(null,attrs)){
return clojure.browser.dom._element.call(null,tag,attrs,children);
} else {
return clojure.browser.dom._element.call(null,tag,null,cljs.core.rest.call(null,this$__$1));
}
});
Element.prototype.clojure$browser$dom$DOMBuilder$ = cljs.core.PROTOCOL_SENTINEL;
Element.prototype.clojure$browser$dom$DOMBuilder$_element$arity$1 = (function (this$){
var this$__$1 = this;
clojure.browser.dom.log.call(null,"js/Element (-element ",this$__$1,")");
return this$__$1;
});
clojure.browser.dom.element = (function clojure$browser$dom$element(var_args){
var G__25676 = arguments.length;
switch (G__25676) {
case 1:
return clojure.browser.dom.element.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
break;
default:
var args_arr__4751__auto__ = [];
var len__4730__auto___25678 = arguments.length;
var i__4731__auto___25679 = (0);
while(true){
if((i__4731__auto___25679 < len__4730__auto___25678)){
args_arr__4751__auto__.push((arguments[i__4731__auto___25679]));
var G__25680 = (i__4731__auto___25679 + (1));
i__4731__auto___25679 = G__25680;
continue;
} else {
}
break;
}
var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((1)),(0),null));
return clojure.browser.dom.element.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4752__auto__);
}
});
clojure.browser.dom.element.cljs$core$IFn$_invoke$arity$1 = (function (tag_or_text){
clojure.browser.dom.log.call(null,"(element ",tag_or_text,")");
return clojure.browser.dom._element.call(null,tag_or_text);
});
clojure.browser.dom.element.cljs$core$IFn$_invoke$arity$variadic = (function (tag,children){
clojure.browser.dom.log.call(null,"(element ",tag," ",children,")");
var attrs = cljs.core.first.call(null,children);
if(cljs.core.map_QMARK_.call(null,attrs)){
return clojure.browser.dom._element.call(null,tag,attrs,cljs.core.rest.call(null,children));
} else {
return clojure.browser.dom._element.call(null,tag,null,children);
}
});
/** @this {Function} */
clojure.browser.dom.element.cljs$lang$applyTo = (function (seq25674){
var G__25675 = cljs.core.first.call(null,seq25674);
var seq25674__$1 = cljs.core.next.call(null,seq25674);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25675,seq25674__$1);
});
clojure.browser.dom.element.cljs$lang$maxFixedArity = (1);
/**
* Remove all children from the element with the passed id.
*/
clojure.browser.dom.remove_children = (function clojure$browser$dom$remove_children(id){
var parent = goog.dom.getElement(cljs.core.name.call(null,id));
return goog.dom.removeChildren(parent);
});
clojure.browser.dom.get_element = (function clojure$browser$dom$get_element(id){
return goog.dom.getElement(cljs.core.name.call(null,id));
});
clojure.browser.dom.html__GT_dom = (function clojure$browser$dom$html__GT_dom(s){
return goog.dom.htmlToDocumentFragment(s);
});
clojure.browser.dom.insert_at = (function clojure$browser$dom$insert_at(parent,child,index){
return goog.dom.insertChildAt(parent,child,index);
});
/**
* Coerce the argument to a dom element if possible.
*/
clojure.browser.dom.ensure_element = (function clojure$browser$dom$ensure_element(e){
if((e instanceof cljs.core.Keyword)){
return clojure.browser.dom.get_element.call(null,e);
} else {
if(typeof e === 'string'){
return clojure.browser.dom.html__GT_dom.call(null,e);
} else {
return e;
}
}
});
/**
* Replace old-node with new-node. old-node can be an element or a
* keyword which is the id of the node to replace. new-node can be an
* element or an html string.
*/
clojure.browser.dom.replace_node = (function clojure$browser$dom$replace_node(old_node,new_node){
var old_node__$1 = clojure.browser.dom.ensure_element.call(null,old_node);
var new_node__$1 = clojure.browser.dom.ensure_element.call(null,new_node);
goog.dom.replaceNode(new_node__$1,old_node__$1);
return new_node__$1;
});
/**
* Set the text content for the passed element returning the
* element. If a keyword is passed in the place of e, the element with
* that id will be used and returned.
*/
clojure.browser.dom.set_text = (function clojure$browser$dom$set_text(e,s){
return goog.dom.setTextContent(clojure.browser.dom.ensure_element.call(null,e),s);
});
/**
* Get the value of an element.
*/
clojure.browser.dom.get_value = (function clojure$browser$dom$get_value(e){
return clojure.browser.dom.ensure_element.call(null,e).value;
});
/**
* Set properties on an element
*/
clojure.browser.dom.set_properties = (function clojure$browser$dom$set_properties(e,m){
return goog.dom.setProperties(clojure.browser.dom.ensure_element.call(null,e),cljs.core.apply.call(null,goog.object.create,cljs.core.interleave.call(null,cljs.core.keys.call(null,m),cljs.core.vals.call(null,m))));
});
/**
* Set the value property for an element.
*/
clojure.browser.dom.set_value = (function clojure$browser$dom$set_value(e,v){
return clojure.browser.dom.set_properties.call(null,e,new cljs.core.PersistentArrayMap(null, 1, ["value",v], null));
});
clojure.browser.dom.click_element = (function clojure$browser$dom$click_element(e){
return clojure.browser.dom.ensure_element.call(null,e).click(cljs.core.List.EMPTY);
});
//# sourceMappingURL=dom.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,289 @@
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns clojure.string
(:refer-clojure :exclude [replace reverse])
(:require [goog.string :as gstring])
(:import [goog.string StringBuffer]))
(defn- seq-reverse
[coll]
(reduce conj () coll))
(def ^:private re-surrogate-pair
(js/RegExp. "([\\uD800-\\uDBFF])([\\uDC00-\\uDFFF])" "g"))
(defn reverse
"Returns s with its characters reversed."
[s]
(-> (.replace s re-surrogate-pair "$2$1")
(.. (split "") (reverse) (join ""))))
(defn- replace-all
[s re replacement]
(let [r (js/RegExp. (.-source re)
(cond-> "g"
(.-ignoreCase re) (str "i")
(.-multiline re) (str "m")
(.-unicode re) (str "u")))]
(.replace s r replacement)))
(defn- replace-with
[f]
(fn [& args]
(let [matches (drop-last 2 args)]
(if (= (count matches) 1)
(f (first matches))
(f (vec matches))))))
(defn replace
"Replaces all instance of match with replacement in s.
match/replacement can be:
string / string
pattern / (string or function of match).
See also replace-first.
The replacement is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.
For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.
Example:
(clojure.string/replace \"Almost Pig Latin\" #\"\\b(\\w)(\\w+)\\b\" \"$2$1ay\")
-> \"lmostAay igPay atinLay\""
[s match replacement]
(cond
(string? match)
(.replace s (js/RegExp. (gstring/regExpEscape match) "g") replacement)
(instance? js/RegExp match)
(if (string? replacement)
(replace-all s match replacement)
(replace-all s match (replace-with replacement)))
:else (throw (str "Invalid match arg: " match))))
(defn replace-first
"Replaces the first instance of match with replacement in s.
match/replacement can be:
string / string
pattern / (string or function of match).
See also replace.
The replacement is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.
For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.
Example:
(clojure.string/replace-first \"swap first two words\"
#\"(\\w+)(\\s+)(\\w+)\" \"$3$2$1\")
-> \"first swap two words\""
[s match replacement]
(.replace s match replacement))
(defn join
"Returns a string of all elements in coll, as returned by (seq coll),
separated by an optional separator."
([coll]
(loop [sb (StringBuffer.) coll (seq coll)]
(if-not (nil? coll)
(recur (. sb (append (str (first coll)))) (next coll))
(.toString sb))))
([separator coll]
(loop [sb (StringBuffer.) coll (seq coll)]
(if-not (nil? coll)
(do
(. sb (append (str (first coll))))
(let [coll (next coll)]
(when-not (nil? coll)
(. sb (append separator)))
(recur sb coll)))
(.toString sb)))))
(defn upper-case
"Converts string to all upper-case."
[s]
(.toUpperCase s))
(defn lower-case
"Converts string to all lower-case."
[s]
(.toLowerCase s))
(defn capitalize
"Converts first character of the string to upper-case, all other
characters to lower-case."
[s]
(gstring/capitalize s))
;; The JavaScript split function takes a limit argument but the return
;; value is not the same as the Java split function.
;;
;; Java: (.split "a-b-c" #"-" 2) => ["a" "b-c"]
;; JavaScript: (.split "a-b-c" #"-" 2) => ["a" "b"]
;;
;; For consistency, the three arg version has been implemented to
;; mimic Java's behavior.
(defn- pop-last-while-empty
[v]
(loop [v v]
(if (identical? "" (peek v))
(recur (pop v))
v)))
(defn- discard-trailing-if-needed
[limit v]
(if (and (== 0 limit) (< 1 (count v)))
(pop-last-while-empty v)
v))
(defn- split-with-empty-regex
[s limit]
(if (or (<= limit 0) (>= limit (+ 2 (count s))))
(conj (vec (cons "" (map str (seq s)))) "")
(condp == limit
1 (vector s)
2 (vector "" s)
(let [c (- limit 2)]
(conj (vec (cons "" (subvec (vec (map str (seq s))) 0 c))) (subs s c))))))
(defn split
"Splits string on a regular expression. Optional argument limit is
the maximum number of splits. Not lazy. Returns vector of the splits."
([s re]
(split s re 0))
([s re limit]
(discard-trailing-if-needed limit
(if (identical? "/(?:)/" (str re))
(split-with-empty-regex s limit)
(if (< limit 1)
(vec (.split (str s) re))
(loop [s s
limit limit
parts []]
(if (== 1 limit)
(conj parts s)
(let [m (re-find re s)]
(if-not (nil? m)
(let [index (.indexOf s m)]
(recur (.substring s (+ index (count m)))
(dec limit)
(conj parts (.substring s 0 index))))
(conj parts s))))))))))
(defn split-lines
"Splits s on \\n or \\r\\n."
[s]
(split s #"\n|\r\n"))
(defn trim
"Removes whitespace from both ends of string."
[s]
(gstring/trim s))
(defn triml
"Removes whitespace from the left side of string."
[s]
(gstring/trimLeft s))
(defn trimr
"Removes whitespace from the right side of string."
[s]
(gstring/trimRight s))
(defn trim-newline
"Removes all trailing newline \\n or return \\r characters from
string. Similar to Perl's chomp."
[s]
(loop [index (.-length s)]
(if (zero? index)
""
(let [ch (get s (dec index))]
(if (or (identical? \newline ch)
(identical? \return ch))
(recur (dec index))
(.substring s 0 index))))))
(defn ^boolean blank?
"True is s is nil, empty, or contains only whitespace."
[s]
(gstring/isEmptySafe s))
(defn escape
"Return a new string, using cmap to escape each character ch
from s as follows:
If (cmap ch) is nil, append ch to the new string.
If (cmap ch) is non-nil, append (str (cmap ch)) instead."
[s cmap]
(let [buffer (StringBuffer.)
length (.-length s)]
(loop [index 0]
(if (== length index)
(. buffer (toString))
(let [ch (.charAt s index)
replacement (get cmap ch)]
(if-not (nil? replacement)
(.append buffer (str replacement))
(.append buffer ch))
(recur (inc index)))))))
(defn index-of
"Return index of value (string or char) in s, optionally searching
forward from from-index or nil if not found."
([s value]
(let [result (.indexOf s value)]
(if (neg? result)
nil
result)))
([s value from-index]
(let [result (.indexOf s value from-index)]
(if (neg? result)
nil
result))))
(defn last-index-of
"Return last index of value (string or char) in s, optionally
searching backward from from-index or nil if not found."
([s value]
(let [result (.lastIndexOf s value)]
(if (neg? result)
nil
result)))
([s value from-index]
(let [result (.lastIndexOf s value from-index)]
(if (neg? result)
nil
result))))
(defn ^boolean starts-with?
"True if s starts with substr."
[s substr]
(gstring/startsWith s substr))
(defn ^boolean ends-with?
"True if s ends with substr."
[s substr]
(gstring/endsWith s substr))
(defn ^boolean includes?
"True if s includes substr."
[s substr]
(gstring/contains s substr))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,477 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('clojure.string');
goog.require('cljs.core');
goog.require('goog.string');
goog.require('goog.string.StringBuffer');
clojure.string.seq_reverse = (function clojure$string$seq_reverse(coll){
return cljs.core.reduce.call(null,cljs.core.conj,cljs.core.List.EMPTY,coll);
});
clojure.string.re_surrogate_pair = (new RegExp("([\\uD800-\\uDBFF])([\\uDC00-\\uDFFF])","g"));
/**
* Returns s with its characters reversed.
*/
clojure.string.reverse = (function clojure$string$reverse(s){
return s.replace(clojure.string.re_surrogate_pair,"$2$1").split("").reverse().join("");
});
clojure.string.replace_all = (function clojure$string$replace_all(s,re,replacement){
var r = (new RegExp(re.source,(function (){var G__21614 = "g";
var G__21614__$1 = (cljs.core.truth_(re.ignoreCase)?[G__21614,"i"].join(''):G__21614);
var G__21614__$2 = (cljs.core.truth_(re.multiline)?[G__21614__$1,"m"].join(''):G__21614__$1);
if(cljs.core.truth_(re.unicode)){
return [G__21614__$2,"u"].join('');
} else {
return G__21614__$2;
}
})()));
return s.replace(r,replacement);
});
clojure.string.replace_with = (function clojure$string$replace_with(f){
return (function() {
var G__21615__delegate = function (args){
var matches = cljs.core.drop_last.call(null,(2),args);
if(cljs.core._EQ_.call(null,cljs.core.count.call(null,matches),(1))){
return f.call(null,cljs.core.first.call(null,matches));
} else {
return f.call(null,cljs.core.vec.call(null,matches));
}
};
var G__21615 = function (var_args){
var args = null;
if (arguments.length > 0) {
var G__21616__i = 0, G__21616__a = new Array(arguments.length - 0);
while (G__21616__i < G__21616__a.length) {G__21616__a[G__21616__i] = arguments[G__21616__i + 0]; ++G__21616__i;}
args = new cljs.core.IndexedSeq(G__21616__a,0,null);
}
return G__21615__delegate.call(this,args);};
G__21615.cljs$lang$maxFixedArity = 0;
G__21615.cljs$lang$applyTo = (function (arglist__21617){
var args = cljs.core.seq(arglist__21617);
return G__21615__delegate(args);
});
G__21615.cljs$core$IFn$_invoke$arity$variadic = G__21615__delegate;
return G__21615;
})()
;
});
/**
* Replaces all instance of match with replacement in s.
*
* match/replacement can be:
*
* string / string
* pattern / (string or function of match).
*
* See also replace-first.
*
* The replacement is literal (i.e. none of its characters are treated
* specially) for all cases above except pattern / string.
*
* For pattern / string, $1, $2, etc. in the replacement string are
* substituted with the string that matched the corresponding
* parenthesized group in the pattern.
*
* Example:
* (clojure.string/replace "Almost Pig Latin" #"\b(\w)(\w+)\b" "$2$1ay")
* -> "lmostAay igPay atinLay"
*/
clojure.string.replace = (function clojure$string$replace(s,match,replacement){
if(typeof match === 'string'){
return s.replace((new RegExp(goog.string.regExpEscape(match),"g")),replacement);
} else {
if((match instanceof RegExp)){
if(typeof replacement === 'string'){
return clojure.string.replace_all.call(null,s,match,replacement);
} else {
return clojure.string.replace_all.call(null,s,match,clojure.string.replace_with.call(null,replacement));
}
} else {
throw ["Invalid match arg: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(match)].join('');
}
}
});
/**
* Replaces the first instance of match with replacement in s.
*
* match/replacement can be:
*
* string / string
* pattern / (string or function of match).
*
* See also replace.
*
* The replacement is literal (i.e. none of its characters are treated
* specially) for all cases above except pattern / string.
*
* For pattern / string, $1, $2, etc. in the replacement string are
* substituted with the string that matched the corresponding
* parenthesized group in the pattern.
*
* Example:
* (clojure.string/replace-first "swap first two words"
* #"(\w+)(\s+)(\w+)" "$3$2$1")
* -> "first swap two words"
*/
clojure.string.replace_first = (function clojure$string$replace_first(s,match,replacement){
return s.replace(match,replacement);
});
/**
* Returns a string of all elements in coll, as returned by (seq coll),
* separated by an optional separator.
*/
clojure.string.join = (function clojure$string$join(var_args){
var G__21619 = arguments.length;
switch (G__21619) {
case 1:
return clojure.string.join.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));
break;
case 2:
return clojure.string.join.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));
}
});
clojure.string.join.cljs$core$IFn$_invoke$arity$1 = (function (coll){
var sb = (new goog.string.StringBuffer());
var coll__$1 = cljs.core.seq.call(null,coll);
while(true){
if((!((coll__$1 == null)))){
var G__21621 = sb.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first.call(null,coll__$1)));
var G__21622 = cljs.core.next.call(null,coll__$1);
sb = G__21621;
coll__$1 = G__21622;
continue;
} else {
return sb.toString();
}
break;
}
});
clojure.string.join.cljs$core$IFn$_invoke$arity$2 = (function (separator,coll){
var sb = (new goog.string.StringBuffer());
var coll__$1 = cljs.core.seq.call(null,coll);
while(true){
if((!((coll__$1 == null)))){
sb.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first.call(null,coll__$1)));
var coll__$2 = cljs.core.next.call(null,coll__$1);
if((coll__$2 == null)){
} else {
sb.append(separator);
}
var G__21623 = sb;
var G__21624 = coll__$2;
sb = G__21623;
coll__$1 = G__21624;
continue;
} else {
return sb.toString();
}
break;
}
});
clojure.string.join.cljs$lang$maxFixedArity = 2;
/**
* Converts string to all upper-case.
*/
clojure.string.upper_case = (function clojure$string$upper_case(s){
return s.toUpperCase();
});
/**
* Converts string to all lower-case.
*/
clojure.string.lower_case = (function clojure$string$lower_case(s){
return s.toLowerCase();
});
/**
* Converts first character of the string to upper-case, all other
* characters to lower-case.
*/
clojure.string.capitalize = (function clojure$string$capitalize(s){
return goog.string.capitalize(s);
});
clojure.string.pop_last_while_empty = (function clojure$string$pop_last_while_empty(v){
var v__$1 = v;
while(true){
if(("" === cljs.core.peek.call(null,v__$1))){
var G__21625 = cljs.core.pop.call(null,v__$1);
v__$1 = G__21625;
continue;
} else {
return v__$1;
}
break;
}
});
clojure.string.discard_trailing_if_needed = (function clojure$string$discard_trailing_if_needed(limit,v){
if(((((0) === limit)) && (((1) < cljs.core.count.call(null,v))))){
return clojure.string.pop_last_while_empty.call(null,v);
} else {
return v;
}
});
clojure.string.split_with_empty_regex = (function clojure$string$split_with_empty_regex(s,limit){
if((((limit <= (0))) || ((limit >= ((2) + cljs.core.count.call(null,s)))))){
return cljs.core.conj.call(null,cljs.core.vec.call(null,cljs.core.cons.call(null,"",cljs.core.map.call(null,cljs.core.str,cljs.core.seq.call(null,s)))),"");
} else {
var pred__21626 = cljs.core._EQ__EQ_;
var expr__21627 = limit;
if(cljs.core.truth_(pred__21626.call(null,(1),expr__21627))){
return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[s],null));
} else {
if(cljs.core.truth_(pred__21626.call(null,(2),expr__21627))){
return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,["",s],null));
} else {
var c = (limit - (2));
return cljs.core.conj.call(null,cljs.core.vec.call(null,cljs.core.cons.call(null,"",cljs.core.subvec.call(null,cljs.core.vec.call(null,cljs.core.map.call(null,cljs.core.str,cljs.core.seq.call(null,s))),(0),c))),cljs.core.subs.call(null,s,c));
}
}
}
});
/**
* Splits string on a regular expression. Optional argument limit is
* the maximum number of splits. Not lazy. Returns vector of the splits.
*/
clojure.string.split = (function clojure$string$split(var_args){
var G__21630 = arguments.length;
switch (G__21630) {
case 2:
return clojure.string.split.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return clojure.string.split.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));
}
});
clojure.string.split.cljs$core$IFn$_invoke$arity$2 = (function (s,re){
return clojure.string.split.call(null,s,re,(0));
});
clojure.string.split.cljs$core$IFn$_invoke$arity$3 = (function (s,re,limit){
return clojure.string.discard_trailing_if_needed.call(null,limit,((("/(?:)/" === cljs.core.str.cljs$core$IFn$_invoke$arity$1(re)))?clojure.string.split_with_empty_regex.call(null,s,limit):(((limit < (1)))?cljs.core.vec.call(null,cljs.core.str.cljs$core$IFn$_invoke$arity$1(s).split(re)):(function (){var s__$1 = s;
var limit__$1 = limit;
var parts = cljs.core.PersistentVector.EMPTY;
while(true){
if(((1) === limit__$1)){
return cljs.core.conj.call(null,parts,s__$1);
} else {
var m = cljs.core.re_find.call(null,re,s__$1);
if((!((m == null)))){
var index = s__$1.indexOf(m);
var G__21632 = s__$1.substring((index + cljs.core.count.call(null,m)));
var G__21633 = (limit__$1 - (1));
var G__21634 = cljs.core.conj.call(null,parts,s__$1.substring((0),index));
s__$1 = G__21632;
limit__$1 = G__21633;
parts = G__21634;
continue;
} else {
return cljs.core.conj.call(null,parts,s__$1);
}
}
break;
}
})())));
});
clojure.string.split.cljs$lang$maxFixedArity = 3;
/**
* Splits s on \n or \r\n.
*/
clojure.string.split_lines = (function clojure$string$split_lines(s){
return clojure.string.split.call(null,s,/\n|\r\n/);
});
/**
* Removes whitespace from both ends of string.
*/
clojure.string.trim = (function clojure$string$trim(s){
return goog.string.trim(s);
});
/**
* Removes whitespace from the left side of string.
*/
clojure.string.triml = (function clojure$string$triml(s){
return goog.string.trimLeft(s);
});
/**
* Removes whitespace from the right side of string.
*/
clojure.string.trimr = (function clojure$string$trimr(s){
return goog.string.trimRight(s);
});
/**
* Removes all trailing newline \n or return \r characters from
* string. Similar to Perl's chomp.
*/
clojure.string.trim_newline = (function clojure$string$trim_newline(s){
var index = s.length;
while(true){
if((index === (0))){
return "";
} else {
var ch = cljs.core.get.call(null,s,(index - (1)));
if(((("\n" === ch)) || (("\r" === ch)))){
var G__21635 = (index - (1));
index = G__21635;
continue;
} else {
return s.substring((0),index);
}
}
break;
}
});
/**
* True is s is nil, empty, or contains only whitespace.
*/
clojure.string.blank_QMARK_ = (function clojure$string$blank_QMARK_(s){
return goog.string.isEmptySafe(s);
});
/**
* Return a new string, using cmap to escape each character ch
* from s as follows:
*
* If (cmap ch) is nil, append ch to the new string.
* If (cmap ch) is non-nil, append (str (cmap ch)) instead.
*/
clojure.string.escape = (function clojure$string$escape(s,cmap){
var buffer = (new goog.string.StringBuffer());
var length = s.length;
var index = (0);
while(true){
if((length === index)){
return buffer.toString();
} else {
var ch = s.charAt(index);
var replacement = cljs.core.get.call(null,cmap,ch);
if((!((replacement == null)))){
buffer.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(replacement));
} else {
buffer.append(ch);
}
var G__21636 = (index + (1));
index = G__21636;
continue;
}
break;
}
});
/**
* Return index of value (string or char) in s, optionally searching
* forward from from-index or nil if not found.
*/
clojure.string.index_of = (function clojure$string$index_of(var_args){
var G__21638 = arguments.length;
switch (G__21638) {
case 2:
return clojure.string.index_of.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return clojure.string.index_of.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));
}
});
clojure.string.index_of.cljs$core$IFn$_invoke$arity$2 = (function (s,value){
var result = s.indexOf(value);
if((result < (0))){
return null;
} else {
return result;
}
});
clojure.string.index_of.cljs$core$IFn$_invoke$arity$3 = (function (s,value,from_index){
var result = s.indexOf(value,from_index);
if((result < (0))){
return null;
} else {
return result;
}
});
clojure.string.index_of.cljs$lang$maxFixedArity = 3;
/**
* Return last index of value (string or char) in s, optionally
* searching backward from from-index or nil if not found.
*/
clojure.string.last_index_of = (function clojure$string$last_index_of(var_args){
var G__21641 = arguments.length;
switch (G__21641) {
case 2:
return clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));
break;
case 3:
return clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));
break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));
}
});
clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$2 = (function (s,value){
var result = s.lastIndexOf(value);
if((result < (0))){
return null;
} else {
return result;
}
});
clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$3 = (function (s,value,from_index){
var result = s.lastIndexOf(value,from_index);
if((result < (0))){
return null;
} else {
return result;
}
});
clojure.string.last_index_of.cljs$lang$maxFixedArity = 3;
/**
* True if s starts with substr.
*/
clojure.string.starts_with_QMARK_ = (function clojure$string$starts_with_QMARK_(s,substr){
return goog.string.startsWith(s,substr);
});
/**
* True if s ends with substr.
*/
clojure.string.ends_with_QMARK_ = (function clojure$string$ends_with_QMARK_(s,substr){
return goog.string.endsWith(s,substr);
});
/**
* True if s includes substr.
*/
clojure.string.includes_QMARK_ = (function clojure$string$includes_QMARK_(s,substr){
return goog.string.contains(s,substr);
});
//# sourceMappingURL=string.js.map

File diff suppressed because one or more lines are too long