{"id":15489217,"url":"https://github.com/roughike/indent","last_synced_at":"2025-04-22T18:19:26.092Z","repository":{"id":52946622,"uuid":"239121617","full_name":"roughike/indent","owner":"roughike","description":"Change indentation in multiline Dart strings while preserving the existing relative indentation. Kotlin's trimIndent and trimMargin for Dart.","archived":false,"fork":false,"pushed_at":"2021-04-12T19:01:37.000Z","size":1040,"stargazers_count":17,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T16:21:53.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roughike.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-08T11:37:51.000Z","updated_at":"2024-08-11T13:10:05.000Z","dependencies_parsed_at":"2022-08-28T03:10:15.215Z","dependency_job_id":null,"html_url":"https://github.com/roughike/indent","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roughike%2Findent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roughike%2Findent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roughike%2Findent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roughike%2Findent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roughike","download_url":"https://codeload.github.com/roughike/indent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250296416,"owners_count":21407037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T07:04:28.023Z","updated_at":"2025-04-22T18:19:26.035Z","avatar_url":"https://github.com/roughike.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# indent\n\n[![pub package](https://img.shields.io/pub/v/indent.svg)](https://pub.dartlang.org/packages/indent)\n [![Build Status](https://travis-ci.org/roughike/indent.svg?branch=master)](https://travis-ci.org/roughike/indent) \n [![Coverage Status](https://coveralls.io/repos/github/roughike/indent/badge.svg?branch=master)](https://coveralls.io/github/roughike/indent?branch=master)\n\nChange indentation in multiline Dart strings while preserving the existing relative indentation.\n\nA GIF speaks more than a thousand words:\n\n![A screencast of the example app in action](https://github.com/roughike/indent/raw/master/indent.gif)\n\nYou can run [the example app](https://github.com/roughike/indent/tree/master/example/web) yourself by running `cd example \u0026\u0026 pub get \u0026\u0026 webdev serve` from the project root.\n\n## Usage\n\nFor convenience, the library adds the following extension members on Dart's `String` class.\n\nYou can also wrap a string with the `Indentation` class and call methods on that - this is what [the extension methods](https://github.com/roughike/indent/blob/master/lib/src/string_extensions.dart) do under the hood.\n\n### unindent()\n\nIf you found this library from a Google search, you're probably looking for the `unindent()` method.\nIt's the use case this library was originally created for.\n\nFor example, this:\n\n```dart\nimport 'package:indent/indent.dart';\n\nprint('''\n          Hello\n        there\n             World!\n'''.unindent());\n```\n\noutputs this:\n\n```\n  Hello\nthere\n     World!\n```\n\nIt gets rid of the common indentation while preserving the relative indentation. This is like [Kotlin's trimIndent()](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-indent.html) or Java 12's `align()`.\n\n### trimMargin([String marginPrefix = '|'])\n\nTrims the leading whitespace followed by the `marginPrefix` from each line.\n\nFor example, this:\n\n```dart\nimport 'package:indent/indent.dart';\n\nprint('''\n        |  Hello\n        |there\n        |    World!\n'''.trimMargin());\n```\n\noutputs this:\n\n```\n  Hello\nthere\n    World!\n```\n\nBehaves just like [trimMargin in Kotlin](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html).\n\n### indent(int indentationLevel)\n\nIndents a string with the desired indentation level while preserving relative indentation.\n\nFor example, this:\n\n```dart\nimport 'package:indent/indent.dart';\n\nprint('''\n   Hello\nWorld\n'''.indent(2));\n```\n\nprints:\n\n```\n     Hello\n  World\n```\n\nIf the starting indentation level is higher than the desired one, the value will be unindented accordingly.\n\nThis:\n\n```dart\nimport 'package:indent/indent.dart';\n\nprint('''\n          Hello\n       World\n'''.indent(2));\n```\n\nalso prints:\n\n```\n     Hello\n  World\n```\n\n\u003csmall\u003e(calling `indent(0)` is equal to calling `unindent()`.)\u003c/small\u003e\n\n### indentBy(int howMuch)\n\nChanges the indentation level in a string by `howMuch`.\n\nA positive value for `howMuch` adds indentation.\n\nFor example, this:\n\n```dart\nimport 'package:indent/indent.dart';\n\nprint('''\n   Hello\nWorld\n'''.indentBy(4));\n```\n\nprints this:\n\n```\n       Hello\n    World\n```\n\nWhen a negative value for `howMuch` is given, indentation is removed accordingly.\n\nThis:\n\n```dart\nimport 'package:indent/indent.dart';\n\nprint('''\n       Hello\n    World\n'''.indentBy(-4));\n```\n\nprints this:\n\n```\n   Hello\nWorld\n```\n\n### getIndentationLevel()\n\nReturns the common indentation level in a string.\n\nFor example, this:\n\n```dart\nimport 'package:indent/indent.dart';\n\nfinal int indentationLevel= '''\n     Hello\n  World\n'''.getIndentationLevel();\n```\n\nreturns `2` as the two spaces before `  World` is the lowest common indentation in the string.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froughike%2Findent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froughike%2Findent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froughike%2Findent/lists"}