string-match-left-right 8.0.4 → 8.0.10

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
@@ -3,26 +3,6 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## 8.0.3 (2021-11-02)
7
-
8
- ### Bug Fixes
9
-
10
- - bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
11
-
12
- ### Features
13
-
14
- - migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
15
-
16
- ### BREAKING CHANGES
17
-
18
- - programs now are in ES Modules and won't work with Common JS require()
19
-
20
- ## 8.0.1 (2021-09-13)
21
-
22
- ### Bug Fixes
23
-
24
- - bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
25
-
26
6
  ## 8.0.0 (2021-09-09)
27
7
 
28
8
  ### Features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-%YEAR% Roy Revelt and other contributors
3
+ Copyright (c) 2010-2021 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
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 7.1.0
38
38
 
39
39
  ```js
40
40
  import { strict as assert } from "assert";
41
+
41
42
  import {
42
43
  matchLeftIncl,
43
44
  matchRightIncl,
@@ -63,7 +64,7 @@ assert.equal(matchRight("abcdefghi", 3, ["ef", `zz`]), "ef");
63
64
 
64
65
  ## Documentation
65
66
 
66
- Please [visit codsen.com](https://codsen.com/os/string-match-left-right/) for a full description of the API and examples.
67
+ Please [visit codsen.com](https://codsen.com/os/string-match-left-right/) for a full description of the API.
67
68
 
68
69
  ## Contributing
69
70
 
@@ -75,4 +76,6 @@ MIT License
75
76
 
76
77
  Copyright (c) 2010-2021 Roy Revelt and other contributors
77
78
 
79
+
78
80
  <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">
81
+
@@ -1,305 +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.0.4
4
+ * @version 8.0.10
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 } from 'arrayiffy-if-string';
11
-
12
- function isObj(something) {
13
- return something && typeof something === "object" && !Array.isArray(something);
14
- }
15
- function isStr(something) {
16
- return typeof something === "string";
17
- }
18
- const defaults = {
19
- cb: undefined,
20
- i: false,
21
- trimBeforeMatching: false,
22
- trimCharsBeforeMatching: [],
23
- maxMismatches: 0,
24
- firstMustMatch: false,
25
- lastMustMatch: false,
26
- hungry: false
27
- };
28
- const defaultGetNextIdx = index => index + 1;
29
- function march(str, position, whatToMatchVal, originalOpts, special = false, getNextIdx = defaultGetNextIdx) {
30
- const whatToMatchValVal = typeof whatToMatchVal === "function" ? whatToMatchVal() : whatToMatchVal;
31
- if (+position < 0 && special && whatToMatchValVal === "EOL") {
32
- return whatToMatchValVal;
33
- }
34
- const opts = { ...defaults,
35
- ...originalOpts
36
- };
37
- if (position >= str.length && !special) {
38
- return false;
39
- }
40
- let charsToCheckCount = special ? 1 : whatToMatchVal.length;
41
- let charsMatchedTotal = 0;
42
- let patienceReducedBeforeFirstMatch = false;
43
- let lastWasMismatched = false;
44
- let atLeastSomethingWasMatched = false;
45
- let patience = opts.maxMismatches;
46
- let i = position;
47
- let somethingFound = false;
48
- let firstCharacterMatched = false;
49
- let lastCharacterMatched = false;
50
- function whitespaceInFrontOfFirstChar() {
51
- return (
52
- charsMatchedTotal === 1 &&
53
- patience < opts.maxMismatches - 1
54
- );
55
- }
56
- while (str[i]) {
57
- const nextIdx = getNextIdx(i);
58
- if (opts.trimBeforeMatching && str[i].trim() === "") {
59
- if (!str[nextIdx] && special && whatToMatchVal === "EOL") {
60
- return true;
61
- }
62
- i = getNextIdx(i);
63
- continue;
64
- }
65
- if (opts && !opts.i && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.includes(str[i]) || opts && opts.i && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.map(val => val.toLowerCase()).includes(str[i].toLowerCase())) {
66
- if (special && whatToMatchVal === "EOL" && !str[nextIdx]) {
67
- return true;
68
- }
69
- i = getNextIdx(i);
70
- continue;
71
- }
72
- const charToCompareAgainst = nextIdx > i ? whatToMatchVal[whatToMatchVal.length - charsToCheckCount] : whatToMatchVal[charsToCheckCount - 1];
73
- if (!opts.i && str[i] === charToCompareAgainst || opts.i && str[i].toLowerCase() === charToCompareAgainst.toLowerCase()) {
74
- if (!somethingFound) {
75
- somethingFound = true;
76
- }
77
- if (!atLeastSomethingWasMatched) {
78
- atLeastSomethingWasMatched = true;
79
- }
80
- if (charsToCheckCount === whatToMatchVal.length) {
81
- firstCharacterMatched = true;
82
- if (patience !== opts.maxMismatches) {
83
- return false;
84
- }
85
- } else if (charsToCheckCount === 1) {
86
- lastCharacterMatched = true;
87
- }
88
- charsToCheckCount -= 1;
89
- charsMatchedTotal++;
90
- if (whitespaceInFrontOfFirstChar()) {
91
- return false;
92
- }
93
- if (!charsToCheckCount) {
94
- return (
95
- charsMatchedTotal !== whatToMatchVal.length ||
96
- patience === opts.maxMismatches ||
97
- !patienceReducedBeforeFirstMatch ? i : false
98
- );
99
- }
100
- } else {
101
- if (!patienceReducedBeforeFirstMatch && !charsMatchedTotal) {
102
- patienceReducedBeforeFirstMatch = true;
103
- }
104
- if (opts.maxMismatches && patience && i) {
105
- patience -= 1;
106
- for (let y = 0; y <= patience; y++) {
107
- const nextCharToCompareAgainst = nextIdx > i ? whatToMatchVal[whatToMatchVal.length - charsToCheckCount + 1 + y] : whatToMatchVal[charsToCheckCount - 2 - y];
108
- const nextCharInSource = str[getNextIdx(i)];
109
- if (nextCharToCompareAgainst && (!opts.i && str[i] === nextCharToCompareAgainst || opts.i && str[i].toLowerCase() === nextCharToCompareAgainst.toLowerCase()) && (
110
- !opts.firstMustMatch || charsToCheckCount !== whatToMatchVal.length)) {
111
- charsMatchedTotal++;
112
- if (whitespaceInFrontOfFirstChar()) {
113
- return false;
114
- }
115
- charsToCheckCount -= 2;
116
- somethingFound = true;
117
- break;
118
- } else if (nextCharInSource && nextCharToCompareAgainst && (!opts.i && nextCharInSource === nextCharToCompareAgainst || opts.i && nextCharInSource.toLowerCase() === nextCharToCompareAgainst.toLowerCase()) && (
119
- !opts.firstMustMatch || charsToCheckCount !== whatToMatchVal.length)) {
120
- if (!charsMatchedTotal && !opts.hungry) {
121
- return false;
122
- }
123
- charsToCheckCount -= 1;
124
- somethingFound = true;
125
- break;
126
- } else if (nextCharToCompareAgainst === undefined && patience >= 0 && somethingFound && (!opts.firstMustMatch || firstCharacterMatched) && (!opts.lastMustMatch || lastCharacterMatched)) {
127
- return i;
128
- }
129
- }
130
- if (!somethingFound) {
131
- lastWasMismatched = i;
132
- }
133
- } else if (i === 0 && charsToCheckCount === 1 && !opts.lastMustMatch && atLeastSomethingWasMatched) {
134
- return 0;
135
- } else {
136
- return false;
137
- }
138
- }
139
- if (lastWasMismatched !== false && lastWasMismatched !== i) {
140
- lastWasMismatched = false;
141
- }
142
- if (charsToCheckCount < 1) {
143
- return i;
144
- }
145
- i = getNextIdx(i);
146
- }
147
- if (charsToCheckCount > 0) {
148
- if (special && whatToMatchValVal === "EOL") {
149
- return true;
150
- }
151
- if (opts && opts.maxMismatches >= charsToCheckCount && atLeastSomethingWasMatched) {
152
- return lastWasMismatched || 0;
153
- }
154
- return false;
155
- }
156
- }
157
- function main(mode, str, position, originalWhatToMatch, originalOpts) {
158
- if (isObj(originalOpts) && Object.prototype.hasOwnProperty.call(originalOpts, "trimBeforeMatching") && typeof originalOpts.trimBeforeMatching !== "boolean") {
159
- throw new Error(`string-match-left-right/${mode}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(originalOpts.trimBeforeMatching) ? ` Did you mean to use opts.trimCharsBeforeMatching?` : ""}`);
160
- }
161
- const opts = { ...defaults,
162
- ...originalOpts
163
- };
164
- if (typeof opts.trimCharsBeforeMatching === "string") {
165
- opts.trimCharsBeforeMatching = arrayiffy(opts.trimCharsBeforeMatching);
166
- }
167
- opts.trimCharsBeforeMatching = opts.trimCharsBeforeMatching.map(el => isStr(el) ? el : String(el));
168
- if (!isStr(str)) {
169
- return false;
170
- }
171
- if (!str.length) {
172
- return false;
173
- }
174
- if (!Number.isInteger(position) || position < 0) {
175
- throw new Error(`string-match-left-right/${mode}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof position}, equal to:\n${JSON.stringify(position, null, 4)}`);
176
- }
177
- let whatToMatch;
178
- let special;
179
- if (isStr(originalWhatToMatch)) {
180
- whatToMatch = [originalWhatToMatch];
181
- } else if (Array.isArray(originalWhatToMatch)) {
182
- whatToMatch = originalWhatToMatch;
183
- } else if (!originalWhatToMatch) {
184
- whatToMatch = originalWhatToMatch;
185
- } else if (typeof originalWhatToMatch === "function") {
186
- whatToMatch = [];
187
- whatToMatch.push(originalWhatToMatch);
188
- } else {
189
- throw new Error(`string-match-left-right/${mode}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof originalWhatToMatch}, equal to:\n${JSON.stringify(originalWhatToMatch, null, 4)}`);
190
- }
191
- if (originalOpts && !isObj(originalOpts)) {
192
- throw new Error(`string-match-left-right/${mode}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof originalOpts}", and equal to:\n${JSON.stringify(originalOpts, null, 4)}`);
193
- }
194
- let culpritsIndex = 0;
195
- let culpritsVal = "";
196
- if (opts && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.some((el, i) => {
197
- if (el.length > 1) {
198
- culpritsIndex = i;
199
- culpritsVal = el;
200
- return true;
201
- }
202
- return false;
203
- })) {
204
- throw new Error(`string-match-left-right/${mode}(): [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 ${culpritsIndex} is longer than 1 character, ${culpritsVal.length} (equals to ${culpritsVal}). Please split it into separate characters and put into array as separate elements.`);
205
- }
206
- if (!whatToMatch || !Array.isArray(whatToMatch) ||
207
- Array.isArray(whatToMatch) && !whatToMatch.length ||
208
- Array.isArray(whatToMatch) && whatToMatch.length === 1 && isStr(whatToMatch[0]) && !whatToMatch[0].trim()
209
- ) {
210
- if (typeof opts.cb === "function") {
211
- let firstCharOutsideIndex;
212
- let startingPosition = position;
213
- if (mode === "matchLeftIncl" || mode === "matchRight") {
214
- startingPosition += 1;
215
- }
216
- if (mode[5] === "L") {
217
- for (let y = startingPosition; y--;) {
218
- const currentChar = str[y];
219
- if ((!opts.trimBeforeMatching || opts.trimBeforeMatching && currentChar !== undefined && currentChar.trim()) && (!opts.trimCharsBeforeMatching || !opts.trimCharsBeforeMatching.length || currentChar !== undefined && !opts.trimCharsBeforeMatching.includes(currentChar))) {
220
- firstCharOutsideIndex = y;
221
- break;
222
- }
223
- }
224
- } else if (mode.startsWith("matchRight")) {
225
- for (let y = startingPosition; y < str.length; y++) {
226
- const currentChar = str[y];
227
- if ((!opts.trimBeforeMatching || opts.trimBeforeMatching && currentChar.trim()) && (!opts.trimCharsBeforeMatching || !opts.trimCharsBeforeMatching.length || !opts.trimCharsBeforeMatching.includes(currentChar))) {
228
- firstCharOutsideIndex = y;
229
- break;
230
- }
231
- }
232
- }
233
- if (firstCharOutsideIndex === undefined) {
234
- return false;
235
- }
236
- const wholeCharacterOutside = str[firstCharOutsideIndex];
237
- const indexOfTheCharacterAfter = firstCharOutsideIndex + 1;
238
- let theRemainderOfTheString = "";
239
- if (indexOfTheCharacterAfter && indexOfTheCharacterAfter > 0) {
240
- theRemainderOfTheString = str.slice(0, indexOfTheCharacterAfter);
241
- }
242
- if (mode[5] === "L") {
243
- return opts.cb(wholeCharacterOutside, theRemainderOfTheString, firstCharOutsideIndex);
244
- }
245
- if (firstCharOutsideIndex && firstCharOutsideIndex > 0) {
246
- theRemainderOfTheString = str.slice(firstCharOutsideIndex);
247
- }
248
- return opts.cb(wholeCharacterOutside, theRemainderOfTheString, firstCharOutsideIndex);
249
- }
250
- let extraNote = "";
251
- if (!originalOpts) {
252
- extraNote = " More so, the whole options object, the fourth input argument, is missing!";
253
- }
254
- throw new Error(`string-match-left-right/${mode}(): [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!${extraNote}`);
255
- }
256
- for (let i = 0, len = whatToMatch.length; i < len; i++) {
257
- special = typeof whatToMatch[i] === "function";
258
- const whatToMatchVal = whatToMatch[i];
259
- let fullCharacterInFront;
260
- let indexOfTheCharacterInFront;
261
- let restOfStringInFront = "";
262
- let startingPosition = position;
263
- if (mode === "matchRight") {
264
- startingPosition += 1;
265
- } else if (mode === "matchLeft") {
266
- startingPosition -= 1;
267
- }
268
- const found = march(str, startingPosition, whatToMatchVal, opts, special, i2 => mode[5] === "L" ? i2 - 1 : i2 + 1);
269
- if (found && special && typeof whatToMatchVal === "function" && whatToMatchVal() === "EOL") {
270
- return whatToMatchVal() && (opts.cb ? opts.cb(fullCharacterInFront, restOfStringInFront, indexOfTheCharacterInFront) : true) ? whatToMatchVal() : false;
271
- }
272
- if (Number.isInteger(found)) {
273
- indexOfTheCharacterInFront = mode.startsWith("matchLeft") ? found - 1 : found + 1;
274
- if (mode[5] === "L") {
275
- restOfStringInFront = str.slice(0, found);
276
- } else {
277
- restOfStringInFront = str.slice(indexOfTheCharacterInFront);
278
- }
279
- }
280
- if (indexOfTheCharacterInFront < 0) {
281
- indexOfTheCharacterInFront = undefined;
282
- }
283
- if (str[indexOfTheCharacterInFront]) {
284
- fullCharacterInFront = str[indexOfTheCharacterInFront];
285
- }
286
- if (Number.isInteger(found) && (opts.cb ? opts.cb(fullCharacterInFront, restOfStringInFront, indexOfTheCharacterInFront) : true)) {
287
- return whatToMatchVal;
288
- }
289
- }
290
- return false;
291
- }
292
- function matchLeftIncl(str, position, whatToMatch, opts) {
293
- return main("matchLeftIncl", str, position, whatToMatch, opts);
294
- }
295
- function matchLeft(str, position, whatToMatch, opts) {
296
- return main("matchLeft", str, position, whatToMatch, opts);
297
- }
298
- function matchRightIncl(str, position, whatToMatch, opts) {
299
- return main("matchRightIncl", str, position, whatToMatch, opts);
300
- }
301
- function matchRight(str, position, whatToMatch, opts) {
302
- return main("matchRight", str, position, whatToMatch, opts);
303
- }
304
-
305
- export { matchLeft, matchLeftIncl, matchRight, matchRightIncl };
10
+ import{arrayiffy as S}from"arrayiffy-if-string";function p(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},w=t=>t+1;function N(t,a,n,s,h=!1,o=w){let l=typeof n=="function"?n():n;if(+a<0&&h&&l==="EOL")return l;let r={...R,...s};if(a>=t.length&&!h)return!1;let c=h?1:n.length,E=0,u=!1,i=!1,m=!1,b=r.maxMismatches,e=a,g=!1,f=!1,$=!1;function T(){return E===1&&b<r.maxMismatches-1}for(;t[e];){let V=o(e);if(r.trimBeforeMatching&&t[e].trim()===""){if(!t[V]&&h&&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(h&&n==="EOL"&&!t[V])return!0;e=o(e);continue}let d=V>e?n[n.length-c]:n[c-1];if(!r.i&&t[e]===d||r.i&&t[e].toLowerCase()===d.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++,T())return!1;if(!c)return E!==n.length||b===r.maxMismatches||!u?e:!1}else if(!u&&!E&&(u=!0),r.maxMismatches&&b&&e){b-=1;for(let D=0;D<=b;D++){let C=V>e?n[n.length-c+1+D]:n[c-2-D],O=t[o(e)];if(C&&(!r.i&&t[e]===C||r.i&&t[e].toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(E++,T())return!1;c-=2,g=!0;break}else if(O&&C&&(!r.i&&O===C||r.i&&O.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||(i=e)}else return e===0&&c===1&&!r.lastMustMatch&&m?0:!1;if(i!==!1&&i!==e&&(i=!1),c<1)return e;e=o(e)}if(c>0)return h&&l==="EOL"?!0:r&&r.maxMismatches>=c&&m?i||0:!1}function y(t,a,n,s,h){if(p(h)&&Object.prototype.hasOwnProperty.call(h,"trimBeforeMatching")&&typeof h.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(h.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let o={...R,...h};if(typeof o.trimCharsBeforeMatching=="string"&&(o.trimCharsBeforeMatching=S(o.trimCharsBeforeMatching)),o.trimCharsBeforeMatching=o.trimCharsBeforeMatching.map(u=>M(u)?u:String(u)),!M(a)||!a.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 l,r;if(M(s))l=[s];else if(Array.isArray(s))l=s;else if(!s)l=s;else if(typeof s=="function")l=[],l.push(s);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 s}, equal to:
12
+ ${JSON.stringify(s,null,4)}`);if(h&&!p(h))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 h}", and equal to:
13
+ ${JSON.stringify(h,null,4)}`);let c=0,E="";if(o?.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.some((u,i)=>u.length>1?(c=i,E=u,!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(!l||!Array.isArray(l)||Array.isArray(l)&&!l.length||Array.isArray(l)&&l.length===1&&M(l[0])&&!l[0].trim()){if(typeof o.cb=="function"){let i,m=n;if((t==="matchLeftIncl"||t==="matchRight")&&(m+=1),t[5]==="L")for(let f=m;f--;){let $=a[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$!==void 0&&$.trim())&&(!o.trimCharsBeforeMatching||!o.trimCharsBeforeMatching.length||$!==void 0&&!o.trimCharsBeforeMatching.includes($))){i=f;break}}else if(t.startsWith("matchRight"))for(let f=m;f<a.length;f++){let $=a[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$.trim())&&(!o.trimCharsBeforeMatching||!o.trimCharsBeforeMatching.length||!o.trimCharsBeforeMatching.includes($))){i=f;break}}if(i===void 0)return!1;let b=a[i],e=i+1,g="";return e&&e>0&&(g=a.slice(0,e)),t[5]==="L"||i&&i>0&&(g=a.slice(i)),o.cb(b,g,i)}let u="";throw h||(u=" 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!${u}`)}for(let u=0,i=l.length;u<i;u++){r=typeof l[u]=="function";let m=l[u],b,e,g="",f=n;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=N(a,f,m,o,r,T=>t[5]==="L"?T-1:T+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=a.slice(0,$):g=a.slice(e)),e<0&&(e=void 0),a[e]&&(b=a[e]),Number.isInteger($)&&(o.cb?o.cb(b,g,e):!0))return m}return!1}function A(t,a,n,s){return y("matchLeftIncl",t,a,n,s)}function k(t,a,n,s){return y("matchLeft",t,a,n,s)}function B(t,a,n,s){return y("matchRightIncl",t,a,n,s)}function I(t,a,n,s){return y("matchRight",t,a,n,s)}export{k as matchLeft,A as matchLeftIncl,I as matchRight,B as matchRightIncl};
@@ -1,18 +1,21 @@
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.0.4
4
+ * @version 8.0.10
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
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).stringMatchLeftRight={})}(this,(function(t){"use strict";
10
+ var stringMatchLeftRight=(()=>{var y=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var N=(t,n,e)=>n in t?y(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,V=(t,n)=>{for(var e in n||(n={}))w.call(n,e)&&N(t,e,n[e]);if(S)for(var e of S(n))J.call(n,e)&&N(t,e,n[e]);return t};var x=t=>y(t,"__esModule",{value:!0});var F=(t,n)=>{for(var e in n)y(t,e,{get:n[e],enumerable:!0})},H=(t,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of I(n))!w.call(t,l)&&(e||l!=="default")&&y(t,l,{get:()=>n[l],enumerable:!(s=B(n,l))||s.enumerable});return t};var P=(t=>(n,e)=>t&&t.get(n)||(e=H(x({}),n,1),t&&t.set(n,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var G={};F(G,{matchLeft:()=>_,matchLeftIncl:()=>W,matchRight:()=>Y,matchRightIncl:()=>q});function L(t){return typeof t=="string"?t.length?[t]:[]:t}function A(t){return t&&typeof t=="object"&&!Array.isArray(t)}function O(t){return typeof t=="string"}var k={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},U=t=>t+1;function j(t,n,e,s,l=!1,r=U){var K;let i=typeof e=="function"?e():e;if(+n<0&&l&&i==="EOL")return i;let a=V(V({},k),s);if(n>=t.length&&!l)return!1;let u=l?1:e.length,E=0,h=!1,c=!1,m=!1,b=a.maxMismatches,o=n,g=!1,f=!1,$=!1;function T(){return E===1&&b<a.maxMismatches-1}for(;t[o];){let M=r(o);if(a.trimBeforeMatching&&t[o].trim()===""){if(!t[M]&&l&&e==="EOL")return!0;o=r(o);continue}if(a&&!a.i&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.includes(t[o])||(a==null?void 0:a.i)&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(t[o].toLowerCase())){if(l&&e==="EOL"&&!t[M])return!0;o=r(o);continue}let R=M>o?e[e.length-u]:e[u-1];if(!a.i&&t[o]===R||a.i&&t[o].toLowerCase()===R.toLowerCase()){if(g||(g=!0),m||(m=!0),u===e.length){if(f=!0,b!==a.maxMismatches)return!1}else u===1&&($=!0);if(u-=1,E++,T())return!1;if(!u)return E!==e.length||b===a.maxMismatches||!h?o:!1}else if(!h&&!E&&(h=!0),a.maxMismatches&&b&&o){b-=1;for(let D=0;D<=b;D++){let C=M>o?e[e.length-u+1+D]:e[u-2-D],p=t[r(o)];if(C&&(!a.i&&t[o]===C||a.i&&t[o].toLowerCase()===C.toLowerCase())&&(!a.firstMustMatch||u!==e.length)){if(E++,T())return!1;u-=2,g=!0;break}else if(p&&C&&(!a.i&&p===C||a.i&&p.toLowerCase()===C.toLowerCase())&&(!a.firstMustMatch||u!==e.length)){if(!E&&!a.hungry)return!1;u-=1,g=!0;break}else if(C===void 0&&b>=0&&g&&(!a.firstMustMatch||f)&&(!a.lastMustMatch||$))return o}g||(c=o)}else return o===0&&u===1&&!a.lastMustMatch&&m?0:!1;if(c!==!1&&c!==o&&(c=!1),u<1)return o;o=r(o)}if(u>0)return l&&i==="EOL"?!0:a&&a.maxMismatches>=u&&m?c||0:!1}function d(t,n,e,s,l){if(A(l)&&Object.prototype.hasOwnProperty.call(l,"trimBeforeMatching")&&typeof l.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(l.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let r=V(V({},k),l);if(typeof r.trimCharsBeforeMatching=="string"&&(r.trimCharsBeforeMatching=L(r.trimCharsBeforeMatching)),r.trimCharsBeforeMatching=r.trimCharsBeforeMatching.map(h=>O(h)?h:String(h)),!O(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 i,a;if(O(s))i=[s];else if(Array.isArray(s))i=s;else if(!s)i=s;else if(typeof s=="function")i=[],i.push(s);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 s}, equal to:
12
+ ${JSON.stringify(s,null,4)}`);if(l&&!A(l))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 l}", and equal to:
13
+ ${JSON.stringify(l,null,4)}`);let u=0,E="";if((r==null?void 0:r.trimCharsBeforeMatching)&&r.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(!i||!Array.isArray(i)||Array.isArray(i)&&!i.length||Array.isArray(i)&&i.length===1&&O(i[0])&&!i[0].trim()){if(typeof r.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((!r.trimBeforeMatching||r.trimBeforeMatching&&$!==void 0&&$.trim())&&(!r.trimCharsBeforeMatching||!r.trimCharsBeforeMatching.length||$!==void 0&&!r.trimCharsBeforeMatching.includes($))){c=f;break}}else if(t.startsWith("matchRight"))for(let f=m;f<n.length;f++){let $=n[f];if((!r.trimBeforeMatching||r.trimBeforeMatching&&$.trim())&&(!r.trimCharsBeforeMatching||!r.trimCharsBeforeMatching.length||!r.trimCharsBeforeMatching.includes($))){c=f;break}}if(c===void 0)return!1;let b=n[c],o=c+1,g="";return o&&o>0&&(g=n.slice(0,o)),t[5]==="L"||c&&c>0&&(g=n.slice(c)),r.cb(b,g,c)}let h="";throw l||(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=i.length;h<c;h++){a=typeof i[h]=="function";let m=i[h],b,o,g="",f=e;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=j(n,f,m,r,a,T=>t[5]==="L"?T-1:T+1);if($&&a&&typeof m=="function"&&m()==="EOL")return m()&&(r.cb?r.cb(b,g,o):!0)?m():!1;if(Number.isInteger($)&&(o=t.startsWith("matchLeft")?$-1:$+1,t[5]==="L"?g=n.slice(0,$):g=n.slice(o)),o<0&&(o=void 0),n[o]&&(b=n[o]),Number.isInteger($)&&(r.cb?r.cb(b,g,o):!0))return m}return!1}function W(t,n,e,s){return d("matchLeftIncl",t,n,e,s)}function _(t,n,e,s){return d("matchLeft",t,n,e,s)}function q(t,n,e,s){return d("matchRightIncl",t,n,e,s)}function Y(t,n,e,s){return d("matchRight",t,n,e,s)}return P(G);})();
11
14
  /**
12
15
  * @name arrayiffy-if-string
13
16
  * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
14
- * @version 4.0.4
17
+ * @version 4.0.10
15
18
  * @author Roy Revelt, Codsen Ltd
16
19
  * @license MIT
17
20
  * {@link https://codsen.com/os/arrayiffy-if-string/}
18
- */function e(t){return t&&"object"==typeof t&&!Array.isArray(t)}function r(t){return"string"==typeof t}const i={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},n=t=>t+1;function a(t,e,r,a,o=!1,s=n){const h="function"==typeof r?r():r;if(+e<0&&o&&"EOL"===h)return h;const c={...i,...a};if(e>=t.length&&!o)return!1;let f=o?1:r.length,u=0,l=!1,g=!1,m=!1,M=c.maxMismatches,y=e,p=!1,b=!1,d=!1;function B(){return 1===u&&M<c.maxMismatches-1}for(;t[y];){const e=s(y);if(c.trimBeforeMatching&&""===t[y].trim()){if(!t[e]&&o&&"EOL"===r)return!0;y=s(y);continue}if(c&&!c.i&&c.trimCharsBeforeMatching&&c.trimCharsBeforeMatching.includes(t[y])||c&&c.i&&c.trimCharsBeforeMatching&&c.trimCharsBeforeMatching.map((t=>t.toLowerCase())).includes(t[y].toLowerCase())){if(o&&"EOL"===r&&!t[e])return!0;y=s(y);continue}const i=e>y?r[r.length-f]:r[f-1];if(!c.i&&t[y]===i||c.i&&t[y].toLowerCase()===i.toLowerCase()){if(p||(p=!0),m||(m=!0),f===r.length){if(b=!0,M!==c.maxMismatches)return!1}else 1===f&&(d=!0);if(f-=1,u++,B())return!1;if(!f)return(u!==r.length||M===c.maxMismatches||!l)&&y}else{if(l||u||(l=!0),!(c.maxMismatches&&M&&y))return!(0!==y||1!==f||c.lastMustMatch||!m)&&0;M-=1;for(let i=0;i<=M;i++){const n=e>y?r[r.length-f+1+i]:r[f-2-i],a=t[s(y)];if(n&&(!c.i&&t[y]===n||c.i&&t[y].toLowerCase()===n.toLowerCase())&&(!c.firstMustMatch||f!==r.length)){if(u++,B())return!1;f-=2,p=!0;break}if(a&&n&&(!c.i&&a===n||c.i&&a.toLowerCase()===n.toLowerCase())&&(!c.firstMustMatch||f!==r.length)){if(!u&&!c.hungry)return!1;f-=1,p=!0;break}if(void 0===n&&M>=0&&p&&(!c.firstMustMatch||b)&&(!c.lastMustMatch||d))return y}p||(g=y)}if(!1!==g&&g!==y&&(g=!1),f<1)return y;y=s(y)}return f>0?!(!o||"EOL"!==h)||!!(c&&c.maxMismatches>=f&&m)&&(g||0):void 0}function o(t,n,o,s,h){if(e(h)&&Object.prototype.hasOwnProperty.call(h,"trimBeforeMatching")&&"boolean"!=typeof h.trimBeforeMatching)throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(h.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);const c={...i,...h};var f;if("string"==typeof c.trimCharsBeforeMatching&&(c.trimCharsBeforeMatching="string"==typeof(f=c.trimCharsBeforeMatching)?f.length?[f]:[]:f),c.trimCharsBeforeMatching=c.trimCharsBeforeMatching.map((t=>r(t)?t:String(t))),!r(n))return!1;if(!n.length)return!1;if(!Number.isInteger(o)||o<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 o}, equal to:\n${JSON.stringify(o,null,4)}`);let u,l;if(r(s))u=[s];else if(Array.isArray(s))u=s;else if(s){if("function"!=typeof s)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 s}, equal to:\n${JSON.stringify(s,null,4)}`);u=[],u.push(s)}else u=s;if(h&&!e(h))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 h}", and equal to:\n${JSON.stringify(h,null,4)}`);let g=0,m="";if(c&&c.trimCharsBeforeMatching&&c.trimCharsBeforeMatching.some(((t,e)=>t.length>1&&(g=e,m=t,!0))))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 ${g} is longer than 1 character, ${m.length} (equals to ${m}). Please split it into separate characters and put into array as separate elements.`);if(!u||!Array.isArray(u)||Array.isArray(u)&&!u.length||Array.isArray(u)&&1===u.length&&r(u[0])&&!u[0].trim()){if("function"==typeof c.cb){let e,r=o;if("matchLeftIncl"!==t&&"matchRight"!==t||(r+=1),"L"===t[5])for(let t=r;t--;){const r=n[t];if((!c.trimBeforeMatching||c.trimBeforeMatching&&void 0!==r&&r.trim())&&(!c.trimCharsBeforeMatching||!c.trimCharsBeforeMatching.length||void 0!==r&&!c.trimCharsBeforeMatching.includes(r))){e=t;break}}else if(t.startsWith("matchRight"))for(let t=r;t<n.length;t++){const r=n[t];if((!c.trimBeforeMatching||c.trimBeforeMatching&&r.trim())&&(!c.trimCharsBeforeMatching||!c.trimCharsBeforeMatching.length||!c.trimCharsBeforeMatching.includes(r))){e=t;break}}if(void 0===e)return!1;const i=n[e],a=e+1;let s="";return a&&a>0&&(s=n.slice(0,a)),"L"===t[5]?c.cb(i,s,e):(e&&e>0&&(s=n.slice(e)),c.cb(i,s,e))}let e="";throw h||(e=" 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!${e}`)}for(let e=0,r=u.length;e<r;e++){l="function"==typeof u[e];const r=u[e];let i,s,h="",f=o;"matchRight"===t?f+=1:"matchLeft"===t&&(f-=1);const g=a(n,f,r,c,l,(e=>"L"===t[5]?e-1:e+1));if(g&&l&&"function"==typeof r&&"EOL"===r())return!(!r()||c.cb&&!c.cb(i,h,s))&&r();if(Number.isInteger(g)&&(s=t.startsWith("matchLeft")?g-1:g+1,h="L"===t[5]?n.slice(0,g):n.slice(s)),s<0&&(s=void 0),n[s]&&(i=n[s]),Number.isInteger(g)&&(!c.cb||c.cb(i,h,s)))return r}return!1}t.matchLeft=function(t,e,r,i){return o("matchLeft",t,e,r,i)},t.matchLeftIncl=function(t,e,r,i){return o("matchLeftIncl",t,e,r,i)},t.matchRight=function(t,e,r,i){return o("matchRight",t,e,r,i)},t.matchRightIncl=function(t,e,r,i){return o("matchRightIncl",t,e,r,i)},Object.defineProperty(t,"__esModule",{value:!0})}));
21
+ */
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import {
5
6
  matchLeftIncl,
6
7
  matchRightIncl,
package/examples/cb.js CHANGED
@@ -1,6 +1,8 @@
1
+ /* eslint-disable no-unused-vars */
1
2
  // The Callback Use
2
3
 
3
4
  import { strict as assert } from "assert";
5
+
4
6
  import {
5
7
  matchLeftIncl,
6
8
  matchRightIncl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-match-left-right",
3
- "version": "8.0.4",
3
+ "version": "8.0.10",
4
4
  "description": "Match substrings on the left or right of a given index, ignoring whitespace",
5
5
  "keywords": [
6
6
  "left",
@@ -31,98 +31,42 @@
31
31
  },
32
32
  "types": "types/index.d.ts",
33
33
  "scripts": {
34
- "build": "rollup -c",
35
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
36
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
37
- "clean_types": "../../scripts/cleanTypes.js",
38
- "dev": "rollup -c --dev",
39
- "devunittest": "npm run dev && tap --only -R 'base'",
40
- "esbuild": "node '../../scripts/esbuild.js'",
41
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
42
- "format": "npm run lect && npm run prettier && npm run lint",
43
- "lect": "lect",
44
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
45
- "perf": "node perf/check",
46
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
47
- "republish": "npm publish || :",
48
- "tap": "tap",
49
- "pretest": "npm run build",
50
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
51
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
52
- "tsc": "tsc",
53
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
34
+ "build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
35
+ "dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
36
+ "dts": "rollup -c",
37
+ "examples": "node '../../ops/scripts/run-examples.js'",
38
+ "lect": "node '../../ops/lect/lect.js'",
39
+ "letspublish": "yarn publish || :",
40
+ "lint": "eslint . --fix",
41
+ "perf": "node perf/check.js",
42
+ "prepare": "echo 'ready'",
43
+ "pretest": "yarn run lect && yarn run build",
44
+ "test": "c8 yarn run unit && yarn run examples && yarn run lint",
45
+ "unit": "uvu test"
54
46
  },
55
- "tap": {
56
- "check-coverage": false,
57
- "coverage-report": [
58
- "json-summary",
59
- "text"
60
- ],
61
- "node-arg": [
62
- "--no-warnings",
63
- "--experimental-loader",
64
- "@istanbuljs/esm-loader-hook"
47
+ "engines": {
48
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
49
+ },
50
+ "c8": {
51
+ "check-coverage": true,
52
+ "exclude": [
53
+ "**/test/**/*.*"
65
54
  ],
66
- "timeout": 0
55
+ "lines": 100
67
56
  },
68
57
  "lect": {
69
58
  "licence": {
70
59
  "extras": [
71
60
  ""
72
61
  ]
73
- },
74
- "req": "{ matchLeftIncl, matchRightIncl, matchLeft, matchRight }",
75
- "various": {
76
- "devDependencies": [
77
- "@types/lodash.isplainobject"
78
- ]
79
62
  }
80
63
  },
81
64
  "dependencies": {
82
- "@babel/runtime": "^7.16.0",
83
- "arrayiffy-if-string": "^4.0.4",
65
+ "arrayiffy-if-string": "^4.0.10",
84
66
  "lodash.isplainobject": "^4.0.6",
85
- "string-character-is-astral-surrogate": "^2.0.4"
67
+ "string-character-is-astral-surrogate": "^2.0.10"
86
68
  },
87
69
  "devDependencies": {
88
- "@babel/cli": "^7.16.0",
89
- "@babel/core": "^7.16.0",
90
- "@babel/node": "^7.16.0",
91
- "@babel/plugin-external-helpers": "^7.16.0",
92
- "@babel/plugin-proposal-class-properties": "^7.16.0",
93
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
94
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
95
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
96
- "@babel/plugin-transform-runtime": "^7.16.0",
97
- "@babel/preset-env": "^7.16.0",
98
- "@babel/preset-typescript": "^7.16.0",
99
- "@babel/register": "^7.16.0",
100
- "@istanbuljs/esm-loader-hook": "^0.1.2",
101
- "@rollup/plugin-babel": "^5.3.0",
102
- "@rollup/plugin-commonjs": "^21.0.1",
103
- "@rollup/plugin-node-resolve": "^13.0.6",
104
- "@rollup/plugin-strip": "^2.1.0",
105
- "@rollup/plugin-typescript": "^8.3.0",
106
- "@types/lodash.isplainobject": "^4.0.6",
107
- "@types/node": "^16.11.6",
108
- "@types/tap": "^15.0.5",
109
- "@typescript-eslint/eslint-plugin": "^5.3.0",
110
- "@typescript-eslint/parser": "^5.3.0",
111
- "core-js": "^3.19.1",
112
- "cross-env": "^7.0.3",
113
- "eslint": "^8.1.0",
114
- "lect": "^0.18.4",
115
- "rollup": "^2.59.0",
116
- "rollup-plugin-ascii": "^0.0.3",
117
- "rollup-plugin-banner": "^0.2.1",
118
- "rollup-plugin-cleanup": "^3.2.1",
119
- "rollup-plugin-dts": "^4.0.0",
120
- "rollup-plugin-terser": "^7.0.2",
121
- "tap": "^15.0.10",
122
- "tslib": "^2.3.1",
123
- "typescript": "^4.4.4"
124
- },
125
- "engines": {
126
- "node": ">=12"
70
+ "@types/lodash.isplainobject": "^4.0.6"
127
71
  }
128
72
  }
package/types/index.d.ts CHANGED
File without changes
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B;\n matchLeftIncl,\n matchRightIncl,\n matchLeft,\n matchRight,\n&#x7D; from \"string-match-left-right\";\n\n// 3rd character is \"d\" because indexes start from zero.\n// We're checking the string to the left of it, \"bcd\", inclusive of current character (\"d\").\n// This means, \"bcd\" has to end with existing character and the other chars to the left\n// must match exactly:\nassert.equal(matchLeftIncl(\"abcdefghi\", 3, [\"bcd\"]), \"bcd\");\n\n// neither \"ab\" nor \"zz\" are to the left of 3rd index, \"d\":\nassert.equal(matchLeft(\"abcdefghi\", 3, [\"ab\", `zz`]), false);\n\n// \"def\" is to the right of 3rd index (including it), \"d\":\nassert.equal(matchRightIncl(\"abcdefghi\", 3, [\"def\", `zzz`]), \"def\");\n\n// One of values, \"ef\" is exactly to the right of 3rd index, \"d\":\nassert.equal(matchRight(\"abcdefghi\", 3, [\"ef\", `zz`]), \"ef\");"},"cb.js":{"title":"The Callback Use","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B;\n matchLeftIncl,\n matchRightIncl,\n matchLeft,\n matchRight,\n&#x7D; from \"string-match-left-right\";\n\n// imagine you looped the string and wanted to catch where does attribute \"class\" start\n// and end (not to mention to ensure that it's a real attribute, not something ending with this\n// string \"class\").\n// You catch \"=\", an index number 8.\n// This library can check, is \"class\" to the left of it and feed what's to the left of it\n// to your supplied callback function, which happens to be a checker \"is it a space\":\nfunction isSpace(char) &#x7B;\n return typeof char === \"string\" && char.trim() === \"\";\n&#x7D;\n\nassert.equal(\n matchLeft('<a class=\"something\">', 8, \"class\", &#x7B; cb: isSpace &#x7D;),\n \"class\"\n);"}}