slice-location
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    slice-location

    String slices by line and column indexes

    Coverage Status version node-version downloads

    MIT License PRs Welcome Code of Conduct XO code style

    Watch on GitHub Star on GitHub

    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-location

    Usage

    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
    //=> Li

    API

    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
    • beginColumn: The column number where the slice begins.
      • Type: number
      • Default: 0
    • endLine: The line number where the slice ends.
      • Type: number
      • Default: The number of the last line of the string
    • endColumn: The column number where the slice ends.
      • Type: number
      • Default: The number of the last column of the last line of the string
    • offsetLine: by default, the value of the first line is 0. If you need the first line begin at 1 or more, set offsetLine in the option parameter object to the desired value.
      • Type: number
      • Default: 0
    • offsetColumn: by default, the value of the first column is 0. If you need the first line begin at 1 or more, set offsetColumn in the option parameter object to the desired value.
      • Type: number
      • Default: 0

    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

    Install

    npm i slice-location

    DownloadsWeekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    11.2 kB

    Total Files

    5

    Last publish

    Collaborators

    • forresst17