Current section

Files

Jump to
spellweaver priv bun node_modules cspell-config-lib dist CSpellConfigFile CSpellConfigFileJson.js
Raw

priv/bun/node_modules/cspell-config-lib/dist/CSpellConfigFile/CSpellConfigFileJson.js

import { parse, stringify } from 'comment-json';
import { ImplCSpellConfigFile } from '../CSpellConfigFile.js';
import { detectIndent } from '../serializers/util.js';
import { ParseError } from './Errors.js';
export class CSpellConfigFileJson extends ImplCSpellConfigFile {
url;
settings;
indent = 2;
constructor(url, settings) {
super(url, settings);
this.url = url;
this.settings = settings;
}
serialize() {
return stringify(this.settings, undefined, this.indent) + '\n';
}
static parse(file) {
try {
const cspell = parse(file.content);
if (!isCSpellSettings(cspell)) {
throw new ParseError(file.url);
}
const indent = detectIndent(file.content);
const cfg = new CSpellConfigFileJson(file.url, cspell);
cfg.indent = indent;
return cfg;
}
catch (cause) {
if (cause instanceof ParseError) {
throw cause;
}
throw new ParseError(file.url, undefined, { cause });
}
}
}
export function parseCSpellConfigFileJson(file) {
return CSpellConfigFileJson.parse(file);
}
function isCSpellSettings(cfg) {
return !(!cfg || typeof cfg !== 'object' || Array.isArray(cfg));
}
//# sourceMappingURL=CSpellConfigFileJson.js.map