string-match-left-right 8.2.1 → 8.2.3

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/CHANGELOG.md CHANGED
@@ -107,8 +107,8 @@ Accidental version bump during migration to sourcehut. Sorry about that.
107
107
 
108
108
  ## CHANGES
109
109
 
110
- - Remove anything emoji-related to make things run faster. Emoji can be of varying length and previous algorithm worked only for 2 character-long emojis only anyway. And there can be emoji as long as 8 characters.
111
- - Remove `opts.relaxedApi` - now it's always relaxed. Idea is, this is an internal library, if parent programs want to check something, let them do so.
110
+ - Remove anything emoji-related to make things run faster. Emoji can be of varying length and previous algorithm worked only for 2 character-long emojis only anyway. And there can be emoji as long as 8 characters.
111
+ - Remove `opts.relaxedApi` - now it's always relaxed. Idea is, this is an internal library, if parent programs want to check something, let them do so.
112
112
 
113
113
  ## 3.11.0 (2019-08-08)
114
114
 
@@ -118,41 +118,41 @@ Accidental version bump during migration to sourcehut. Sorry about that.
118
118
 
119
119
  ## 3.10.0 (2019-01-20)
120
120
 
121
- - Various documentation and setup tweaks after we migrated to monorepo
122
- - Setup refresh: updated dependencies and all config files using automated tools
121
+ - Various documentation and setup tweaks after we migrated to monorepo
122
+ - Setup refresh: updated dependencies and all config files using automated tools
123
123
 
124
124
  ## 3.6.0 (2018-12-26)
125
125
 
