Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

fretted-strings

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fretted-strings

Mark on your strings and get it's position

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
96
128.57%
Maintainers
1
Weekly downloads
 
Created
Source

fretted-strings

npm version GitHub license

Marks on your strings and get it's position.

npm i fretted-strings

Basic usage

import assert from 'node:assert';
import { extract } from 'fretted-strings';

const [content, frets] = extract(
  `
      hogehoge
  %%% ^      ^   %%%
  %%% p1     p2  %%%
      fooo`,
);

// The 1st value of the tuple is a string which is removed lines enclosed by '%%%' tags from the parameter.
assert.equal(
  content,
  `
      hogehoge
      fooo`,
);

// The 2nd value of the tuple is an object whose value represents location corresponding to "^" character.
// And names under "^" character are available to use as keys of the object.
assert.equal(frets.p1.pos, 7);
assert.equal(frets.p1.line, 1);
assert.equal(frets.p1.character, 6);

assert.equal(frets.p2.pos, 14);
assert.equal(frets.p2.line, 1);
assert.equal(frets.p2.character, 13);

Use custom tag

import { createExtractFn } from 'fretted-strings';

const extract = createExtractFn('<!--%%', '%%-->');

const [content, frets] = extract(
  `
    <html>
      <div>hogehoge</div>
      <!--%%   ^    %%-->
      <!--%%   p    %%-->
    </html>
  `,
);

LICENSE

MIT

Keywords

string

FAQs

Package last updated on 02 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts