{"id":13713001,"url":"https://github.com/zzwx/interval","last_synced_at":"2025-12-24T12:30:12.602Z","repository":{"id":57532958,"uuid":"279731368","full_name":"zzwx/interval","owner":"zzwx","description":"An almost useless utility for normalizing a numeric range, with a wrapping function useful for polar coordinates. It's exploring go 1.x code generation. It is a clone of a JavaScript project by James Talmage (https://github.com/jamestalmage/normalize-range).","archived":false,"fork":false,"pushed_at":"2021-10-10T16:37:03.000Z","size":100,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-12-29T13:39:39.714Z","etag":null,"topics":["generated","go","interval"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/zzwx/interval","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/zzwx.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}},"created_at":"2020-07-15T01:27:12.000Z","updated_at":"2021-10-10T16:37:06.000Z","dependencies_parsed_at":"2022-09-26T18:20:48.012Z","dependency_job_id":null,"html_url":"https://github.com/zzwx/interval","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzwx%2Finterval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzwx%2Finterval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzwx%2Finterval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zzwx%2Finterval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zzwx","download_url":"https://codeload.github.com/zzwx/interval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239708990,"owners_count":19684165,"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":["generated","go","interval"],"created_at":"2024-08-02T23:01:25.808Z","updated_at":"2025-12-24T12:30:12.525Z","avatar_url":"https://github.com/zzwx.png","language":"Go","readme":"[![https://github.com/zzwx/interval](./doc/gobadge.svg)](https://pkg.go.dev/github.com/zzwx/interval)\n\n# Interval\n\nAn almost useless utility for normalizing a numeric range, with a wrapping function for polar coordinates, implemented using `go generate`.\n\nIt is a **golang clone** of a JavaScript project by [James Talmage](https://github.com/jamestalmage/normalize-range).\n\nFor dealing with the strict typing in Go, functions were auto-generated for all of the following types:\n\n* `int`\n* `int64`\n* `int32`\n* `int16`\n* `int8`\n* `uint`\n* `uint64`\n* `uint32`\n* `uint16`\n* `uint8`\n* `float32`\n* `float64`\n\n## Motivation\n\nThis approach is inspired by [Rob Pike's article](https://blog.golang.org/generate) on code generation. Until generics are implemented, this is simply an example of code generation, exploiting templates in this case.\n\n## Installation\n\n```\ngo get -u github.com/zzwx/interval\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/zzwx/interval\"\n)\n\nfunc main() {\n\tfmt.Println(interval.WrapInt(0, 360, 400))  //=\u003e 40\n\tfmt.Println(interval.WrapInt(0, 360, -90))  //=\u003e 270\n\tfmt.Println(interval.ClampInt(0, 100, 500)) //=\u003e 100\n\tfmt.Println(interval.ClampInt(0, 100, -20)) //=\u003e 0\n\n\tr := interval.NewRangeFloat64(0, 100, false, false)\n\tfmt.Println(r.Wrap(120))     //=\u003e 20\n\tfmt.Println(r.Validate(120)) //=\u003e 0, error(120 is outside of range [0,100])\n\tfmt.Println(r.Test(120))     //=\u003e false\n\tfmt.Println(r)               //=\u003e [0,100] (uses Stringer interface)\n}\n```\n\n[Go Playground](https://play.golang.org/p/c_cqte_YoAe)\n\n## API\n\nhttps://pkg.go.dev/github.com/zzwx/interval\n\n## License\n\nOriginal JavaScript author: [James Talmage](https://github.com/jamestalmage/normalize-range)\n\nMIT © [Anton Veretennikov](https://github.com/zzwx)\n","funding_links":[],"categories":["Repositories"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzzwx%2Finterval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzzwx%2Finterval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzzwx%2Finterval/lists"}