UNPKG

monk-import-export

Version:

Simple import & export sorting ESLint plugin

38 lines (37 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSource = void 0; const getImportExportKind_1 = require("./getImportExportKind"); function getSource(node) { const source = node.source.value; return { // Sort by directory level rather than by string length. source: source // Treat `.` as `./`, `..` as `../`, `../..` as `../../` etc. .replace(/^[./]*\.$/, '$&/') // Make `../` sort after `../../` but before `../a` etc. // Why a comma? See the next comment. .replace(/^[./]*\/$/, '$&,') // Make `.` and `/` sort before any other punctation. // The default order is: _ - , x x x . x x x / x x x // We’re changing it to: . / , x x x _ x x x - x x x .replace(/[./_-]/g, (char) => { switch (char) { case '.': return '_'; case '/': return '-'; case '_': return '.'; case '-': return '/'; // istanbul ignore next default: throw new Error(`Unknown source substitution character: ${char}`); } }), originalSource: source, kind: (0, getImportExportKind_1.getImportExportKind)(node) }; } exports.getSource = getSource;