Probably unsupported. Sourcegraph doesn't support TypeScript, which appears to be this repository's primary language. The supported languages are Python, Go, Ruby, and JavaScript (node.js with package.json only).

To attempt to use Sourcegraph's code browsing and code review features on this repository anyway, enable this repository.

Parse lines from text.

README.md

linez

Parses lines from text, preserving line numbers, offsets and line endings.

Build Status Dependency Status NPM version Views

NPM

Getting Started

Installation

$ npm install linez

TypeScript Usage

/// <reference path="node_modules/linez/linez.d.ts" />
import linez = require('linez');

JavaScript Usage

var linez = require('linez');

Introduction

By default, linez uses /\r?\n/g as the regular expression to detect newline character sequences and split lines. This regular expression is tuned for performance and only covers the most common newline types (i.e., \n and \r\n). If you have need for more newline character sequences, you can configure linez with the configure method.

linez.configure({
  newlines: ['\n', '\r\n', '\r', '\u000B']
});

Setting this property will automatically create a piped regular expression for you and use it in any future linez.parse() calls. You can make up your own newlines if you want. Linez doesn’t care one way or the other.

linez.configure({
  newlines: ['foo', 'bar']
});

This would be converted into /(?:foo|bar). Newlines are just strings. They can be anything. There are, however, some known newline character sequences. Should you need them, refer to the following table:

String Unicode Name
\n U+000A Line feed
\r\n U+000D, U+000A Carriage Return + Line Feed
\r U+000D Carriage Return
\u000B U+000B Vertical Tab
\u000C U+000C Form Feed
\u0085 U+0085 Next Line
\u2028 U+2028 Line Separator
\u2029 U+2029 Paragraph Separator

API

configure(options: IOptions)

Configures linez to use the supplied options. Currently, only the newlines property is available, where you can specify any number of newline character sequences.

linez.configure({
  newlines = ['\n', '\r\n', '\r', '\u000B']
});

Document

constructor(public lines: ILine[]);

Calling the toString() method converts the documents lines into a string, discarding information about line numbers and offsets.

ILine

interface ILine {
  offset: number;
  number: number;
  text: string;
  ending?: string;
}

ILine

interface IOptions {
  newlines?: string[];
}

parse(text: string): void

Parses text into a Document.

The specs show some great usage examples.

var lines = linez.parse('foo\nbar\nbaz').lines;
lines[1].offset; // 4
lines[1].number; // 2
lines[1].text; // bar
lines[1].ending; // \n

License

Released under the MIT license.

Bitdeli Badge