{"id":47540642,"url":"https://github.com/Wissance/stringFormatter","last_synced_at":"2026-04-01T18:01:11.521Z","repository":{"id":43103105,"uuid":"290164466","full_name":"Wissance/stringFormatter","owner":"Wissance","description":"A set of tools to manipulate text, i.e. making text from templates in C#/Python way is faster than fmt.Sprintf","archived":false,"fork":false,"pushed_at":"2026-03-25T13:05:14.000Z","size":3564,"stargazers_count":63,"open_issues_count":9,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2026-03-26T15:01:36.586Z","etag":null,"topics":["golang","golang-library","golang-text","string","string-formatter","string-template","template-processor","text-templating-engine"],"latest_commit_sha":null,"homepage":"https://wissance.github.io/stringFormatter/","language":"Go","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/Wissance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-08-25T08:53:26.000Z","updated_at":"2026-03-25T16:46:17.000Z","dependencies_parsed_at":"2024-01-26T07:27:52.832Z","dependency_job_id":"a72df84d-4e61-46d3-b3cf-3e365d6738a8","html_url":"https://github.com/Wissance/stringFormatter","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/Wissance/stringFormatter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wissance%2FstringFormatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wissance%2FstringFormatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wissance%2FstringFormatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wissance%2FstringFormatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wissance","download_url":"https://codeload.github.com/Wissance/stringFormatter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wissance%2FstringFormatter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31290740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","golang-library","golang-text","string","string-formatter","string-template","template-processor","text-templating-engine"],"created_at":"2026-03-28T14:00:25.164Z","updated_at":"2026-04-01T18:01:11.505Z","avatar_url":"https://github.com/Wissance.png","language":"Go","readme":"# Wissance/StringFormatter\n[![Awesome Package](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/wissance/stringFormatter?style=plastic) \n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wissance/stringFormatter?style=plastic) \n![GitHub issues](https://img.shields.io/github/issues/wissance/stringFormatter?style=plastic)\n![GitHub Release Date](https://img.shields.io/github/release-date/wissance/stringFormatter) \n[![Wissance.StringFormatter CI](https://github.com/Wissance/stringFormatter/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Wissance/stringFormatter/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wissance/stringFormatter)](https://goreportcard.com/report/github.com/wissance/stringFormatter)\n[![Coverage Status](https://coveralls.io/repos/github/Wissance/stringFormatter/badge.svg?branch=master)](https://coveralls.io/github/Wissance/stringFormatter?branch=master)\n\n![String Formatter: a convenient string formatting tool](img/sf_logo_sm.png)\n\n`StringFormatter` is a ***high-performance*** Go library for string (text) formatting. It offers a syntax *familiar* to `C#`, `Java` and `Python` developers (via template arguments - `{0}` (positional), `{name}` (named)), extensive argument formatting options (numbers, lists, code style), and a set of text utilities — all while being significantly fast as the standard `fmt` package and even more! Typical usage of `sf` are:\n1. Create `e-mails`, `Messages` (`SMS`, `Telegram`, other `Notifications`) or other complicated text **based on templates**\n2. Create a complicated log text with specific argument formatting\n3. Use for **template-based src code generator**\n4. Other text proccessing\n\nOther important resources: \n* [Go Report Card A+](https://goreportcard.com/report/github.com/wissance/stringFormatter)\n* [Coverage \u003e 80%](https://coveralls.io/github/Wissance/stringFormatter)\n\n\n## ✨ 1 Features\n\n🔤 Flexible Syntax: Supports both indexed / positional (`{0}`) and named (`{user}`) *placeholders* in templates.\n\n🎨 Advanced Formatting: Built-in directives for numbers (`HEX`, `BIN`), `floats`, `lists`, and code styles (camelCase, SNAKE_CASE).\n\n🚀 Performance: Template formatting and slice conversion are even faster then `fmt`.\n\n🛠 Utilities: Functions to convert `maps` and `slices` into strings with custom separators and formats.\n\n:man_technologist: Safe : `StringFormatter` aka `sf` **is safe** (`SAST` and tests are running automatically on push) \n\n## 📦 2 Installation\n\n```bash\ngo get github.com/Wissance/stringFormatter\n```\n\n## 🚀 3  Usage\n\n### 3.1 Template Formatting\n\n#### 3.1.1 By Argument Order (Format)\nThe Format function replaces `{n}` placeholders with the corresponding argument in the provided order.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    sf \"github.com/Wissance/stringFormatter\"\n)\n\nfunc main() {\n    template := \"Hello, {0}! Your balance is {1} USD.\"\n    result := sf.Format(template, \"Alex\", 2500)\n    fmt.Println(result)\n    // Output: Hello, Alex! Your balance is 2500 USD.\n}\n```\n\n#### 3.1.2 By Argument Name (FormatComplex)\nThe FormatComplex function uses a `map[string]any` to replace named placeholders like `{key}`.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    sf \"github.com/Wissance/stringFormatter\"\n)\n\nfunc main() {\n    template := \"User {user} (ID: {id}) logged into {app}.\"\n    args := map[string]any{\n        \"user\": \"john_doe\",\n        \"id\":   12345,\n        \"app\":  \"dashboard\",\n    }\n    result := sf.FormatComplex(template, args)\n    fmt.Println(result)\n    // Output: User john_doe (ID: 12345) logged into dashboard.\n}\n```\n\n### 3.2 Advanced Argument Formatting\nYou can control how arguments are displayed by adding a colon (:) and a format specifier to the placeholder.\n\n| Type | Specifier | Description | Example Template | Example Value | Output |\n| :--- | :--- | :--- | :--- | :--- | :--- |\n| **Numbers** | `:B` | Binary (without padding) | `\"{0:B}\"` | `15` | `1111` |\n| | `:B8` | Binary with 8-digit padding | `\"{0:B8}\"` | `15` | `00001111` |\n| | `:X` | Hexadecimal (lowercase) | `\"{0:X}\"` | `250` | `fa` |\n| | `:X4` | Hexadecimal with 4-digit padding | `\"{0:X4}\"` | `250` | `00fa` |\n| | `:o` | Octal | `\"{0:o}\"` | `11` | `14` |\n| **Floating Point** | `:F` | Default float format | `\"{0:F}\"` | `10.4567890` | `10.456789` |\n| | `:F2` | Float with 2 decimal places | `\"{0:F2}\"` | `10.4567890` | `10.46` |\n| | `:F4` | Float with 4 decimal places | `\"{0:F4}\"` | `10.4567890` | `10.4568` |\n| | `:F8` | Float with 8 decimal places | `\"{0:F8}\"` | `10.4567890` | `10.45678900` |\n| | `:E2` | Scientific notation | `\"{0:E2}\"` | `191.0478` | `1.91e+02` |\n| **Percentage** | `:P100` | Percentage (multiply by 100) | `\"{0:P100}\"` | `12` | `12%` |\n| **Lists (Slices)** | `:L-` | Join with hyphen | `\"{0:L-}\"` | `[1 2 3]` | `1-2-3` |\n| | `:L, ` | Join with comma and space | `\"{0:L, }\"` | `[1 2 3]` | `1, 2, 3` |\n| **Code Styles** | `:c:snake` | Convert to snake_case | `\"{0:c:snake}\"` | `myFunc` | `my_func` |\n| | `:c:Snake` | Convert to Snake_Case (PascalSnake) | `\"{0:c:Snake}\"` | `myFunc` | `My_Func` |\n| | `:c:SNAKE` | Convert to SNAKE_CASE (upper) | `\"{0:c:SNAKE}\"` | `read-timeout` | `READ_TIMEOUT` |\n| | `:c:camel` | Convert to camelCase | `\"{0:c:camel}\"` | `my_variable` | `myVariable` |\n| | `:c:Camel` | Convert to CamelCase (PascalCase) | `\"{0:c:Camel}\"` | `my_variable` | `MyVariable` |\n| | `:c:kebab` | Convert to kebab-case | `\"{0:c:kebab}\"` | `myVariable` | `my-variable` |\n| | `:c:Kebab` | Convert to Kebab-Case (PascalKebab) | `\"{0:c:Kebab}\"` | `myVariable` | `My-Variable` |\n| | `:c:KEBAB` | Convert to KEBAB-CASE (upper) | `\"{0:c:KEBAB}\"` | `myVariable` | `MY-VARIABLE` |\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    sf \"github.com/Wissance/stringFormatter\"\n)\n\nfunc main() {\n    template := \"Status 0x{0:X4} (binary: {0:B8}), temp: {1:F1}°C, items: {2:L, }.\"\n    result := sf.Format(template, 475, 23.876, []int{1, 2, 3})\n    fmt.Println(result)\n    // Output: Status 0x01DB (binary: 00011101), temp: 23.9°C, items: 1, 2, 3.\n}\n```\n\n## 🛠 4 Text Utilities\n\n### 4.1 Map to String (MapToString)\nConverts a map with primitive keys to a formatted string.\n```go\noptions := map[string]any{\n    \"host\": \"localhost\",\n    \"port\": 8080,\n    \"ssl\":  true,\n}\n\nstr := sf.MapToString(\u0026options, \"{key} = {value}\", \"\\n\")\n// Possible output (key order is not guaranteed):\n// host = localhost\n// port = 8080\n// ssl = true\n```\n\n### 4.2 Slice to String (SliceToString, SliceSameTypeToString)\nConverts slices to a string using a specified separator.\n\n```go\n// For a slice of any type\nmixedSlice := []any{100, \"text\", 3.14}\nseparator := \" | \"\nresult1 := sf.SliceToString(\u0026mixedSlice, \u0026separator)\n// result1: \"100 | text | 3.14\"\n\n// For a typed slice\nnumSlice := []int{10, 20, 30}\nresult2 := sf.SliceSameTypeToString(\u0026numSlice, \u0026separator)\n// result2: \"10 | 20 | 30\"\n```\n\n## 📊 5 Benchmarks\nThe library is optimized for high-load scenarios. Key benchmarks show significant performance gains (performance could be differ due to 1. different CPU architectures 2. statistics):\n\nFormatting (Format) vs fmt.Sprintf: 3-5x faster for complex templates.\nSlices (SliceToString) vs manual fmt-based joining: from `2.5` faster up to 20 items.\n\nRun the benchmarks yourself:\n```bash\ngo test -bench=Format -benchmem -cpu 1\ngo test -bench=Fmt -benchmem -cpu 1\ngo test -bench=MapToStr -benchmem -cpu 1\n```\nSome benchmark screenshots:\n\n1. `Format` and `FormatComplex`:\n![Format](img/benchmarks2.png)\n\n2. `MapToStr`:\n![MapToStr benchmarks](img/map2str_benchmarks.png)\n\n3. `SliceToStr`:\n![SliceToStr benchmarks](img/slice2str_benchmarks.png)\n\n## 📄 6 License\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## 🤝 7 Contributing\nContributions are welcome! If you find a bug or have a feature suggestion, please open an issue or submit a pull request.\n\n**Contributors:**\n\n\u003ca href=\"https://github.com/Wissance/stringFormatter/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=Wissance/stringFormatter\" /\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":["Miscellaneous","Microsoft Office"],"sub_categories":["Strings"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWissance%2FstringFormatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWissance%2FstringFormatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWissance%2FstringFormatter/lists"}