tiny-editorconfig
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Tiny EditorConfig

A tiny isomorphic parser and resolver for EditorConfig.

Install

npm install --save tiny-editorconfig

Usage

import * as EditorConfig from 'tiny-editorconfig';

// It can parse an .editorconfig string

const INPUT1 = `
  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 parsed1 = EditorConfig.parse ( INPUT );
// {
//   root: true,
//   overrides: {
//     '*': {
//       charset: 'utf-8',
//       endOfLine: 'lf',
//       indentSize: 2,
//       indentStyle: 'space',
//       insertFinalNewline: true,
//       trimTrailingWhitespace: true
//     },
//     '*.md': {
//       trimTrailingWhitespace: false
//     }
//   }
// }

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

const parsed2 = EditorConfig.parse ( INPUT );
// {
//   overrides: {
//     '*': {
//       endOfLine: 'crlf',
//       indentSize: 4
//     }
//   }
// }

// It can resolve multiple configurations for a given path

const resolved = resolve ( [PARSED1, PARSED2], '/path/to/test.md' );
// {
//   root: true,
//   charset: 'utf-8',
//   endOfLine: 'crlf',
//   indentSize: 4,
//   indentStyle: 'space',
//   insertFinalNewline: true,
//   trimTrailingWhitespace: false
// }

License

MIT © Fabio Spampinato

Package Sidebar

Install

npm i tiny-editorconfig

Weekly Downloads

23,794

Version

1.0.0

License

none

Unpacked Size

18.2 kB

Total Files

29

Last publish

Collaborators

  • fabiospampinato