{"id":15578170,"url":"https://github.com/superioone/format_string","last_synced_at":"2025-07-21T15:07:44.486Z","repository":{"id":211842535,"uuid":"730055696","full_name":"SuperioOne/format_string","owner":"SuperioOne","description":"Replaces placeholders in a format string with provided named or positional arguments.","archived":false,"fork":false,"pushed_at":"2024-01-20T14:47:59.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T13:56:13.623Z","etag":null,"topics":["javascript","string-formatter","utility-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/SuperioOne.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-11T05:27:20.000Z","updated_at":"2023-12-11T08:12:14.000Z","dependencies_parsed_at":"2025-03-29T07:27:10.611Z","dependency_job_id":"2b8a50ed-ed25-4ba2-8729-91653b7f63d5","html_url":"https://github.com/SuperioOne/format_string","commit_stats":null,"previous_names":["superioone/format_string"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/SuperioOne/format_string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperioOne%2Fformat_string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperioOne%2Fformat_string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperioOne%2Fformat_string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperioOne%2Fformat_string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SuperioOne","download_url":"https://codeload.github.com/SuperioOne/format_string/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuperioOne%2Fformat_string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266324497,"owners_count":23911226,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["javascript","string-formatter","utility-library"],"created_at":"2024-10-02T19:06:57.454Z","updated_at":"2025-07-21T15:07:44.426Z","avatar_url":"https://github.com/SuperioOne.png","language":"JavaScript","readme":"# Yet another format string function\n\nFast, small and basic string templating function. This library is intended for use cases where the position of\nparameters\nin a format string is not known at compile-time.\n\n\u003e **For situations with predictable/constant string formats, using JavaScript's built-in string templating is highly\nrecommended.**\n\n## Getting Started\n\n1. Add the library into your project.\n   ```shell \n   npm install @superior-one/format_string\n    ```\n2. Import `default` function and start using.\n    * Named parameters:\n       ```javascript\n       import format_string from \"@superior-one/format_string\";\n    \n       const format_tag = \"({userTag}){name}, [{hash}]\";\n       const format_email = \"\u003c{email}\u003e{name}, {hash}\";\n       const args = {\n         email: \"john+doe@abc.com\",\n         name: \"John Doe\",\n         hash: \"18c54d073b2\",\n         userTag: \"@john\" \n       };\n    \n       const text0 = format_string(format_tag, args);\n       console.log(text0); // (@john)John Doe, [18c54d073b2]\n    \n       const text1 = format_string(format_email, args);\n       console.log(text1); // \u003cjohn+doe@abc.com\u003eJohn Doe, 18c54d073b2\n       ```\n    * Positional parameters:\n       ```javascript\n       import format_string from \"@superior-one/format_string\";\n    \n       const format = \"{2} {1} {0} {0} {2}\\n{2} {0} {1} {0} {2}\\n{2} {0} {0} {1} {2}\\n\";\n       const text = format_string(format, [\"a\", 5, \"|\"]);\n    \n       console.log(text);\n       // | 5 a a |\n       // | a 5 a |\n       // | a a 5 |\n       ```\n\n## Format Syntax\n\nConsider `arg=\"value\"`\n\n| Format          | Output          | Description                                                               |\n|-----------------|-----------------|---------------------------------------------------------------------------|\n| `{arg}`         | `value`         | Replaces `{arg}` with the value of `arg`                                  |\n| `{arg }`        | `{arg }`        | Treats `{arg }` as a string as it doesn't follow correct formatting       |\n| `{ arg}`        | `{ arg}`        | Treats `{ arg}` as a string since it doesn't follow correct formatting    |\n| `{arg arg}`     | `{arg arg}`     | Treats `{arg arg}` as a string since it doesn't follow correct formatting |\n| `{\\narg}`       | `{\\narg}`       | Treats `{\\narg}` as a string since it doesn't follow correct formatting   |\n| `{}`            | `{}`            | Empty placeholders are ignored and treats as a string                     |\n| `{{arg}}`       | `{arg}`         | Escapes the placeholder syntax                                            |\n| `{{{{arg}}}}`   | `{{{arg}}}`     | Escapes the inner placeholder syntax, outputting `{{{arg}}}` as a string  |\n| `{{{ {arg} }}}` | `{{{ value }}}` | Inserts `value` within triple curly braces, outputting `{{{ value }}}`    |\n\nAvoid using space, feed, tab and separator characters in placeholder names as they will be interpreted as strings, not\nplaceholders.\n\nList of invalid placeholder characters;\n\n- `{`\n- `}`\n- `' '`\n- `\\f`\n- `\\n`\n- `\\r`\n- `\\t`\n- `\\v`\n- `\\u00a0`\n- `\\u1680`\n- `\\u2000` to `\\u200a`\n- `\\u2028`\n- `\\u2029`\n- `\\u202f`\n- `\\u205f`\n- `\\u3000`\n- `\\ufeff`\n\n## Building the Project\n\nBuild step only generates type decleration and CommonJS version.\n\n```shell\nnpm install\nnpm run build\n```\n\n## Contributing\n\nPull requests are welcome, especially ideas for time and memory allocation reduction.\n\n## Benchmarks\n\nTested against some popular packages with four parameters and single escape.\n\n\u003e Keep in mind some of the listed libraries provides more features like number formatting, padding etc.\n\n```\nTest Environment:\nCPU       : AMD Ryzen 9 5950X 16-Core @ 32x 5.177GHz\nOS        : x86_64 Linux 6.6.3-1\nnode      : v20.7.0\nvitest    : v1.0.4\ntinybench : v2.5.1\n\n  name                                                        hz     min     max    mean     p75     p99    p995    p999     rme  samples\n· @superior-one/format_string with positional args  2,693,972.54  0.0003  0.9917  0.0004  0.0004  0.0004  0.0006  0.0016  ±0.31%  2693973\n· @superior-one/format_string with named args       2,260,906.19  0.0004  0.5987  0.0004  0.0004  0.0009  0.0009  0.0010  ±0.20%  2260907  \n· string-template with named args                     858,246.92  0.0011  0.2475  0.0012  0.0011  0.0021  0.0022  0.0024  ±0.16%   858247  \n· string-template with positional args              1,016,520.83  0.0009  0.1932  0.0010  0.0010  0.0011  0.0012  0.0019  ±0.11%  1016521  \n· @stdlib/string-format with positional args        1,771,259.33  0.0005  0.2183  0.0006  0.0006  0.0007  0.0008  0.0011  ±0.19%  1771260  \n· string-format with positional args                  548,726.51  0.0017  0.2494  0.0018  0.0018  0.0021  0.0029  0.0036  ±0.22%   548727  \n· string-format with named args                       377,298.69  0.0025  0.1892  0.0027  0.0026  0.0029  0.0030  0.0061  ±0.16%   377299 \n· pupa with positional args                           522,948.55  0.0018  0.1503  0.0019  0.0019  0.0021  0.0035  0.0041  ±0.15%   522949  \n· pupa with named args                                455,937.12  0.0021  0.9894  0.0022  0.0022  0.0038  0.0043  0.0051  ±0.23%   455938  \n· string replaceAll positional args                 1,619,706.37  0.0006  0.1692  0.0006  0.0006  0.0007  0.0008  0.0011  ±0.13%  1619707  \n· string replaceAll named args                      1,705,262.53  0.0005  0.2296  0.0006  0.0006  0.0007  0.0011  0.0012  ±0.07%  1705263  \n\nBENCH  Summary\n\n@superior-one/format_string with positional args - index.bench.js \u003e \n 1.19x faster than @superior-one/format_string with named args\n 1.52x faster than @stdlib/string-format with positional args\n 1.58x faster than string replaceAll named args\n 1.66x faster than string replaceAll positional args\n 2.65x faster than string-template with positional args\n 3.14x faster than string-template with named args\n 4.91x faster than string-format with positional args\n 5.15x faster than pupa with positional args\n 5.91x faster than pupa with named args\n 7.14x faster than string-format with named args\n```\n\n## License\n\nThis project is licensed under the terms of the MIT license.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperioone%2Fformat_string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperioone%2Fformat_string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperioone%2Fformat_string/lists"}