JSPM

@daiyam/balanced-pairs

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q46458F
  • License MIT

Find your brackets and quotes in pairs

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

MIT licensed NPM Version License License License

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 ko-fi.com/daiyam
Liberapay liberapay.com/daiyam/donate
PayPal paypal.me/daiyam99

License

Copyright © 2021-present Baptiste Augrain

Licensed under the MIT license.