Installations
npm install linez
Score
93.5
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Developer
jedmao
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
7.4.0
NPM Version
4.0.5
Statistics
4 Stars
123 Commits
2 Forks
2 Watching
1 Branches
4 Contributors
Updated on 02 Mar 2017
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,545,801
Last day
12.4%
3,144
Compared to previous day
Last week
15.3%
18,417
Compared to previous week
Last month
13.5%
68,890
Compared to previous month
Last year
-31.7%
870,136
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
linez
Parses lines from text, preserving line numbers, offsets and line endings.
Getting Started
Installation
1$ npm install linez
Importing
TypeScript
1import * as linez from 'linez';
Babel/ES6+
1import linez from 'linez';
JavaScript
1var 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.
1linez.configure({ 2 newlines: ['\n', '\r\n', '\r', '\u000B'] 3});
Setting this property will automatically create a piped regular expression for you and use it in any future linez()
calls. You can make up your own newlines if you want. Linez doesn't care one way or the other.
1linez.configure({ 2 newlines: ['foo', 'bar'] 3});
This would be converted into /(foo|bar)/g
. 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 |
Byte Order Marks
Also referred to as BOM signatures, these are the bytes at the beginning of a file that indicating the encoding in which the file is written. Currently, linez only reads BOMs to detect the encoding and does not take into account the contents of the file.
Supported BOMs
- utf-8-bom
- utf-16le
- utf-16be
Unsupported BOMs
- utf-32le
- utf-32be
If linez detects an unsupported BOM, an error will be thrown, indicating that decoding the detected charset is not supported.
Default decoding
By default, the document will attempt to be decoded as utf8. This is the default behavior of the Node API's conversion from buffers into strings.
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.
1linez.configure({ 2 newlines: ['\n', '\r\n', '\r', '\u000B'] 3});
resetConfiguration()
Resets the configuration to the default settings, using /\r?\n/g
as the newlines regular expression.
Document
1constructor(public lines: Line[]);
Calling the toString()
method converts the document's lines into a string, discarding information about line numbers and offsets.
Line
1interface Line { 2 offset: number; 3 number: number; 4 text: string; 5 ending: string; 6}
Options
1interface Options { 2 newlines?: string[]; 3}
linez(file: string|Buffer): Document
Parses text into a Document
.
The specs show some great usage examples.
1var lines = linez('foo\nbar\nbaz').lines; 2lines[1].offset; // 4 3lines[1].number; // 2 4lines[1].text; // bar 5lines[1].ending; // \n
Note: You can also pass-in a Buffer.
License
Released under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 4/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 16 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More