Socket
Book a DemoInstallSign in
Socket

src-location

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

src-location

Convert source location from line and column to index position (character offset), and vise versa.

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
2K
27.71%
Maintainers
1
Weekly downloads
 
Created
Source

src-location

Convert source location from line and column to index position (character offset), and vise versa.

This lib will take account \r\n as 1 character, so regardless the end of line (DOS/Unix/Mac), the line number always the same.

CircleCI npm

Install

npm install src-location

Usage

  • locationToIndex(srcStr: string, line: number, column: number, noMergeCRLF) -> number

noMergeCRLF: will not merge CRLF as 1 char.

var lib = require('src-location')
var src = 'var a=1;\r\n2\n3\r4var b=2;'
expect(lib.locationToIndex(src, 4, 2)).equal(15)
  • indexToLocation(srcStr: string, index: number) -> {line: number, column: number}

noMergeCRLF: will not merge CRLF as 1 char.

var lib = require('src-location')
var src = 'var a=1;\r\n2\n3\r4var b=2;'
expect(lib.indexToLocation(src, 15)).deep.equal({line: 4, column: 2})

Keywords

source

FAQs

Package last updated on 19 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts