fix: flatten log-tail/ files into monorepo (no sub-repo)
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright 2017 Kat Marchán
|
||||
* Copyright npm, Inc.
|
||||
* Copyright 2023 Isaac Z. Schlueter
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ---
|
||||
*
|
||||
* 'polite-json' is a fork of 'json-parse-even-better-errors',
|
||||
* extended and distributed under the terms of the MIT license
|
||||
* above.
|
||||
*
|
||||
* 'json-parse-even-better-errors' is a fork of
|
||||
* 'json-parse-better-errors' by Kat Marchán, extended and
|
||||
* distributed under the terms of the MIT license above.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
export declare class JSONParseError extends SyntaxError {
|
||||
code: 'EJSONPARSE';
|
||||
systemError: Error;
|
||||
position: number;
|
||||
constructor(er: Error, txt: string, context?: number, caller?: Function | ((...a: any[]) => any));
|
||||
get name(): string;
|
||||
set name(_: string);
|
||||
get [Symbol.toStringTag](): string;
|
||||
}
|
||||
export declare const kIndent: unique symbol;
|
||||
export declare const kNewline: unique symbol;
|
||||
export type Reviver = (this: any, key: string, value: any) => any;
|
||||
export type Replacer = ((this: any, key: string, value: any) => any) | (string | number)[] | null;
|
||||
export type Scalar = string | number | null;
|
||||
export type JSONResult = {
|
||||
[k: string]: JSONResult;
|
||||
[kIndent]?: string;
|
||||
[kNewline]?: string;
|
||||
} | (JSONResult[] & {
|
||||
[kIndent]?: string;
|
||||
[kNewline]?: string;
|
||||
}) | Scalar;
|
||||
export declare const parse: (txt: string | Buffer, reviver?: Reviver | null, context?: number) => JSONResult;
|
||||
export declare const parseNoExceptions: (txt: string | Buffer, reviver?: Reviver) => any;
|
||||
export declare const stringify: (obj: any, replacer?: Replacer, indent?: string | number) => string;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;AAwEH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,IAAI,EAAE,YAAY,CAAA;IAClB,WAAW,EAAE,KAAK,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;gBAEd,EAAE,EAAE,KAAK,EACT,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAW,EACpB,MAAM,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAS5C,IAAI,IAAI,WAEP;IACD,IAAI,IAAI,CAAC,CAAC,QAAA,EAAI;IACd,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;CACF;AAED,eAAO,MAAM,OAAO,eAAuB,CAAA;AAC3C,eAAO,MAAM,QAAQ,eAAwB,CAAA;AAQ7C,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAA;AACjE,MAAM,MAAM,QAAQ,GAChB,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,GAC7C,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GACnB,IAAI,CAAA;AACR,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;AAC3C,MAAM,MAAM,UAAU,GAClB;IACE,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IACvB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CACpB,GACD,CAAC,UAAU,EAAE,GAAG;IAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC5D,MAAM,CAAA;AAEV,eAAO,MAAM,KAAK,QACX,MAAM,GAAG,MAAM,YACV,OAAO,GAAG,IAAI,YACd,MAAM,KACf,UAqCF,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,MAAM,GAAG,MAAM,YAAY,OAAO,QAIxE,CAAA;AAOD,eAAO,MAAM,SAAS,QACf,GAAG,aACG,QAAQ,WACV,MAAM,GAAG,MAAM,WAYzB,CAAA"}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Copyright 2017 Kat Marchán
|
||||
* Copyright npm, Inc.
|
||||
* Copyright 2023 Isaac Z. Schlueter
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* ---
|
||||
*
|
||||
* 'polite-json' is a fork of 'json-parse-even-better-errors',
|
||||
* extended and distributed under the terms of the MIT license
|
||||
* above.
|
||||
*
|
||||
* 'json-parse-even-better-errors' is a fork of
|
||||
* 'json-parse-better-errors' by Kat Marchán, extended and
|
||||
* distributed under the terms of the MIT license above.
|
||||
*/
|
||||
// version specific
|
||||
/* c8 ignore start */
|
||||
const hexify = (s) => Array.from(s)
|
||||
.map(c => '0x' + c.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0'))
|
||||
.join('');
|
||||
const parseError = (e, txt, context) => {
|
||||
if (!txt) {
|
||||
return {
|
||||
message: e.message + ' while parsing empty string',
|
||||
position: 0,
|
||||
};
|
||||
}
|
||||
const badToken = e.message.match(/^Unexpected (?:token (.*?))?/i);
|
||||
const atPos = e.message.match(/at positions? (\d+)/);
|
||||
const errIdx = /^Unexpected end of JSON|Unterminated string in JSON/i.test(e.message)
|
||||
? txt.length - 1
|
||||
: atPos && atPos[1]
|
||||
? +atPos[1]
|
||||
: /is not valid JSON$/.test(e.message)
|
||||
? 0
|
||||
: null;
|
||||
// version specific
|
||||
/* c8 ignore start */
|
||||
const msg = badToken && badToken[1]
|
||||
? e.message.replace(/^Unexpected token ./, `Unexpected token ${JSON.stringify(badToken[1])} (${hexify(badToken[1])})`)
|
||||
: e.message;
|
||||
/* c8 ignore stop */
|
||||
if (errIdx !== null && errIdx !== undefined) {
|
||||
const start = errIdx <= context ? 0 : errIdx - context;
|
||||
const end = errIdx + context >= txt.length ? txt.length : errIdx + context;
|
||||
const slice = (start === 0 ? '' : '...') +
|
||||
txt.slice(start, end) +
|
||||
(end === txt.length ? '' : '...');
|
||||
const near = txt === slice ? '' : 'near ';
|
||||
return {
|
||||
message: msg + ` while parsing ${near}${JSON.stringify(slice)}`,
|
||||
position: errIdx,
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
message: msg + ` while parsing '${txt.slice(0, context * 2)}'`,
|
||||
position: 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
export class JSONParseError extends SyntaxError {
|
||||
code;
|
||||
systemError;
|
||||
position;
|
||||
constructor(er, txt, context = 20, caller) {
|
||||
const { message, position } = parseError(er, txt, context);
|
||||
super(message);
|
||||
this.position = position;
|
||||
this.code = 'EJSONPARSE';
|
||||
this.systemError = er;
|
||||
Error.captureStackTrace(this, caller || this.constructor);
|
||||
}
|
||||
get name() {
|
||||
return this.constructor.name;
|
||||
}
|
||||
set name(_) { }
|
||||
get [Symbol.toStringTag]() {
|
||||
return this.constructor.name;
|
||||
}
|
||||
}
|
||||
export const kIndent = Symbol.for('indent');
|
||||
export const kNewline = Symbol.for('newline');
|
||||
// only respect indentation if we got a line break, otherwise squash it
|
||||
// things other than objects and arrays aren't indented, so ignore those
|
||||
// Important: in both of these regexps, the $1 capture group is the newline
|
||||
// or undefined, and the $2 capture group is the indent, or undefined.
|
||||
const formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/;
|
||||
const emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/;
|
||||
export const parse = (txt, reviver, context) => {
|
||||
const parseText = stripBOM(String(txt));
|
||||
if (!reviver)
|
||||
reviver = undefined;
|
||||
context = context || 20;
|
||||
try {
|
||||
// get the indentation so that we can save it back nicely
|
||||
// if the file starts with {" then we have an indent of '', ie, none
|
||||
// otherwise, pick the indentation of the next line after the first \n
|
||||
// If the pattern doesn't match, then it means no indentation.
|
||||
// JSON.stringify ignores symbols, so this is reasonably safe.
|
||||
// if the string is '{}' or '[]', then use the default 2-space indent.
|
||||
const [, newline = '\n', indent = ' '] = parseText.match(emptyRE) ||
|
||||
parseText.match(formatRE) || [, '', ''];
|
||||
const result = JSON.parse(parseText, reviver);
|
||||
if (result && typeof result === 'object') {
|
||||
result[kNewline] = newline;
|
||||
result[kIndent] = indent;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (e) {
|
||||
if (typeof txt !== 'string' && !Buffer.isBuffer(txt)) {
|
||||
const isEmptyArray = Array.isArray(txt) && txt.length === 0;
|
||||
throw Object.assign(new TypeError(`Cannot parse ${isEmptyArray ? 'an empty array' : String(txt)}`), {
|
||||
code: 'EJSONPARSE',
|
||||
systemError: e,
|
||||
});
|
||||
}
|
||||
throw new JSONParseError(e, parseText, context, parse);
|
||||
}
|
||||
};
|
||||
export const parseNoExceptions = (txt, reviver) => {
|
||||
try {
|
||||
return JSON.parse(stripBOM(String(txt)), reviver);
|
||||
}
|
||||
catch (e) { }
|
||||
};
|
||||
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
||||
// because the buffer-to-string conversion in `fs.readFileSync()`
|
||||
// translates it to FEFF, the UTF-16 BOM.
|
||||
const stripBOM = (txt) => String(txt).replace(/^\uFEFF/, '');
|
||||
export const stringify = (obj, replacer, indent) => {
|
||||
const space = indent === undefined ? obj[kIndent] : indent;
|
||||
// TS is so weird with parameter overloads
|
||||
const res =
|
||||
/* c8 ignore start */
|
||||
typeof replacer === 'function'
|
||||
? JSON.stringify(obj, replacer, space)
|
||||
: JSON.stringify(obj, replacer, space);
|
||||
/* c8 ignore stop */
|
||||
const nl = obj[kNewline] || '\n';
|
||||
return space ? (nl === '\n' ? res : res.split('\n').join(nl)) + nl : res;
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
Reference in New Issue
Block a user