feat: docker compose maybe
This commit is contained in:
50
node_modules/detect-indent/index.d.ts
generated
vendored
Normal file
50
node_modules/detect-indent/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
declare namespace detectIndent {
|
||||
interface Indent {
|
||||
/**
|
||||
Type of indentation. Is `undefined` if no indentation is detected.
|
||||
*/
|
||||
type: 'tab' | 'space' | undefined;
|
||||
|
||||
/**
|
||||
Amount of indentation, for example `2`.
|
||||
*/
|
||||
amount: number;
|
||||
|
||||
/**
|
||||
Actual indentation.
|
||||
*/
|
||||
indent: string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Detect the indentation of code.
|
||||
|
||||
@param string - A string of any kind of text.
|
||||
|
||||
@example
|
||||
```
|
||||
import * as fs from 'fs';
|
||||
import detectIndent = require('detect-indent');
|
||||
|
||||
// {
|
||||
// "ilove": "pizza"
|
||||
// }
|
||||
const file = fs.readFileSync('foo.json', 'utf8');
|
||||
|
||||
// Tries to detect the indentation and falls back to a default if it can't
|
||||
const indent = detectIndent(file).indent || ' ';
|
||||
|
||||
const json = JSON.parse(file);
|
||||
|
||||
json.ilove = 'unicorns';
|
||||
|
||||
fs.writeFileSync('foo.json', JSON.stringify(json, null, indent));
|
||||
// {
|
||||
// "ilove": "unicorns"
|
||||
// }
|
||||
```
|
||||
*/
|
||||
declare function detectIndent(string: string): detectIndent.Indent;
|
||||
|
||||
export = detectIndent;
|
160
node_modules/detect-indent/index.js
generated
vendored
Normal file
160
node_modules/detect-indent/index.js
generated
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
'use strict';
|
||||
|
||||
// Detect either spaces or tabs but not both to properly handle tabs for indentation and spaces for alignment
|
||||
const INDENT_REGEX = /^(?:( )+|\t+)/;
|
||||
|
||||
const INDENT_TYPE_SPACE = 'space';
|
||||
const INDENT_TYPE_TAB = 'tab';
|
||||
|
||||
// Make a Map that counts how many indents/unindents have occurred for a given size and how many lines follow a given indentation.
|
||||
// The key is a concatenation of the indentation type (s = space and t = tab) and the size of the indents/unindents.
|
||||
//
|
||||
// indents = {
|
||||
// t3: [1, 0],
|
||||
// t4: [1, 5],
|
||||
// s5: [1, 0],
|
||||
// s12: [1, 0],
|
||||
// }
|
||||
function makeIndentsMap(string, ignoreSingleSpaces) {
|
||||
const indents = new Map();
|
||||
|
||||
// Remember the size of previous line's indentation
|
||||
let previousSize = 0;
|
||||
let previousIndentType;
|
||||
|
||||
// Indents key (ident type + size of the indents/unindents)
|
||||
let key;
|
||||
|
||||
for (const line of string.split(/\n/g)) {
|
||||
if (!line) {
|
||||
// Ignore empty lines
|
||||
continue;
|
||||
}
|
||||
|
||||
let indent;
|
||||
let indentType;
|
||||
let weight;
|
||||
let entry;
|
||||
const matches = line.match(INDENT_REGEX);
|
||||
|
||||
if (matches === null) {
|
||||
previousSize = 0;
|
||||
previousIndentType = '';
|
||||
} else {
|
||||
indent = matches[0].length;
|
||||
|
||||
if (matches[1]) {
|
||||
indentType = INDENT_TYPE_SPACE;
|
||||
} else {
|
||||
indentType = INDENT_TYPE_TAB;
|
||||
}
|
||||
|
||||
// Ignore single space unless it's the only indent detected to prevent common false positives
|
||||
if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (indentType !== previousIndentType) {
|
||||
previousSize = 0;
|
||||
}
|
||||
|
||||
previousIndentType = indentType;
|
||||
|
||||
weight = 0;
|
||||
|
||||
const indentDifference = indent - previousSize;
|
||||
previousSize = indent;
|
||||
|
||||
// Previous line have same indent?
|
||||
if (indentDifference === 0) {
|
||||
weight++;
|
||||
// We use the key from previous loop
|
||||
} else {
|
||||
const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
|
||||
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
||||
}
|
||||
|
||||
// Update the stats
|
||||
entry = indents.get(key);
|
||||
|
||||
if (entry === undefined) {
|
||||
entry = [1, 0]; // Init
|
||||
} else {
|
||||
entry = [++entry[0], entry[1] + weight];
|
||||
}
|
||||
|
||||
indents.set(key, entry);
|
||||
}
|
||||
}
|
||||
|
||||
return indents;
|
||||
}
|
||||
|
||||
// Encode the indent type and amount as a string (e.g. 's4') for use as a compound key in the indents Map.
|
||||
function encodeIndentsKey(indentType, indentAmount) {
|
||||
const typeCharacter = indentType === INDENT_TYPE_SPACE ? 's' : 't';
|
||||
return typeCharacter + String(indentAmount);
|
||||
}
|
||||
|
||||
// Extract the indent type and amount from a key of the indents Map.
|
||||
function decodeIndentsKey(indentsKey) {
|
||||
const keyHasTypeSpace = indentsKey[0] === 's';
|
||||
const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
||||
|
||||
const amount = Number(indentsKey.slice(1));
|
||||
|
||||
return {type, amount};
|
||||
}
|
||||
|
||||
// Return the key (e.g. 's4') from the indents Map that represents the most common indent,
|
||||
// or return undefined if there are no indents.
|
||||
function getMostUsedKey(indents) {
|
||||
let result;
|
||||
let maxUsed = 0;
|
||||
let maxWeight = 0;
|
||||
|
||||
for (const [key, [usedCount, weight]] of indents) {
|
||||
if (usedCount > maxUsed || (usedCount === maxUsed && weight > maxWeight)) {
|
||||
maxUsed = usedCount;
|
||||
maxWeight = weight;
|
||||
result = key;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function makeIndentString(type, amount) {
|
||||
const indentCharacter = type === INDENT_TYPE_SPACE ? ' ' : '\t';
|
||||
return indentCharacter.repeat(amount);
|
||||
}
|
||||
|
||||
module.exports = string => {
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
}
|
||||
|
||||
// Identify indents while skipping single space indents to avoid common edge cases (e.g. code comments)
|
||||
// If no indents are identified, run again and include all indents for comprehensive detection
|
||||
let indents = makeIndentsMap(string, true);
|
||||
if (indents.size === 0) {
|
||||
indents = makeIndentsMap(string, false);
|
||||
}
|
||||
|
||||
const keyOfMostUsedIndent = getMostUsedKey(indents);
|
||||
|
||||
let type;
|
||||
let amount = 0;
|
||||
let indent = '';
|
||||
|
||||
if (keyOfMostUsedIndent !== undefined) {
|
||||
({type, amount} = decodeIndentsKey(keyOfMostUsedIndent));
|
||||
indent = makeIndentString(type, amount);
|
||||
}
|
||||
|
||||
return {
|
||||
amount,
|
||||
type,
|
||||
indent
|
||||
};
|
||||
};
|
9
node_modules/detect-indent/license
generated
vendored
Normal file
9
node_modules/detect-indent/license
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
45
node_modules/detect-indent/package.json
generated
vendored
Normal file
45
node_modules/detect-indent/package.json
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "detect-indent",
|
||||
"version": "6.1.0",
|
||||
"description": "Detect the indentation of code",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/detect-indent",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"indent",
|
||||
"indentation",
|
||||
"detect",
|
||||
"infer",
|
||||
"identify",
|
||||
"code",
|
||||
"string",
|
||||
"text",
|
||||
"source",
|
||||
"space",
|
||||
"tab"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"xo": {
|
||||
"ignores": [
|
||||
"fixture"
|
||||
]
|
||||
}
|
||||
}
|
120
node_modules/detect-indent/readme.md
generated
vendored
Normal file
120
node_modules/detect-indent/readme.md
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
# detect-indent
|
||||
|
||||
> Detect the indentation of code
|
||||
|
||||
Pass in a string of any kind of text and get the indentation.
|
||||
|
||||
|
||||
## Use cases
|
||||
|
||||
- Persisting the indentation when modifying a file.
|
||||
- Have new content match the existing indentation.
|
||||
- Setting the right indentation in your editor.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install detect-indent
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Here we modify a JSON file while persisting the indentation:
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const detectIndent = require('detect-indent');
|
||||
|
||||
/*
|
||||
{
|
||||
"ilove": "pizza"
|
||||
}
|
||||
*/
|
||||
const file = fs.readFileSync('foo.json', 'utf8');
|
||||
|
||||
// Tries to detect the indentation and falls back to a default if it can't
|
||||
const indent = detectIndent(file).indent || ' ';
|
||||
|
||||
const json = JSON.parse(file);
|
||||
|
||||
json.ilove = 'unicorns';
|
||||
|
||||
fs.writeFileSync('foo.json', JSON.stringify(json, null, indent));
|
||||
/*
|
||||
{
|
||||
"ilove": "unicorns"
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
Accepts a string and returns an object with stats about the indentation:
|
||||
|
||||
* `amount` {number} - Amount of indentation, for example `2`
|
||||
* `type` {'tab' | 'space' | undefined} - Type of indentation. Possible values are `'tab'`, `'space'` or `undefined` if no indentation is detected
|
||||
* `indent` {string} - Actual indentation
|
||||
|
||||
|
||||
## Algorithm
|
||||
|
||||
The current algorithm looks for the most common difference between two consecutive non-empty lines.
|
||||
|
||||
In the following example, even if the 4-space indentation is used 3 times whereas the 2-space one is used 2 times, it is detected as less used because there were only 2 differences with this value instead of 4 for the 2-space indentation:
|
||||
|
||||
```css
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background: gray;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.3em;
|
||||
margin-top: 1em;
|
||||
text-indent: 2em;
|
||||
}
|
||||
```
|
||||
|
||||
[Source.](https://medium.com/@heatherarthur/detecting-code-indentation-eff3ed0fb56b#3918)
|
||||
|
||||
Furthermore, if there are more than one most used difference, the indentation with the most lines is selected.
|
||||
|
||||
In the following example, the indentation is detected as 4-spaces:
|
||||
|
||||
```css
|
||||
body {
|
||||
background: gray;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.3em;
|
||||
margin-top: 1em;
|
||||
text-indent: 2em;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [detect-indent-cli](https://github.com/sindresorhus/detect-indent-cli) - CLI for this module
|
||||
- [detect-newline](https://github.com/sindresorhus/detect-newline) - Detect the dominant newline character of a string
|
||||
- [detect-indent-rs](https://github.com/stefanpenner/detect-indent-rs) - Rust port
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-detect-indent?utm_source=npm-detect-indent&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
Reference in New Issue
Block a user