Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daiyam/node-balanced-pairs
https://github.com/daiyam/node-balanced-pairs
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/daiyam/node-balanced-pairs
- Owner: daiyam
- License: mit
- Created: 2021-08-12T15:02:57.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-12T16:35:41.000Z (over 3 years ago)
- Last Synced: 2024-08-08T19:57:07.497Z (5 months ago)
- Language: TypeScript
- Size: 117 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[@daiyam/balanced-pairs](https://github.com/daiyam/node-balanced-pairs)
=======================================================================[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![NPM Version](https://img.shields.io/npm/v/@daiyam/balanced-pairs.svg?colorB=green)](https://www.npmjs.com/package/@daiyam/balanced-pairs)
[![License](https://img.shields.io/badge/donate-ko--fi-green)](https://ko-fi.com/daiyam)
[![License](https://img.shields.io/badge/donate-liberapay-green)](https://liberapay.com/daiyam/donate)
[![License](https://img.shields.io/badge/donate-paypal-green)](https://paypal.me/daiyam99)Find your brackets and quotes in pairs
Getting Started
---------------With [node](http://nodejs.org) previously installed:
npm install @daiyam/balanced-pairs
```typescript
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](https://opensource.org/licenses/MIT).