(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.locateCharacter = global.locateCharacter || {}))); }(this, (function (exports) { 'use strict'; function getLocator(source, options) { if (options === void 0) { options = {}; } var offsetLine = options.offsetLine || 0; var offsetColumn = options.offsetColumn || 0; var originalLines = source.split('\n'); var start = 0; var lineRanges = originalLines.map(function (line, i) { var end = start + line.length + 1; var range = { start: start, end: end, line: i }; start = end; return range; }); var i = 0; function rangeContains(range, index) { return range.start <= index && index < range.end; } function getLocation(range, index) { return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index }; } function locate(search, startIndex) { if (typeof search === 'string') { search = source.indexOf(search, startIndex || 0); } var range = lineRanges[i]; var d = search >= range.end ? 1 : -1; while (range) { if (rangeContains(range, search)) return getLocation(range, search); i += d; range = lineRanges[i]; } } ; return locate; } function locate(source, search, options) { if (typeof options === 'number') { throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument'); } return getLocator(source, options)(search, options && options.startIndex); } exports.getLocator = getLocator; exports.locate = locate; Object.defineProperty(exports, '__esModule', { value: true }); })));