Changelog

All notable changes to this project will be documented in this file.
See Conventional Commits opens in a new tab for commit guidelines.

9.0.0

1 Dec 2022

💥 BREAKING CHANGES

  • Minimum supported Node version is v14.18; we’re dropping v12 support

8.2.0

12 Aug 2022

Features

8.1.0

10 Apr 2022

Features

  • export defaults and version (405add5)

8.0.0

9 Sept 2021

Features

💥 BREAKING CHANGES

  • programs now are in ES Modules and won’t work with Common JS require()

7.1.0

24 May 2021

Features

  • config file based major bump blacklisting (e15f9bb)

7.0.9

11 Apr 2021

Reverts

  • Revert “chore: setup refresh” (23cf206)

7.0.0

27 Feb 2021

🔧 Fixed

  • if the first char was matched, don’t tolerate any mismatches leading up to it (c482851)

Features

  • algorithm improvements to avoid false positives in too early matches (552df88)
  • opts.hungry (68b1c0f)

💥 BREAKING CHANGES

  • This flag, disabled by default, prevents from too-eager matching in the beginning, wasting maxMismatches. To get old behaviour like before this release, set opts.hungry to true.

6.0.1

28 Jan 2021

🔧 Fixed

  • add testStats to npmignore (f3c84e9)

6.0.0

23 Jan 2021

Features

💥 BREAKING CHANGES

  • there should be no API changes, but we’re bumping major just in case

5.0.0

28 Nov 2020

Accidental version bump during migration to SourceHut. Sorry about that.

4.0.1

24 Mar 2020

🔧 Fixed

  • fix opts.firstMustMatch (195350b)

4.0.0

16 Mar 2020

🔧 Fixed

  • opts.maxMismatches higher than one (c0a416a)
  • add insurance against the variable being not string (e53f435)
  • fix opts.matchRight (ba40509)
  • fix maxMismatches (be34351)
  • fix the excessive skipping (e97899d)
  • insurance against undefined value (a0d5193)

Features

  • opts.maxMismatches (5288fe9)
  • case when character is omitted from the source and maxMismatches allows that (1b47eba)
  • merge marchForward and marchBackward into one, simplify the API (e873ee6)
  • opts.lastMustMatch (12ad597)
  • opts.skipWhitespace (6d9c847)
  • rebase to make twice as fast (4530b9f)
  • remove opts.skipInnerWhitespace (541c1c5)

💥 BREAKING CHANGES

  • no more opts.relaxedApi — it’s relaxed as much as possible by default, no emoji-related code

CHANGES

  • 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.
  • 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.

3.11.0

8 Aug 2019

Features

  • second callback’s argument returns empty string when EOL is reached (previously — undefined) (b480821)

3.10.0

20 Jan 2019
  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

3.6.0

26 Dec 2018
  • Add EOL matching and code refresh (ca834a7)
  • Add opts.relaxedApi (f30626c)

3.5.0

4 Dec 2018
  • 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.
  • 🔧 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.
  • Implemented and released (but not documented) opts.strictApi was merged with opts.relaxedApi
  • Restored unit test coverage and ava linting

3.4.0

11 Jun 2018
  • migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
  • dropped BitHound (RIP) and Travis
  • removed package-lock

3.3.0

16 May 2018
  • Add opts.relaxedApi

3.2.0

15 May 2018
  • Set up Prettier
  • Removed package.lock and .editorconfig
  • Wired Rollup to remove comments from non-dev builds. This means we can now leave the console.logs in the source code — Rollup will remove them from production code.
  • Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed
  • Removed DEBUG statements from the code
  • Added esm config to package.json which somehow enables CJS compat in ava.

3.1.1

6 Mar 2018
  • 🔧 Looks like the new callback feature was causing throws on certain cases. Not any more. Sorry about that. Very big release in coming soon with great new features. 👍

3.1.0

1 Mar 2018
  • 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.

3.0.0

15 Jan 2018
  • Rewrote a lot of code, relieving us from all lodash dependencies.

  • 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.

  • Callback cb now returns three arguments:

    1. char — the character just outside of the matched substring (as previously)
    2. theRemainderOfTheString — whole string outside of the matched substring (as previously)
    3. index — NEW — the index of the char.

    Index is handy in cases when you set trimming and it’s not clear where exactly is the char located in the string. Also, from here you can easily calculate the index of the match — just substract its length from index.

🔧 Fixed

  • 🔧 I think matchLeftIncl previously was returning theRemainderOfTheString together with the matched substring (on the right of it). That’s against the spec because the spec says “everything outside of the matched substring is given”. But not including it. Sorry for this error. I’ll bump the major just in case the correct behaviour breaks somebody’s code.

2.0.0

21 Dec 2017

✈️ Changes

  • 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.

Instructions to upgrade from 1.x

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.

  • 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.

1.4.0

10 Dec 2017

Features

  • Stringifying of opts.trimCharsBeforeMatching now occurs only if element is not string.
  • Callbacks, opts.cbLeft and opts.cbRight, 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).

I needed this when I was coding 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).

1.3.0

23 Nov 2017
  • Add opts.trimCharsBeforeMatching

1.2.0

22 Nov 2017
  • Add opts.trimBeforeMatching

1.1.0

28 Oct 2017
  • Add opts.cbLeft
  • Add opts.cbRight

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!

Here comes in the callback functions.

They have to be callbacks because I can’t predict what checks you will want to check on the outer-left and outer-right characters. Just pass your function and this library will feed them (the outer-left and outer-right characters) as arguments. You can then find out yourself what to do about it.

1.0.0

28 Oct 2017
  • First public release