squint-cljs 0.3.35 → 0.3.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/lib/cli.js +41 -41
- package/lib/compiler.js +602 -599
- package/lib/compiler.node.js +25 -25
- package/lib/compiler.sci.js +1139 -1139
- package/lib/squint.core.umd.js +1 -1
- package/package.json +1 -1
- package/src/squint/core.js +185 -21
- package/string.js +54 -1
package/lib/squint.core.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var squint;(squint||={}).core=(()=>{var S=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var Se=(e,t)=>{for(var n in t)S(e,n,{get:t[n],enumerable:!0})},je=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ke(t))!Qe.call(e,o)&&o!==n&&S(e,o,{get:()=>t[o],enumerable:!(r=Ee(t,o))||r.enumerable});return e};var Ie=e=>je(S({},"__esModule",{value:!0}),e);var bn={};Se(bn,{Atom:()=>re,IIterable:()=>N,IIterable__iterator:()=>H,LazySeq:()=>Vt,PROTOCOL_SENTINEL:()=>tt,_:()=>Te,_PLUS_:()=>Oe,_iterator:()=>E,aclone:()=>cn,add_watch:()=>sn,alength:()=>rn,apply:()=>at,array_QMARK_:()=>_t,aset:()=>on,assoc:()=>I,assoc_BANG_:()=>x,assoc_in:()=>W,assoc_in_BANG_:()=>Be,atom:()=>ot,boolean$:()=>Ht,butlast:()=>Wt,comp:()=>Le,compare:()=>yn,complement:()=>ce,concat:()=>se,conj:()=>$,conj_BANG_:()=>T,cons:()=>ee,constantly:()=>xt,contains_QMARK_:()=>Ge,count:()=>be,cycle:()=>Kt,dec:()=>qe,deref:()=>oe,disj:()=>ke,disj_BANG_:()=>J,dissoc:()=>Ye,dissoc_BANG_:()=>Pe,distinct:()=>Qt,doall:()=>fn,dorun:()=>un,drop:()=>Q,drop_last:()=>$t,drop_while:()=>_e,empty:()=>xe,empty_QMARK_:()=>Gt,es6_iterator:()=>B,even_QMARK_:()=>fe,every_QMARK_:()=>we,every_pred:()=>xn,false_QMARK_:()=>Dt,ffirst:()=>Ce,filter:()=>k,filterv:()=>Ze,first:()=>g,fn_QMARK_:()=>mn,fnil:()=>q,frequencies:()=>Ct,get:()=>m,get_in:()=>ye,group_by:()=>zt,identical_QMARK_:()=>vt,identity:()=>le,inc:()=>U,interleave:()=>ae,interpose:()=>wt,into:()=>de,into_array:()=>ge,iterable:()=>i,iterate:()=>hn,js_obj:()=>nn,juxt:()=>_n,keep:()=>Ot,keep_indexed:()=>He,last:()=>We,lazy:()=>f,list:()=>ht,list_QMARK_:()=>dt,map:()=>A,map_QMARK_:()=>pn,map_indexed:()=>Fe,mapcat:()=>yt,mapv:()=>ie,max:()=>v,merge:()=>gt,min:()=>j,neg_QMARK_:()=>en,next:()=>Me,nil_QMARK_:()=>et,not:()=>te,not_any_QMARK_:()=>Lt,not_every_QMARK_:()=>It,nth:()=>D,number_QMARK_:()=>An,odd_QMARK_:()=>pt,partial:()=>Et,partition:()=>bt,partition_all:()=>At,pos_QMARK_:()=>tn,pr_str:()=>ne,println:()=>Z,prn:()=>rt,rand_int:()=>Ae,rand_nth:()=>Pt,range:()=>it,re_matches:()=>ft,re_seq:()=>Re,reduce:()=>Ue,reduce_kv:()=>an,reduced:()=>$e,reduced_QMARK_:()=>Je,remove:()=>De,remove_watch:()=>ln,repeat:()=>P,repeatedly:()=>qt,replace:()=>kt,reset_BANG_:()=>ue,rest:()=>Ve,reverse:()=>Tt,satisfies_QMARK_:()=>Ne,second:()=>ze,select_keys:()=>mt,seq:()=>X,seqable_QMARK_:()=>F,set:()=>lt,shuffle:()=>Bt,some:()=>me,some_QMARK_:()=>Ft,some_fn:()=>dn,sort:()=>Nt,split_at:()=>Jt,split_with:()=>Ut,str:()=>Xe,subs:()=>ve,subvec:()=>ct,swap_BANG_:()=>ut,system_time:()=>Mt,take:()=>Y,take_nth:()=>Rt,take_while:()=>he,to_array:()=>wn,true_QMARK_:()=>Zt,update:()=>St,update_BANG_:()=>z,update_in:()=>jt,vec:()=>b,vector:()=>G,vector_QMARK_:()=>st,zero_QMARK_:()=>Xt});function Oe(...e){return e.reduce((t,n)=>t+n,0)}function Te(...e){return e.reduce((t,n)=>t-n)}function Ne(e,t){return t[e]}function x(e,t,n,...r){if(r.length%2!==0)throw new Error("Illegal argument: assoc expects an odd number of arguments.");switch(s(e)){case a:e.set(t,n);for(let o=0;o<r.length;o+=2)e.set(r[o],r[o+1]);break;case p:case d:e[t]=n;for(let o=0;o<r.length;o+=2)e[r[o]]=r[o+1];break;default:throw new Error("Illegal argument: assoc! expects a Map, Array, or Object as the first argument.")}return e}function I(e,t,n,...r){switch(e||(e={}),s(e)){case a:return x(new Map(e.entries()),t,n,...r);case p:return x([...e],t,n,...r);case d:return x({...e},t,n,...r);default:throw new Error("Illegal argument: assoc expects a Map, Array, or Object as the first argument.")}}const a=1,p=2,d=3,w=4,h=5,R=6;function O(e){switch(e){case a:return new Map;case p:return[];case d:return{};case w:return new K;case h:return new Set;case R:return f(function*(){})}}function s(e){if(e instanceof Map)return a;if(e instanceof Set)return h;if(e instanceof K)return w;if(e instanceof Array)return p;if(e instanceof L)return R;if(e instanceof Object)return d}function V(e,t,n,r,o){let u=s(n);if(u!==a&&u!==p&&u!==d)throw new Error(`Illegal argument: ${t} expects the first argument to be a Map, Array, or Object.`);const c=[n];let _=n;for(let l=0;l<r.length-1;l+=1){let C=r[l],y;_ instanceof Map?y=_.get(C):y=_[C],y||(y=O(u)),c.push(y),_=y}c.push(o);for(let l=c.length-2;l>=0;l-=1)c[l]=e(c[l],r[l],c[l+1]);return c[0]}function W(e,t,n){return V(I,"assoc-in",e,t,n)}function Be(e,t,n){return V(x,"assoc-in!",e,t,n)}function Le(...e){if(e.length===0)return le;if(e.length===1)return e[0];let[t,...n]=e.slice().reverse();return function(...r){let o=t(...r);for(const u of n)o=u(o);return o}}function T(...e){if(e.length===0)return G();let[t,...n]=e;switch(t==null&&(t=[]),s(t)){case h:for(const r of n)t.add(r);break;case w:t.unshift(...n.reverse());break;case p:t.push(...n);break;case a:for(const r of n)r instanceof Array?t.set(r[0],r[1]):i(r).forEach(o=>{t.set(o[0],o[1])});break;case d:for(const r of n)r instanceof Array?t[r[0]]=r[1]:Object.assign(t,r);break;default:throw new Error("Illegal argument: conj! expects a Set, Array, List, Map, or Object as the first argument.")}return t}function $(...e){if(e.length===0)return G();let[t,...n]=e;switch(t==null&&(t=[]),s(t)){case h:return new Set([...t,...n]);case w:return new K(...n.reverse(),...t);case p:return[...t,...n];case a:const r=new Map(t);for(const u of n)u instanceof Array?r.set(u[0],u[1]):i(u).forEach(c=>{r.set(c[0],c[1])});return r;case R:return f(function*(){yield*n,yield*t});case d:const o={...t};for(const u of n)u instanceof Array?o[u[0]]=u[1]:Object.assign(o,u);return o;default:throw new Error("Illegal argument: conj expects a Set, Array, List, Map, or Object as the first argument.")}}function J(e,...t){for(const n of t)e.delete(n);return e}function ke(e,...t){let n=new Set([...e]);return J(n,...t)}function Ge(e,t){switch(s(e)){case h:case a:return e.has(t);case void 0:return!1;default:return t in e}}function Pe(e,...t){for(const n of t)delete e[n];return e}function Ye(e,...t){let n={...e};for(const r of t)delete n[r];return n}function U(e){return e+1}function qe(e){return e-1}function Z(...e){console.log(...e)}function D(e,t,n){if(e){var r=void 0;if(e instanceof Array)r=e[t];else{let o=i(e),u=0;for(let c of o)if(u++==t){r=c;break}}if(r!==void 0)return r}return n}function m(e,t,n=void 0){let r;switch(s(e)){case h:e.has(t)&&(r=t);break;case a:r=e.get(t);break;case void 0:break;default:r=e[t];break}return r!==void 0?r:n}function F(e){return typeof e=="string"||e===null||e===void 0||Symbol.iterator in e}function i(e){return e==null?[]:F(e)?e:Object.entries(e)}const N=Symbol("Iterable"),H=Symbol.iterator;function E(e){return e[Symbol.iterator]()}const B=E;function X(e){let t=i(e);return t.length===0||t.size===0?null:t}function g(e){let[t]=i(e);return t}function ze(e){let[t,n]=i(e);return n}function Ce(e){return g(g(e))}function Ve(e){return f(function*(){let t=!0;for(const n of i(e))t?t=!1:yield n})}class M{value;constructor(t){this.value=t}_deref(){return this.value}}function We(e){switch(e=i(e),s(e)){case p:return e[e.length-1];default:let t;for(const n of e)t=n;return t}}function $e(e){return new M(e)}function Je(e){return e instanceof M}function Ue(e,t,n){let r,o;if(n===void 0){let u=i(t)[Symbol.iterator]();o=u.next().value,r=u}else o=t,r=i(n);if(o instanceof M)return o.value;for(const u of r)if(o=e(o,u),o instanceof M){o=o.value;break}return o}class L{constructor(t){this.gen=t}[Symbol.iterator](){return this.gen()}}L.prototype[N]=!0;function f(e){return new L(e)}function ee(e,t){return f(function*(){yield e,yield*i(t)})}function A(e,...t){switch(t.length){case 0:throw new Error("map with 2 arguments is not supported yet");case 1:return f(function*(){for(const n of i(t[0]))yield e(n)});default:return f(function*(){const n=t.map(r=>B(i(r)));for(;;){let r=[];for(const o of n){const u=o.next();if(u.done)return;r.push(u.value)}yield e(...r)}})}}function k(e,t){return f(function*(){for(const n of i(t))e(n)&&(yield n)})}function Ze(e,t){return[...k(e,t)]}function De(e,t){return k(ce(e),t)}function Fe(e,t){let n=[],r=0;for(const o of i(t))n.push(e(r,o)),r++;return n}function He(e,t){let n=[],r=0;for(const o of i(t)){let u=e(r,o);u&&n.push(u),r++}return n}function Xe(...e){return e.join("")}function te(e){return!e}function et(e){return e==null}const tt={};function nt(e){return JSON.stringify(e,(t,n)=>{switch(s(n)){case h:case R:return[...n];case a:return Object.fromEntries(n);default:return n}})}function ne(...e){return e.map(nt).join(" ")}function rt(...e){Z(ne(...e))}function re(e){this.val=e,this._watches={},this._deref=()=>this.val,this._hasWatches=!1,this._reset_BANG_=t=>{let n=this.val;if(this.val=t,this._hasWatches)for(let r of Object.entries(this._watches)){let o=r[0],u=r[1];u(o,this,n,t)}return t},this._add_watch=(t,n)=>{this._watches[t]=n,this._hasWatches=!0},this._remove_watch=t=>{delete this._watches[t]}}function ot(e){return new re(e)}function oe(e){return e._deref()}function ue(e,t){e._reset_BANG_(t)}function ut(e,t,...n){const r=t(oe(e),...n);return ue(e,r),r}function it(e,t,n){return f(function*(){let r=e,o=t,u=n;t===void 0&&(r=0,o=e);let c=r||0;for(u=n||1;o===void 0||c<o;)yield c,c+=u})}function ft(e,t){let n=e.exec(t);if(n&&t===n[0])return n.length===1?n[0]:n}function ct(e,t,n){return e.slice(t,n)}function G(...e){return e}function st(e){return s(e)===p}function ie(...e){return[...A(...e)]}function b(e){return[...i(e)]}function lt(e){return new Set(i(e))}function at(e,...t){const n=t.slice(0,t.length-1),r=t[t.length-1];return e(...n,...r)}function fe(e){return e%2==0}function pt(e){return!fe(e)}function ce(e){return(...t)=>te(e(...t))}function xt(e){return(...t)=>e}class K extends Array{constructor(...t){super(),this.push(...t)}}function dt(e){return s(e)===w}function ht(...e){return new K(...e)}function _t(e){return e instanceof Array}function se(...e){return f(function*(){for(const t of e)yield*i(t)})}function yt(e,...t){return se(...A(e,...t))}function le(e){return e}function ae(...e){return f(function*(){const t=e.map(n=>B(i(n)));for(;;){let n=[];for(const r of t){const o=r.next();if(o.done)return;n.push(o.value)}yield*n}})}function wt(e,t){return Q(1,ae(P(e),t))}function mt(e,t){const n=s(e),r=O(n);for(const o of t){const u=m(e,o);u!=null&&x(r,o,u)}return r}function At(e,...t){let n=e,r=t[0];return t.length===2&&([n,r]=t),pe(e,n,[],r,!0)}function bt(e,...t){let n=e,r=[],o=t[0];return t.length===2?[n,o]=t:t.length>2&&([n,r,o]=t),pe(e,n,r,o,!1)}function pe(e,t,n,r,o){return f(function*(){let u=[],c=0;for(let _ of i(r))c<e&&(u.push(_),u.length===e&&(yield u,u=t<e?u.slice(t):[])),c++,c===t&&(c=0);u.length>0&&(u.length===e||o?yield u:n.length&&(u.push(...n.slice(0,e-u.length)),yield u))})}function xe(e){const t=s(e);return O(t)}function gt(...e){const t=e[0];let n;return t==null?n={}:n=de(xe(t),t),T(n,...e.slice(1))}function Mt(){return performance.now()}function de(...e){switch(e.length){case 0:return[];case 1:return e[0];default:return $(e[0]??[],...i(e[1]))}}function vt(e,t){return e===t}function P(...e){if(e.length==0||e.length>2)throw new Error(`Invalid arity: ${e.length}`);return{[N]:!0,[H]:e.length==1?function*(){let t=e[0];for(;;)yield t}:function*(){let[t,n]=e;for(var r=0;r<t;r++)yield n}}}function Y(e,t){return f(function*(){let n=e-1;for(const r of i(t))if(n-->=0&&(yield r),n<0)return})}function he(e,t){return f(function*(){for(const n of i(t))if(e(n))yield n;else return})}function Rt(e,t){return e<=0?P(g(t)):f(function*(){let n=0;for(let r of i(t))n%e===0&&(yield r),n++})}function Et(e,...t){return function(...n){return e(...t,...n)}}function Kt(e){return f(function*(){for(;;)yield*e})}function Q(e,t){return f(function*(){let n=E(i(t));for(let r=0;r<e;r++)n.next();yield*n})}function _e(e,t){return f(function*(){let n=E(i(t));for(;;){let r=n.next();if(r.done)break;let o=r.value;if(!e(o)){yield o;break}}yield*n})}function Qt(e){return f(function*(){let t=new Set;for(const n of i(e))t.has(n)||(yield n),t.add(n)})}function St(e,t,n,...r){return I(e,t,n(m(e,t),...r))}function ye(e,t,n){let r=e;for(const o of t)r=m(r,o);return r===void 0?n:r}function jt(e,t,n,...r){return W(e,t,n(ye(e,t),...r))}function q(e,t,...n){return function(r,...o){return r?e(r,...n,...o):e(t,...n,...o)}}function we(e,t){for(let n of i(t))if(!e(n))return!1;return!0}function It(e,t){return!we(e,t)}function Ot(e,t){return f(function*(){for(const n of i(t)){const r=e(n);r&&(yield r)}})}function Tt(e){return e instanceof Array?e.reverse():[...e].reverse()}function Nt(e,t){return t===void 0&&(t=e,e=void 0),[...t].sort(e)}function Bt(e){return[...e].sort(function(t,n){return Math.random()-.5})}function me(e,t){for(const n of i(t)){const r=e(n);if(r)return r}}function Lt(e,t){return!me(e,t)}function kt(e,t){return(t instanceof Array?ie:A)(r=>{const o=e[r];return o!==void 0?o:r},t)}function Gt(e){return!X(e)}function Ae(e){return Math.floor(Math.random()*e)}function Pt(e){let t=Ae(be(e));return D(e,t)}function Yt(e){return f(function*(){for(;;)yield e()})}function qt(e,t){t===void 0&&(t=e,e=void 0);const n=Yt(t);return e?Y(e,n):n}function z(e,t,n,...r){const o=m(e,t);return x(e,t,n(o,...r))}function zt(e,t){const n={};for(const r of i(t)){const o=e(r);z(n,o,q(T,[]),r)}return n}function Ct(e){const t={},n=q(U,0);for(const r of i(e))z(t,r,n);return t}class Vt{constructor(t){this.f=t}*[Symbol.iterator](){yield*i(this.f())}}function Wt(e){let t=[...i(e)];return t.pop(),t.length>0?t:null}function $t(...e){let[t,n]=e.length>1?e:[1,e[0]];return A((r,o)=>r,n,Q(t,n))}function Jt(e,t){return[Y(e,t),Q(e,t)]}function Ut(e,t){return[he(e,t),_e(e,t)]}function be(e){if(!e)return 0;const t=e.length||e.size;if(typeof t=="number")return t;let n=0;for(const r of i(e))n++;return n}function Zt(e){return e===!0}function Dt(e){return e===!1}function Ft(e){return e!=null}function Ht(e){return!!e}function Xt(e){return e===0}function en(e){return e<0}function tn(e){return e>0}function nn(...e){var t=0;let n={};for(;!(t>=e.length);)n[e[t]]=e[t+1],t=t+2;return n}function rn(e){return e.length}function on(e,t,n){return e[t]=n,n}function un(e){for(const t of i(e));return null}function fn(e){return b(e)}function cn(e){return[...e]}function sn(e,t,n){return e._add_watch(t,n)}function ln(e,t){return e._remove_watch(t)}function an(e,t,n){if(!n)return t;var r=t;for(let o of Object.entries(n))r=e(r,o[0],o[1]);return r}function v(e,t,...n){return t==null?e:n.length==0?e>t?e:t:v(v(e,t),...n)}function j(e,t,...n){return t==null?e:n.length==0?e<t?e:t:j(j(e,t),...n)}function pn(e){return e instanceof Object}function xn(...e){return(...t)=>{for(let n of e)for(let r of t)if(!n(r))return!1;return!0}}function dn(...e){return(...t)=>{for(let n of e)for(let r of t){let o=n(r);if(o)return o}}}function ge(e,t){return b(t||e)}function hn(e,t){var n=t;return f(function*(){for(;;)yield n,n=e(n)})}function _n(...e){return(...t)=>{let n=[];for(let r of e)n.push(r(...t));return n}}function Me(e){if(e instanceof Array){let t=e.slice(1);return t.length>0?t:null}else return Me(b(e))}function yn(e,t){if(e===t)return 0;if(e==null)return-1;if(t==null)return 1;if(typeof e=="number"){if(typeof t=="number")return e===t?0:e<t?-1:1;throw new Error("comparing number to other type")}else throw new Error("comparing number to other type")}function wn(e){return ge(e)}function ve(e,t,n){return e.substring(t,n)}function mn(e){return typeof e=="function"}function*Re(e,t){let n=e.exec(t);if(n){let r=n[0],o=n.length===1?r:b(n);yield*ee(o,f(function*(){let u=n.index+v(1,r.length);u<=t.length&&(yield*Re(e,ve(t,u)))}))}}function An(e){return typeof e=="number"}return Ie(bn);})();
|
|
1
|
+
var squint;(squint||={}).core=(()=>{var k=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Pe=(e,t)=>{for(var n in t)k(e,n,{get:t[n],enumerable:!0})},Ye=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Le(t))!Ge.call(e,o)&&o!==n&&k(e,o,{get:()=>t[o],enumerable:!(r=Be(t,o))||r.enumerable});return e};var qe=e=>Ye(k({},"__esModule",{value:!0}),e);var Wn={};Pe(Wn,{Atom:()=>ce,IIterable:()=>L,IIterable__iterator:()=>oe,LazySeq:()=>Xt,NaN_QMARK_:()=>Sn,PROTOCOL_SENTINEL:()=>st,_:()=>Ce,_PLUS_:()=>ze,_iterator:()=>Q,aclone:()=>yn,add_watch:()=>wn,alength:()=>xn,apply:()=>mt,array_QMARK_:()=>vt,aset:()=>_n,assoc:()=>m,assoc_BANG_:()=>b,assoc_in:()=>Z,assoc_in_BANG_:()=>Ve,atom:()=>pt,boolean$:()=>cn,boolean_QMARK_:()=>Cn,bounded_count:()=>$n,butlast:()=>en,coll_QMARK_:()=>Nn,comp:()=>We,compare:()=>En,complement:()=>xe,concat:()=>_e,conj:()=>F,conj_BANG_:()=>B,cons:()=>ue,constantly:()=>At,contains_QMARK_:()=>X,count:()=>R,counted_QMARK_:()=>Te,cycle:()=>Bt,dec:()=>Ze,deref:()=>se,disj:()=>Je,disj_BANG_:()=>H,dissoc:()=>Ue,dissoc_BANG_:()=>De,distinct:()=>Lt,doall:()=>hn,dorun:()=>dn,drop:()=>O,drop_last:()=>tn,drop_while:()=>Me,empty:()=>we,empty_QMARK_:()=>Jt,es6_iterator:()=>G,even_QMARK_:()=>pe,every_QMARK_:()=>Re,every_pred:()=>gn,ex_cause:()=>Gn,ex_data:()=>Bn,ex_info:()=>Pn,ex_message:()=>Ln,false_QMARK_:()=>un,ffirst:()=>He,filter:()=>q,filterv:()=>rt,find:()=>Vn,first:()=>M,fn_QMARK_:()=>Qn,fnil:()=>$,frequencies:()=>Ht,get:()=>h,get_in:()=>ve,group_by:()=>Ft,identical_QMARK_:()=>It,identity:()=>de,inc:()=>ee,int_QMARK_:()=>Ie,integer_QMARK_:()=>Yn,interleave:()=>he,interpose:()=>Et,into:()=>Ae,into_array:()=>Qe,iterable:()=>i,iterate:()=>vn,js_keys:()=>On,js_obj:()=>pn,juxt:()=>Rn,keep:()=>qt,keep_indexed:()=>it,key:()=>me,keys:()=>ke,last:()=>et,lazy:()=>c,list:()=>Mt,list_QMARK_:()=>gt,map:()=>A,map_QMARK_:()=>An,map_indexed:()=>ut,mapcat:()=>Rt,mapv:()=>ae,max:()=>E,merge:()=>jt,merge_with:()=>Ot,meta:()=>qn,min:()=>N,neg_QMARK_:()=>ln,next:()=>Se,nil_QMARK_:()=>ct,not:()=>ie,not_any_QMARK_:()=>Vt,not_every_QMARK_:()=>Yt,nth:()=>ne,number_QMARK_:()=>jn,odd_QMARK_:()=>bt,partial:()=>Tt,partition:()=>St,partition_all:()=>Qt,pos_QMARK_:()=>an,pr_str:()=>fe,println:()=>te,prn:()=>at,rand_int:()=>Ke,rand_nth:()=>Dt,range:()=>_t,re_matches:()=>dt,re_seq:()=>Oe,reduce:()=>I,reduce_kv:()=>bn,reduced:()=>tt,reduced_QMARK_:()=>nt,regexp_QMARK_:()=>Tn,remove:()=>ot,remove_watch:()=>mn,repeat:()=>C,repeatedly:()=>Zt,replace:()=>Wt,reset_BANG_:()=>le,rest:()=>Xe,reverse:()=>zt,satisfies_QMARK_:()=>$e,second:()=>Fe,select_keys:()=>Kt,seq:()=>P,seqable_QMARK_:()=>re,set:()=>wt,shuffle:()=>$t,some:()=>Ee,some_QMARK_:()=>fn,some_fn:()=>Mn,sort:()=>Ct,split_at:()=>nn,split_with:()=>rn,str:()=>ft,string_QMARK_:()=>In,subs:()=>je,subvec:()=>ht,swap_BANG_:()=>xt,system_time:()=>kt,take:()=>j,take_nth:()=>Nt,take_while:()=>ge,to_array:()=>Kn,true_QMARK_:()=>on,update:()=>Gt,update_BANG_:()=>V,update_in:()=>Pt,val:()=>be,vals:()=>kn,vec:()=>g,vector:()=>z,vector_QMARK_:()=>yt,with_meta:()=>zn,zero_QMARK_:()=>sn});function ze(...e){return e.reduce((t,n)=>t+n,0)}function Ce(...e){return e.reduce((t,n)=>t-n)}function $e(e,t){return t[e]}function b(e,t,n,...r){if(r.length%2!==0)throw new Error("Illegal argument: assoc expects an odd number of arguments.");switch(s(e)){case p:e.set(t,n);for(let o=0;o<r.length;o+=2)e.set(r[o],r[o+1]);break;case x:case _:e[t]=n;for(let o=0;o<r.length;o+=2)e[r[o]]=r[o+1];break;default:throw new Error("Illegal argument: assoc! expects a Map, Array, or Object as the first argument.")}return e}function D(e){switch(s(e)){case p:return new Map(e.entries());case x:return[...e];case _:return{...e};default:throw new Error(`Don't know how to copy object of type ${typeof e}.`)}}function m(e,t,n,...r){e||(e={});let o=D(e);return b(o,t,n,...r),o}const p=1,x=2,_=3,w=4,d=5,K=6;function T(e){switch(e){case p:return new Map;case x:return[];case _:return{};case w:return new S;case d:return new Set;case K:return c(function*(){})}}function s(e){if(e instanceof Map)return p;if(e instanceof Set)return d;if(e instanceof S)return w;if(e instanceof Array)return x;if(e instanceof Y)return K;if(e instanceof Object)return _}function U(e,t,n,r,o){let u=s(n);if(u!==p&&u!==x&&u!==_)throw new Error(`Illegal argument: ${t} expects the first argument to be a Map, Array, or Object.`);const f=[n];let a=n;for(let l=0;l<r.length-1;l+=1){let J=r[l],y;a instanceof Map?y=a.get(J):y=a[J],y||(y=T(u)),f.push(y),a=y}f.push(o);for(let l=f.length-2;l>=0;l-=1)f[l]=e(f[l],r[l],f[l+1]);return f[0]}function Z(e,t,n){return U(m,"assoc-in",e,t,n)}function Ve(e,t,n){return U(b,"assoc-in!",e,t,n)}function We(...e){if(e.length===0)return de;if(e.length===1)return e[0];let[t,...n]=e.slice().reverse();return function(...r){let o=t(...r);for(const u of n)o=u(o);return o}}function B(...e){if(e.length===0)return z();let[t,...n]=e;switch(t==null&&(t=[]),s(t)){case d:for(const r of n)t.add(r);break;case w:t.unshift(...n.reverse());break;case x:t.push(...n);break;case p:for(const r of n)r instanceof Array?t.set(r[0],r[1]):i(r).forEach(o=>{t.set(o[0],o[1])});break;case _:for(const r of n)r instanceof Array?t[r[0]]=r[1]:Object.assign(t,r);break;default:throw new Error("Illegal argument: conj! expects a Set, Array, List, Map, or Object as the first argument.")}return t}function F(...e){if(e.length===0)return z();let[t,...n]=e;switch(t==null&&(t=[]),s(t)){case d:return new Set([...t,...n]);case w:return new S(...n.reverse(),...t);case x:return[...t,...n];case p:const r=new Map(t);for(const u of n)u instanceof Array?r.set(u[0],u[1]):i(u).forEach(f=>{r.set(f[0],f[1])});return r;case K:return c(function*(){yield*n,yield*t});case _:const o={...t};for(const u of n)u instanceof Array?o[u[0]]=u[1]:Object.assign(o,u);return o;default:throw new Error("Illegal argument: conj expects a Set, Array, List, Map, or Object as the first argument.")}}function H(e,...t){for(const n of t)e.delete(n);return e}function Je(e,...t){let n=new Set([...e]);return H(n,...t)}function X(e,t){switch(s(e)){case d:case p:return e.has(t);case void 0:return!1;default:return t in e}}function De(e,...t){for(const n of t)delete e[n];return e}function Ue(e,...t){let n={...e};for(const r of t)delete n[r];return n}function ee(e){return e+1}function Ze(e){return e-1}function te(...e){console.log(...e)}function ne(e,t,n){if(e){var r=void 0;if(e instanceof Array)r=e[t];else{let o=i(e),u=0;for(let f of o)if(u++==t){r=f;break}}if(r!==void 0)return r}return n}function h(e,t,n=void 0){let r;switch(s(e)){case d:e.has(t)&&(r=t);break;case p:r=e.get(t);break;case void 0:break;default:r=e[t];break}return r!==void 0?r:n}function re(e){return typeof e=="string"||e===null||e===void 0||e instanceof Object&&Symbol.iterator in e}function i(e){return e==null?[]:re(e)?e:Object.entries(e)}const L=Symbol("Iterable"),oe=Symbol.iterator;function Q(e){return e[Symbol.iterator]()}const G=Q;function P(e){let t=i(e);return t.length===0||t.size===0?null:t}function M(e){let[t]=i(e);return t}function Fe(e){let[t,n]=i(e);return n}function He(e){return M(M(e))}function Xe(e){return c(function*(){let t=!0;for(const n of i(e))t?t=!1:yield n})}class v{value;constructor(t){this.value=t}_deref(){return this.value}}function et(e){switch(e=i(e),s(e)){case x:return e[e.length-1];default:let t;for(const n of e)t=n;return t}}function tt(e){return new v(e)}function nt(e){return e instanceof v}function I(e,t,n){let r,o;if(n===void 0){let u=i(t)[Symbol.iterator]();o=u.next().value,r=u}else o=t,r=i(n);if(o instanceof v)return o.value;for(const u of r)if(o=e(o,u),o instanceof v){o=o.value;break}return o}class Y{constructor(t){this.gen=t}[Symbol.iterator](){return this.gen()}}Y.prototype[L]=!0;function c(e){return new Y(e)}function ue(e,t){return c(function*(){yield e,yield*i(t)})}function A(e,...t){switch(t.length){case 0:throw new Error("map with 2 arguments is not supported yet");case 1:return c(function*(){for(const n of i(t[0]))yield e(n)});default:return c(function*(){const n=t.map(r=>G(i(r)));for(;;){let r=[];for(const o of n){const u=o.next();if(u.done)return;r.push(u.value)}yield e(...r)}})}}function q(e,t){return c(function*(){for(const n of i(t))e(n)&&(yield n)})}function rt(e,t){return[...q(e,t)]}function ot(e,t){return q(xe(e),t)}function ut(e,t){let n=[],r=0;for(const o of i(t))n.push(e(r,o)),r++;return n}function it(e,t){let n=[],r=0;for(const o of i(t)){let u=e(r,o);u&&n.push(u),r++}return n}function ft(...e){return e.join("")}function ie(e){return!e}function ct(e){return e==null}const st={};function lt(e){return JSON.stringify(e,(t,n)=>{switch(s(n)){case d:case K:return[...n];case p:return Object.fromEntries(n);default:return n}})}function fe(...e){return e.map(lt).join(" ")}function at(...e){te(fe(...e))}function ce(e){this.val=e,this._watches={},this._deref=()=>this.val,this._hasWatches=!1,this._reset_BANG_=t=>{let n=this.val;if(this.val=t,this._hasWatches)for(let r of Object.entries(this._watches)){let o=r[0],u=r[1];u(o,this,n,t)}return t},this._add_watch=(t,n)=>{this._watches[t]=n,this._hasWatches=!0},this._remove_watch=t=>{delete this._watches[t]}}function pt(e){return new ce(e)}function se(e){return e._deref()}function le(e,t){e._reset_BANG_(t)}function xt(e,t,...n){const r=t(se(e),...n);return le(e,r),r}function _t(e,t,n){return c(function*(){let r=e,o=t,u=n;t===void 0&&(r=0,o=e);let f=r||0;for(u=n||1;o===void 0||f<o;)yield f,f+=u})}function dt(e,t){let n=e.exec(t);if(n&&t===n[0])return n.length===1?n[0]:n}function ht(e,t,n){return e.slice(t,n)}function z(...e){return e}function yt(e){return s(e)===x}function ae(...e){return[...A(...e)]}function g(e){return[...i(e)]}function wt(e){return new Set(i(e))}function mt(e,...t){const n=t.slice(0,t.length-1),r=t[t.length-1];return e(...n,...r)}function pe(e){return e%2==0}function bt(e){return!pe(e)}function xe(e){return(...t)=>ie(e(...t))}function At(e){return(...t)=>e}class S extends Array{constructor(...t){super(),this.push(...t)}}function gt(e){return s(e)===w}function Mt(...e){return new S(...e)}function vt(e){return e instanceof Array}function _e(...e){return c(function*(){for(const t of e)yield*i(t)})}function Rt(e,...t){return _e(...A(e,...t))}function de(e){return e}function he(...e){return c(function*(){const t=e.map(n=>G(i(n)));for(;;){let n=[];for(const r of t){const o=r.next();if(o.done)return;n.push(o.value)}yield*n}})}function Et(e,t){return O(1,he(C(e),t))}function Kt(e,t){const n=s(e),r=T(n);for(const o of t){const u=h(e,o);u!=null&&b(r,o,u)}return r}function Qt(e,...t){let n=e,r=t[0];return t.length===2&&([n,r]=t),ye(e,n,[],r,!0)}function St(e,...t){let n=e,r=[],o=t[0];return t.length===2?[n,o]=t:t.length>2&&([n,r,o]=t),ye(e,n,r,o,!1)}function ye(e,t,n,r,o){return c(function*(){let u=[],f=0;for(let a of i(r))f<e&&(u.push(a),u.length===e&&(yield u,u=t<e?u.slice(t):[])),f++,f===t&&(f=0);u.length>0&&(u.length===e||o?yield u:n.length&&(u.push(...n.slice(0,e-u.length)),yield u))})}function we(e){const t=s(e);if(t!=null)return T(t);throw new Error(`Can't create empty of ${typeof e}`)}function jt(...e){const t=e[0];let n;return t==null?n={}:n=Ae(we(t),t),B(n,...e.slice(1))}function me(e){return e[0]}function be(e){return e[1]}function Ot(e,...t){var n=!1;for(const r of t)if(r!=null){n=!0;break}if(n){let r=(u,f)=>{let a=me(f),l=be(f);return X(u,a)?m(u,a,e(h(u,a),l)):m(u,a,l)};return I((u,f)=>I(r,u||{},P(f)),t)}else return null}function kt(){return performance.now()}function Ae(...e){switch(e.length){case 0:return[];case 1:return e[0];default:return F(e[0]??[],...i(e[1]))}}function It(e,t){return e===t}function C(...e){if(e.length==0||e.length>2)throw new Error(`Invalid arity: ${e.length}`);return{[L]:!0,[oe]:e.length==1?function*(){let t=e[0];for(;;)yield t}:function*(){let[t,n]=e;for(var r=0;r<t;r++)yield n}}}function j(e,t){return c(function*(){let n=e-1;for(const r of i(t))if(n-->=0&&(yield r),n<0)return})}function ge(e,t){return c(function*(){for(const n of i(t))if(e(n))yield n;else return})}function Nt(e,t){return e<=0?C(M(t)):c(function*(){let n=0;for(let r of i(t))n%e===0&&(yield r),n++})}function Tt(e,...t){return function(...n){return e(...t,...n)}}function Bt(e){return c(function*(){for(;;)yield*e})}function O(e,t){return c(function*(){let n=Q(i(t));for(let r=0;r<e;r++)n.next();yield*n})}function Me(e,t){return c(function*(){let n=Q(i(t));for(;;){let r=n.next();if(r.done)break;let o=r.value;if(!e(o)){yield o;break}}yield*n})}function Lt(e){return c(function*(){let t=new Set;for(const n of i(e))t.has(n)||(yield n),t.add(n)})}function Gt(e,t,n,...r){return m(e,t,n(h(e,t),...r))}function ve(e,t,n){let r=e;for(const o of t)r=h(r,o);return r===void 0?n:r}function Pt(e,t,n,...r){return Z(e,t,n(ve(e,t),...r))}function $(e,t,...n){return function(r,...o){return r?e(r,...n,...o):e(t,...n,...o)}}function Re(e,t){for(let n of i(t))if(!e(n))return!1;return!0}function Yt(e,t){return!Re(e,t)}function qt(e,t){return c(function*(){for(const n of i(t)){const r=e(n);r&&(yield r)}})}function zt(e){return e instanceof Array?e.reverse():[...e].reverse()}function Ct(e,t){return t===void 0&&(t=e,e=void 0),[...t].sort(e)}function $t(e){return[...e].sort(function(t,n){return Math.random()-.5})}function Ee(e,t){for(const n of i(t)){const r=e(n);if(r)return r}}function Vt(e,t){return!Ee(e,t)}function Wt(e,t){return(t instanceof Array?ae:A)(r=>{const o=e[r];return o!==void 0?o:r},t)}function Jt(e){return!P(e)}function Ke(e){return Math.floor(Math.random()*e)}function Dt(e){let t=Ke(R(e));return ne(e,t)}function Ut(e){return c(function*(){for(;;)yield e()})}function Zt(e,t){t===void 0&&(t=e,e=void 0);const n=Ut(t);return e?j(e,n):n}function V(e,t,n,...r){const o=h(e,t);return b(e,t,n(o,...r))}function Ft(e,t){const n={};for(const r of i(t)){const o=e(r);V(n,o,$(B,[]),r)}return n}function Ht(e){const t={},n=$(ee,0);for(const r of i(e))V(t,r,n);return t}class Xt{constructor(t){this.f=t}*[Symbol.iterator](){yield*i(this.f())}}function en(e){let t=[...i(e)];return t.pop(),t.length>0?t:null}function tn(...e){let[t,n]=e.length>1?e:[1,e[0]];return A((r,o)=>r,n,O(t,n))}function nn(e,t){return[j(e,t),O(e,t)]}function rn(e,t){return[ge(e,t),Me(e,t)]}function R(e){if(!e)return 0;const t=e.length||e.size;if(typeof t=="number")return t;let n=0;for(const r of i(e))n++;return n}function on(e){return e===!0}function un(e){return e===!1}function fn(e){return e!=null}function cn(e){return!!e}function sn(e){return e===0}function ln(e){return e<0}function an(e){return e>0}function pn(...e){var t=0;let n={};for(;!(t>=e.length);)n[e[t]]=e[t+1],t=t+2;return n}function xn(e){return e.length}function _n(e,t,n){return e[t]=n,n}function dn(e){for(const t of i(e));return null}function hn(e){return g(e)}function yn(e){return[...e]}function wn(e,t,n){return e._add_watch(t,n)}function mn(e,t){return e._remove_watch(t)}function bn(e,t,n){if(!n)return t;var r=t;for(let o of Object.entries(n))r=e(r,o[0],o[1]);return r}function E(e,t,...n){return t==null?e:n.length==0?e>t?e:t:E(E(e,t),...n)}function N(e,t,...n){return t==null?e:n.length==0?e<t?e:t:N(N(e,t),...n)}function An(e){return e instanceof Object}function gn(...e){return(...t)=>{for(let n of e)for(let r of t)if(!n(r))return!1;return!0}}function Mn(...e){return(...t)=>{for(let n of e)for(let r of t){let o=n(r);if(o)return o}}}function Qe(e,t){return g(t||e)}function vn(e,t){var n=t;return c(function*(){for(;;)yield n,n=e(n)})}function Rn(...e){return(...t)=>{let n=[];for(let r of e)n.push(r(...t));return n}}function Se(e){if(e instanceof Array){let t=e.slice(1);return t.length>0?t:null}else return Se(g(e))}function En(e,t){if(e===t)return 0;if(e==null)return-1;if(t==null)return 1;if(typeof e=="number"){if(typeof t=="number")return e===t?0:e<t?-1:1;throw new Error("comparing number to other type")}else throw new Error("comparing number to other type")}function Kn(e){return Qe(e)}function je(e,t,n){return e.substring(t,n)}function Qn(e){return typeof e=="function"}function*Oe(e,t){let n=e.exec(t);if(n){let r=n[0],o=n.length===1?r:g(n);yield*ue(o,c(function*(){let u=n.index+E(1,r.length);u<=t.length&&(yield*Oe(e,je(t,u)))}))}}function Sn(e){return Number.isNaN(e)}function jn(e){return typeof e=="number"}function ke(e){return e?Object.keys(e):null}function On(e){return ke(e)}function kn(e){return e?Object.values(e):null}function In(e){return typeof e=="string"}function Nn(e){return s(e)!=null}function Tn(e){return e instanceof RegExp}class W extends Error{constructor(t,n,r){super(t),this._data=n,this._cause=r}}function Bn(e){return e instanceof W?e._data:null}function Ln(e){return e instanceof Error?e.message:null}function Gn(e){return e instanceof W?e._cause:null}function Pn(e,t,n){return new W(e,t,n)}function Ie(e){return Number.isInteger(e)}const Yn=Ie,Ne=Symbol("meta");function qn(e){return e instanceof Object?e[Ne]:null}function zn(e,t){let n=D(e);return n[Ne]=t,n}function Cn(e){return e===!0||e===!1}function Te(e){switch(s(e)){case d:return!0}return!1}function $n(e,t){return Te(t)?R(t):R(j(e,t))}function Vn(e,t){let n=h(e,t);if(n!==void 0)return[t,n]}return qe(Wn);})();
|
package/package.json
CHANGED
package/src/squint/core.js
CHANGED
|
@@ -41,22 +41,26 @@ export function assoc_BANG_(m, k, v, ...kvs) {
|
|
|
41
41
|
return m;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
if (!o) {
|
|
46
|
-
o = {};
|
|
47
|
-
}
|
|
44
|
+
function copy(o) {
|
|
48
45
|
switch (typeConst(o)) {
|
|
49
46
|
case MAP_TYPE:
|
|
50
|
-
return
|
|
47
|
+
return new Map(o.entries());
|
|
51
48
|
case ARRAY_TYPE:
|
|
52
|
-
return
|
|
49
|
+
return [...o];
|
|
53
50
|
case OBJECT_TYPE:
|
|
54
|
-
return
|
|
51
|
+
return { ...o };
|
|
55
52
|
default:
|
|
56
|
-
throw new Error(
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
throw new Error(`Don't know how to copy object of type ${typeof o}.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function assoc(o, k, v, ...kvs) {
|
|
58
|
+
if (!o) {
|
|
59
|
+
o = {};
|
|
59
60
|
}
|
|
61
|
+
let ret = copy(o);
|
|
62
|
+
assoc_BANG_(ret, k, v, ...kvs);
|
|
63
|
+
return ret;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
const MAP_TYPE = 1;
|
|
@@ -345,7 +349,12 @@ export function get(coll, key, otherwise = undefined) {
|
|
|
345
349
|
|
|
346
350
|
export function seqable_QMARK_(x) {
|
|
347
351
|
// String is iterable but doesn't allow `m in s`
|
|
348
|
-
return
|
|
352
|
+
return (
|
|
353
|
+
typeof x === 'string' ||
|
|
354
|
+
x === null ||
|
|
355
|
+
x === undefined ||
|
|
356
|
+
(x instanceof Object && Symbol.iterator in x)
|
|
357
|
+
);
|
|
349
358
|
}
|
|
350
359
|
|
|
351
360
|
export function iterable(x) {
|
|
@@ -483,6 +492,9 @@ export function cons(x, coll) {
|
|
|
483
492
|
}
|
|
484
493
|
|
|
485
494
|
export function map(f, ...colls) {
|
|
495
|
+
// if (! (f instanceof Function)) {
|
|
496
|
+
// throw new Error(`Argument f must be a function but is ${typeof(f)}`);
|
|
497
|
+
// }
|
|
486
498
|
switch (colls.length) {
|
|
487
499
|
case 0:
|
|
488
500
|
throw new Error('map with 2 arguments is not supported yet');
|
|
@@ -829,7 +841,11 @@ function partitionInternal(n, step, pad, coll, all) {
|
|
|
829
841
|
|
|
830
842
|
export function empty(coll) {
|
|
831
843
|
const type = typeConst(coll);
|
|
832
|
-
|
|
844
|
+
if (type != null) {
|
|
845
|
+
return emptyOfType(type);
|
|
846
|
+
} else {
|
|
847
|
+
throw new Error(`Can't create empty of ${typeof coll}`);
|
|
848
|
+
}
|
|
833
849
|
}
|
|
834
850
|
|
|
835
851
|
export function merge(...args) {
|
|
@@ -844,6 +860,41 @@ export function merge(...args) {
|
|
|
844
860
|
return conj_BANG_(obj, ...args.slice(1));
|
|
845
861
|
}
|
|
846
862
|
|
|
863
|
+
export function key(entry) {
|
|
864
|
+
return entry[0];
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
export function val(entry) {
|
|
868
|
+
return entry[1];
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
export function merge_with(f, ...maps) {
|
|
872
|
+
var hasMap = false;
|
|
873
|
+
for (const m of maps) {
|
|
874
|
+
if (m != null) {
|
|
875
|
+
hasMap = true;
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
if (hasMap) {
|
|
880
|
+
let mergeEntry = (m, e) => {
|
|
881
|
+
let k = key(e);
|
|
882
|
+
let v = val(e);
|
|
883
|
+
if (contains_QMARK_(m, k)) {
|
|
884
|
+
return assoc(m, k, f(get(m, k), v));
|
|
885
|
+
} else {
|
|
886
|
+
return assoc(m, k, v);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
let merge2 = (m1, m2) => {
|
|
890
|
+
return reduce(mergeEntry, m1 || {}, seq(m2));
|
|
891
|
+
};
|
|
892
|
+
return reduce(merge2, maps);
|
|
893
|
+
} else {
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
847
898
|
export function system_time() {
|
|
848
899
|
return performance.now();
|
|
849
900
|
}
|
|
@@ -1373,29 +1424,142 @@ export function to_array(aseq) {
|
|
|
1373
1424
|
// return ( x != null && x !== false );
|
|
1374
1425
|
// }
|
|
1375
1426
|
|
|
1376
|
-
|
|
1377
1427
|
export function subs(s, start, end) {
|
|
1378
1428
|
return s.substring(start, end);
|
|
1379
1429
|
}
|
|
1380
1430
|
|
|
1381
1431
|
export function fn_QMARK_(x) {
|
|
1382
|
-
return
|
|
1432
|
+
return 'function' === typeof x;
|
|
1383
1433
|
}
|
|
1384
1434
|
|
|
1385
1435
|
export function* re_seq(re, s) {
|
|
1386
1436
|
let matches = re.exec(s);
|
|
1387
1437
|
if (matches) {
|
|
1388
1438
|
let match_str = matches[0];
|
|
1389
|
-
let match_vals =
|
|
1390
|
-
yield* cons(
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1439
|
+
let match_vals = matches.length === 1 ? match_str : vec(matches);
|
|
1440
|
+
yield* cons(
|
|
1441
|
+
match_vals,
|
|
1442
|
+
lazy(function* () {
|
|
1443
|
+
let post_idx = matches.index + max(1, match_str.length);
|
|
1444
|
+
if (post_idx <= s.length) {
|
|
1445
|
+
yield* re_seq(re, subs(s, post_idx));
|
|
1446
|
+
}
|
|
1447
|
+
})
|
|
1448
|
+
);
|
|
1396
1449
|
}
|
|
1397
1450
|
}
|
|
1398
1451
|
|
|
1452
|
+
export function NaN_QMARK_(x) {
|
|
1453
|
+
return Number.isNaN(x);
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1399
1456
|
export function number_QMARK_(x) {
|
|
1400
1457
|
return typeof x == 'number';
|
|
1401
1458
|
}
|
|
1459
|
+
|
|
1460
|
+
export function keys(obj) {
|
|
1461
|
+
if (obj) {
|
|
1462
|
+
return Object.keys(obj);
|
|
1463
|
+
} else {
|
|
1464
|
+
return null;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
export function js_keys(obj) {
|
|
1469
|
+
return keys(obj);
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
export function vals(obj) {
|
|
1473
|
+
if (obj) {
|
|
1474
|
+
return Object.values(obj);
|
|
1475
|
+
} else {
|
|
1476
|
+
return null;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
export function string_QMARK_(s) {
|
|
1481
|
+
return typeof s === 'string';
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
export function coll_QMARK_(coll) {
|
|
1485
|
+
return typeConst(coll) != undefined;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
export function regexp_QMARK_(coll) {
|
|
1489
|
+
return coll instanceof RegExp;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
class ExceptionInfo extends Error {
|
|
1493
|
+
constructor(message, data, cause) {
|
|
1494
|
+
super(message);
|
|
1495
|
+
this._data = data;
|
|
1496
|
+
this._cause = cause;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
export function ex_data(e) {
|
|
1501
|
+
if (e instanceof ExceptionInfo) return e._data;
|
|
1502
|
+
else return null;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
export function ex_message(e) {
|
|
1506
|
+
if (e instanceof Error) return e.message;
|
|
1507
|
+
else return null;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
export function ex_cause(e) {
|
|
1511
|
+
if (e instanceof ExceptionInfo) return e._cause;
|
|
1512
|
+
else return null;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
export function ex_info(message, data, cause) {
|
|
1516
|
+
return new ExceptionInfo(message, data, cause);
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
export function int_QMARK_(x) {
|
|
1520
|
+
return Number.isInteger(x);
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
export const integer_QMARK_ = int_QMARK_;
|
|
1524
|
+
|
|
1525
|
+
const _metaSym = Symbol('meta');
|
|
1526
|
+
|
|
1527
|
+
export function meta(x) {
|
|
1528
|
+
if (x instanceof Object) {
|
|
1529
|
+
return x[_metaSym];
|
|
1530
|
+
} else return null;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
export function with_meta(x, m) {
|
|
1534
|
+
let ret = copy(x);
|
|
1535
|
+
ret[_metaSym] = m;
|
|
1536
|
+
return ret;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
export function boolean_QMARK_(x) {
|
|
1540
|
+
return x === true || x === false;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
export function counted_QMARK_(x) {
|
|
1544
|
+
let tc = typeConst(x);
|
|
1545
|
+
switch (tc) {
|
|
1546
|
+
case (ARRAY_TYPE, MAP_TYPE, OBJECT_TYPE, LIST_TYPE, SET_TYPE):
|
|
1547
|
+
return true;
|
|
1548
|
+
}
|
|
1549
|
+
return false;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
export function bounded_count(n, coll) {
|
|
1553
|
+
if (counted_QMARK_(coll)) {
|
|
1554
|
+
return count(coll);
|
|
1555
|
+
} else {
|
|
1556
|
+
return count(take(n, coll));
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
export function find(m, k) {
|
|
1561
|
+
let v = get(m, k);
|
|
1562
|
+
if (v !== undefined) {
|
|
1563
|
+
return [k, v];
|
|
1564
|
+
}
|
|
1565
|
+
}
|
package/string.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { iterable } from './core.js';
|
|
1
|
+
import { iterable, string_QMARK_ } from './core.js';
|
|
2
2
|
|
|
3
3
|
export function blank_QMARK_(s) {
|
|
4
4
|
if (!s) return true;
|
|
@@ -29,6 +29,14 @@ export function trim(s) {
|
|
|
29
29
|
return s.trim();
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export function triml(s) {
|
|
33
|
+
return s.trimLeft();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function trimr(s) {
|
|
37
|
+
return s.trimRight();
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
export function split(s, re) {
|
|
33
41
|
return s.split(re);
|
|
34
42
|
}
|
|
@@ -36,3 +44,48 @@ export function split(s, re) {
|
|
|
36
44
|
export function starts_with_QMARK_(s, substr) {
|
|
37
45
|
return s.startsWith(substr);
|
|
38
46
|
}
|
|
47
|
+
|
|
48
|
+
const escapeRegex = function(s) {
|
|
49
|
+
return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').replace(/\x08/g, '\\x08');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const replaceAll = function(s, re, replacement) {
|
|
53
|
+
var flags = "g";
|
|
54
|
+
if (re.ignoreCase) {
|
|
55
|
+
flags += "i";
|
|
56
|
+
}
|
|
57
|
+
if (re.multiline) {
|
|
58
|
+
flags += "m";
|
|
59
|
+
}
|
|
60
|
+
if (re.unicode) {
|
|
61
|
+
flags += "u";
|
|
62
|
+
}
|
|
63
|
+
let r = new RegExp(re.source, flags);
|
|
64
|
+
return s.replace(r, replacement);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const replaceWith = function(f) {
|
|
68
|
+
return (...args) => {
|
|
69
|
+
let [matches, _, __] = args;
|
|
70
|
+
if (matches.length == 1) {
|
|
71
|
+
return f(matches[0]);
|
|
72
|
+
} else {
|
|
73
|
+
return f(matches);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export function replace(s, match, replacement) {
|
|
79
|
+
if (string_QMARK_(match)) {
|
|
80
|
+
return s.replace(new RegExp(escapeRegex(match), "g"), replacement);
|
|
81
|
+
}
|
|
82
|
+
if (match instanceof RegExp) {
|
|
83
|
+
if (string_QMARK_(replacement)) {
|
|
84
|
+
return replaceAll(s, match, replacement);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return replaceAll(s, match, replaceWith(replacement));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw `Invalid match arg: $match`;
|
|
91
|
+
};
|