{"id":19836489,"url":"https://github.com/guobinhit/sylph","last_synced_at":"2025-05-01T18:30:23.184Z","repository":{"id":41297647,"uuid":"509080498","full_name":"guobinhit/sylph","owner":"guobinhit","description":"♨️ A practical tool box of Go, include to slices, dates and so on.","archived":false,"fork":false,"pushed_at":"2023-03-03T06:49:26.000Z","size":249,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T16:48:46.952Z","etag":null,"topics":["go","golang","slices","strings","utils"],"latest_commit_sha":null,"homepage":"https://guobinhit.github.io/sylph/","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/guobinhit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2022-06-30T12:56:02.000Z","updated_at":"2024-01-12T18:32:36.000Z","dependencies_parsed_at":"2024-06-21T17:54:36.013Z","dependency_job_id":"04647738-f659-468b-81e2-41f092f471ff","html_url":"https://github.com/guobinhit/sylph","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fsylph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fsylph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fsylph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guobinhit%2Fsylph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guobinhit","download_url":"https://codeload.github.com/guobinhit/sylph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251924543,"owners_count":21665987,"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":["go","golang","slices","strings","utils"],"created_at":"2024-11-12T12:11:30.233Z","updated_at":"2025-05-01T18:30:22.717Z","avatar_url":"https://github.com/guobinhit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sylph\n\n![author](https://img.shields.io/badge/author-chariesgavin-blueviolet.svg)[![Go](https://github.com/guobinhit/sylph/actions/workflows/go.yml/badge.svg)](https://github.com/guobinhit/sylph/actions/workflows/go.yml)![issues](https://img.shields.io/github/issues/guobinhit/sylph.svg)![stars](https://img.shields.io/github/stars/guobinhit/sylph.svg)![forks](https://img.shields.io/github/forks/guobinhit/sylph.svg)![license](https://img.shields.io/github/license/guobinhit/sylph.svg)\n\n\u003e Sylph is the fairy of the wind. \n\u003e \n\u003e It is said that the breeze is the whisper of the fairy. \n\u003e \n\u003e Anyone with a pure heart will eventually become Sylph.\n\n# Contributing\n\nContributions are very welcome!\n\nIf you see a problem that you'd like to see fixed, the best way to make it happen is to help out by submitting a pull request implementing it. Refer to the [CONTRIBUTING.md](../master/CONTRIBUTING.md) file for more details about the workflow.\n\nYou can also ask for problem-solving ideas and discuss in GitHub issues directly.\n\n# INDEX\n\n- [Overview](#overview)\n- [Usage](#usage)\n\n# Overview\n\nIn specified package, provides some practical util, as below:\n\n- `dates`: includes some practical date util, such as `GetTodayStart`.\n  - `format`: format a `time` value to `string`, such as `GetYyyyMmDdHhMmSs`,\n  - `parse`: parse a `string` value to `time`, such as `GetYyyyMmDdHhMmSs`.\n- `diffs`: includes some diff util, as below:\n  - `jsondiff`: diff json and return difference item.\n  - `textdiff`: diff text and return difference item.\n- `maps`: includes some practical map util, such as `Keys`.\n- `maths`: includes some practical math util, such as `RangeRandomLCRO`.\n- `pointers`: convert base type to pointer, such as `Int`.\n- `slices`: check base type slice contains target element or not, such as `ContainStringsIgnoreCase`.\n- `strings`: check string element equals or not, can ignore case, such as `EqualsIgnoreCase`.\n- `unpointers`: convert pointer to base type, such as `Int64OrDefault`.\n- `utils`: includes some practical util, such as `If`.\n\nIn `constant` package, provides some practical constant definitions, as below:\n\n- `date_const`: includes some dates format constant, such as `YyyyMmDdHhMmSs`.\n- `string_const`: includes some string constant, such as `EmptyString`.\n\n# Usage\n\nFirstly, download this pkg,\n\n```go\ngo get github.com/guobinhit/sylph\n```\n\nSecondly, use it.\n\n## dates\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/dates\"\n    \"github.com/guobinhit/sylph/dates/format\"\n    \"github.com/guobinhit/sylph/dates/parse\"\n)\n\n// Get a specified time by add days, such as d is 2022-04-13 10:20:30 and days is 10,\n// then aDate is 2022-04-23 10:20:30\naDate := dates.GetTimeAddDays(time.Now(), 10)\n\n// Get a specified date format time string of common version, such as d is 2022-04-13 10:20:30,\n// then aString is \"2022-04-23 10:20:30\"\naString := format.GetYyyyMmDdHhMmSs(time.Now())\n\n// Get a specified date format time string of china version, such as d is 2022-04-13 10:20:30,\n// then aString2 is \"2022年04月23日 10:20:30\", like GetCnOfYyyyMmDdHhMmSs method, \n// GetEnOfYyyyMmDdHhMmSs return \"2022/04/23 10:20:30\" and GetCptOfYyyyMmDdHhMmSs return \"20220423102030\".\naString2 := format.GetCnOfYyyyMmDdHhMmSs(time.Now())\n\n// Get a specified date format time, such as dStr is \"2022-04-13 10:20:30\",\n// then aTime is 2022-04-23 10:20:30\naTime, err := parse.GetYyyyMmDdHhMmSs(\"2022-04-13 10:20:30\")\n```\n\n## diffs\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/diffs/jsondiff\"\n    \"github.com/guobinhit/sylph/diffs/textdiff\"\n)\n\n// Build compare param, convert to []byte type, call Compare method,\n// return two result, diffType can ignore, diffStr is compare result.\nfirstParam := map[string]interface{}{}\nsecondParam := map[string]interface{}{}\nopts := DefaultJsonOptions()\ndiffType, diffStr := jsondiff.Compare([]byte(utils.Json(firstParam)), []byte(utils.Json(secondParam)), opts)\n\n// Build compare param, init DiffMatchPatch object, call Diff-style method,\n// return []Diff, but Diff.Type is number, can call GetDiffPrettyStyle method get pretty result.\ntext1 := \"Hello World\"\ntext2 := \"Hello Girl\"\ndmp := textdiff.New()\ndiffs := dmp.DiffMain(text1, text2, false)\nfmt.Println(utils.Json(dmp.GetDiffPrettyStyle(diffs)))\n```\n\n## maps\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/maps\"\n)\n\n// Get a slice from map, element of slice is key of map, such as map is {\"a\":1, \"b\":2},\n// then aKeySlice is {\"a\", \"b\"}, we can use assert convert to actual type.\naKeySlice := maps.Keys(map[string]string{\"a\":1, \"b\":2})\naActualKeySlice := aKeySlice.([]string)\n\n// Get a slice from map, element of slice is value of map, such as map is {\"a\":1, \"b\":2},\n// then aValueSlice is {1, 2}, we can use assert convert to actual type.\naValueSlice := maps.Values(map[string]string{\"a\":1, \"b\":2})\naActualValueSlice := aValueSlice.([]int)\n```\n\n## maths\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/maths\"\n)\n\n// Get a random int value, LCRC means left close right close, left is 1, right is 10\n// then min value of aRandIntOfLCRC is 1, max value of aRandIntOfLCRC is 10\naRandIntOfLCRC := maths.RangeRandomLCRC(1, 10)\n\n// Get a random int value, LCRO means left close right open, left is 1, right is 10\n// then min value of aRandIntOfLCRO is 1, max value of aRandIntOfLCRO is 9\naRandIntOfLCRO := maths.RangeRandomLCRO(1, 10)\n\n// Get a random int value, LORO means left open right open, left is 1, right is 10\n// then min value of aRandIntOfLORO is 2, max value of aRandIntOfLORO is 9\naRandIntOfLORO := maths.RangeRandomLORO(1, 10)\n```\n\n## pointers\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/pointers\"\n)\n\n// Get a pointer type of int, \n// supports int, int8, int16, int32, int64, float32, float64 and string.\naIntPtr := pointers.Int(413)\n```\n\n## unpointers\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/unpointers\"\n)\n\n// Get a base type value from pointer, \n// supports int, int8, int16, int32, int64, float32, float64 and string.\naInt := unpointers.Int(pointer.Int(413))\n\n// Get a base type value or default value from pointer, if pointer is nil, then return default value,\n// supports int, int8, int16, int32, int64, float32, float64 and string.\naIntOrDefault := unpointers.IntOrDefault(pointer.Int(413), 0)\n```\n\n## slices\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/slices\"\n)\n\n// Get a distinct slice from param slice, such as param s is {\"a\",\"b\", \"c\", \"a\"},\n// then aDistinctSlice is {\"a\",\"b\", \"c\"}.\naDistinctSlice := slices.DistinctStrings([]string{\"a\",\"b\", \"c\", \"a\"})\n\n// Get a bool value, if slice param contains specified element e return true, else return false,\n// such as s is {\"a\",\"b\", \"c\"}, e is \"c\", then aContainBool true.\n// Like ContainStrings method, ContainStringsIgnoreCase method can ignore case.\naContainBool := slices.ContainStrings([]string{\"a\",\"b\", \"c\"}, \"c\")\n\n// Get a filter slice, applies a fn to each element of s, return a slices of make fn true,\n// such as fn is func(v string) bool { return len(v) \u003e 3} and s is {\"abc\", \"zora\"}, then aFilterSlice is {\"zora\"}\n// Like ContainStrings method, AllStrings and AnyStrings method can provide similar functions,\n// supports int, int8, int16, int32, int64, float32, float64 and string.\naFilterSlice := slices.FilterStrings([]string{\"abc\", \"zora\"}, func(v string) bool { return len(v) \u003e 3})\n\n// Paging slice and returns the current page results and hasNext mark,\n// such as arr is {\"1\", \"2\", \"3\",\"4\", \"5\"}, pageNum is 2 and pageLimit is 2,\n// then aPageSlice is {\"3\", \"4\"}, hasNext is true. We can use assert convert to actual type.\naPageSlice, hasNext := slices.Page([]string{\"1\", \"2\", \"3\",\"4\", \"5\"}, 2, 2)\naActualPageSlice := aPageSlice.([]string)\n```\n\n## strings\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/strings\"\n)\n\n// Get a bool value, if s1 is equals to s2 return true, else return false,\n// such as s1 is \"abc\", s2 is \"ABC\", then aBool is false.\naBool := strings.Equals(\"abc\", \"ABC\")\n\n// Get a bool value, if s1 is equals to s2 (ignore case) return true, else return false,\n// such as s1 is \"abc\", s2 is \"ABC\", then aBool2 is true.\naBool2 := strings.EqualsIgnoreCase(\"abc\", \"ABC\")\n```\n\n## utils\n\n```go\nimport (\n    \"github.com/guobinhit/sylph/utils\"\n)\n\n// If function similar to ternary operators，if b is ture return t, else return f.\naValue := utils.If(b, t, f)\n\n// Returns a json format string.\naJsonString := utils.Json(struct{Value string `json:\"value\"`}{Value: \"sylph\"})\n\n// DeepCopy source and target must have the same structure, and target must be a pointer.\nemptyStruct := struct{Value string `json:\"value\"`}{}\nutils.DeepCopy(struct{Value string `json:\"value\"`}{Value: \"sylph\"}, \u0026emptyStruct)\n```\n\nFinally, good luck guys!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguobinhit%2Fsylph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguobinhit%2Fsylph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguobinhit%2Fsylph/lists"}