string-left-right 5.0.10 → 5.0.11
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/LICENSE +1 -1
- package/README.md +2 -6
- package/dist/string-left-right.esm.js +4 -4
- package/dist/string-left-right.umd.js +2 -2
- package/package.json +4 -2
- package/types/index.d.ts +36 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -26,14 +26,12 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `4.1.0`.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
npm i string-left-right
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
If you need a legacy version which works with `require`, use version 4.1.0
|
|
36
|
-
|
|
37
35
|
## Quick Take
|
|
38
36
|
|
|
39
37
|
```js
|
|
@@ -76,8 +74,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
76
74
|
|
|
77
75
|
MIT License
|
|
78
76
|
|
|
79
|
-
Copyright (c) 2010-
|
|
80
|
-
|
|
77
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
81
78
|
|
|
82
79
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
83
|
-
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-left-right
|
|
3
3
|
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-left-right/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import c from"lodash.isplainobject";import f from"lodash.clonedeep";var S="5.0.
|
|
10
|
+
import c from"lodash.isplainobject";import f from"lodash.clonedeep";var S="5.0.11";var C=S,h="\xA0";function I(n){let e={value:n,hungry:!1,optional:!1};return(e.value.endsWith("?*")||e.value.endsWith("*?"))&&e.value.length>2?(e.value=e.value.slice(0,e.value.length-2),e.optional=!0,e.hungry=!0):e.value.endsWith("?")&&e.value.length>1?(e.value=e.value.slice(0,~-e.value.length),e.optional=!0):e.value.endsWith("*")&&e.value.length>1&&(e.value=e.value.slice(0,~-e.value.length),e.hungry=!0),e}function R(n){return typeof n=="number"}function p(n){return typeof n=="string"}function E({str:n,idx:e=0,stopAtNewlines:l=!1,stopAtRawNbsp:u=!1}){if(typeof n!="string"||!n.length||((!e||typeof e!="number")&&(e=0),!n[e+1]))return null;if(n[e+1]&&(n[e+1].trim()||l&&`
|
|
11
11
|
\r`.includes(n[e+1])||u&&n[e+1]===h))return e+1;if(n[e+2]&&(n[e+2].trim()||l&&`
|
|
12
|
-
\r`.includes(n[e+2])||u&&n[e+2]===h))return e+2;for(let t=e+1,
|
|
12
|
+
\r`.includes(n[e+2])||u&&n[e+2]===h))return e+2;for(let t=e+1,m=n.length;t<m;t++)if(n[t].trim()||l&&`
|
|
13
13
|
\r`.includes(n[t])||u&&n[t]===h)return t;return null}function y(n,e=0){return E({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function j(n,e){return E({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function k(n,e){return E({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function D({str:n,idx:e,stopAtNewlines:l,stopAtRawNbsp:u}){if(typeof n!="string"||!n.length||((!e||typeof e!="number")&&(e=0),e<1))return null;if(n[~-e]&&(n[~-e].trim()||l&&`
|
|
14
14
|
\r`.includes(n[~-e])||u&&n[~-e]===h))return~-e;if(n[e-2]&&(n[e-2].trim()||l&&`
|
|
15
15
|
\r`.includes(n[e-2])||u&&n[e-2]===h))return e-2;for(let t=e;t--;)if(n[t]&&(n[t].trim()||l&&`
|
|
16
|
-
\r`.includes(n[t])||u&&n[t]===h))return t;return null}function V(n,e=0){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function M(n,e){return D({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function W(n,e){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function O(n,e,l,u,t){if(typeof e!="string"||!e.length||(typeof l!="number"&&(l=0),n==="right"&&!e[l+1]||n==="left"&&!e[~-l]))return null;let
|
|
16
|
+
\r`.includes(n[t])||u&&n[t]===h))return t;return null}function V(n,e=0){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function M(n,e){return D({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function W(n,e){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function O(n,e,l,u,t){if(typeof e!="string"||!e.length||(typeof l!="number"&&(l=0),n==="right"&&!e[l+1]||n==="left"&&!e[~-l]))return null;let m=l,o=[],a,i,s,r=0;for(;r<t.length;){if(!p(t[r])||!t[r].length){r+=1;continue}let{value:$,optional:w,hungry:T}=I(t[r]),g=n==="right"?y(e,m):V(e,m);if(u.i&&e[g].toLowerCase()===$.toLowerCase()||!u.i&&e[g]===$){let N=n==="right"?y(e,g):V(e,g);T&&(u.i&&e[N].toLowerCase()===$.toLowerCase()||!u.i&&e[N]===$)?s=!0:r+=1,typeof g=="number"&&n==="right"&&g>m+1?o.push([m+1,g]):n==="left"&&typeof g=="number"&&g<~-m&&o.unshift([g+1,m]),m=g,n==="right"?(a===void 0&&(a=g),i=g):(i===void 0&&(i=g),a=g)}else if(w){r+=1;continue}else if(s){r+=1,s=void 0;continue}else return null}return a===void 0||i===void 0?null:{gaps:o,leftmostChar:a,rightmostChar:i}}var d={i:!1};function J(n,e,...l){if(!l||!l.length)throw new Error("string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?");let u;return c(l[0])?u={...d,...l.shift()}:u=d,O("left",n,e,u,Array.from(l).reverse())}function L(n,e,...l){if(!l||!l.length)throw new Error("string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?");let u;return c(l[0])?u={...d,...l.shift()}:u=d,O("right",n,e,u,l)}function b(n,e,l,u,t=[]){if(typeof e!="string"||!e.length||((!l||typeof l!="number")&&(l=0),n==="right"&&!e[l+1]||n==="left"&&+l==0))return null;let m=null,o=null;do m=n==="right"?L(e,typeof o=="number"?o:l,...t):J(e,typeof o=="number"?o:l,...t),m!==null&&(o=n==="right"?m.rightmostChar:m.leftmostChar);while(m);if(o!=null&&n==="right"&&(o+=1),o===null)return null;if(n==="right"){if(e[o]?.trim())return o;let i=y(e,o);if(!u||u.mode===0){if(i===o+1)return o;if(e.slice(o,i||e.length).trim()||e.slice(o,i||e.length).includes(`
|
|
17
17
|
`)||e.slice(o,i||e.length).includes("\r")){for(let s=o,r=e.length;s<r;s++)if(`
|
|
18
18
|
\r`.includes(e[s]))return s}else return i?~-i:e.length}else{if(u.mode===1)return o;if(u.mode===2){let s=e.slice(o);if(s.trim()||s.includes(`
|
|
19
19
|
`)||s.includes("\r")){for(let r=o,$=e.length;r<$;r++)if(e[r].trim()||`
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-left-right
|
|
3
3
|
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-left-right/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var stringLeftRight=(()=>{var pt=Object.create;var A=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,$t=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))fe.call(t,n)&&ge(e,n,t[n]);if(ce)for(var n of ce(t))dt.call(t,n)&&ge(e,n,t[n]);return e};var he=e=>A(e,"__esModule",{value:!0});var pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},me=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bt(t))!fe.call(e,o)&&(n||o!=="default")&&A(e,o,{get:()=>t[o],enumerable:!(r=mt(t,o))||r.enumerable});return e},be=(e,t)=>me(he(A(e!=null?pt($t(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),Et=(e=>(t,n)=>e&&e.get(t)||(n=me(he({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var Ee=pe((br,ye)=>{var St="[object Object]";function Ot(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function _t(e,t){return function(n){return e(t(n))}}var wt=Function.prototype,$e=Object.prototype,de=wt.toString,Tt=$e.hasOwnProperty,Dt=de.call(Object),vt=$e.toString,Vt=_t(Object.getPrototypeOf,Object);function Nt(e){return!!e&&typeof e=="object"}function Rt(e){if(!Nt(e)||vt.call(e)!=St||Ot(e))return!1;var t=Vt(e);if(t===null)return!0;var n=Tt.call(t,"constructor")&&t.constructor;return typeof n=="function"&&n instanceof n&&de.call(n)==Dt}ye.exports=Rt});var st=pe((j,v)=>{var At=200,Se="__lodash_hash_undefined__",Oe=9007199254740991,K="[object Arguments]",Ct="[object Array]",_e="[object Boolean]",we="[object Date]",It="[object Error]",k="[object Function]",Te="[object GeneratorFunction]",F="[object Map]",De="[object Number]",Y="[object Object]",ve="[object Promise]",Ve="[object RegExp]",U="[object Set]",Ne="[object String]",Re="[object Symbol]",X="[object WeakMap]",Ae="[object ArrayBuffer]",J="[object DataView]",Ce="[object Float32Array]",Ie="[object Float64Array]",je="[object Int8Array]",Le="[object Int16Array]",Fe="[object Int32Array]",Ue="[object Uint8Array]",Je="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Me="[object Uint32Array]",jt=/[\\^$.*+?()[\]{}|]/g,Lt=/\w*$/,Ft=/^\[object .+?Constructor\]$/,Ut=/^(?:0|[1-9]\d*)$/,s={};s[K]=s[Ct]=s[Ae]=s[J]=s[_e]=s[we]=s[Ce]=s[Ie]=s[je]=s[Le]=s[Fe]=s[F]=s[De]=s[Y]=s[Ve]=s[U]=s[Ne]=s[Re]=s[Ue]=s[Je]=s[Pe]=s[Me]=!0;s[It]=s[k]=s[X]=!1;var Jt=typeof global=="object"&&global&&global.Object===Object&&global,Pt=typeof self=="object"&&self&&self.Object===Object&&self,m=Jt||Pt||Function("return this")(),qe=typeof j=="object"&&j&&!j.nodeType&&j,xe=qe&&typeof v=="object"&&v&&!v.nodeType&&v,Mt=xe&&xe.exports===qe;function qt(e,t){return e.set(t[0],t[1]),e}function xt(e,t){return e.add(t),e}function Ht(e,t){for(var n=-1,r=e?e.length:0;++n<r&&t(e[n],n,e)!==!1;);return e}function Bt(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}function He(e,t,n,r){var o=-1,i=e?e.length:0;for(r&&i&&(n=e[++o]);++o<i;)n=t(n,e[o],o,e);return n}function Gt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function Wt(e,t){return e==null?void 0:e[t]}function Be(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function Ge(e){var t=-1,n=Array(e.size);return e.forEach(function(r,o){n[++t]=[o,r]}),n}function Z(e,t){return function(n){return e(t(n))}}function We(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}var Kt=Array.prototype,kt=Function.prototype,P=Object.prototype,Q=m["__core-js_shared__"],Ke=function(){var e=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ke=kt.toString,d=P.hasOwnProperty,M=P.toString,Yt=RegExp("^"+ke.call(d).replace(jt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ye=Mt?m.Buffer:void 0,Xe=m.Symbol,Ze=m.Uint8Array,Xt=Z(Object.getPrototypeOf,Object),Zt=Object.create,Qt=P.propertyIsEnumerable,zt=Kt.splice,Qe=Object.getOwnPropertySymbols,en=Ye?Ye.isBuffer:void 0,tn=Z(Object.keys,Object),z=D(m,"DataView"),C=D(m,"Map"),ee=D(m,"Promise"),te=D(m,"Set"),ne=D(m,"WeakMap"),I=D(Object,"create"),nn=S(z),rn=S(C),on=S(ee),ln=S(te),un=S(ne),ze=Xe?Xe.prototype:void 0,et=ze?ze.valueOf:void 0;function y(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function sn(){this.__data__=I?I(null):{}}function an(e){return this.has(e)&&delete this.__data__[e]}function cn(e){var t=this.__data__;if(I){var n=t[e];return n===Se?void 0:n}return d.call(t,e)?t[e]:void 0}function fn(e){var t=this.__data__;return I?t[e]!==void 0:d.call(t,e)}function gn(e,t){var n=this.__data__;return n[e]=I&&t===void 0?Se:t,this}y.prototype.clear=sn;y.prototype.delete=an;y.prototype.get=cn;y.prototype.has=fn;y.prototype.set=gn;function b(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function hn(){this.__data__=[]}function pn(e){var t=this.__data__,n=q(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():zt.call(t,n,1),!0}function mn(e){var t=this.__data__,n=q(t,e);return n<0?void 0:t[n][1]}function bn(e){return q(this.__data__,e)>-1}function $n(e,t){var n=this.__data__,r=q(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}b.prototype.clear=hn;b.prototype.delete=pn;b.prototype.get=mn;b.prototype.has=bn;b.prototype.set=$n;function w(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function dn(){this.__data__={hash:new y,map:new(C||b),string:new y}}function yn(e){return x(this,e).delete(e)}function En(e){return x(this,e).get(e)}function Sn(e){return x(this,e).has(e)}function On(e,t){return x(this,e).set(e,t),this}w.prototype.clear=dn;w.prototype.delete=yn;w.prototype.get=En;w.prototype.has=Sn;w.prototype.set=On;function T(e){this.__data__=new b(e)}function _n(){this.__data__=new b}function wn(e){return this.__data__.delete(e)}function Tn(e){return this.__data__.get(e)}function Dn(e){return this.__data__.has(e)}function vn(e,t){var n=this.__data__;if(n instanceof b){var r=n.__data__;if(!C||r.length<At-1)return r.push([e,t]),this;n=this.__data__=new w(r)}return n.set(e,t),this}T.prototype.clear=_n;T.prototype.delete=wn;T.prototype.get=Tn;T.prototype.has=Dn;T.prototype.set=vn;function Vn(e,t){var n=le(e)||Qn(e)?Gt(e.length,String):[],r=n.length,o=!!r;for(var i in e)(t||d.call(e,i))&&!(o&&(i=="length"||kn(i,r)))&&n.push(i);return n}function tt(e,t,n){var r=e[t];(!(d.call(e,t)&<(r,n))||n===void 0&&!(t in e))&&(e[t]=n)}function q(e,t){for(var n=e.length;n--;)if(lt(e[n][0],t))return n;return-1}function Nn(e,t){return e&&nt(t,ie(t),e)}function re(e,t,n,r,o,i,l){var c;if(r&&(c=i?r(e,o,i,l):r(e)),c!==void 0)return c;if(!H(e))return e;var h=le(e);if(h){if(c=Gn(e),!t)return xn(e,c)}else{var u=E(e),a=u==k||u==Te;if(er(e))return Ln(e,t);if(u==Y||u==K||a&&!i){if(Be(e))return i?e:{};if(c=Wn(a?{}:e),!t)return Hn(e,Nn(c,e))}else{if(!s[u])return i?e:{};c=Kn(e,u,re,t)}}l||(l=new T);var g=l.get(e);if(g)return g;if(l.set(e,c),!h)var _=n?Bn(e):ie(e);return Ht(_||e,function(R,f){_&&(f=R,R=e[f]),tt(c,f,re(R,t,n,r,f,e,l))}),c}function Rn(e){return H(e)?Zt(e):{}}function An(e,t,n){var r=t(e);return le(e)?r:Bt(r,n(e))}function Cn(e){return M.call(e)}function In(e){if(!H(e)||Xn(e))return!1;var t=ut(e)||Be(e)?Yt:Ft;return t.test(S(e))}function jn(e){if(!ot(e))return tn(e);var t=[];for(var n in Object(e))d.call(e,n)&&n!="constructor"&&t.push(n);return t}function Ln(e,t){if(t)return e.slice();var n=new e.constructor(e.length);return e.copy(n),n}function oe(e){var t=new e.constructor(e.byteLength);return new Ze(t).set(new Ze(e)),t}function Fn(e,t){var n=t?oe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}function Un(e,t,n){var r=t?n(Ge(e),!0):Ge(e);return He(r,qt,new e.constructor)}function Jn(e){var t=new e.constructor(e.source,Lt.exec(e));return t.lastIndex=e.lastIndex,t}function Pn(e,t,n){var r=t?n(We(e),!0):We(e);return He(r,xt,new e.constructor)}function Mn(e){return et?Object(et.call(e)):{}}function qn(e,t){var n=t?oe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function xn(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}function nt(e,t,n,r){n||(n={});for(var o=-1,i=t.length;++o<i;){var l=t[o],c=r?r(n[l],e[l],l,n,e):void 0;tt(n,l,c===void 0?e[l]:c)}return n}function Hn(e,t){return nt(e,rt(e),t)}function Bn(e){return An(e,ie,rt)}function x(e,t){var n=e.__data__;return Yn(t)?n[typeof t=="string"?"string":"hash"]:n.map}function D(e,t){var n=Wt(e,t);return In(n)?n:void 0}var rt=Qe?Z(Qe,Object):rr,E=Cn;(z&&E(new z(new ArrayBuffer(1)))!=J||C&&E(new C)!=F||ee&&E(ee.resolve())!=ve||te&&E(new te)!=U||ne&&E(new ne)!=X)&&(E=function(e){var t=M.call(e),n=t==Y?e.constructor:void 0,r=n?S(n):void 0;if(r)switch(r){case nn:return J;case rn:return F;case on:return ve;case ln:return U;case un:return X}return t});function Gn(e){var t=e.length,n=e.constructor(t);return t&&typeof e[0]=="string"&&d.call(e,"index")&&(n.index=e.index,n.input=e.input),n}function Wn(e){return typeof e.constructor=="function"&&!ot(e)?Rn(Xt(e)):{}}function Kn(e,t,n,r){var o=e.constructor;switch(t){case Ae:return oe(e);case _e:case we:return new o(+e);case J:return Fn(e,r);case Ce:case Ie:case je:case Le:case Fe:case Ue:case Je:case Pe:case Me:return qn(e,r);case F:return Un(e,r,n);case De:case Ne:return new o(e);case Ve:return Jn(e);case U:return Pn(e,r,n);case Re:return Mn(e)}}function kn(e,t){return t=t==null?Oe:t,!!t&&(typeof e=="number"||Ut.test(e))&&e>-1&&e%1==0&&e<t}function Yn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Xn(e){return!!Ke&&Ke in e}function ot(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||P;return e===n}function S(e){if(e!=null){try{return ke.call(e)}catch(t){}try{return e+""}catch(t){}}return""}function Zn(e){return re(e,!0,!0)}function lt(e,t){return e===t||e!==e&&t!==t}function Qn(e){return zn(e)&&d.call(e,"callee")&&(!Qt.call(e,"callee")||M.call(e)==K)}var le=Array.isArray;function it(e){return e!=null&&tr(e.length)&&!ut(e)}function zn(e){return nr(e)&&it(e)}var er=en||or;function ut(e){var t=H(e)?M.call(e):"";return t==k||t==Te}function tr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Oe}function H(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function nr(e){return!!e&&typeof e=="object"}function ie(e){return it(e)?Vn(e):jn(e)}function rr(){return[]}function or(){return!1}v.exports=Zn});var pr={};yt(pr,{chompLeft:()=>gr,chompRight:()=>hr,left:()=>G,leftSeq:()=>gt,leftStopAtNewLines:()=>cr,leftStopAtRawNbsp:()=>fr,right:()=>B,rightSeq:()=>ht,rightStopAtNewLines:()=>sr,rightStopAtRawNbsp:()=>ar,version:()=>ir});var O=be(Ee(),1),$=be(st(),1);var at="5.0.10";var ir=at,V="\xA0";function ur(e){let t={value:e,hungry:!1,optional:!1};return(t.value.endsWith("?*")||t.value.endsWith("*?"))&&t.value.length>2?(t.value=t.value.slice(0,t.value.length-2),t.optional=!0,t.hungry=!0):t.value.endsWith("?")&&t.value.length>1?(t.value=t.value.slice(0,~-t.value.length),t.optional=!0):t.value.endsWith("*")&&t.value.length>1&&(t.value=t.value.slice(0,~-t.value.length),t.hungry=!0),t}function ct(e){return typeof e=="number"}function L(e){return typeof e=="string"}function ue({str:e,idx:t=0,stopAtNewlines:n=!1,stopAtRawNbsp:r=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||n&&`
|
|
10
|
+
var stringLeftRight=(()=>{var pt=Object.create;var A=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,$t=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))fe.call(t,n)&&ge(e,n,t[n]);if(ce)for(var n of ce(t))dt.call(t,n)&&ge(e,n,t[n]);return e};var he=e=>A(e,"__esModule",{value:!0});var pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},me=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bt(t))!fe.call(e,o)&&(n||o!=="default")&&A(e,o,{get:()=>t[o],enumerable:!(r=mt(t,o))||r.enumerable});return e},be=(e,t)=>me(he(A(e!=null?pt($t(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),Et=(e=>(t,n)=>e&&e.get(t)||(n=me(he({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var Ee=pe((br,ye)=>{var St="[object Object]";function Ot(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function _t(e,t){return function(n){return e(t(n))}}var wt=Function.prototype,$e=Object.prototype,de=wt.toString,Tt=$e.hasOwnProperty,Dt=de.call(Object),vt=$e.toString,Vt=_t(Object.getPrototypeOf,Object);function Nt(e){return!!e&&typeof e=="object"}function Rt(e){if(!Nt(e)||vt.call(e)!=St||Ot(e))return!1;var t=Vt(e);if(t===null)return!0;var n=Tt.call(t,"constructor")&&t.constructor;return typeof n=="function"&&n instanceof n&&de.call(n)==Dt}ye.exports=Rt});var st=pe((j,v)=>{var At=200,Se="__lodash_hash_undefined__",Oe=9007199254740991,K="[object Arguments]",Ct="[object Array]",_e="[object Boolean]",we="[object Date]",It="[object Error]",k="[object Function]",Te="[object GeneratorFunction]",F="[object Map]",De="[object Number]",Y="[object Object]",ve="[object Promise]",Ve="[object RegExp]",U="[object Set]",Ne="[object String]",Re="[object Symbol]",X="[object WeakMap]",Ae="[object ArrayBuffer]",J="[object DataView]",Ce="[object Float32Array]",Ie="[object Float64Array]",je="[object Int8Array]",Le="[object Int16Array]",Fe="[object Int32Array]",Ue="[object Uint8Array]",Je="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Me="[object Uint32Array]",jt=/[\\^$.*+?()[\]{}|]/g,Lt=/\w*$/,Ft=/^\[object .+?Constructor\]$/,Ut=/^(?:0|[1-9]\d*)$/,s={};s[K]=s[Ct]=s[Ae]=s[J]=s[_e]=s[we]=s[Ce]=s[Ie]=s[je]=s[Le]=s[Fe]=s[F]=s[De]=s[Y]=s[Ve]=s[U]=s[Ne]=s[Re]=s[Ue]=s[Je]=s[Pe]=s[Me]=!0;s[It]=s[k]=s[X]=!1;var Jt=typeof global=="object"&&global&&global.Object===Object&&global,Pt=typeof self=="object"&&self&&self.Object===Object&&self,m=Jt||Pt||Function("return this")(),qe=typeof j=="object"&&j&&!j.nodeType&&j,xe=qe&&typeof v=="object"&&v&&!v.nodeType&&v,Mt=xe&&xe.exports===qe;function qt(e,t){return e.set(t[0],t[1]),e}function xt(e,t){return e.add(t),e}function Ht(e,t){for(var n=-1,r=e?e.length:0;++n<r&&t(e[n],n,e)!==!1;);return e}function Bt(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}function He(e,t,n,r){var o=-1,i=e?e.length:0;for(r&&i&&(n=e[++o]);++o<i;)n=t(n,e[o],o,e);return n}function Gt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function Wt(e,t){return e==null?void 0:e[t]}function Be(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function Ge(e){var t=-1,n=Array(e.size);return e.forEach(function(r,o){n[++t]=[o,r]}),n}function Z(e,t){return function(n){return e(t(n))}}function We(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}var Kt=Array.prototype,kt=Function.prototype,P=Object.prototype,Q=m["__core-js_shared__"],Ke=function(){var e=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ke=kt.toString,d=P.hasOwnProperty,M=P.toString,Yt=RegExp("^"+ke.call(d).replace(jt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ye=Mt?m.Buffer:void 0,Xe=m.Symbol,Ze=m.Uint8Array,Xt=Z(Object.getPrototypeOf,Object),Zt=Object.create,Qt=P.propertyIsEnumerable,zt=Kt.splice,Qe=Object.getOwnPropertySymbols,en=Ye?Ye.isBuffer:void 0,tn=Z(Object.keys,Object),z=D(m,"DataView"),C=D(m,"Map"),ee=D(m,"Promise"),te=D(m,"Set"),ne=D(m,"WeakMap"),I=D(Object,"create"),nn=S(z),rn=S(C),on=S(ee),ln=S(te),un=S(ne),ze=Xe?Xe.prototype:void 0,et=ze?ze.valueOf:void 0;function y(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function sn(){this.__data__=I?I(null):{}}function an(e){return this.has(e)&&delete this.__data__[e]}function cn(e){var t=this.__data__;if(I){var n=t[e];return n===Se?void 0:n}return d.call(t,e)?t[e]:void 0}function fn(e){var t=this.__data__;return I?t[e]!==void 0:d.call(t,e)}function gn(e,t){var n=this.__data__;return n[e]=I&&t===void 0?Se:t,this}y.prototype.clear=sn;y.prototype.delete=an;y.prototype.get=cn;y.prototype.has=fn;y.prototype.set=gn;function b(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function hn(){this.__data__=[]}function pn(e){var t=this.__data__,n=q(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():zt.call(t,n,1),!0}function mn(e){var t=this.__data__,n=q(t,e);return n<0?void 0:t[n][1]}function bn(e){return q(this.__data__,e)>-1}function $n(e,t){var n=this.__data__,r=q(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}b.prototype.clear=hn;b.prototype.delete=pn;b.prototype.get=mn;b.prototype.has=bn;b.prototype.set=$n;function w(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function dn(){this.__data__={hash:new y,map:new(C||b),string:new y}}function yn(e){return x(this,e).delete(e)}function En(e){return x(this,e).get(e)}function Sn(e){return x(this,e).has(e)}function On(e,t){return x(this,e).set(e,t),this}w.prototype.clear=dn;w.prototype.delete=yn;w.prototype.get=En;w.prototype.has=Sn;w.prototype.set=On;function T(e){this.__data__=new b(e)}function _n(){this.__data__=new b}function wn(e){return this.__data__.delete(e)}function Tn(e){return this.__data__.get(e)}function Dn(e){return this.__data__.has(e)}function vn(e,t){var n=this.__data__;if(n instanceof b){var r=n.__data__;if(!C||r.length<At-1)return r.push([e,t]),this;n=this.__data__=new w(r)}return n.set(e,t),this}T.prototype.clear=_n;T.prototype.delete=wn;T.prototype.get=Tn;T.prototype.has=Dn;T.prototype.set=vn;function Vn(e,t){var n=le(e)||Qn(e)?Gt(e.length,String):[],r=n.length,o=!!r;for(var i in e)(t||d.call(e,i))&&!(o&&(i=="length"||kn(i,r)))&&n.push(i);return n}function tt(e,t,n){var r=e[t];(!(d.call(e,t)&<(r,n))||n===void 0&&!(t in e))&&(e[t]=n)}function q(e,t){for(var n=e.length;n--;)if(lt(e[n][0],t))return n;return-1}function Nn(e,t){return e&&nt(t,ie(t),e)}function re(e,t,n,r,o,i,l){var c;if(r&&(c=i?r(e,o,i,l):r(e)),c!==void 0)return c;if(!H(e))return e;var h=le(e);if(h){if(c=Gn(e),!t)return xn(e,c)}else{var u=E(e),a=u==k||u==Te;if(er(e))return Ln(e,t);if(u==Y||u==K||a&&!i){if(Be(e))return i?e:{};if(c=Wn(a?{}:e),!t)return Hn(e,Nn(c,e))}else{if(!s[u])return i?e:{};c=Kn(e,u,re,t)}}l||(l=new T);var g=l.get(e);if(g)return g;if(l.set(e,c),!h)var _=n?Bn(e):ie(e);return Ht(_||e,function(R,f){_&&(f=R,R=e[f]),tt(c,f,re(R,t,n,r,f,e,l))}),c}function Rn(e){return H(e)?Zt(e):{}}function An(e,t,n){var r=t(e);return le(e)?r:Bt(r,n(e))}function Cn(e){return M.call(e)}function In(e){if(!H(e)||Xn(e))return!1;var t=ut(e)||Be(e)?Yt:Ft;return t.test(S(e))}function jn(e){if(!ot(e))return tn(e);var t=[];for(var n in Object(e))d.call(e,n)&&n!="constructor"&&t.push(n);return t}function Ln(e,t){if(t)return e.slice();var n=new e.constructor(e.length);return e.copy(n),n}function oe(e){var t=new e.constructor(e.byteLength);return new Ze(t).set(new Ze(e)),t}function Fn(e,t){var n=t?oe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}function Un(e,t,n){var r=t?n(Ge(e),!0):Ge(e);return He(r,qt,new e.constructor)}function Jn(e){var t=new e.constructor(e.source,Lt.exec(e));return t.lastIndex=e.lastIndex,t}function Pn(e,t,n){var r=t?n(We(e),!0):We(e);return He(r,xt,new e.constructor)}function Mn(e){return et?Object(et.call(e)):{}}function qn(e,t){var n=t?oe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function xn(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}function nt(e,t,n,r){n||(n={});for(var o=-1,i=t.length;++o<i;){var l=t[o],c=r?r(n[l],e[l],l,n,e):void 0;tt(n,l,c===void 0?e[l]:c)}return n}function Hn(e,t){return nt(e,rt(e),t)}function Bn(e){return An(e,ie,rt)}function x(e,t){var n=e.__data__;return Yn(t)?n[typeof t=="string"?"string":"hash"]:n.map}function D(e,t){var n=Wt(e,t);return In(n)?n:void 0}var rt=Qe?Z(Qe,Object):rr,E=Cn;(z&&E(new z(new ArrayBuffer(1)))!=J||C&&E(new C)!=F||ee&&E(ee.resolve())!=ve||te&&E(new te)!=U||ne&&E(new ne)!=X)&&(E=function(e){var t=M.call(e),n=t==Y?e.constructor:void 0,r=n?S(n):void 0;if(r)switch(r){case nn:return J;case rn:return F;case on:return ve;case ln:return U;case un:return X}return t});function Gn(e){var t=e.length,n=e.constructor(t);return t&&typeof e[0]=="string"&&d.call(e,"index")&&(n.index=e.index,n.input=e.input),n}function Wn(e){return typeof e.constructor=="function"&&!ot(e)?Rn(Xt(e)):{}}function Kn(e,t,n,r){var o=e.constructor;switch(t){case Ae:return oe(e);case _e:case we:return new o(+e);case J:return Fn(e,r);case Ce:case Ie:case je:case Le:case Fe:case Ue:case Je:case Pe:case Me:return qn(e,r);case F:return Un(e,r,n);case De:case Ne:return new o(e);case Ve:return Jn(e);case U:return Pn(e,r,n);case Re:return Mn(e)}}function kn(e,t){return t=t==null?Oe:t,!!t&&(typeof e=="number"||Ut.test(e))&&e>-1&&e%1==0&&e<t}function Yn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Xn(e){return!!Ke&&Ke in e}function ot(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||P;return e===n}function S(e){if(e!=null){try{return ke.call(e)}catch(t){}try{return e+""}catch(t){}}return""}function Zn(e){return re(e,!0,!0)}function lt(e,t){return e===t||e!==e&&t!==t}function Qn(e){return zn(e)&&d.call(e,"callee")&&(!Qt.call(e,"callee")||M.call(e)==K)}var le=Array.isArray;function it(e){return e!=null&&tr(e.length)&&!ut(e)}function zn(e){return nr(e)&&it(e)}var er=en||or;function ut(e){var t=H(e)?M.call(e):"";return t==k||t==Te}function tr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Oe}function H(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function nr(e){return!!e&&typeof e=="object"}function ie(e){return it(e)?Vn(e):jn(e)}function rr(){return[]}function or(){return!1}v.exports=Zn});var pr={};yt(pr,{chompLeft:()=>gr,chompRight:()=>hr,left:()=>G,leftSeq:()=>gt,leftStopAtNewLines:()=>cr,leftStopAtRawNbsp:()=>fr,right:()=>B,rightSeq:()=>ht,rightStopAtNewLines:()=>sr,rightStopAtRawNbsp:()=>ar,version:()=>ir});var O=be(Ee(),1),$=be(st(),1);var at="5.0.11";var ir=at,V="\xA0";function ur(e){let t={value:e,hungry:!1,optional:!1};return(t.value.endsWith("?*")||t.value.endsWith("*?"))&&t.value.length>2?(t.value=t.value.slice(0,t.value.length-2),t.optional=!0,t.hungry=!0):t.value.endsWith("?")&&t.value.length>1?(t.value=t.value.slice(0,~-t.value.length),t.optional=!0):t.value.endsWith("*")&&t.value.length>1&&(t.value=t.value.slice(0,~-t.value.length),t.hungry=!0),t}function ct(e){return typeof e=="number"}function L(e){return typeof e=="string"}function ue({str:e,idx:t=0,stopAtNewlines:n=!1,stopAtRawNbsp:r=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||n&&`
|
|
11
11
|
\r`.includes(e[t+1])||r&&e[t+1]===V))return t+1;if(e[t+2]&&(e[t+2].trim()||n&&`
|
|
12
12
|
\r`.includes(e[t+2])||r&&e[t+2]===V))return t+2;for(let o=t+1,i=e.length;o<i;o++)if(e[o].trim()||n&&`
|
|
13
13
|
\r`.includes(e[o])||r&&e[o]===V)return o;return null}function B(e,t=0){return ue({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function sr(e,t){return ue({str:e,idx:t,stopAtNewlines:!0,stopAtRawNbsp:!1})}function ar(e,t){return ue({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!0})}function se({str:e,idx:t,stopAtNewlines:n,stopAtRawNbsp:r}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||n&&`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-left-right",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.11",
|
|
4
4
|
"description": "Looks up the first non-whitespace character to the left/right of a given index",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"check",
|
|
@@ -38,13 +38,15 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
40
40
|
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
41
|
-
"dts": "rollup -c",
|
|
41
|
+
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
|
|
42
42
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
43
43
|
"lect": "node '../../ops/lect/lect.js'",
|
|
44
44
|
"letspublish": "yarn publish || :",
|
|
45
45
|
"lint": "eslint . --fix",
|
|
46
46
|
"perf": "node perf/check.js",
|
|
47
47
|
"prepare": "echo 'ready'",
|
|
48
|
+
"prettier": "prettier",
|
|
49
|
+
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
|
|
48
50
|
"pretest": "yarn run lect && yarn run build",
|
|
49
51
|
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
50
52
|
"unit": "uvu test"
|
package/types/index.d.ts
CHANGED
|
@@ -6,13 +6,41 @@ declare function left(str: string, idx?: number | null): number | null;
|
|
|
6
6
|
declare function leftStopAtNewLines(str: string, idx: number): number | null;
|
|
7
7
|
declare function leftStopAtRawNbsp(str: string, idx: number): number | null;
|
|
8
8
|
interface SeqOutput {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
gaps: [number, number][];
|
|
10
|
+
leftmostChar: number;
|
|
11
|
+
rightmostChar: number;
|
|
12
12
|
}
|
|
13
|
-
declare function leftSeq(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
declare function leftSeq(
|
|
14
|
+
str: string,
|
|
15
|
+
idx: number,
|
|
16
|
+
...args: any[]
|
|
17
|
+
): SeqOutput | null;
|
|
18
|
+
declare function rightSeq(
|
|
19
|
+
str: string,
|
|
20
|
+
idx: number,
|
|
21
|
+
...args: any[]
|
|
22
|
+
): SeqOutput | null;
|
|
23
|
+
declare function chompLeft(
|
|
24
|
+
str: string,
|
|
25
|
+
idx: number,
|
|
26
|
+
...args: any[]
|
|
27
|
+
): number | null;
|
|
28
|
+
declare function chompRight(
|
|
29
|
+
str: string,
|
|
30
|
+
idx: number,
|
|
31
|
+
...args: any[]
|
|
32
|
+
): number | null;
|
|
17
33
|
|
|
18
|
-
export {
|
|
34
|
+
export {
|
|
35
|
+
chompLeft,
|
|
36
|
+
chompRight,
|
|
37
|
+
left,
|
|
38
|
+
leftSeq,
|
|
39
|
+
leftStopAtNewLines,
|
|
40
|
+
leftStopAtRawNbsp,
|
|
41
|
+
right,
|
|
42
|
+
rightSeq,
|
|
43
|
+
rightStopAtNewLines,
|
|
44
|
+
rightStopAtRawNbsp,
|
|
45
|
+
version,
|
|
46
|
+
};
|