cspell
Version:
A Spelling Checker for Code!
35 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const dictionaryPath = () => path.join(__dirname, '..', '..', 'dist', 'dictionaries');
function filterDictDefsToLoad(dictIds, defs) {
const dictIdSet = new Set(dictIds);
const activeDefs = defs
.filter(({ name }) => dictIdSet.has(name))
.map(def => (Object.assign({}, def, { path: getFullPathName(def) })))
// Remove any empty paths.
.filter(def => !!def.path)
.map(def => [def.name, def]);
return [...(new Map(activeDefs))];
}
exports.filterDictDefsToLoad = filterDictDefsToLoad;
function getFullPathName(def) {
const { path: filePath = '', file = '' } = def;
if (filePath + file === '') {
return '';
}
const dictPath = path.join(filePath || dictionaryPath(), file);
return dictPath;
}
function normalizePathForDictDefs(defs, defaultPath) {
return defs
.map(def => normalizePathForDictDef(def, defaultPath));
}
exports.normalizePathForDictDefs = normalizePathForDictDefs;
function normalizePathForDictDef(def, defaultPath) {
const { path: relPath = '.' } = def;
const absPath = relPath.match(/^\./) ? path.join(defaultPath, relPath) : relPath;
return Object.assign({}, def, { path: absPath });
}
exports.normalizePathForDictDef = normalizePathForDictDef;
//# sourceMappingURL=DictionarySettings.js.map