feat: docker compose maybe
This commit is contained in:
		
							
								
								
									
										66
									
								
								node_modules/locate-character/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								node_modules/locate-character/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
# locate-character
 | 
			
		||||
 | 
			
		||||
Get the line and column number of a particular character in a string.
 | 
			
		||||
 | 
			
		||||
## Installation
 | 
			
		||||
 | 
			
		||||
`npm install locate-character`, or get it from [unpkg.com/locate-character](https://unpkg.com/locate-character).
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
To search for a particular character, using the index or a search string, use `locate`:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
import { locate } from 'locate-character';
 | 
			
		||||
 | 
			
		||||
const sample = `
 | 
			
		||||
A flea and a fly in a flue
 | 
			
		||||
Were imprisoned, so what could they do?
 | 
			
		||||
Said the fly, "let us flee!"
 | 
			
		||||
"Let us fly!" said the flea.
 | 
			
		||||
So they flew through a flaw in the flue.
 | 
			
		||||
`.trim();
 | 
			
		||||
 | 
			
		||||
// Using a character index
 | 
			
		||||
const index = sample.indexOf('fly');
 | 
			
		||||
locate(sample, index);
 | 
			
		||||
// -> { line: 0, column: 13, character: 13 }
 | 
			
		||||
 | 
			
		||||
// Using the string itself
 | 
			
		||||
locate(sample, 'fly');
 | 
			
		||||
// -> { line: 0, column: 13, character: 13 }
 | 
			
		||||
 | 
			
		||||
// Using the string with a start index
 | 
			
		||||
locate(sample, 'fly', { startIndex: 14 });
 | 
			
		||||
// -> { line: 2, column: 9, character: 76 }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
If you will be searching the same string repeatedly, it's much faster if you use `getLocator`:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
import { getLocator } from 'locate-character';
 | 
			
		||||
 | 
			
		||||
const locate = getLocator(sample);
 | 
			
		||||
 | 
			
		||||
let location = locate(13);
 | 
			
		||||
// -> { line: 0, column: 13, character: 13 }
 | 
			
		||||
 | 
			
		||||
location = locate('fly', { startIndex: location.character + 1 });
 | 
			
		||||
// -> { line: 2, column: 9, character: 76 }
 | 
			
		||||
 | 
			
		||||
location = locate('fly', { startIndex: location.character + 1 });
 | 
			
		||||
// -> { line: 3, column: 8, character: 104 }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
In some situations (for example, dealing with sourcemaps), you need one-based line numbers:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
getLocator(sample, { offsetLine: 1 });
 | 
			
		||||
locate(sample, { offsetLine: 1 });
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
There's also an `offsetColumn` option which is less useful in real-world situations.
 | 
			
		||||
 | 
			
		||||
## License
 | 
			
		||||
 | 
			
		||||
MIT
 | 
			
		||||
							
								
								
									
										44
									
								
								node_modules/locate-character/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								node_modules/locate-character/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "locate-character",
 | 
			
		||||
  "version": "3.0.0",
 | 
			
		||||
  "description": "Get the line and column number of a specific character in a string",
 | 
			
		||||
  "type": "module",
 | 
			
		||||
  "types": "./types/index.d.ts",
 | 
			
		||||
  "exports": {
 | 
			
		||||
    "types": "./types/index.d.ts",
 | 
			
		||||
    "import": "./src/index.js"
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "test": "node test/test.js",
 | 
			
		||||
    "build": "dts-buddy",
 | 
			
		||||
    "prepublishOnly": "npm test && npm run build"
 | 
			
		||||
  },
 | 
			
		||||
  "files": [
 | 
			
		||||
    "src",
 | 
			
		||||
    "types",
 | 
			
		||||
    "README.md"
 | 
			
		||||
  ],
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git+https://gitlab.com/Rich-Harris/locate-character.git"
 | 
			
		||||
  },
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "string",
 | 
			
		||||
    "character",
 | 
			
		||||
    "locate",
 | 
			
		||||
    "line",
 | 
			
		||||
    "column",
 | 
			
		||||
    "location"
 | 
			
		||||
  ],
 | 
			
		||||
  "author": "Rich Harris",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "bugs": {
 | 
			
		||||
    "url": "https://gitlab.com/Rich-Harris/locate-character/issues"
 | 
			
		||||
  },
 | 
			
		||||
  "homepage": "https://gitlab.com/Rich-Harris/locate-character#README",
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "dts-buddy": "^0.1.6",
 | 
			
		||||
    "typescript": "^5.1.3"
 | 
			
		||||
  },
 | 
			
		||||
  "packageManager": "pnpm@8.6.2"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										72
									
								
								node_modules/locate-character/src/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								node_modules/locate-character/src/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,72 @@
 | 
			
		||||
