string-left-right 6.0.16 → 6.0.20
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 +1 -1
- package/dist/string-left-right.esm.js +2 -2
- package/dist/string-left-right.umd.js +17 -17
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2025 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
|
@@ -71,6 +71,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
71
71
|
|
|
72
72
|
MIT License.
|
|
73
73
|
|
|
74
|
-
Copyright © 2010-
|
|
74
|
+
Copyright © 2010-2025 Roy Revelt and other contributors.
|
|
75
75
|
|
|
76
76
|
<p align="center"><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"></p>
|
|
@@ -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 6.0.
|
|
4
|
+
* @version 6.0.20
|
|
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{isPlainObject as p,isStr as b,isInt as R}from"codsen-utils";import I from"rfdc";var S="6.0.
|
|
10
|
+
import{isPlainObject as p,isStr as b,isInt as R}from"codsen-utils";import I from"rfdc";var S="6.0.20";var $=I(),j=S,c="\xA0";function J(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 D({str:n,idx:e=0,stopAtNewlines:l=!1,stopAtRawNbsp:o=!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])||o&&n[e+1]===c))return e+1;if(n[e+2]&&(n[e+2].trim()||l&&`
|
|
12
12
|
\r`.includes(n[e+2])||o&&n[e+2]===c))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])||o&&n[t]===c)return t;return null}function E(n,e=0){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function k(n,e){return D({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function M(n,e){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function V({str:n,idx:e,stopAtNewlines:l,stopAtRawNbsp:o}){if(typeof n!="string"||!n.length||((!e||typeof e!="number")&&(e=0),e<1))return null;if(n[~-e]&&(n[~-e].trim()||l&&`
|
|
@@ -1,31 +1,31 @@
|
|
|
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 6.0.
|
|
4
|
+
* @version 6.0.20
|
|
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
|
-
"use strict";var stringLeftRight=(()=>{var
|
|
11
|
-
\r`.includes(n[e+1])||
|
|
12
|
-
\r`.includes(n[e+2])||
|
|
13
|
-
\r`.includes(n[
|
|
14
|
-
\r`.includes(n[~-e])||
|
|
15
|
-
\r`.includes(n[e-2])||
|
|
16
|
-
\r`.includes(n[
|
|
17
|
-
`)||e.slice(
|
|
18
|
-
\r`.includes(e[
|
|
19
|
-
`)||
|
|
20
|
-
\r`.includes(e[
|
|
21
|
-
`)||e.slice(0,
|
|
22
|
-
\r`.includes(e[
|
|
23
|
-
`)||
|
|
24
|
-
\r`.includes(e[
|
|
10
|
+
"use strict";var stringLeftRight=(()=>{var H=Object.create;var O=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,Q=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var j=(n,e,t)=>e in n?O(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,p=(n,e)=>{for(var t in e||(e={}))I.call(e,t)&&j(n,t,e[t]);if(C)for(var t of C(e))_.call(e,t)&&j(n,t,e[t]);return n};var K=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Z=(n,e)=>{for(var t in e)O(n,t,{get:e[t],enumerable:!0})},L=(n,e,t,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of x(e))!I.call(n,l)&&l!==t&&O(n,l,{get:()=>e[l],enumerable:!(u=W(e,l))||u.enumerable});return n};var F=(n,e,t)=>(t=n!=null?H(Q(n)):{},L(e||!n||!n.__esModule?O(t,"default",{value:n,enumerable:!0}):t,n)),z=n=>L(O({},"__esModule",{value:!0}),n);var A=K((ae,k)=>{"use strict";k.exports=G;function d(n){return n instanceof Buffer?Buffer.from(n):new n.constructor(n.buffer.slice(),n.byteOffset,n.length)}function G(n){if(n=n||{},n.circles)return Y(n);let e=new Map;if(e.set(Date,r=>new Date(r)),e.set(Map,(r,a)=>new Map(u(Array.from(r),a))),e.set(Set,(r,a)=>new Set(u(Array.from(r),a))),n.constructorHandlers)for(let r of n.constructorHandlers)e.set(r[0],r[1]);let t=null;return n.proto?m:l;function u(r,a){let o=Object.keys(r),s=new Array(o.length);for(let c=0;c<o.length;c++){let i=o[c],f=r[i];typeof f!="object"||f===null?s[i]=f:f.constructor!==Object&&(t=e.get(f.constructor))?s[i]=t(f,a):ArrayBuffer.isView(f)?s[i]=d(f):s[i]=a(f)}return s}function l(r){if(typeof r!="object"||r===null)return r;if(Array.isArray(r))return u(r,l);if(r.constructor!==Object&&(t=e.get(r.constructor)))return t(r,l);let a={};for(let o in r){if(Object.hasOwnProperty.call(r,o)===!1)continue;let s=r[o];typeof s!="object"||s===null?a[o]=s:s.constructor!==Object&&(t=e.get(s.constructor))?a[o]=t(s,l):ArrayBuffer.isView(s)?a[o]=d(s):a[o]=l(s)}return a}function m(r){if(typeof r!="object"||r===null)return r;if(Array.isArray(r))return u(r,m);if(r.constructor!==Object&&(t=e.get(r.constructor)))return t(r,m);let a={};for(let o in r){let s=r[o];typeof s!="object"||s===null?a[o]=s:s.constructor!==Object&&(t=e.get(s.constructor))?a[o]=t(s,m):ArrayBuffer.isView(s)?a[o]=d(s):a[o]=m(s)}return a}}function Y(n){let e=[],t=[],u=new Map;if(u.set(Date,o=>new Date(o)),u.set(Map,(o,s)=>new Map(m(Array.from(o),s))),u.set(Set,(o,s)=>new Set(m(Array.from(o),s))),n.constructorHandlers)for(let o of n.constructorHandlers)u.set(o[0],o[1]);let l=null;return n.proto?a:r;function m(o,s){let c=Object.keys(o),i=new Array(c.length);for(let f=0;f<c.length;f++){let h=c[f],g=o[h];if(typeof g!="object"||g===null)i[h]=g;else if(g.constructor!==Object&&(l=u.get(g.constructor)))i[h]=l(g,s);else if(ArrayBuffer.isView(g))i[h]=d(g);else{let w=e.indexOf(g);w!==-1?i[h]=t[w]:i[h]=s(g)}}return i}function r(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return m(o,r);if(o.constructor!==Object&&(l=u.get(o.constructor)))return l(o,r);let s={};e.push(o),t.push(s);for(let c in o){if(Object.hasOwnProperty.call(o,c)===!1)continue;let i=o[c];if(typeof i!="object"||i===null)s[c]=i;else if(i.constructor!==Object&&(l=u.get(i.constructor)))s[c]=l(i,r);else if(ArrayBuffer.isView(i))s[c]=d(i);else{let f=e.indexOf(i);f!==-1?s[c]=t[f]:s[c]=r(i)}}return e.pop(),t.pop(),s}function a(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return m(o,a);if(o.constructor!==Object&&(l=u.get(o.constructor)))return l(o,a);let s={};e.push(o),t.push(s);for(let c in o){let i=o[c];if(typeof i!="object"||i===null)s[c]=i;else if(i.constructor!==Object&&(l=u.get(i.constructor)))s[c]=l(i,a);else if(ArrayBuffer.isView(i))s[c]=d(i);else{let f=e.indexOf(i);f!==-1?s[c]=t[f]:s[c]=a(i)}}return e.pop(),t.pop(),s}}});var ie={};Z(ie,{chompLeft:()=>ue,chompRight:()=>se,left:()=>V,leftSeq:()=>M,leftStopAtNewLines:()=>le,leftStopAtRawNbsp:()=>oe,right:()=>S,rightSeq:()=>P,rightStopAtNewLines:()=>te,rightStopAtRawNbsp:()=>re,version:()=>ee});var J=F(A(),1);var fe=(0,J.default)();function b(n){if(n==null||typeof n!="object")return!1;let e=Object.getPrototypeOf(n);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:!(Symbol.iterator in n)&&!(Symbol.toStringTag in n)}function y(n){return typeof n=="string"}function R(n){return Number.isSafeInteger(n)&&n>=0}var B=F(A(),1);var U="6.0.20";var $=(0,B.default)(),ee=U,E="\xA0";function ne(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 T({str:n,idx:e=0,stopAtNewlines:t=!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()||t&&`
|
|
11
|
+
\r`.includes(n[e+1])||u&&n[e+1]===E))return e+1;if(n[e+2]&&(n[e+2].trim()||t&&`
|
|
12
|
+
\r`.includes(n[e+2])||u&&n[e+2]===E))return e+2;for(let l=e+1,m=n.length;l<m;l++)if(n[l].trim()||t&&`
|
|
13
|
+
\r`.includes(n[l])||u&&n[l]===E)return l;return null}function S(n,e=0){return T({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function te(n,e){return T({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function re(n,e){return T({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function v({str:n,idx:e,stopAtNewlines:t,stopAtRawNbsp:u}){if(typeof n!="string"||!n.length||((!e||typeof e!="number")&&(e=0),e<1))return null;if(n[~-e]&&(n[~-e].trim()||t&&`
|
|
14
|
+
\r`.includes(n[~-e])||u&&n[~-e]===E))return~-e;if(n[e-2]&&(n[e-2].trim()||t&&`
|
|
15
|
+
\r`.includes(n[e-2])||u&&n[e-2]===E))return e-2;for(let l=e;l--;)if(n[l]&&(n[l].trim()||t&&`
|
|
16
|
+
\r`.includes(n[l])||u&&n[l]===E))return l;return null}function V(n,e=0){return v({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function le(n,e){return v({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function oe(n,e){return v({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function q(n,e,t,u,l){if(typeof e!="string"||!e.length||(typeof t!="number"&&(t=0),n==="right"&&!e[t+1]||n==="left"&&!e[~-t]))return null;let m=t,r=[],a,o,s,c=0;for(;c<l.length;){if(!y(l[c])||!l[c].length){c+=1;continue}let{value:i,optional:f,hungry:h}=ne(l[c]),g=n==="right"?S(e,m):V(e,m);if(u.i&&e[g].toLowerCase()===i.toLowerCase()||!u.i&&e[g]===i){let w=n==="right"?S(e,g):V(e,g);h&&(u.i&&e[w].toLowerCase()===i.toLowerCase()||!u.i&&e[w]===i)?s=!0:c+=1,typeof g=="number"&&n==="right"&&g>m+1?r.push([m+1,g]):n==="left"&&typeof g=="number"&&g<~-m&&r.unshift([g+1,m]),m=g,n==="right"?(a===void 0&&(a=g),o=g):(o===void 0&&(o=g),a=g)}else if(f){c+=1;continue}else if(s){c+=1,s=void 0;continue}else return null}return a===void 0||o===void 0?null:{gaps:r,leftmostChar:a,rightmostChar:o}}var N={i:!1};function M(n,e,...t){if(!(t!=null&&t.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 b(t[0])?u=p(p({},N),t.shift()):u=N,q("left",n,e,u,Array.from(t).reverse())}function P(n,e,...t){if(!(t!=null&&t.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 b(t[0])?u=p(p({},N),t.shift()):u=N,q("right",n,e,u,t)}function D(n,e,t,u,l=[]){var o,s;if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),n==="right"&&!e[t+1]||n==="left"&&+t==0))return null;let m=null,r=null;do m=n==="right"?P(e,typeof r=="number"?r:t,...l):M(e,typeof r=="number"?r:t,...l),m!==null&&(r=n==="right"?m.rightmostChar:m.leftmostChar);while(m);if(r!=null&&n==="right"&&(r+=1),r===null)return null;if(n==="right"){if((o=e[r])!=null&&o.trim())return r;let c=S(e,r);if(!u||u.mode===0){if(c===r+1)return r;if(e.slice(r,c||e.length).trim()||e.slice(r,c||e.length).includes(`
|
|
17
|
+
`)||e.slice(r,c||e.length).includes("\r")){for(let i=r,f=e.length;i<f;i++)if(`
|
|
18
|
+
\r`.includes(e[i]))return i}else return c?~-c:e.length}else{if(u.mode===1)return r;if(u.mode===2){let i=e.slice(r);if(i.trim()||i.includes(`
|
|
19
|
+
`)||i.includes("\r")){for(let f=r,h=e.length;f<h;f++)if(e[f].trim()||`
|
|
20
|
+
\r`.includes(e[f]))return f}return e.length}}return c||e.length}if(e[r]&&((s=e[~-r])!=null&&s.trim()))return r;let a=V(e,r);if(!u||u.mode===0){if(a===r-2)return r;if(e.slice(0,r).trim()||e.slice(0,r).includes(`
|
|
21
|
+
`)||e.slice(0,r).includes("\r")){for(let c=r;c--;)if(`
|
|
22
|
+
\r`.includes(e[c])||e[c].trim())return c+1+(e[c].trim()?1:0)}return 0}if(u.mode===1)return r;if(u.mode===2){let c=e.slice(0,r);if(c.trim()||c.includes(`
|
|
23
|
+
`)||c.includes("\r")){for(let i=r;i--;)if(e[i].trim()||`
|
|
24
|
+
\r`.includes(e[i]))return i+1}return 0}return a!==null?a+1:0}function ue(n,e,...t){if(!t.length||t.length===1&&b(t[0]))return null;let u={mode:0};if(b(t[0])){let l=p(p({},u),$(t[0]));if(!l.mode)l.mode=0;else if(y(l.mode)&&l.mode.length===1&&"0123".includes(l.mode))l.mode=+l.mode;else if(!R(l.mode))throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${l.mode} (type ${typeof l.mode})`);return D("left",n,e,l,$(t).slice(1))}return y(t[0])?D("left",n,e,u,$(t)):D("left",n,e,u,$(t).slice(1))}function se(n,e,...t){if(!t.length||t.length===1&&b(t[0]))return null;let u={mode:0};if(b(t[0])){let l=p(p({},u),$(t[0]));if(!l.mode)l.mode=0;else if(y(l.mode)&&"0123".includes(l.mode))l.mode=Number.parseInt(l.mode,10);else if(!R(l.mode))throw new Error(`string-left-right/chompRight(): [THROW_ID_02] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${l.mode} (type ${typeof l.mode})`);return D("right",n,e,l,$(t).slice(1))}return y(t[0])?D("right",n,e,u,$(t)):D("right",n,e,u,$(t).slice(1))}return z(ie);})();
|
|
25
25
|
/**
|
|
26
26
|
* @name codsen-utils
|
|
27
27
|
* @fileoverview Various utility functions
|
|
28
|
-
* @version 1.6.
|
|
28
|
+
* @version 1.6.7
|
|
29
29
|
* @author Roy Revelt, Codsen Ltd
|
|
30
30
|
* @license MIT
|
|
31
31
|
* {@link https://codsen.com/os/codsen-utils/}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-left-right",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.20",
|
|
4
4
|
"description": "Looks up the first non-whitespace character to the left/right of a given index",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"check",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"homepage": "https://codsen.com/os/string-left-right",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "https://github.com/codsen/codsen.git",
|
|
23
|
+
"url": "git+https://github.com/codsen/codsen.git",
|
|
24
24
|
"directory": "packages/string-left-right"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
47
47
|
"lect": "node '../../ops/lect/lect.js' && npm run prettier -- 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
|
|
48
48
|
"letspublish": "npm publish || :",
|
|
49
|
-
"lint": "eslint . --
|
|
49
|
+
"lint": "eslint . --fix",
|
|
50
50
|
"perf": "node perf/check.js",
|
|
51
51
|
"prep": "echo 'ready'",
|
|
52
52
|
"prettier": "prettier",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"codsen-utils": "^1.6.
|
|
77
|
-
"rfdc": "^1.
|
|
76
|
+
"codsen-utils": "^1.6.7",
|
|
77
|
+
"rfdc": "^1.4.1"
|
|
78
78
|
}
|
|
79
79
|
}
|