tslint-to-eslint-config
Version:
Converts your TSLint configuration to the closest reasonable ESLint equivalent.
67 lines (66 loc) • 2.05 kB
JavaScript
;
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseJson =
exports.uniqueFromSources =
exports.separateErrors =
exports.removeEmptyMembers =
exports.isTruthy =
exports.isError =
exports.isDefined =
exports.asError =
void 0;
const json5_1 = __importDefault(require("json5"));
const asError = (error) => (error instanceof Error ? error : new Error(`${error}`));
exports.asError = asError;
const isDefined = (item) => item !== undefined;
exports.isDefined = isDefined;
const isError = (item) => item instanceof Error;
exports.isError = isError;
const isTruthy = (item) => !!item;
exports.isTruthy = isTruthy;
const removeEmptyMembers = (items) => {
const result = {};
for (const [key, value] of Object.entries(items)) {
if (
!(value instanceof Array && value.length === 0) &&
!(value instanceof Object && Object.keys(value).length === 0)
) {
result[key] = value;
}
}
return result;
};
exports.removeEmptyMembers = removeEmptyMembers;
const separateErrors = (mixed) => {
const errors = [];
const items = [];
for (const item of mixed) {
if (item instanceof Error) {
errors.push(item);
} else {
items.push(item);
}
}
return [errors, items];
};
exports.separateErrors = separateErrors;
const uniqueFromSources = (...sources) => {
const items = [];
for (const source of sources) {
if (source instanceof Array) {
items.push(...source.filter(exports.isDefined));
} else if (source !== undefined) {
items.push(source);
}
}
return Array.from(new Set(items));
};
exports.uniqueFromSources = uniqueFromSources;
const parseJson = (text) => json5_1.default.parse(text);
exports.parseJson = parseJson;
//# sourceMappingURL=utils.js.map