String slices by line and column indexes
This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies
:
npm install --save-dev slice-location
import sliceLocation from 'slice-location';
const inputString = `Line 1
Line 2
Line 4
Line 5
Line 7
`;
const options = {beginLine: 4, beginColumn: 1, endLine: 5, endColumn: 2, offsetLine: 1, offsetColumn: 1};
console.log(sliceLocation(inputString, options));
//=> Line 4
//=> Li
Slice a string by line and column indexes. Returns a string
sliced.
Type: string
The string to slice.
Type: object
beginLine
: The line number where the slice begins.- Type:
number
- Default:
0
- Type:
beginColumn
: The column number where the slice begins.- Type:
number
- Default:
0
- Type:
endLine
: The line number where the slice ends.- Type:
number
- Default: The number of the last line of the string
- Type:
endColumn
: The column number where the slice ends.- Type:
number
- Default: The number of the last column of the last line of the string
- Type:
offsetLine
: by default, the value of the first line is0
. If you need the first line begin at1
or more, setoffsetLine
in theoption
parameter object to the desired value.- Type:
number
- Default:
0
- Type:
offsetColumn
: by default, the value of the first column is0
. If you need the first line begin at1
or more, setoffsetColumn
in theoption
parameter object to the desired value.- Type:
number
- Default:
0
- Type:
Type: string
The string sliced.
index.js
:
import sliceLocation from 'slice-location'; const inputString = `Line 1 Line 2 Line 4 Line 5 Line 7 `; const options = {beginLine: 4, beginColumn: 1, endLine: 5, endColumn: 2, offsetLine: 1, offsetColumn: 1}; console.log(sliceLocation(inputString, options)); //=> Line 4 //=> Li
MIT