{"id":22887160,"url":"https://github.com/lcaballero/codefmt","last_synced_at":"2025-03-31T19:13:19.663Z","repository":{"id":177093071,"uuid":"659863334","full_name":"lcaballero/codefmt","owner":"lcaballero","description":"A library for buffer with a string format interface.","archived":false,"fork":false,"pushed_at":"2023-06-29T23:10:00.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T23:30:36.409Z","etag":null,"topics":["code-generation","string-formatting","string-interpolation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lcaballero.png","metadata":{"files":{"readme":"readme.org","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-28T18:19:06.000Z","updated_at":"2023-07-07T17:46:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"d43b9076-95af-44e3-8cd2-5e684c5d5f74","html_url":"https://github.com/lcaballero/codefmt","commit_stats":null,"previous_names":["lcaballero/codefmt"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcaballero%2Fcodefmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcaballero%2Fcodefmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcaballero%2Fcodefmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcaballero%2Fcodefmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lcaballero","download_url":"https://codeload.github.com/lcaballero/codefmt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246523874,"owners_count":20791444,"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":["code-generation","string-formatting","string-interpolation"],"created_at":"2024-12-13T20:30:48.186Z","updated_at":"2025-03-31T19:13:19.605Z","avatar_url":"https://github.com/lcaballero.png","language":"Go","readme":"#+PROPERTY: header-args:sh :prologue \"exec 2\u003e\u00261\" :epilogue \":\"\n\n#+begin_src shell :results verbatim raw :exports none\n  # This code block is used to create the html for badges and so is\n  # hidden on export.  Running the block creates a and +begin_html block\n  # inside of the +RESULT block.  Remove the +RESULT before commiting\n  # updates of the readme.org\n  ./run.sh badges\n#+end_src\n\n#+begin_html\n\u003ca href=\"https://github.com/lcaballero/codefmt/actions/workflows/main.yaml/badge.svg\"\u003e\u003cimg alt=\"GitHub Workflow Action Status\" src=\"https://github.com/lcaballero/codefmt/actions/workflows/main.yaml/badge.svg\"/\u003e\u003c/a\u003e \u0026nbsp; \u003ca href=\"https://goreportcard.com/badge/github.com/lcaballero/codefmt\"\u003e\u003cimg alt=\"Go Report codefmt (this repo)\" src=\"https://goreportcard.com/badge/github.com/lcaballero/codefmt\"/\u003e\u003c/a\u003e \n#+end_html\n\n* Overview\n\nThis is a library based around convenience functions for formatting\nand buffering strings in the Go programming language.\n\nThere is _NO GO TEMPLATING_ used by this library.\n\nThink =Sprintf= as the default.  And that the output is collected in a\nbuffer rather than sent to stdout.  Which means the =f= at the end of\n=Sprintf= is redundant, and since all method calls are string oriented\nthe =S= is also redundant, because this library is not geared for\nlow-level IO and strings are good enough, in this case.\n\n* API\n\n#+begin_src shell :results verbatim raw :exports none\n  ./run.sh funcs\n#+end_src\n\n#+begin_src go\nfunc NewBuf() *Buf\nfunc (b *Buf) Bytes() []byte\nfunc (b *Buf) String() string\nfunc (b *Buf) Stdout() *Buf\nfunc (b *Buf) Stderr() *Buf\nfunc (b *Buf) Write(format string, args ...any) *Buf\nfunc (b *Buf) Sub(format string, subs map[string]any) *Buf\nfunc (b *Buf) Expand(format string, args ...any) *Buf\nfunc (b *Buf) Writeln(format string, args ...any) *Buf\nfunc (b *Buf) NL() *Buf\nfunc (b *Buf) Preln(format string, args ...any) *Buf\nfunc (b *Buf) Both(format string, args ...any) *Buf\nfunc NewIndent() Indent\nfunc (n Indent) String() string\nfunc (n Indent) HasIndent() bool\nfunc (n Indent) WriteTo(w io.Writer) error\nfunc (n Indent) Next() Indent\nfunc (n Indent) Prev() Indent\nfunc (r Replacer) Replace(pairs ...any) string\nfunc (b BraceTemplate) Replace(pairs ...any) string\nfunc (b BraceTemplate) MapPair(pairs ...string) string\nfunc MapReplacer(s string) Replacer\nfunc ToCamel(s string) string\nfunc ToPascal(s string) string\nfunc ToPairs(args ...any) map[string]any\n#+end_src\n\n* Examples\n\nThe examples directory includes small programs.\n\n#+begin_src shell :results output\ncat ./examples/ex1/main.go\n#+end_src\n\n#+begin_src go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/lcaballero/codefmt\"\n)\n\nfunc main() {\n\tvar example uses\n\texample.braceTemplate()\n\texample.mapDirectly()\n\texample.usingBuf()\n}\n\ntype uses int\n\nfunc (u uses) usingBuf() {\n\tcodefmt.NewBuf().\n\t\tWrite(\n\t\t\t\"I'll have %d hamburgers with %s, %s, and %s.\",\n\t\t\t4, \"pickle\", \"ketchup\", \"mustard\").\n\t\tNL().Stdout()\n\n\tcodefmt.NewBuf().NL().\n\t\tWriteln(\n\t\t\t\"Your order number is: %d, should be ready at: %v\",\n\t\t\t42, time.Now().Add(time.Minute*15).Format(time.Kitchen)).\n\t\tStdout()\n\n\tcodefmt.NewBuf().NL().\n\t\tExpand(`Order for ${num}, \"${item}\" is ready!!!`,\n\t\t\t\"num\", 42,\n\t\t\t\"item\", \"deluxe hamburger\",\n\t\t).\n\t\tNL().Stdout()\n}\n\nfunc (u uses) mapDirectly() {\n\tworks := map[string]string{\n\t\t\"Robert Frost\": \"The Road Not Taken\",\n\t\t\"Maya Angelou\": \"Stil I Rise\",\n\t\t\"Dylan Thomas\": \"Do Not Go Gentle into that That Good Night\",\n\t}\n\n\tbuf := codefmt.NewBuf()\n\tbuf.Write(\"Author/Poems\").NL()\n\n\tfor author, poem := range works {\n\t\tbuf.Expand(\n\t\t\t\"Author: ${author}, Poem: ${poem}\",\n\t\t\t\"author\", author, \"poem\", poem,\n\t\t).NL()\n\t}\n\n\tfmt.Println(buf)\n}\n\nfunc (u uses) braceTemplate() {\n\thw1 := codefmt.BraceTemplate(\"${greeting}, ${name}!\").Replace(\n\t\t\"greeting\", \"Hello\",\n\t\t\"name\", \"World\",\n\t)\n\tfmt.Println(hw1)\n\tfmt.Println()\n}\n#+end_src\n\nWhich can be ran like so:\n\n#+begin_src shell :results output\ngo run ./examples/ex1/main.go\n#+end_src\n\nAnd outputs the following text:\n\n#+begin_example\nHello, World!\n\nAuthor/Poems\nAuthor: Robert Frost, Poem: The Road Not Taken\nAuthor: Maya Angelou, Poem: Stil I Rise\nAuthor: Dylan Thomas, Poem: Do Not Go Gentle into that That Good Night\n\nI'll have 4 hamburgers with pickle, ketchup, and mustard.\n\nYour order number is: 42, should be ready at: 2:38PM\n\nOrder for 42, \"deluxe hamburger\" is ready!!!\n#+end_example\n\n\n\n* Contriubting\n\nSee [[CONTRIBUTING.md][CONTRIBUTING.md]].  However, this project (at the moment) isn't\nfollowing those guidelines simply becasue the level of interest isn't\nthat high and this lib is quite simple.  It is provided for\nformality's sake.  Just make issues and open PRs for the time being.\nKeeping it simple for now.\n\n\n* License\n\nMIT License, [[LICENSE][LICENSE]].\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcaballero%2Fcodefmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flcaballero%2Fcodefmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcaballero%2Fcodefmt/lists"}