slice-location
v2.0.0
Published
String slices by line and column indexes
Maintainers
Readme
slice-location
String slices by line and column indexes
Table of Contents
Installation
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-locationUsage
Node.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
//=> LiAPI
sliceLocation(input, options)
Slice a string by line and column indexes. Returns a string sliced.
input
Type: string
The string to slice.
options
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 at1or more, setoffsetLinein theoptionparameter 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 at1or more, setoffsetColumnin theoptionparameter object to the desired value.- Type:
number - Default:
0
- Type:
return
Type: string
The string sliced.
Example
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
LICENSE
MIT
