{"id":13414134,"url":"https://github.com/gookit/filter","last_synced_at":"2025-04-05T12:08:32.536Z","repository":{"id":38290580,"uuid":"150399806","full_name":"gookit/filter","owner":"gookit","description":"⏳ Provide filtering, sanitizing, and conversion of Golang data. 提供对Golang数据的过滤，净化，转换。","archived":false,"fork":false,"pushed_at":"2024-07-10T12:11:35.000Z","size":181,"stargazers_count":149,"open_issues_count":0,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-07-31T20:53:33.412Z","etag":null,"topics":["converter","data-conversion","data-filtering","filter","golang-package","sanitization"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/gookit/filter","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/gookit.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":"2018-09-26T09:11:13.000Z","updated_at":"2024-07-26T10:03:46.000Z","dependencies_parsed_at":"2024-01-17T04:17:07.147Z","dependency_job_id":"324c9271-239f-4faa-80dd-c0edef0fda01","html_url":"https://github.com/gookit/filter","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Ffilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Ffilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Ffilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Ffilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332612,"owners_count":20921853,"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":["converter","data-conversion","data-filtering","filter","golang-package","sanitization"],"created_at":"2024-07-30T20:01:58.744Z","updated_at":"2025-04-05T12:08:32.509Z","avatar_url":"https://github.com/gookit.png","language":"Go","readme":"# Filter\n\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/filter)](https://github.com/gookit/filter)\n[![Actions Status](https://github.com/gookit/filter/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/filter/actions)\n[![Coverage Status](https://coveralls.io/repos/github/gookit/filter/badge.svg?branch=master)](https://coveralls.io/github/gookit/filter?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/filter)](https://goreportcard.com/report/github.com/gookit/filter)\n[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/filter.svg)](https://pkg.go.dev/github.com/gookit/filter)\n\n`filter` - provide filtering, sanitizing, and conversion of Golang data.\n\n\u003e 中文说明请查看 **[README.zh-CN](README.zh-CN.md)**\n\n## GoDoc\n\n- [godoc](https://pkg.go.dev/github.com/gookit/filter)\n\n\u003e **NOTE**: To filter and validate Map, Struct data. Please use [gookit/validate](https://github.com/gookit/validate)\n\n## Install\n\n```shell\ngo get github.com/gookit/filter\n```\n\n## Func Usage\n\nQuick usage:\n\n```go\nstr := filter.MustString(23) // \"23\"\n\nintVal, err := filter.Int(\"20\") // int(20)\nstrings := filter.Str2Slice(\"a,b, c\", \",\") // []string{\"a\", \"b\", \"c\"}\n```\n\n## Filtration\n\nFiltering data:\n\n```go\ndata := map[string]any{\n    \"name\":     \" inhere \",\n    \"age\":      \"50\",\n    \"money\":    \"50.34\",\n    // \n    \"remember\": \"yes\",\n    //\n    \"sub1\": []string{\"1\", \"2\"},\n    \"tags\": \"go;lib\",\n    \"str1\": \" word \",\n    \"ids\":  []int{1, 2, 2, 1},\n}\nf := filter.New(data)\nf.AddRule(\"money\", \"float\")\nf.AddRule(\"remember\", \"bool\")\nf.AddRule(\"sub1\", \"strings2ints\")\nf.AddRule(\"tags\", \"str2arr:;\")\nf.AddRule(\"ids\", \"unique\")\nf.AddRule(\"str1\", \"ltrim|rtrim\")\nf.AddRule(\"not-exist\", \"unique\")\n// add multi\nf.AddRules(map[string]string{\n    \"age\": \"trim|int\",\n    \"name\": \"trim|ucFirst\",\n})\n\n// apply all added rules for data.\nf.Filtering() \n\n// get filtered data\nnewData := f.CleanData()\nfmt.Printf(\"%#v\\n\", newData)\n// f.BindStruct(\u0026user)\n```\n\n**Output**:\n\n```go\nmap[string]interface {}{\n    \"remember\":true, \n    \"sub1\":[]int{1, 2}, \n    \"tags\":[]string{\"go\", \"lib\"}, \n    \"ids\":[]int{2, 1}, \n    \"str1\":\"word\", \n    \"name\":\"INHERE\", \n    \"age\":50, \n    \"money\":50.34\n}\n```\n\n## Filters \u0026 Converters\n\n- `ToBool/Bool(s string) (bool, error)`\n- `ToFloat/Float(v interface{}) (float64, error)`\n- `ToInt/Int(v interface{}) (int, error)`\n- `ToUint/Uint(v interface{}) (uint64, error)`\n- `ToInt64/Int64(v interface{}) (int64, error)`\n- `ToString/String(v interface{}) (string, error)`\n- `MustBool(s string) bool`\n- `MustFloat(s string) float64`\n- `MustInt(s string) int`\n- `MustInt64(s string) int64`\n- `MustUint(s string) uint64`\n- `MustString(v interface{}) string`\n- `Trim(s string, cutSet ...string) string`\n- `TrimLeft(s string, cutSet ...string) string`\n- `TrimRight(s string, cutSet ...string) string`\n- `TrimStrings(ss []string, cutSet ...string) (ns []string)`\n- `Substr(s string, pos, length int) string`\n- `Lower/Lowercase(s string) string`\n- `Upper/Uppercase(s string) string`\n- `LowerFirst(s string) string`\n- `UpperFirst(s string) string`\n- `UpperWord(s string) string`\n- `Camel/CamelCase(s string, sep ...string) string`\n- `Snake/SnakeCase(s string, sep ...string) string`\n- `Email(s string) string`\n- `URLDecode(s string) string`\n- `URLEncode(s string) string`\n- `EscapeJS(s string) string`\n- `EscapeHTML(s string) string`\n- `Unique(val interface{}) interface{}` Will remove duplicate values, use for `[]int` `[]int64` `[]string`\n- `StrToSlice(s string, sep ...string) []string`\n- `StrToInts(s string, sep ...string) (ints []int, err error)`\n- `StrToTime(s string, layouts ...string) (t time.Time, err error)`\n- `StringsToInts(ss []string) (ints []int, err error)`\n\n## License\n\n**[MIT](LICENSE)**\n","funding_links":[],"categories":["Utilities","Tool-kits \u0026 helpers","公用事业公司","工具库`可以提升效率的通用代码库和工具`","Utility","工具库"],"sub_categories":["HTTP Clients","Utility/Miscellaneous","实用程序/Miscellaneous","查询语","Fail injection"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Ffilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Ffilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Ffilter/lists"}