Skip to main content

Detects the indentation type and size of any string.

Project description

detect-indent for Python Test

Python port of sindresorhus/detect-indent All attribution goes to that project.

Detect the indentation of code

Pass in a string of any kind of text and get the indentation.

Use cases

  • Persisting the indentation when modifying a file.
  • Have new content match the existing indentation.
  • Setting the right indentation in your editor.

Install

pip install detect-indent

Usage

from detect_indent import detect_indent

sample_string = '''
Example string
  with an indentation
    of two spaces
'''

indent = detect_indent(sample_string)
print(indent)  # {'amount': 2, 'type': 'space', 'indent': '  '}

API

Returns a dictionary with the following stats about indentation:

  • amount {number} - Amount of indentation, for example 2. Will be 0 if indentation could not be detected.
  • type {'tab' | 'space' | None} - Type of indentation. Possible values are 'tab', 'space' or None if no indentation is detected
  • indent {string} - A string representing the actual indentation, for example a string of two spaces.

Algorithm

The current algorithm looks for the most common difference between two consecutive non-empty lines. More Details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detect-indent-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

detect_indent-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file detect-indent-1.0.0.tar.gz.

File metadata

  • Download URL: detect-indent-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for detect-indent-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3817859afbbc758b1ab7576cfc0e7de2c24f1cb04c2ca7566051479f57824144
MD5 63f91df914603aeff24d952f1e48e7d8
BLAKE2b-256 1b161dd92d922a5f00f6254bfc2f4ec6cf11451b90ae4c3d4eebb27549748295

See more details on using hashes here.

File details

Details for the file detect_indent-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for detect_indent-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ef6baaac5b0efd7795cb09904e2340117f3354768a00ac33165f618d03e268f
MD5 db2566fb44fefd3e9c2b89981eb13b84
BLAKE2b-256 3d928b11fdf9b8a6e53b5dafba4c118144ae91d6d1cd0a4caabfea2fcd1ffcd7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page