import-conductor
Version:
Automatically organize your Typescript import statements
35 lines • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.categorizeImportLiterals = void 0;
const is_custom_import_1 = require("../helpers/is-custom-import");
const is_third_party_1 = require("../helpers/is-third-party");
function categorizeImportLiterals(importLiterals) {
const thirdParty = new Map();
const userLibrary = new Map();
const differentModule = new Map();
const sameModule = new Map();
importLiterals.forEach((fullImportStatement, importLiteral) => {
const normalized = importLiteral.replace(/['"]/g, '');
if (normalized.startsWith('./')) {
sameModule.set(importLiteral, fullImportStatement);
return;
}
if (normalized.startsWith('..')) {
differentModule.set(importLiteral, fullImportStatement);
return;
}
if (is_custom_import_1.isCustomImport(normalized)) {
userLibrary.set(importLiteral, fullImportStatement);
return;
}
if (is_third_party_1.isThirdParty(normalized)) {
thirdParty.set(importLiteral, fullImportStatement);
}
else {
differentModule.set(importLiteral, fullImportStatement);
}
});
return { thirdParty, differentModule, sameModule, userLibrary };
}
exports.categorizeImportLiterals = categorizeImportLiterals;
//# sourceMappingURL=categorize-imports.js.map