{"id":17362262,"url":"https://github.com/enescakir/balance","last_synced_at":"2025-03-27T16:46:37.979Z","repository":{"id":72891152,"uuid":"185756662","full_name":"enescakir/balance","owner":"enescakir","description":"A package for validating the balance of parentheses","archived":false,"fork":false,"pushed_at":"2019-05-22T18:50:22.000Z","size":367,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T20:29:45.282Z","etag":null,"topics":["balancing","go","parentheses"],"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/enescakir.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-05-09T08:18:06.000Z","updated_at":"2023-11-12T11:22:38.000Z","dependencies_parsed_at":"2023-05-19T09:30:34.273Z","dependency_job_id":null,"html_url":"https://github.com/enescakir/balance","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/enescakir%2Fbalance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enescakir%2Fbalance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enescakir%2Fbalance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enescakir%2Fbalance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enescakir","download_url":"https://codeload.github.com/enescakir/balance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245887932,"owners_count":20688893,"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":["balancing","go","parentheses"],"created_at":"2024-10-15T19:37:35.521Z","updated_at":"2025-03-27T16:46:37.972Z","avatar_url":"https://github.com/enescakir.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\t\u003cimg width=\"560\" height=\"100\" src=\"https://github.com/EnesCakir/balance/blob/master/logo.png\"\u003e\n\t\u003cbr\u003e \u003cbr\u003e\n    A package for validating the balance of parentheses\n\u003c/p\u003e\n\n## Getting started\nInstall `balance`:\n```shell\n$ go get github.com/enescakir/balance\n```\n\nAdd `balance` to your imports to start using\n```go\nimport \"github.com/enescakir/balance\"\n```\n\n\n## Usage\n\n#### `Check(str string) (valid bool, err error)`\nIt checks given string for parentheses balance for `{}`, `()`, `[]` pairs\n\n```go\nvalid, err := balance.Check(\"{()[]}(())\")\n// Returns: valid =\u003e true, err =\u003e nil\n\nvalid, err := balance.Check(\"([)]\")\n// Returns: valid =\u003e false, err =\u003e MismatchError\n\nvalid, err := balance.Check(\"[[]\")\n// Returns: valid =\u003e false, err =\u003e UnclosedParenthesesError\n\nvalid, err := balance.Check(\"({a})\")\n// Returns: valid =\u003e false, err =\u003e UnknownCharacterError\n```\n\n#### `CheckCustom(str string, opens string, closes string) (bool, err)`\nIt checks given string for parentheses balance for custom pairs.\n\n`opens` and `closes` strings should have pair elements in same order.\n\nGiven pair elements have to be unique. `CheckCustom` function doesn't work properly without unique elements.\n\n```go\nvalid, err := balance.CheckCustom(\"\u003c\u003c\u003e\u003e\u003c\u003e\", \"\u003c\", \"\u003e\")\n// Returns: valid =\u003e true, err =\u003e nil\n\nvalid, err := balance.CheckCustom(\")))()(((\", \")\", \"(\")\n// Returns: valid =\u003e true, err =\u003e nil\n\nvalid, err := balance.CheckCustom(\"\u003c\u003e\u003c\u003e\u003c\u003e\", \"\u003c\u003c\", \"\u003e\")\n// Returns: valid =\u003e false, err =\u003e CustomPairError\n```\n\n## How It Works\nThe balance checking algorithm uses stack at the core. The stack is simple First in Last out data structure.\n\nThe algorithm iterates over the given string. If it encounters an opening character, pushes the character to stack. On the other hand, if it gets a closing character, pops the top element from the stack and checks them for pairing. Eventually, if they aren't matching pairs, it raises `MismatchError`. If the encountered character is not a member of either the opening or closing sets, it raises `UnknownCharacterError`. End of the iteration, the stack should be empty. If not, there is an unclosed parenthesis. So it raises `UnclosedParenthesesError`\n\n## HTTP Server\nIt's a simple HTTP server that shows example usage for `balance` package.\n\nIt checks parenthesis balance of given string and save request history to memory or MySQL database for calculating some metrics.\n\nVisit `server` directory for [detailed documentation](https://github.com/EnesCakir/balance/tree/master/server).\n\n![Dashboard](https://github.com/EnesCakir/balance/blob/master/dashboard.png)\n\n## Testing\nYou can use `go test` method for unit tests.\n\n**Test coverage:** 100%\n\n## Contributing\n`balance` is an open source project run by `Enes Çakır`, and contributions are welcome! Check out the [Issues](https://github.com/enescakir/balance/issues) page to see if your idea for a contribution has already been mentioned, and feel free to raise an issue or submit a pull request.\n\n## License\nCopyright (c) 2019 Enes Çakır. All rights reserved. Use of this source code is\ngoverned by a MIT license that can be found in the LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenescakir%2Fbalance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenescakir%2Fbalance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenescakir%2Fbalance/lists"}