mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-12 05:31:41 +00:00
update
This commit is contained in:
1
node_modules/editorconfig/src/cli.d.ts
generated
vendored
Normal file
1
node_modules/editorconfig/src/cli.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export default function cli(args: string[]): void;
|
53
node_modules/editorconfig/src/cli.js
generated
vendored
Normal file
53
node_modules/editorconfig/src/cli.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// tslint:disable:no-console
|
||||
var commander_1 = __importDefault(require("commander"));
|
||||
var editorconfig = __importStar(require("./"));
|
||||
var package_json_1 = __importDefault(require("../package.json"));
|
||||
function cli(args) {
|
||||
commander_1.default.version('EditorConfig Node.js Core Version ' + package_json_1.default.version);
|
||||
commander_1.default
|
||||
.usage([
|
||||
'[OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]',
|
||||
commander_1.default._version,
|
||||
'FILEPATH can be a hyphen (-) if you want path(s) to be read from stdin.',
|
||||
].join('\n\n '))
|
||||
.option('-f <path>', 'Specify conf filename other than \'.editorconfig\'')
|
||||
.option('-b <version>', 'Specify version (used by devs to test compatibility)')
|
||||
.option('-v, --version', 'Display version information')
|
||||
.parse(args);
|
||||
// Throw away the native -V flag in lieu of the one we've manually specified
|
||||
// to adhere to testing requirements
|
||||
commander_1.default.options.shift();
|
||||
var files = commander_1.default.args;
|
||||
if (!files.length) {
|
||||
commander_1.default.help();
|
||||
}
|
||||
files
|
||||
.map(function (filePath) { return editorconfig.parse(filePath, {
|
||||
config: commander_1.default.F,
|
||||
version: commander_1.default.B,
|
||||
}); })
|
||||
.forEach(function (parsing, i, _a) {
|
||||
var length = _a.length;
|
||||
parsing.then(function (parsed) {
|
||||
if (length > 1) {
|
||||
console.log("[" + files[i] + "]");
|
||||
}
|
||||
Object.keys(parsed).forEach(function (key) {
|
||||
console.log(key + "=" + parsed[key]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = cli;
|
29
node_modules/editorconfig/src/index.d.ts
generated
vendored
Normal file
29
node_modules/editorconfig/src/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/// <reference types="node" />
|
||||
import { parseString, ParseStringResult } from './lib/ini';
|
||||
export { parseString };
|
||||
export interface KnownProps {
|
||||
end_of_line?: 'lf' | 'crlf' | 'unset';
|
||||
indent_style?: 'tab' | 'space' | 'unset';
|
||||
indent_size?: number | 'tab' | 'unset';
|
||||
insert_final_newline?: true | false | 'unset';
|
||||
tab_width?: number | 'unset';
|
||||
trim_trailing_whitespace?: true | false | 'unset';
|
||||
charset?: string | 'unset';
|
||||
}
|
||||
export interface ECFile {
|
||||
name: string;
|
||||
contents: string | Buffer;
|
||||
}
|
||||
export interface FileConfig {
|
||||
name: string;
|
||||
contents: ParseStringResult;
|
||||
}
|
||||
export interface ParseOptions {
|
||||
config?: string;
|
||||
version?: string;
|
||||
root?: string;
|
||||
}
|
||||
export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<KnownProps>;
|
||||
export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): KnownProps;
|
||||
export declare function parse(_filepath: string, _options?: ParseOptions): Promise<KnownProps>;
|
||||
export declare function parseSync(_filepath: string, _options?: ParseOptions): KnownProps;
|
261
node_modules/editorconfig/src/index.js
generated
vendored
Normal file
261
node_modules/editorconfig/src/index.js
generated
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fs = __importStar(require("fs"));
|
||||
var path = __importStar(require("path"));
|
||||
var semver = __importStar(require("semver"));
|
||||
var fnmatch_1 = __importDefault(require("./lib/fnmatch"));
|
||||
var ini_1 = require("./lib/ini");
|
||||
exports.parseString = ini_1.parseString;
|
||||
var package_json_1 = __importDefault(require("../package.json"));
|
||||
var knownProps = {
|
||||
end_of_line: true,
|
||||
indent_style: true,
|
||||
indent_size: true,
|
||||
insert_final_newline: true,
|
||||
trim_trailing_whitespace: true,
|
||||
charset: true,
|
||||
};
|
||||
function fnmatch(filepath, glob) {
|
||||
var matchOptions = { matchBase: true, dot: true, noext: true };
|
||||
glob = glob.replace(/\*\*/g, '{*,**/**/**}');
|
||||
return fnmatch_1.default(filepath, glob, matchOptions);
|
||||
}
|
||||
function getConfigFileNames(filepath, options) {
|
||||
var paths = [];
|
||||
do {
|
||||
filepath = path.dirname(filepath);
|
||||
paths.push(path.join(filepath, options.config));
|
||||
} while (filepath !== options.root);
|
||||
return paths;
|
||||
}
|
||||
function processMatches(matches, version) {
|
||||
// Set indent_size to 'tab' if indent_size is unspecified and
|
||||
// indent_style is set to 'tab'.
|
||||
if ('indent_style' in matches
|
||||
&& matches.indent_style === 'tab'
|
||||
&& !('indent_size' in matches)
|
||||
&& semver.gte(version, '0.10.0')) {
|
||||
matches.indent_size = 'tab';
|
||||
}
|
||||
// Set tab_width to indent_size if indent_size is specified and
|
||||
// tab_width is unspecified
|
||||
if ('indent_size' in matches
|
||||
&& !('tab_width' in matches)
|
||||
&& matches.indent_size !== 'tab') {
|
||||
matches.tab_width = matches.indent_size;
|
||||
}
|
||||
// Set indent_size to tab_width if indent_size is 'tab'
|
||||
if ('indent_size' in matches
|
||||
&& 'tab_width' in matches
|
||||
&& matches.indent_size === 'tab') {
|
||||
matches.indent_size = matches.tab_width;
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
function processOptions(options, filepath) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return {
|
||||
config: options.config || '.editorconfig',
|
||||
version: options.version || package_json_1.default.version,
|
||||
root: path.resolve(options.root || path.parse(filepath).root),
|
||||
};
|
||||
}
|
||||
function buildFullGlob(pathPrefix, glob) {
|
||||
switch (glob.indexOf('/')) {
|
||||
case -1:
|
||||
glob = '**/' + glob;
|
||||
break;
|
||||
case 0:
|
||||
glob = glob.substring(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return path.join(pathPrefix, glob);
|
||||
}
|
||||
function extendProps(props, options) {
|
||||
if (props === void 0) { props = {}; }
|
||||
if (options === void 0) { options = {}; }
|
||||
for (var key in options) {
|
||||
if (options.hasOwnProperty(key)) {
|
||||
var value = options[key];
|
||||
var key2 = key.toLowerCase();
|
||||
var value2 = value;
|
||||
if (knownProps[key2]) {
|
||||
value2 = value.toLowerCase();
|
||||
}
|
||||
try {
|
||||
value2 = JSON.parse(value);
|
||||
}
|
||||
catch (e) { }
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
// null and undefined are values specific to JSON (no special meaning
|
||||
// in editorconfig) & should just be returned as regular strings.
|
||||
value2 = String(value);
|
||||
}
|
||||
props[key2] = value2;
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
function parseFromConfigs(configs, filepath, options) {
|
||||
return processMatches(configs
|
||||
.reverse()
|
||||
.reduce(function (matches, file) {
|
||||
var pathPrefix = path.dirname(file.name);
|
||||
file.contents.forEach(function (section) {
|
||||
var glob = section[0];
|
||||
var options2 = section[1];
|
||||
if (!glob) {
|
||||
return;
|
||||
}
|
||||
var fullGlob = buildFullGlob(pathPrefix, glob);
|
||||
if (!fnmatch(filepath, fullGlob)) {
|
||||
return;
|
||||
}
|
||||
matches = extendProps(matches, options2);
|
||||
});
|
||||
return matches;
|
||||
}, {}), options.version);
|
||||
}
|
||||
function getConfigsForFiles(files) {
|
||||
var configs = [];
|
||||
for (var i in files) {
|
||||
if (files.hasOwnProperty(i)) {
|
||||
var file = files[i];
|
||||
var contents = ini_1.parseString(file.contents);
|
||||
configs.push({
|
||||
name: file.name,
|
||||
contents: contents,
|
||||
});
|
||||
if ((contents[0][1].root || '').toLowerCase() === 'true') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
function readConfigFiles(filepaths) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, Promise.all(filepaths.map(function (name) { return new Promise(function (resolve) {
|
||||
fs.readFile(name, 'utf8', function (err, data) {
|
||||
resolve({
|
||||
name: name,
|
||||
contents: err ? '' : data,
|
||||
});
|
||||
});
|
||||
}); }))];
|
||||
});
|
||||
});
|
||||
}
|
||||
function readConfigFilesSync(filepaths) {
|
||||
var files = [];
|
||||
var file;
|
||||
filepaths.forEach(function (filepath) {
|
||||
try {
|
||||
file = fs.readFileSync(filepath, 'utf8');
|
||||
}
|
||||
catch (e) {
|
||||
file = '';
|
||||
}
|
||||
files.push({
|
||||
name: filepath,
|
||||
contents: file,
|
||||
});
|
||||
});
|
||||
return files;
|
||||
}
|
||||
function opts(filepath, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var resolvedFilePath = path.resolve(filepath);
|
||||
return [
|
||||
resolvedFilePath,
|
||||
processOptions(options, resolvedFilePath),
|
||||
];
|
||||
}
|
||||
function parseFromFiles(filepath, files, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _a, resolvedFilePath, processedOptions;
|
||||
return __generator(this, function (_b) {
|
||||
_a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
|
||||
return [2 /*return*/, files.then(getConfigsForFiles)
|
||||
.then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.parseFromFiles = parseFromFiles;
|
||||
function parseFromFilesSync(filepath, files, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
|
||||
return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
|
||||
}
|
||||
exports.parseFromFilesSync = parseFromFilesSync;
|
||||
function parse(_filepath, _options) {
|
||||
if (_options === void 0) { _options = {}; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _a, resolvedFilePath, processedOptions, filepaths;
|
||||
return __generator(this, function (_b) {
|
||||
_a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
|
||||
filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
|
||||
return [2 /*return*/, readConfigFiles(filepaths)
|
||||
.then(getConfigsForFiles)
|
||||
.then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.parse = parse;
|
||||
function parseSync(_filepath, _options) {
|
||||
if (_options === void 0) { _options = {}; }
|
||||
var _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
|
||||
var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
|
||||
var files = readConfigFilesSync(filepaths);
|
||||
return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
|
||||
}
|
||||
exports.parseSync = parseSync;
|
214
node_modules/editorconfig/src/lib/fnmatch.d.ts
generated
vendored
Normal file
214
node_modules/editorconfig/src/lib/fnmatch.d.ts
generated
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
// Type definitions for Minimatch 3.0
|
||||
// Project: https://github.com/isaacs/minimatch
|
||||
// Definitions by: vvakame <https://github.com/vvakame>
|
||||
// Shant Marouti <https://github.com/shantmarouti>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Tests a path against the pattern using the options.
|
||||
*/
|
||||
declare function M(target: string, pattern: string, options?: M.IOptions): boolean;
|
||||
|
||||
declare namespace M {
|
||||
/**
|
||||
* Match against the list of files, in the style of fnmatch or glob.
|
||||
* If nothing is matched, and options.nonull is set,
|
||||
* then return a list containing the pattern itself.
|
||||
*/
|
||||
function match(list: string[], pattern: string, options?: IOptions): string[];
|
||||
|
||||
/**
|
||||
* Returns a function that tests its supplied argument, suitable for use with Array.filter
|
||||
*/
|
||||
function filter(pattern: string, options?: IOptions): (element: string, indexed: number, array: string[]) => boolean;
|
||||
|
||||
/**
|
||||
* Make a regular expression object from the pattern.
|
||||
*/
|
||||
function makeRe(pattern: string, options?: IOptions): RegExp;
|
||||
|
||||
var Minimatch: IMinimatchStatic;
|
||||
|
||||
interface IOptions {
|
||||
/**
|
||||
* Dump a ton of stuff to stderr.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
debug?: boolean;
|
||||
|
||||
/**
|
||||
* Do not expand {a,b} and {1..3} brace sets.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
nobrace?: boolean;
|
||||
|
||||
/**
|
||||
* Disable ** matching against multiple folder names.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
noglobstar?: boolean;
|
||||
|
||||
/**
|
||||
* Allow patterns to match filenames starting with a period,
|
||||
* even if the pattern does not explicitly have a period in that spot.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
dot?: boolean;
|
||||
|
||||
/**
|
||||
* Disable "extglob" style patterns like +(a|b).
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
noext?: boolean;
|
||||
|
||||
/**
|
||||
* Perform a case-insensitive match.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
nocase?: boolean;
|
||||
|
||||
/**
|
||||
* When a match is not found by minimatch.match,
|
||||
* return a list containing the pattern itself if this option is set.
|
||||
* Otherwise, an empty list is returned if there are no matches.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
nonull?: boolean;
|
||||
|
||||
/**
|
||||
* If set, then patterns without slashes will be matched against
|
||||
* the basename of the path if it contains slashes.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
matchBase?: boolean;
|
||||
|
||||
/**
|
||||
* Suppress the behavior of treating #
|
||||
* at the start of a pattern as a comment.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
nocomment?: boolean;
|
||||
|
||||
/**
|
||||
* Suppress the behavior of treating a leading ! character as negation.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
nonegate?: boolean;
|
||||
|
||||
/**
|
||||
* Returns from negate expressions the same as if they were not negated.
|
||||
* (Ie, true on a hit, false on a miss.)
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
flipNegate?: boolean;
|
||||
}
|
||||
|
||||
interface IMinimatchStatic {
|
||||
new(pattern: string, options?: IOptions): IMinimatch;
|
||||
prototype: IMinimatch;
|
||||
}
|
||||
|
||||
interface IMinimatch {
|
||||
/**
|
||||
* The original pattern the minimatch object represents.
|
||||
*/
|
||||
pattern: string;
|
||||
|
||||
/**
|
||||
* The options supplied to the constructor.
|
||||
*/
|
||||
options: IOptions;
|
||||
|
||||
/**
|
||||
* A 2-dimensional array of regexp or string expressions.
|
||||
*/
|
||||
set: any[][]; // (RegExp | string)[][]
|
||||
|
||||
/**
|
||||
* A single regular expression expressing the entire pattern.
|
||||
* Created by the makeRe method.
|
||||
*/
|
||||
regexp: RegExp;
|
||||
|
||||
/**
|
||||
* True if the pattern is negated.
|
||||
*/
|
||||
negate: boolean;
|
||||
|
||||
/**
|
||||
* True if the pattern is a comment.
|
||||
*/
|
||||
comment: boolean;
|
||||
|
||||
/**
|
||||
* True if the pattern is ""
|
||||
*/
|
||||
empty: boolean;
|
||||
|
||||
/**
|
||||
* Generate the regexp member if necessary, and return it.
|
||||
* Will return false if the pattern is invalid.
|
||||
*/
|
||||
makeRe(): RegExp; // regexp or boolean
|
||||
|
||||
/**
|
||||
* Return true if the filename matches the pattern, or false otherwise.
|
||||
*/
|
||||
match(fname: string): boolean;
|
||||
|
||||
/**
|
||||
* Take a /-split filename, and match it against a single row in the regExpSet.
|
||||
* This method is mainly for internal use, but is exposed so that it can be used
|
||||
* by a glob-walker that needs to avoid excessive filesystem calls.
|
||||
*/
|
||||
matchOne(files: string[], pattern: string[], partial: boolean): boolean;
|
||||
|
||||
/**
|
||||
* Deprecated. For internal use.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
debug(): void;
|
||||
|
||||
/**
|
||||
* Deprecated. For internal use.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
make(): void;
|
||||
|
||||
/**
|
||||
* Deprecated. For internal use.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
parseNegate(): void;
|
||||
|
||||
/**
|
||||
* Deprecated. For internal use.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
braceExpand(pattern: string, options: IOptions): void;
|
||||
|
||||
/**
|
||||
* Deprecated. For internal use.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
parse(pattern: string, isSub?: boolean): void;
|
||||
}
|
||||
}
|
||||
|
||||
export = M;
|
1047
node_modules/editorconfig/src/lib/fnmatch.js
generated
vendored
Normal file
1047
node_modules/editorconfig/src/lib/fnmatch.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14
node_modules/editorconfig/src/lib/ini.d.ts
generated
vendored
Normal file
14
node_modules/editorconfig/src/lib/ini.d.ts
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference types="node" />
|
||||
import { URL } from 'url';
|
||||
/**
|
||||
* Parses an .ini file
|
||||
* @param file The location of the .ini file
|
||||
*/
|
||||
export declare function parse(file: string | number | Buffer | URL): Promise<[string | null, SectionBody][]>;
|
||||
export declare function parseSync(file: string | number | Buffer | URL): [string | null, SectionBody][];
|
||||
export declare type SectionName = string | null;
|
||||
export interface SectionBody {
|
||||
[key: string]: string;
|
||||
}
|
||||
export declare type ParseStringResult = Array<[SectionName, SectionBody]>;
|
||||
export declare function parseString(data: string): ParseStringResult;
|
106
node_modules/editorconfig/src/lib/ini.js
generated
vendored
Normal file
106
node_modules/editorconfig/src/lib/ini.js
generated
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
// Based on iniparser by shockie <https://npmjs.org/package/iniparser>
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fs = __importStar(require("fs"));
|
||||
/**
|
||||
* define the possible values:
|
||||
* section: [section]
|
||||
* param: key=value
|
||||
* comment: ;this is a comment
|
||||
*/
|
||||
var regex = {
|
||||
section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
|
||||
param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
|
||||
comment: /^\s*[#;].*$/,
|
||||
};
|
||||
/**
|
||||
* Parses an .ini file
|
||||
* @param file The location of the .ini file
|
||||
*/
|
||||
function parse(file) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, new Promise(function (resolve, reject) {
|
||||
fs.readFile(file, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(parseString(data));
|
||||
});
|
||||
})];
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.parse = parse;
|
||||
function parseSync(file) {
|
||||
return parseString(fs.readFileSync(file, 'utf8'));
|
||||
}
|
||||
exports.parseSync = parseSync;
|
||||
function parseString(data) {
|
||||
var sectionBody = {};
|
||||
var sectionName = null;
|
||||
var value = [[sectionName, sectionBody]];
|
||||
var lines = data.split(/\r\n|\r|\n/);
|
||||
lines.forEach(function (line) {
|
||||
var match;
|
||||
if (regex.comment.test(line)) {
|
||||
return;
|
||||
}
|
||||
if (regex.param.test(line)) {
|
||||
match = line.match(regex.param);
|
||||
sectionBody[match[1]] =
|
||||
match[2];
|
||||
}
|
||||
else if (regex.section.test(line)) {
|
||||
match = line.match(regex.section);
|
||||
sectionName = match[1];
|
||||
sectionBody = {};
|
||||
value.push([sectionName, sectionBody]);
|
||||
}
|
||||
});
|
||||
return value;
|
||||
}
|
||||
exports.parseString = parseString;
|
Reference in New Issue
Block a user