juliangruber / balanced-match

Match balanced character pairs, like { and }
MIT License
125 stars 40 forks source link

No body when delimiters match #26

Closed F1LT3R closed 3 years ago

F1LT3R commented 6 years ago

I would expect matching delimiters to work. Ie: code fences in Markdown.

    ```js
    const foo = bar => baz

It seems imposible to balance matching delimiters with `balanced-match`.

Is this expected?

Example:

```js
const balanced = require('balanced-match')

const contents = 'PRE ___BODY___ POST'
const result = balanced('___', '___', contents)

console.log(result)

Result:

(Where is the body?)

{ start: 11, end: 11, pre: 'PRE ___BODY', body: '', post: ' POST' }

Expected:

(I was thinking we should see this)

{ start: 4, end: 11, pre: 'PRE ', body: 'BODY', post: ' POST' }
dimaio77 commented 5 years ago

this is a issue because a === b . adding the following in line 31 fix the problem if(a===b) {return [ai,bi]}

juliangruber commented 5 years ago

Thank you for reporting and investigating this, would you mind opening a PR with your fix, and even better, with some tests too?