/** @typedef {import('./types').Location} Location */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param {import('./types').Range} range
 | 
			
		||||
 * @param {number} index
 | 
			
		||||
 */
 | 
			
		||||
function rangeContains(range, index) {
 | 
			
		||||
	return range.start <= index && index < range.end;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param {string} source
 | 
			
		||||
 * @param {import('./types').Options} [options]
 | 
			
		||||
 */
 | 
			
		||||
export function getLocator(source, options = {}) {
 | 
			
		||||
	const { offsetLine = 0, offsetColumn = 0 } = options;
 | 
			
		||||
 | 
			
		||||
	let start = 0;
 | 
			
		||||
	const ranges = source.split('\n').map((line, i) => {
 | 
			
		||||
		const end = start + line.length + 1;
 | 
			
		||||
 | 
			
		||||
		/** @type {import('./types').Range} */
 | 
			
		||||
		const range = { start, end, line: i };
 | 
			
		||||
 | 
			
		||||
		start = end;
 | 
			
		||||
		return range;
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	let i = 0;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param {string | number} search
 | 
			
		||||
	 * @param {number} [index]
 | 
			
		||||
	 * @returns {Location | undefined}
 | 
			
		||||
	 */
 | 
			
		||||
	function locator(search, index) {
 | 
			
		||||
		if (typeof search === 'string') {
 | 
			
		||||
			search = source.indexOf(search, index ?? 0);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (search === -1) return undefined;
 | 
			
		||||
 | 
			
		||||
		let range = ranges[i];
 | 
			
		||||
 | 
			
		||||
		const d = search >= range.end ? 1 : -1;
 | 
			
		||||
 | 
			
		||||
		while (range) {
 | 
			
		||||
			if (rangeContains(range, search)) {
 | 
			
		||||
				return {
 | 
			
		||||
					line: offsetLine + range.line,
 | 
			
		||||
					column: offsetColumn + search - range.start,
 | 
			
		||||
					character: search
 | 
			
		||||
				};
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			i += d;
 | 
			
		||||
			range = ranges[i];
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return locator;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @param {string} source
 | 
			
		||||
 * @param {string | number} search
 | 
			
		||||
 * @param {import('./types').Options} [options]
 | 
			
		||||
 * @returns {Location | undefined}
 | 
			
		||||
 */
 | 
			
		||||
export function locate(source, search, options) {
 | 
			
		||||
	return getLocator(source, options)(search, options && options.startIndex);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								node_modules/locate-character/src/types.d.ts
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								node_modules/locate-character/src/types.d.ts
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
export interface Options {
 | 
			
		||||
	offsetLine?: number;
 | 
			
		||||
	offsetColumn?: number;
 | 
			
		||||
	startIndex?: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface Range {
 | 
			
		||||
	start: number;
 | 
			
		||||
	end: number;
 | 
			
		||||
	line: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface Location {
 | 
			
		||||
	line: number;
 | 
			
		||||
	column: number;
 | 
			
		||||
	character: number;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								node_modules/locate-character/types/index.d.ts
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								node_modules/locate-character/types/index.d.ts
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
declare module 'locate-character' {
 | 
			
		||||
	export function getLocator(source: string, options?: Options | undefined): (search: string | number, index?: number | undefined) => Location | undefined;
 | 
			
		||||
 | 
			
		||||
	export function locate(source: string, search: string | number, options?: Options | undefined): Location | undefined;
 | 
			
		||||
	export type Location = Location_1;
 | 
			
		||||
	interface Options {
 | 
			
		||||
		offsetLine?: number;
 | 
			
		||||
		offsetColumn?: number;
 | 
			
		||||
		startIndex?: number;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	interface Location_1 {
 | 
			
		||||
		line: number;
 | 
			
		||||
		column: number;
 | 
			
		||||
		character: number;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//# sourceMappingURL=index.d.ts.map
 | 
			
		||||
							
								
								
									
										19
									
								
								node_modules/locate-character/types/index.d.ts.map
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								node_modules/locate-character/types/index.d.ts.map
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
{
 | 
			
		||||
	"version": 3,
 | 
			
		||||
	"file": "index.d.ts",
 | 
			
		||||
	"names": [
 | 
			
		||||
		"getLocator",
 | 
			
		||||
		"locate",
 | 
			
		||||
		"Location",
 | 
			
		||||
		"Options"
 | 
			
		||||
	],
 | 
			
		||||
	"sources": [
 | 
			
		||||
		"../src/index.js",
 | 
			
		||||
		"../src/types.d.ts"
 | 
			
		||||
	],
 | 
			
		||||
	"sourcesContent": [
 | 
			
		||||
		null,
 | 
			
		||||
		null
 | 
			
		||||
	],
 | 
			
		||||
	"mappings": ";iBAcgBA,UAAUA;;iBAuDVC,MAAMA;aCzDLC,QAAQA;WAZRC,OAAOA"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user