{"id":15888234,"url":"https://github.com/corecii/lua-fmt","last_synced_at":"2025-04-02T16:44:21.826Z","repository":{"id":105909075,"uuid":"208289610","full_name":"Corecii/lua-fmt","owner":"Corecii","description":"Easier-to-read string formatter based on string.format","archived":false,"fork":false,"pushed_at":"2020-11-22T03:34:54.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T07:25:17.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","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/Corecii.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":"2019-09-13T15:10:08.000Z","updated_at":"2020-11-22T03:34:56.000Z","dependencies_parsed_at":"2024-06-13T11:41:35.316Z","dependency_job_id":null,"html_url":"https://github.com/Corecii/lua-fmt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corecii%2Flua-fmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corecii%2Flua-fmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corecii%2Flua-fmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corecii%2Flua-fmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Corecii","download_url":"https://codeload.github.com/Corecii/lua-fmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246853376,"owners_count":20844569,"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-06T06:06:49.545Z","updated_at":"2025-04-02T16:44:21.807Z","avatar_url":"https://github.com/Corecii.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"Not heavily tested yet. Feel free to try it out and submit an issue or pull request if you find a problem.\r\n\r\n# fmt.lua\r\n\r\nConverts easy-to-read formatting to formats strings\r\n\r\n## Examples:\r\n\r\n```lua\r\nlocal fmt = require('fmt')\r\n\r\nfmt('Index %s',5) --\u003e Index 5\r\nfmt('Index %04d',5) --\u003e Index 0005\r\nfmt('User input: %s',input) --\u003e User input:\r\nfmt('Multiple format patterns (%d',2,'), string \"%s','safe string!','\"') --\u003e Multiple format patterns (2), string \"safe string!\"\r\nfmt('Reusing options: option 1: \"%s','hello!','\"; option 2: %d',5,'; repeat: $1 $2') --\u003e Reusing options: option 1: \"hello!\"; option 2: 5; repeat: hello! 5\r\nfmt('Escape percent: %%s') --\u003e Escape percent: %s\r\n```\r\n\r\nThe following will error:\r\n```lua\r\nfmt('Format patterns %s must be at the end of format string')\r\nfmt('Format patterns other than %%s must type-match %d','oops')\r\nfmt(5, 'First argument must be a format string')\r\n```\r\n\r\n## Full Formatting Specification\r\n\r\n* The formatter takes in a list of format strings and options.\r\n* The first value (starter) is always treated as a format string.\r\n* If a format string ends with a string.format pattern, then the following value is treated as an option.\r\n* If a string is not preceded by a string.format pattern, then it is treated as a format string.\r\n* If a non-string is not preceded by a string.format pattern, then it is tostringed and treated as an option to `%s`.\r\n* If an option is used for `%s`, it is tostringed. It is safe to use all values for `%s`.\r\n* Format strings are only allowed to have string.format patterns at the end.\r\n* You can reuse previous values by including `%X` to re-use option X where X is an integer.\r\n\tFor example, `fmt('Index %d',5,' (also index is %1)')` will result in `Index 5 (also index is 5)`\r\n\tOnly named (non-automatic) options can be reused by index.\r\n\r\nWhen formatting with a user-input string or an unknown type, always explicitly use the `%s` formatting option.\r\nThis should be done so that user-input strings such as 'hello %d' do not get treated as format string.\r\nThis is practically escaping or parameterizing your user-input strings.\r\n\r\nThe Formatter object can be used, for example, if you want an interactive logger that lets you inspect\r\nthe formattervalues in a debug console.\r\n\r\n## Docs\r\n\r\n```plain\r\nstring fmt(string starter, ...)\r\n\tFormats (starter, ...) and returns the formatted string\r\n\r\nFormatter fmt.new(string starter, ...)\r\n\tReturns a formatter for (starter, ...)\r\n\r\nstring, any[], any[], string[] fmt.raw(string starter, ...)\r\n\tReturns (formatString, formatOptions, rawOptionsByIndex, rawFormattersByIndex)\r\n\r\nFormatter\r\n\tstring Formatter()\r\n\t\tReturns the formatted string\r\n\tstring tostring(Formatter)\r\n\t\tReturns the formatted string\r\n\tstring .FormatString\r\n\t\tThe format string that will be passed to string.format\r\n\tany[] .Options\r\n\t\tThe options that will be passed to string.format\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorecii%2Flua-fmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorecii%2Flua-fmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorecii%2Flua-fmt/lists"}