Tiny EditorConfig

1.0.2 · active · verified Tue Apr 21

tiny-editorconfig is an isomorphic JavaScript/TypeScript library designed to parse and resolve EditorConfig configurations. It provides functionality to take a raw `.editorconfig` string and convert it into a structured JavaScript object, as well as to resolve multiple parsed configurations for a given file path, applying the cascading rules of EditorConfig. The current stable version is 1.0.2. Being isomorphic, it can run seamlessly in both Node.js and browser environments without specific environment dependencies. Its primary differentiator is its minimal footprint and focused scope, offering a lightweight alternative to larger configuration processing tools. Release cadence is expected to be infrequent, primarily for bug fixes or minor specification updates, due to the stability of the EditorConfig specification itself.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing two EditorConfig strings and then resolving them for a given file path to get the final effective configuration.

import { parse, resolve } from 'tiny-editorconfig';

const editorConfigString1 = `
  root=true

  [*]
  charset = UTF-8
  end_of_line = lf
  indent_size = 2
  indent_style = "space"
  insert_final_newline = true
  trim_trailing_whitespace = true

  [*.md]
  trim_trailing_whitespace = false
`;

const editorConfigString2 = `
  [*]
  end_of_line = crlf
  indent_size = 4
`;

const parsed1 = parse(editorConfigString1);
const parsed2 = parse(editorConfigString2);

// Resolve the configurations for a specific path, applying EditorConfig rules
const resolvedConfig = resolve([parsed1, parsed2], '/path/to/my-document.md');

console.log(resolvedConfig);
/* Expected Output:
{
  root: true,
  charset: 'utf-8',
  endOfLine: 'crlf',
  indentSize: 4,
  indentStyle: 'space',
  insertFinalNewline: true,
  trimTrailingWhitespace: false
}
*/

view raw JSON →