126
- - Add `EOL` matching and code refresh ([ca834a7](https://gitlab.com/codsen/codsen/tree/master/packages/string-match-left-right/commits/ca834a7))
127
- - Add `opts.relaxedApi` ([f30626c](https://gitlab.com/codsen/codsen/tree/master/packages/string-match-left-right/commits/f30626c))
126
+ - Add `EOL` matching and code refresh ([ca834a7](https://gitlab.com/codsen/codsen/tree/master/packages/string-match-left-right/commits/ca834a7))
127
+ - Add `opts.relaxedApi` ([f30626c](https://gitlab.com/codsen/codsen/tree/master/packages/string-match-left-right/commits/f30626c))
128
128
 
129
129
  ## 3.5.0 (2018-12-04)
130
130
 
131
- - **NEW!** Now you can match against `EOL` - end of string (beginning or ending). Since you can't pass letters `"EOL"`, you must pass them as an ES6 arrow function, `() => "EOL"`. In all other aspects, the use is the same.
131
+ - **NEW!** Now you can match against `EOL` - end of string (beginning or ending). Since you can't pass letters `"EOL"`, you must pass them as an ES6 arrow function, `() => "EOL"`. In all other aspects, the use is the same.
132
132
  - 🔧 Previously, `opts.cb` second argument, which means the rest of the string on particular side, depending on the method called, left or right, was giving empty string when there was nothing on that side. This, however looked inconsistent when all other callback values were `undefined`. Now, second `opts.cb` argument comes as `undefined` instead of `empty` string when there's nothing to return.
133
- - Implemented and released (but not documented) `opts.strictApi` was merged with `opts.relaxedApi`
134
- - Restored unit test coverage and ava linting
133
+ - Implemented and released (but not documented) `opts.strictApi` was merged with `opts.relaxedApi`
134
+ - Restored unit test coverage and ava linting
135
135
 
136
136
  ## 3.4.0 (2018-06-11)
137
137
 
138
138
  GitHub sold us out. In the meantime, we:
139
139
 
140
- - Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
141
- - Dropped BitHound (RIP) and Travis
142
- - Removed `package-lock`
140
+ - Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
141
+ - Dropped BitHound (RIP) and Travis
142
+ - Removed `package-lock`
143
143
 
144
144
  ## 3.3.0 (2018-05-16)
145
145
 
146
- - Add `opts.relaxedApi`
146
+ - Add `opts.relaxedApi`
147
147
 
148
148
  ## 3.2.0 (2018-05-15)
149
149
 
150
- - Set up [Prettier](https://prettier.io)
151
- - Removed `package.lock` and `.editorconfig`
152
- - Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — Rollup will remove them from production code.
153
- - Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed
154
- - Removed `DEBUG` statements from the code
155
- - Added `esm` config to package.json which somehow enables CJS compat in `ava`.
150
+ - Set up [Prettier](https://prettier.io)
151
+ - Removed `package.lock` and `.editorconfig`
152
+ - Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — Rollup will remove them from production code.
153
+ - Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed
154
+ - Removed `DEBUG` statements from the code
155
+ - Added `esm` config to package.json which somehow enables CJS compat in `ava`.
156
156
 
157
157
  ## 3.1.1 (2018-03-06)
158
158
 
@@ -160,13 +160,13 @@ GitHub sold us out. In the meantime, we:
160
160
 
161
161
  ## 3.1.0 (2018-03-01)
162
162
 
163
- - Add the third argument, `whatToMatch`, can now be empty string. In such case, you have to provide callback and result will be calculated purely using the callback. It's handy when you want to perform complex matching, beyond "character is equal to" level. Personally, I reached this level and it's necessary for the feature I'm producing on the other package. It must be handy for everybody else too.
163
+ - Add the third argument, `whatToMatch`, can now be empty string. In such case, you have to provide callback and result will be calculated purely using the callback. It's handy when you want to perform complex matching, beyond "character is equal to" level. Personally, I reached this level and it's necessary for the feature I'm producing on the other package. It must be handy for everybody else too.
164
164
 
165
165
  ## 3.0.0 (2018-01-15)
166
166
 
167
- - Rewrote a lot of code, relieving us from all `lodash` dependencies.
168
- - `opts.trimCharsBeforeMatching` must be a string of single character or an array of single characters. Previously merged string of characters was accepted but now it's not accepted.
169
- - Callback `cb` now returns three arguments:
167
+ - Rewrote a lot of code, relieving us from all `lodash` dependencies.
168
+ - `opts.trimCharsBeforeMatching` must be a string of single character or an array of single characters. Previously merged string of characters was accepted but now it's not accepted.
169
+ - Callback `cb` now returns three arguments:
170
170
 
171
171
  1. `char` - the character just outside of the matched substring (as previously)
172
172
  2. `theRemainderOfTheString` - whole string outside of the matched substring (as previously)
@@ -182,35 +182,35 @@ GitHub sold us out. In the meantime, we:
182
182
 
183
183
  ### Changed
184
184
 
185
- - Let's say you want to check, does a string contain "something" to the right or to the left of somewhere in it (a given index). We allow "something" to be an **array** of strings. If those strings are of a varying length, how do you find out, what exactly did match from the "something" array and especially, how long it is? As a solution for that, I'm going to return a positive result not Boolean `true` which is meaningless, but actually the value of a matched string from "something". It is equally `truthy` but you can now query it further, like find its `length`.
185
+ - Let's say you want to check, does a string contain "something" to the right or to the left of somewhere in it (a given index). We allow "something" to be an **array** of strings. If those strings are of a varying length, how do you find out, what exactly did match from the "something" array and especially, how long it is? As a solution for that, I'm going to return a positive result not Boolean `true` which is meaningless, but actually the value of a matched string from "something". It is equally `truthy` but you can now query it further, like find its `length`.
186
186
 
187
187
  **Instructions to upgrade from `1.x`**
188
188
 
189
189
  If you relied on the result being explicitly Boolean, `true` or `false`, prepare that truthy outcome now will be string. Just us double negation `!!` and you'll convert it to `true`. Or better, you can just use the truthy (string) result in the Boolean logic. It's `truthy` anyway.
190
190
 
191
- - `opts.cbLeft` and `opts.cbRight` were joined into one, `opts.cb`. Same behaviour, except there's less to think about. Just pass the callback function - it will be called with the substring which is on the left or right, depending if you called left-side (`matchLeftIncl`/`matchLeft`) or right-side (`matchRightIncl`/`matchRight`) method.
191
+ - `opts.cbLeft` and `opts.cbRight` were joined into one, `opts.cb`. Same behaviour, except there's less to think about. Just pass the callback function - it will be called with the substring which is on the left or right, depending if you called left-side (`matchLeftIncl`/`matchLeft`) or right-side (`matchRightIncl`/`matchRight`) method.
192
192
 
193
193
  ## 1.4.0 (2017-12-10)
194
194
 
195
195
  ### Added
196
196
 
197
- - Stringifying of `opts.trimCharsBeforeMatching` now occurs only if element is not string.
198
- - Callbacks, [opts.cbLeft and opts.cbRight](https://www.npmjs.com/package/string-match-left-right#optscbleft-and-optscbright), get second argument - whole substring of what's on that side. First argument it received is first character, second is whole substring (including first character).
197
+ - Stringifying of `opts.trimCharsBeforeMatching` now occurs only if element is not string.
198
+ - Callbacks, [opts.cbLeft and opts.cbRight](https://www.npmjs.com/package/string-match-left-right#optscbleft-and-optscbright), get second argument - whole substring of what's on that side. First argument it received is first character, second is whole substring (including first character).
199
199
 
200
200
  I needed this when I was coding [email-remove-unused-css](https://github.com/codsen/email-remove-unused-css) and I was traversing the string. I wanted to check, do any of given _heads_ are equal to what's on the right of the current character being traversed. For example, if there are Nunjucks variables in HTML, they would start with `{{` and end with `}}`. I wanted `email-remove-unused-css` to ignore everything between such `heads` and `tails` (which can be customised to anything, to support any templating/programming languages).
201
201
 
202
202
  ## 1.3.0 (2017-11-23)
203
203
 
204
- - Add `opts.trimCharsBeforeMatching`
204
+ - Add `opts.trimCharsBeforeMatching`
205
205
 
206
206
  ## 1.2.0 (2017-11-22)
207
207
 
208
- - Add `opts.trimBeforeMatching`
208
+ - Add `opts.trimBeforeMatching`
209
209
 
210
210
  ## 1.1.0 (2017-10-28)
211
211
 
212
- - Add `opts.cbLeft`
213
- - Add `opts.cbRight`
212
+ - Add `opts.cbLeft`
213
+ - Add `opts.cbRight`
214
214
 
215
215
  Often you want to check not only what's to the left or right of the certain index in the string, but also perform certain checks on what's even further to the left/right. For example, you have a piace of HTML, `class=` and you are an index which is at character `=`. You can use `string-match-left-right` to check, is `class` on the left using `matchLeft`. Which is fine. There's a gotcha though. You also need to check, what's further to the left of `class=` - is it a character, a space or something else? Because it might be that you looked for `class` attribute but matched `superclass`, an (imaginary) custom attribute!
216
216
 
@@ -220,4 +220,4 @@ They have to be callbacks because I can't predict what checks you will want to c
220
220
 
221
221
  ## 1.0.0 (2017-10-28)
222
222
 
223
- - First public release
223
+ - First public release
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @name string-match-left-right
3
3
  * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
4
- * @version 8.2.1
4
+ * @version 8.2.3
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-match-left-right/}
8
8
  */
9
9
 
10
- import{arrayiffy as N}from"arrayiffy-if-string";var O="8.2.1";var x=O;function w(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function p(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},k=t=>t+1;function A(t,s,n,a,u=!1,r=k){let i=typeof n=="function"?n():n;if(+s<0&&u&&i==="EOL")return i;let o={...R,...a};if(s>=t.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,l=!1,m=!1,b=o.maxMismatches,e=s,g=!1,f=!1,$=!1;function d(){return E===1&&b<o.maxMismatches-1}for(;t[e];){let T=r(e);if(o.trimBeforeMatching&&t[e].trim()===""){if(!t[T]&&u&&n==="EOL")return!0;e=r(e);continue}if(o&&!o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.includes(t[e])||o?.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(t[e].toLowerCase())){if(u&&n==="EOL"&&!t[T])return!0;e=r(e);continue}let y=T>e?n[n.length-c]:n[c-1];if(!o.i&&t[e]===y||o.i&&t[e].toLowerCase()===y.toLowerCase()){if(g||(g=!0),m||(m=!0),c===n.length){if(f=!0,b!==o.maxMismatches)return!1}else c===1&&($=!0);if(c-=1,E++,d())return!1;if(!c)return E!==n.length||b===o.maxMismatches||!h?e:!1}else if(!h&&!E&&(h=!0),o.maxMismatches&&b&&e){b-=1;for(let D=0;D<=b;D++){let C=T>e?n[n.length-c+1+D]:n[c-2-D],M=t[r(e)];if(C&&(!o.i&&t[e]===C||o.i&&t[e].toLowerCase()===C.toLowerCase())&&(!o.firstMustMatch||c!==n.length)){if(E++,d())return!1;c-=2,g=!0;break}else if(M&&C&&(!o.i&&M===C||o.i&&M.toLowerCase()===C.toLowerCase())&&(!o.firstMustMatch||c!==n.length)){if(!E&&!o.hungry)return!1;c-=1,g=!0;break}else if(C===void 0&&b>=0&&g&&(!o.firstMustMatch||f)&&(!o.lastMustMatch||$))return e}g||(l=e)}else return e===0&&c===1&&!o.lastMustMatch&&m?0:!1;if(l!==!1&&l!==e&&(l=!1),c<1)return e;e=r(e)}if(c>0)return u&&i==="EOL"?!0:o&&o.maxMismatches>=c&&m?l||0:!1}function V(t,s,n,a,u){if(w(u)&&Object.prototype.hasOwnProperty.call(u,"trimBeforeMatching")&&u&&typeof u.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let r={...R,...u};if(typeof r.trimCharsBeforeMatching=="string"&&(r.trimCharsBeforeMatching=N(r.trimCharsBeforeMatching)),r.trimCharsBeforeMatching=r.trimCharsBeforeMatching.map(h=>p(h)?h:String(h)),!p(s)||!s.length)return!1;if(!Number.isInteger(n)||n<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof n}, equal to:
11
- ${JSON.stringify(n,null,4)}`);let i,o;if(p(a))i=[a];else if(Array.isArray(a))i=a;else if(!a)i=a;else if(typeof a=="function")i=[],i.push(a);else throw new Error(`string-match-left-right/${t}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof a}, equal to:
10
+ import{arrayiffy as N}from"arrayiffy-if-string";var O="8.2.3";var x=O;function w(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function p(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},k=t=>t+1;function A(t,s,n,a,u=!1,o=k){let i=typeof n=="function"?n():n;if(+s<0&&u&&i==="EOL")return i;let r={...R,...a};if(s>=t.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,l=!1,m=!1,b=r.maxMismatches,e=s,g=!1,f=!1,$=!1;function d(){return E===1&&b<r.maxMismatches-1}for(;t[e];){let T=o(e);if(r.trimBeforeMatching&&t[e].trim()===""){if(!t[T]&&u&&n==="EOL")return!0;e=o(e);continue}if(r&&!r.i&&r.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.includes(t[e])||r?.i&&r.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(t[e].toLowerCase())){if(u&&n==="EOL"&&!t[T])return!0;e=o(e);continue}let M=T>e?n[n.length-c]:n[c-1];if(!r.i&&t[e]===M||r.i&&t[e].toLowerCase()===M.toLowerCase()){if(g||(g=!0),m||(m=!0),c===n.length){if(f=!0,b!==r.maxMismatches)return!1}else c===1&&($=!0);if(c-=1,E++,d())return!1;if(!c)return E!==n.length||b===r.maxMismatches||!h?e:!1}else if(!h&&!E&&(h=!0),r.maxMismatches&&b&&e){b-=1;for(let D=0;D<=b;D++){let C=T>e?n[n.length-c+1+D]:n[c-2-D],y=t[o(e)];if(C&&(!r.i&&t[e]===C||r.i&&t[e].toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(E++,d())return!1;c-=2,g=!0;break}else if(y&&C&&(!r.i&&y===C||r.i&&y.toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(!E&&!r.hungry)return!1;c-=1,g=!0;break}else if(C===void 0&&b>=0&&g&&(!r.firstMustMatch||f)&&(!r.lastMustMatch||$))return e}g||(l=e)}else return e===0&&c===1&&!r.lastMustMatch&&m?0:!1;if(l!==!1&&l!==e&&(l=!1),c<1)return e;e=o(e)}if(c>0)return u&&i==="EOL"?!0:r&&r.maxMismatches>=c&&m?l||0:!1}function V(t,s,n,a,u){if(w(u)&&Object.prototype.hasOwnProperty.call(u,"trimBeforeMatching")&&u&&typeof u.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let o={...R,...u};if(typeof o.trimCharsBeforeMatching=="string"&&(o.trimCharsBeforeMatching=N(o.trimCharsBeforeMatching)),o.trimCharsBeforeMatching=o.trimCharsBeforeMatching.map(h=>p(h)?h:String(h)),!p(s)||!s.length)return!1;if(!Number.isInteger(n)||n<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof n}, equal to:
11
+ ${JSON.stringify(n,null,4)}`);let i,r;if(p(a))i=[a];else if(Array.isArray(a))i=a;else if(!a)i=a;else if(typeof a=="function")i=[],i.push(a);else throw new Error(`string-match-left-right/${t}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof a}, equal to:
12
12
  ${JSON.stringify(a,null,4)}`);if(u&&!w(u))throw new Error(`string-match-left-right/${t}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof u}", and equal to:
13
- ${JSON.stringify(u,null,4)}`);let c=0,E="";if(r?.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.some((h,l)=>h.length>1?(c=l,E=h,!0):!1))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${c} is longer than 1 character, ${E.length} (equals to ${E}). Please split it into separate characters and put into array as separate elements.`);if(!i||!Array.isArray(i)||Array.isArray(i)&&!i.length||Array.isArray(i)&&i.length===1&&p(i[0])&&!i[0].trim()){if(typeof r.cb=="function"){let l,m=n;if((t==="matchLeftIncl"||t==="matchRight")&&(m+=1),t[5]==="L")for(let f=m;f--;){let $=s[f];if((!r.trimBeforeMatching||r.trimBeforeMatching&&$!==void 0&&$.trim())&&(!r.trimCharsBeforeMatching||!r.trimCharsBeforeMatching.length||$!==void 0&&!r.trimCharsBeforeMatching.includes($))){l=f;break}}else if(t.startsWith("matchRight"))for(let f=m;f<s.length;f++){let $=s[f];if((!r.trimBeforeMatching||r.trimBeforeMatching&&$.trim())&&(!r.trimCharsBeforeMatching||!r.trimCharsBeforeMatching.length||!r.trimCharsBeforeMatching.includes($))){l=f;break}}if(l===void 0)return!1;let b=s[l],e=l+1,g="";return e&&e>0&&(g=s.slice(0,e)),t[5]==="L"||l&&l>0&&(g=s.slice(l)),r.cb(b,g,l)}let h="";throw u||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${h}`)}for(let h=0,l=i.length;h<l;h++){o=typeof i[h]=="function";let m=i[h],b,e,g="",f=n;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=A(s,f,m,r,o,d=>t[5]==="L"?d-1:d+1);if($&&o&&typeof m=="function"&&m()==="EOL")return m()&&(r.cb?r.cb(b,g,e):!0)?m():!1;if(Number.isInteger($)&&(e=t.startsWith("matchLeft")?$-1:$+1,t[5]==="L"?g=s.slice(0,$):g=s.slice(e)),e<0&&(e=void 0),s[e]&&(b=s[e]),Number.isInteger($)&&(r.cb?r.cb(b,g,e):!0))return m}return!1}function J(t,s,n,a){return V("matchLeftIncl",t,s,n,a)}function F(t,s,n,a){return V("matchLeft",t,s,n,a)}function H(t,s,n,a){return V("matchRightIncl",t,s,n,a)}function j(t,s,n,a){return V("matchRight",t,s,n,a)}export{k as defaultGetNextIdx,R as defaults,F as matchLeft,J as matchLeftIncl,j as matchRight,H as matchRightIncl,x as version};
13
+ ${JSON.stringify(u,null,4)}`);let c=0,E="";if(o?.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.some((h,l)=>h.length>1?(c=l,E=h,!0):!1))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${c} is longer than 1 character, ${E.length} (equals to ${E}). Please split it into separate characters and put into array as separate elements.`);if(!i||!Array.isArray(i)||Array.isArray(i)&&!i.length||Array.isArray(i)&&i.length===1&&p(i[0])&&!i[0].trim()){if(typeof o.cb=="function"){let l,m=n;if((t==="matchLeftIncl"||t==="matchRight")&&(m+=1),t[5]==="L")for(let f=m;f--;){let $=s[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$!==void 0&&$.trim())&&(!o.trimCharsBeforeMatching?.length||$!==void 0&&!o.trimCharsBeforeMatching.includes($))){l=f;break}}else if(t.startsWith("matchRight"))for(let f=m;f<s.length;f++){let $=s[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$.trim())&&(!o.trimCharsBeforeMatching?.length||!o.trimCharsBeforeMatching.includes($))){l=f;break}}if(l===void 0)return!1;let b=s[l],e=l+1,g="";return e&&e>0&&(g=s.slice(0,e)),t[5]==="L"||l&&l>0&&(g=s.slice(l)),o.cb(b,g,l)}let h="";throw u||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${h}`)}for(let h=0,l=i.length;h<l;h++){r=typeof i[h]=="function";let m=i[h],b,e,g="",f=n;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=A(s,f,m,o,r,d=>t[5]==="L"?d-1:d+1);if($&&r&&typeof m=="function"&&m()==="EOL")return m()&&(o.cb?o.cb(b,g,e):!0)?m():!1;if(Number.isInteger($)&&(e=t.startsWith("matchLeft")?$-1:$+1,t[5]==="L"?g=s.slice(0,$):g=s.slice(e)),e<0&&(e=void 0),s[e]&&(b=s[e]),Number.isInteger($)&&(o.cb?o.cb(b,g,e):!0))return m}return!1}function J(t,s,n,a){return V("matchLeftIncl",t,s,n,a)}function F(t,s,n,a){return V("matchLeft",t,s,n,a)}function H(t,s,n,a){return V("matchRightIncl",t,s,n,a)}function j(t,s,n,a){return V("matchRight",t,s,n,a)}export{k as defaultGetNextIdx,R as defaults,F as matchLeft,J as matchLeftIncl,j as matchRight,H as matchRightIncl,x as version};
@@ -1,20 +1,20 @@
1
1
  /**
2
2
  * @name string-match-left-right
3
3
  * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
4
- * @version 8.2.1
4
+ * @version 8.2.3
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-match-left-right/}
8
8
  */
9
9
 
10
- "use strict";var stringMatchLeftRight=(()=>{var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var N=(t,n,e)=>n in t?p(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,T=(t,n)=>{for(var e in n||(n={}))k.call(n,e)&&N(t,e,n[e]);if(S)for(var e of S(n))F.call(n,e)&&N(t,e,n[e]);return t};var H=(t,n)=>{for(var e in n)p(t,e,{get:n[e],enumerable:!0})},j=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of J(n))!k.call(t,a)&&a!==e&&p(t,a,{get:()=>n[a],enumerable:!(i=x(n,a))||i.enumerable});return t};var P=t=>j(p({},"__esModule",{value:!0}),t);var K={};H(K,{defaultGetNextIdx:()=>I,defaults:()=>w,matchLeft:()=>q,matchLeftIncl:()=>_,matchRight:()=>G,matchRightIncl:()=>Y,version:()=>v});function A(t){return typeof t!="string"?t:t.length?[t]:[]}var L="8.2.1";var v=L;function B(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function y(t){return typeof t=="string"}var w={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},I=t=>t+1;function W(t,n,e,i,a=!1,o=I){let l=typeof e=="function"?e():e;if(+n<0&&a&&l==="EOL")return l;let s=T(T({},w),i);if(n>=t.length&&!a)return!1;let u=a?1:e.length,E=0,h=!1,c=!1,m=!1,b=s.maxMismatches,r=n,g=!1,f=!1,$=!1;function d(){return E===1&&b<s.maxMismatches-1}for(;t[r];){let V=o(r);if(s.trimBeforeMatching&&t[r].trim()===""){if(!t[V]&&a&&e==="EOL")return!0;r=o(r);continue}if(s&&!s.i&&s.trimCharsBeforeMatching&&s.trimCharsBeforeMatching.includes(t[r])||(s==null?void 0:s.i)&&s.trimCharsBeforeMatching&&s.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(t[r].toLowerCase())){if(a&&e==="EOL"&&!t[V])return!0;r=o(r);continue}let R=V>r?e[e.length-u]:e[u-1];if(!s.i&&t[r]===R||s.i&&t[r].toLowerCase()===R.toLowerCase()){if(g||(g=!0),m||(m=!0),u===e.length){if(f=!0,b!==s.maxMismatches)return!1}else u===1&&($=!0);if(u-=1,E++,d())return!1;if(!u)return E!==e.length||b===s.maxMismatches||!h?r:!1}else if(!h&&!E&&(h=!0),s.maxMismatches&&b&&r){b-=1;for(let D=0;D<=b;D++){let C=V>r?e[e.length-u+1+D]:e[u-2-D],O=t[o(r)];if(C&&(!s.i&&t[r]===C||s.i&&t[r].toLowerCase()===C.toLowerCase())&&(!s.firstMustMatch||u!==e.length)){if(E++,d())return!1;u-=2,g=!0;break}else if(O&&C&&(!s.i&&O===C||s.i&&O.toLowerCase()===C.toLowerCase())&&(!s.firstMustMatch||u!==e.length)){if(!E&&!s.hungry)return!1;u-=1,g=!0;break}else if(C===void 0&&b>=0&&g&&(!s.firstMustMatch||f)&&(!s.lastMustMatch||$))return r}g||(c=r)}else return r===0&&u===1&&!s.lastMustMatch&&m?0:!1;if(c!==!1&&c!==r&&(c=!1),u<1)return r;r=o(r)}if(u>0)return a&&l==="EOL"?!0:s&&s.maxMismatches>=u&&m?c||0:!1}function M(t,n,e,i,a){if(B(a)&&Object.prototype.hasOwnProperty.call(a,"trimBeforeMatching")&&a&&typeof a.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(a.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let o=T(T({},w),a);if(typeof o.trimCharsBeforeMatching=="string"&&(o.trimCharsBeforeMatching=A(o.trimCharsBeforeMatching)),o.trimCharsBeforeMatching=o.trimCharsBeforeMatching.map(h=>y(h)?h:String(h)),!y(n)||!n.length)return!1;if(!Number.isInteger(e)||e<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof e}, equal to:
11
- ${JSON.stringify(e,null,4)}`);let l,s;if(y(i))l=[i];else if(Array.isArray(i))l=i;else if(!i)l=i;else if(typeof i=="function")l=[],l.push(i);else throw new Error(`string-match-left-right/${t}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof i}, equal to:
12
- ${JSON.stringify(i,null,4)}`);if(a&&!B(a))throw new Error(`string-match-left-right/${t}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof a}", and equal to:
13
- ${JSON.stringify(a,null,4)}`);let u=0,E="";if((o==null?void 0:o.trimCharsBeforeMatching)&&o.trimCharsBeforeMatching.some((h,c)=>h.length>1?(u=c,E=h,!0):!1))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${u} is longer than 1 character, ${E.length} (equals to ${E}). Please split it into separate characters and put into array as separate elements.`);if(!l||!Array.isArray(l)||Array.isArray(l)&&!l.length||Array.isArray(l)&&l.length===1&&y(l[0])&&!l[0].trim()){if(typeof o.cb=="function"){let c,m=e;if((t==="matchLeftIncl"||t==="matchRight")&&(m+=1),t[5]==="L")for(let f=m;f--;){let $=n[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$!==void 0&&$.trim())&&(!o.trimCharsBeforeMatching||!o.trimCharsBeforeMatching.length||$!==void 0&&!o.trimCharsBeforeMatching.includes($))){c=f;break}}else if(t.startsWith("matchRight"))for(let f=m;f<n.length;f++){let $=n[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$.trim())&&(!o.trimCharsBeforeMatching||!o.trimCharsBeforeMatching.length||!o.trimCharsBeforeMatching.includes($))){c=f;break}}if(c===void 0)return!1;let b=n[c],r=c+1,g="";return r&&r>0&&(g=n.slice(0,r)),t[5]==="L"||c&&c>0&&(g=n.slice(c)),o.cb(b,g,c)}let h="";throw a||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${h}`)}for(let h=0,c=l.length;h<c;h++){s=typeof l[h]=="function";let m=l[h],b,r,g="",f=e;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=W(n,f,m,o,s,d=>t[5]==="L"?d-1:d+1);if($&&s&&typeof m=="function"&&m()==="EOL")return m()&&(o.cb?o.cb(b,g,r):!0)?m():!1;if(Number.isInteger($)&&(r=t.startsWith("matchLeft")?$-1:$+1,t[5]==="L"?g=n.slice(0,$):g=n.slice(r)),r<0&&(r=void 0),n[r]&&(b=n[r]),Number.isInteger($)&&(o.cb?o.cb(b,g,r):!0))return m}return!1}function _(t,n,e,i){return M("matchLeftIncl",t,n,e,i)}function q(t,n,e,i){return M("matchLeft",t,n,e,i)}function Y(t,n,e,i){return M("matchRightIncl",t,n,e,i)}function G(t,n,e,i){return M("matchRight",t,n,e,i)}return P(K);})();
10
+ "use strict";var stringMatchLeftRight=(()=>{var y=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var k=(t,n,e)=>n in t?y(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,p=(t,n)=>{for(var e in n||(n={}))A.call(n,e)&&k(t,e,n[e]);if(N)for(var e of N(n))H.call(n,e)&&k(t,e,n[e]);return t};var j=(t,n)=>{for(var e in n)y(t,e,{get:n[e],enumerable:!0})},P=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of F(n))!A.call(t,a)&&a!==e&&y(t,a,{get:()=>n[a],enumerable:!(i=J(n,a))||i.enumerable});return t};var U=t=>P(y({},"__esModule",{value:!0}),t);var X={};j(X,{defaultGetNextIdx:()=>x,defaults:()=>R,matchLeft:()=>Y,matchLeftIncl:()=>q,matchRight:()=>K,matchRightIncl:()=>G,version:()=>W});function L(t){return typeof t!="string"?t:t.length?[t]:[]}var B="8.2.3";var W=B;function I(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function M(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},x=t=>t+1;function _(t,n,e,i,a=!1,s=x){let c=typeof e=="function"?e():e;if(+n<0&&a&&c==="EOL")return c;let o=p(p({},R),i);if(n>=t.length&&!a)return!1;let u=a?1:e.length,E=0,T=!1,C=!1,h=!1,l=o.maxMismatches,r=n,f=!1,$=!1,b=!1;function g(){return E===1&&l<o.maxMismatches-1}for(;t[r];){let D=s(r);if(o.trimBeforeMatching&&t[r].trim()===""){if(!t[D]&&a&&e==="EOL")return!0;r=s(r);continue}if(o&&!o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.includes(t[r])||(o==null?void 0:o.i)&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(V=>V.toLowerCase()).includes(t[r].toLowerCase())){if(a&&e==="EOL"&&!t[D])return!0;r=s(r);continue}let S=D>r?e[e.length-u]:e[u-1];if(!o.i&&t[r]===S||o.i&&t[r].toLowerCase()===S.toLowerCase()){if(f||(f=!0),h||(h=!0),u===e.length){if($=!0,l!==o.maxMismatches)return!1}else u===1&&(b=!0);if(u-=1,E++,g())return!1;if(!u)return E!==e.length||l===o.maxMismatches||!T?r:!1}else if(!T&&!E&&(T=!0),o.maxMismatches&&l&&r){l-=1;for(let V=0;V<=l;V++){let d=D>r?e[e.length-u+1+V]:e[u-2-V],w=t[s(r)];if(d&&(!o.i&&t[r]===d||o.i&&t[r].toLowerCase()===d.toLowerCase())&&(!o.firstMustMatch||u!==e.length)){if(E++,g())return!1;u-=2,f=!0;break}else if(w&&d&&(!o.i&&w===d||o.i&&w.toLowerCase()===d.toLowerCase())&&(!o.firstMustMatch||u!==e.length)){if(!E&&!o.hungry)return!1;u-=1,f=!0;break}else if(d===void 0&&l>=0&&f&&(!o.firstMustMatch||$)&&(!o.lastMustMatch||b))return r}f||(C=r)}else return r===0&&u===1&&!o.lastMustMatch&&h?0:!1;if(C!==!1&&C!==r&&(C=!1),u<1)return r;r=s(r)}if(u>0)return a&&c==="EOL"?!0:o&&o.maxMismatches>=u&&h?C||0:!1}function O(t,n,e,i,a){var T,C;if(I(a)&&Object.prototype.hasOwnProperty.call(a,"trimBeforeMatching")&&a&&typeof a.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(a.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let s=p(p({},R),a);if(typeof s.trimCharsBeforeMatching=="string"&&(s.trimCharsBeforeMatching=L(s.trimCharsBeforeMatching)),s.trimCharsBeforeMatching=s.trimCharsBeforeMatching.map(h=>M(h)?h:String(h)),!M(n)||!n.length)return!1;if(!Number.isInteger(e)||e<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof e}, equal to:
11
+ ${JSON.stringify(e,null,4)}`);let c,o;if(M(i))c=[i];else if(Array.isArray(i))c=i;else if(!i)c=i;else if(typeof i=="function")c=[],c.push(i);else throw new Error(`string-match-left-right/${t}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof i}, equal to:
12
+ ${JSON.stringify(i,null,4)}`);if(a&&!I(a))throw new Error(`string-match-left-right/${t}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof a}", and equal to:
13
+ ${JSON.stringify(a,null,4)}`);let u=0,E="";if((s==null?void 0:s.trimCharsBeforeMatching)&&s.trimCharsBeforeMatching.some((h,l)=>h.length>1?(u=l,E=h,!0):!1))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${u} is longer than 1 character, ${E.length} (equals to ${E}). Please split it into separate characters and put into array as separate elements.`);if(!c||!Array.isArray(c)||Array.isArray(c)&&!c.length||Array.isArray(c)&&c.length===1&&M(c[0])&&!c[0].trim()){if(typeof s.cb=="function"){let l,r=e;if((t==="matchLeftIncl"||t==="matchRight")&&(r+=1),t[5]==="L")for(let g=r;g--;){let m=n[g];if((!s.trimBeforeMatching||s.trimBeforeMatching&&m!==void 0&&m.trim())&&(!((T=s.trimCharsBeforeMatching)!=null&&T.length)||m!==void 0&&!s.trimCharsBeforeMatching.includes(m))){l=g;break}}else if(t.startsWith("matchRight"))for(let g=r;g<n.length;g++){let m=n[g];if((!s.trimBeforeMatching||s.trimBeforeMatching&&m.trim())&&(!((C=s.trimCharsBeforeMatching)!=null&&C.length)||!s.trimCharsBeforeMatching.includes(m))){l=g;break}}if(l===void 0)return!1;let f=n[l],$=l+1,b="";return $&&$>0&&(b=n.slice(0,$)),t[5]==="L"||l&&l>0&&(b=n.slice(l)),s.cb(f,b,l)}let h="";throw a||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${h}`)}for(let h=0,l=c.length;h<l;h++){o=typeof c[h]=="function";let r=c[h],f,$,b="",g=e;t==="matchRight"?g+=1:t==="matchLeft"&&(g-=1);let m=_(n,g,r,s,o,D=>t[5]==="L"?D-1:D+1);if(m&&o&&typeof r=="function"&&r()==="EOL")return r()&&(s.cb?s.cb(f,b,$):!0)?r():!1;if(Number.isInteger(m)&&($=t.startsWith("matchLeft")?m-1:m+1,t[5]==="L"?b=n.slice(0,m):b=n.slice($)),$<0&&($=void 0),n[$]&&(f=n[$]),Number.isInteger(m)&&(s.cb?s.cb(f,b,$):!0))return r}return!1}function q(t,n,e,i){return O("matchLeftIncl",t,n,e,i)}function Y(t,n,e,i){return O("matchLeft",t,n,e,i)}function G(t,n,e,i){return O("matchRightIncl",t,n,e,i)}function K(t,n,e,i){return O("matchRight",t,n,e,i)}return U(X);})();
14
14
  /**
15
15
  * @name arrayiffy-if-string
16
16
  * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
17
- * @version 4.1.1
17
+ * @version 4.1.2
18
18
  * @author Roy Revelt, Codsen Ltd
19
19
  * @license MIT
20
20
  * {@link https://codsen.com/os/arrayiffy-if-string/}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-match-left-right",
3
- "version": "8.2.1",
3
+ "version": "8.2.3",
4
4
  "description": "Match substrings on the left or right of a given index, ignoring whitespace",
5
5
  "keywords": [
6
6
  "left",
@@ -66,9 +66,9 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "arrayiffy-if-string": "^4.1.1",
69
+ "arrayiffy-if-string": "^4.1.2",
70
70
  "lodash.isplainobject": "^4.0.6",
71
- "string-character-is-astral-surrogate": "^2.1.1"
71
+ "string-character-is-astral-surrogate": "^2.1.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/lodash.isplainobject": "^4.0.7"