Package Exports
- @daiyam/balanced-pairs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@daiyam/balanced-pairs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@daiyam/balanced-pairs
Find your brackets and quotes in pairs
Getting Started
With node previously installed:
npm install @daiyam/balanced-pairs
import { matchPair } from '@daiyam/balanced-pairs';
const JSON_WITH_COMMENTS_CONFIG = {
pairs: {
blocks: [
['{', '}'],
['[', ']'],
],
strings: [
['"', '"', '\\"', '\\\\'],
['\'', '\'', '\'', '\\\\'],
['`', '`', '`', '\\\\'],
],
},
comments: {
lines: [
'//',
],
blocks: [
['/*', '*/'],
],
},
};
/*
* @param {string} text - The JSON string
* @param {number} index - The index of the first character of the pair
* @return {number} The index of the last character of the pair
*/
function matchPairPerIndex(text: string, index: number): number {
return matchPair(text, index, JSON_WITH_COMMENTS_CONFIG);
}
/*
* @param {string | string[]} text - The JSON string
* @param {line: number, column: number} position - The position of first character of the pair
* @return {line: number, column: number} The position of the last character of the pair
*/
function matchPairPerPosition(text: string | string[], position: {line: number, column: number}): {line: number, column: number} {
return matchPair(text, position, JSON_WITH_COMMENTS_CONFIG);
}
Donations
Support this project by becoming a financial contributor.
![]() |
ko-fi.com/daiyam |
![]() |
liberapay.com/daiyam/donate |
![]() |
paypal.me/daiyam99 |
License
Copyright © 2021-present Baptiste Augrain
Licensed under the MIT license.