@emmetio/field-parser
Parses snippet fields (aka tab-stops) like `${1:foo}` in given string
Last updated 7 years ago by emmetio .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @emmetio/field-parser 
SYNC missed versions from official npm registry.

Fields (tab-stops) parser

Parses snippet fields (aka tab-stops) like ${1:foo} in given string and produces a model that contains clean string without fields and list of fields locations.

Usage example

import parse from '@emmetio/field-parser';

const fieldModel = parse('foo $0 ${1:bar} ${2}${1}');

console.log(fieldModel.string);
// outputs "foo  bar "

// `.fields` is array of `{index, location, length}` fields
console.log(fieldModel.fields);
// outputs:
// {index: 0, location: 4, length: 0}
// {index: 1, location: 5, length: 3}
// {index: 2, location: 9, length: 0}
// {index: 1, location: 9, length: 0}

You can also mark string with fields:

import { mark } from '@emmetio/field-parser';

const marked = mark('foo bar', [
    {index: 1, location: 0, length: 3},
    {index: 5, location: 4, length: 3},
]);

console.log(marked); // ${1:foo} ${5:bar}

...or parse string and then use built-it mark method:

import parse from '@emmetio/field-parser';

const fieldModel = parse('foo $0 ${1:bar} ${2}${1}');
fieldModel.forEach(field => field.index += 100);

console.log(fieldModel.mark()); // foo $100 ${101:bar} ${102}${101}

Current Tags

  • 0.3.1                                ...           latest (7 years ago)

5 Versions

  • 0.3.1                                ...           7 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |