{"id":18015604,"url":"https://github.com/nomemory/aleph-formatter","last_synced_at":"2025-03-26T18:31:23.896Z","repository":{"id":52427462,"uuid":"86550197","full_name":"nomemory/aleph-formatter","owner":"nomemory","description":"A simple and efficient StringFormatter that supports named parameters (with a twist)","archived":false,"fork":false,"pushed_at":"2021-04-29T16:06:48.000Z","size":75,"stargazers_count":19,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T06:41:38.467Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nomemory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-29T07:13:39.000Z","updated_at":"2023-11-07T08:43:47.000Z","dependencies_parsed_at":"2022-08-18T02:06:20.483Z","dependency_job_id":null,"html_url":"https://github.com/nomemory/aleph-formatter","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Faleph-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Faleph-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Faleph-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Faleph-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nomemory","download_url":"https://codeload.github.com/nomemory/aleph-formatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245712678,"owners_count":20660278,"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-30T04:14:30.627Z","updated_at":"2025-03-26T18:31:23.615Z","avatar_url":"https://github.com/nomemory.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aleph-formatter\n\nAleph Formatter is a lightweight library for string formatting that supports both named and positional parameters with a twist: it has a limited support for object introspection.\n\n\n# installing\n\nHistorically, the library was found in `jcenter()`. But given `jcenter()`'s [service end](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/) it was moved to maven central:\n\nMaven:\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.andreinc\u003c/groupId\u003e\n  \u003cartifactId\u003ealeph\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nGradle:\n```groovy\nimplementation 'net.andreinc:aleph:0.1.1'\n```\n\n# benchmarks\n\nAleph Formatter performs better than `String.format` for simple cases. A **jmh** benchmark is showing the following results (smaller is better):\n\n```\nCPU: AMD Ryzen 7 5800x, PBO\nWindows Version\t10.0.19041 Build 19041\nBenchmark                     (N)  Mode  Cnt    Score    Error  Units\nAlephFormatter.alephFormat      1  avgt    5   67.101 ±  2.103  ns/op\nAlephFormatter.stringFormat     1  avgt    5  273.048 ±  5.632  ns/op\nAlephFormatter.alephFormat     10  avgt    5   76.470 ±  4.423  ns/op\nAlephFormatter.stringFormat    10  avgt    5  264.106 ±  3.018  ns/op\nAlephFormatter.alephFormat    100  avgt    5  113.705 ±  5.941  ns/op\nAlephFormatter.stringFormat   100  avgt    5  328.445 ± 15.986  ns/op\nAlephFormatter.alephFormat   1000  avgt    5  257.674 ± 19.363  ns/op\nAlephFormatter.stringFormat  1000  avgt    5  437.688 ± 11.813  ns/op\n```\n\nSource [here](https://github.com/PhaseRush/Benched/blob/master/src/main/java/strings/AlephFormatter.java).\n\n#### Example - basic usage:\n\n```java\nimport static net.andreinc.aleph.AlephFormatter.str\n\n//...\n\nString s1 = str(\"#{1} #{0} #{1} #{0}\", 1, 2)\n            .fmt();\nSystem.out.println(s1);\n```    \n\nOutput:\n\n```\n2 1 2 1\n```\n\n#### Example - simple introspection\n\nEach parameter supports limited method invocation:\n\n```java\nString s2 = str(\"#{1}#{0.simpleName}\", String.class, \"Class:\")\n            .fmt();\nSystem.out.println(s2);\n```        \n\nOutput\n\n```\nClass:String\n```\n\nOn the `String.class` you can invoke the method: `getSimpleName` directly in the template. `String.class` is the `#{0}` param. \n\n#### Example - Named arguments\n\n```java\nString s3 = str(\"#{date.dayOfMonth}-#{date.month}-#{date.year}\")\n            .arg(\"date\", LocalDate.now())\n            .fmt();\nSystem.out.println(s3);\n\nString s4 = str(\"#{2.simpleName}, #{1}, #{0}, #{aNumber}, #{anArray}\", 1, \"A\", String.class)\n            .args(\"aNumber\", 100, \"anArray\", new int[]{1,2,3,})\n            .fmt();\nSystem.out.println(s4);                        \n```                        \n\nOutput:\n\n```\n8-MAY-2018\nString, A, 1, 100, [1, 2, 3]\n```\n\n#### Example - Escaping `#{`\n\n```java\nString s5 = str(\"`#{escaped} #{notEscaped}\").args(\"escaped\", 1, \"notEscaped\", 2)\n            .fmt();\nSystem.out.println(s5);\n```\n\nOutput:\n\n```\n#{escaped} 2\n```\n\n#### Example - Changing Interpolation Styles\n\n```java\n//Note the use of ${var} not #{var}\nString s6 = str(\"${dollars}\").args(\"dollars\", \"notPound\")\n            .style(Styles.DOLLARS).fmt();\n```\n\nOutput:\n\n```\nnotPound\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnomemory%2Faleph-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnomemory%2Faleph-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnomemory%2Faleph-formatter/lists"}