{"id":15966245,"url":"https://github.com/davidafsilva/pretty-string","last_synced_at":"2025-04-04T13:27:07.395Z","repository":{"id":57742563,"uuid":"469361650","full_name":"davidafsilva/pretty-string","owner":"davidafsilva","description":"Kotlin's data class toString pretty cousin","archived":false,"fork":false,"pushed_at":"2023-01-07T17:18:43.000Z","size":116,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-09T23:17:11.295Z","etag":null,"topics":["data-class","kotlin","pretty","tostring"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidafsilva.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-03-13T12:15:16.000Z","updated_at":"2024-06-13T09:37:41.000Z","dependencies_parsed_at":"2023-02-07T17:45:17.061Z","dependency_job_id":null,"html_url":"https://github.com/davidafsilva/pretty-string","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidafsilva%2Fpretty-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidafsilva%2Fpretty-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidafsilva%2Fpretty-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidafsilva%2Fpretty-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidafsilva","download_url":"https://codeload.github.com/davidafsilva/pretty-string/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247184085,"owners_count":20897708,"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":["data-class","kotlin","pretty","tostring"],"created_at":"2024-10-07T18:01:13.983Z","updated_at":"2025-04-04T13:27:07.363Z","avatar_url":"https://github.com/davidafsilva.png","language":"Kotlin","readme":"# pretty-string\n\n\n[![Main Build Status](https://img.shields.io/github/actions/workflow/status/davidafsilva/pretty-string/main-build.yml?branch=main\u0026label=Build\u0026style=flat-square)](https://github.com/davidafsilva/pretty-string/actions/workflows/main-build.yml)\n[![Coverage Report](https://img.shields.io/coveralls/github/davidafsilva/pretty-string?color=brightgreen\u0026label=Coverage\u0026style=flat-square)](https://coveralls.io/github/davidafsilva/pretty-string)\n[![Latest Release](https://img.shields.io/maven-central/v/pt.davidafsilva.jvm.kotlin/pretty-string?color=brightgreen\u0026label=Latest%20Release\u0026style=flat-square)](https://repo1.maven.org/maven2/pt/davidafsilva/jvm/kotlin/pretty-string/)\n[![License](https://img.shields.io/github/license/davidafsilva/pretty-string?color=brightgreen\u0026label=License\u0026logo=License\u0026style=flat-square)](https://opensource.org/licenses/BSD-3-Clause)\n\nThis small Kotlin library provides an alternative to the regular `toString` implementation that is generated for data\nclasses, which does not support prettifying its output right out-of-the-box.\n\n## Table of Contents\n* [Usage](#usage)\n  + [Import](#import)\n    - [Gradle](#gradle)\n    - [Maven](#maven)\n  + [API](#api)\n    - [Example](#example)\n* [Building](#building)\n\n## Usage\n\n### Import\n1. Add maven central repository to your configuration\n2. Import the library\n\n#### Gradle\nGroovy:\n```kotlin\nrepositories {\n    mavenCentral()\n}\ndependencies {\n    implementation(\"pt.davidafsilva.jvm.kotlin:pretty-string:0.1.0\")\n    // be sure to include kotlin-reflect as one of your kotlin dependencies, if you don't have it already\n    // implementation(kotlin(\"reflect\")) \n}\n```\n\n#### Maven\n```xml\n\u003cdependencies\u003e\n  \u003cdependency\u003e\n      \u003cgroupId\u003ept.davidafsilva.jvm.kotlin\u003c/groupId\u003e\n      \u003cartifactId\u003epretty-string\u003c/artifactId\u003e\n      \u003cversion\u003e0.1.0\u003c/version\u003e\n  \u003c/dependency\u003e\n  \u003c!-- be sure to include kotlin-reflect as one of your kotlin dependencies, if you don't have it already --\u003e\n  \u003c!--\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.jetbrains.kotlin\u003c/groupId\u003e\n    \u003cartifactId\u003ekotlin-reflect\u003c/artifactId\u003e\n  \u003c/dependency\u003e\n  --\u003e\n\u003c/dependencies\u003e\n```\n\n### API\n\nThis public API is very small. In fact, it only exposes single `toPrettyString()` top-level function. It is defined \nas an extension of `Any?`, thus you should be able to call it with any receiver.\n\n#### Example\n\nLet's say you have the following data classes definitions:\n\n```kotlin\n\ndata class Person(\n    val fullName: String,\n    val birthDate: LocalDate,\n    val children: List\u003cPerson\u003e = emptyList(),\n    val socialProfiles: List\u003cSocialProfile\u003e = emptyList(),\n)\n\ndata class SocialProfile(\n    val name: String,\n    val url: String\n)\n```\n\nAnd you have the following instance of it:\n```kotlin\nval person = Person(\n    fullName = \"John Doe\",\n    birthDate = LocalDate.of(2000, Month.JANUARY, 31),\n    children = listOf(\n        Person(fullName = \"John Doe Jr.\", birthDate = LocalDate.of(2022, Month.MARCH, 13))\n    )\n)\n```\n\nCalling `person.toPrettyString()` should return something along the lines of:\n```text\nPerson@3e3abc88(\n  fullName = \"John Doe\",\n  birthDate = \"2000-01-31\",\n  children = [\n    Person@7857fe2(\n      fullName = \"John Doe Jr.\",\n      birthDate = \"2022-03-13\",\n      children = [],\n      socialProfiles = [],\n    ),\n  ],\n  socialProfiles = [],\n)\n```\n\nOptionally, you can specify the indentation to be applied during the formatting via the `indentationWidth` parameter. \nWhen omitted, it defaults to `2`.\n\n## Building\nAt the project root, run the following command:\n```shell\n./gradlew clean build\n```\n\nThe above command will run both the tests and verification checks.\n\n## Disclaimer\n\nThe function has support for what I consider to be the bare minimum to properly prettify most of the data class\ndefinitions we (developers) usually create. If there's something missing and you'd like to see it supported, feel free\nto file an issue or just go ahead an open the PR with its support :)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidafsilva%2Fpretty-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidafsilva%2Fpretty-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidafsilva%2Fpretty-string/lists"}