detect-indent

  • Version 7.0.1
  • Published
  • 9.75 kB
  • No dependencies
  • MIT license

Install

npm i detect-indent
yarn add detect-indent
pnpm add detect-indent

Overview

Detect the indentation of code

Index

Functions

function detectIndent

detectIndent: (string: string) => Indent;
  • Detect the indentation of code.

    Parameter string

    A string of any kind of text.

    Example 1

    import fs from 'node:fs';
    import detectIndent from 'detect-indent';
    // {
    // "ilove": "pizza"
    // }
    const file = fs.readFileSync('foo.json', 'utf8');
    // Tries to detect the indentation and falls back to a default if it can't
    const indent = detectIndent(file).indent || ' ';
    const json = JSON.parse(file);
    json.ilove = 'unicorns';
    fs.writeFileSync('foo.json', JSON.stringify(json, undefined, indent));
    // {
    // "ilove": "unicorns"
    // }

Interfaces

interface Indent

interface Indent {}

    property amount

    amount: number;
    • The amount of indentation. For example, 2.

    property indent

    indent: string;
    • The actual indentation.

    property type

    type: 'tab' | 'space' | undefined;
    • The type of indentation.

      It is undefined if no indentation is detected.

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (4)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/detect-indent.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/detect-indent)
    • HTML
      <a href="https://www.jsdocs.io/package/detect-indent"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>