Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

README.md 2.4 KiB

il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # strcase
  2. [![Godoc Reference](https://godoc.org/github.com/iancoleman/strcase?status.svg)](http://godoc.org/github.com/iancoleman/strcase)
  3. [![Build Status](https://travis-ci.org/iancoleman/strcase.svg)](https://travis-ci.org/iancoleman/strcase)
  4. [![Coverage](http://gocover.io/_badge/github.com/iancoleman/strcase?0)](http://gocover.io/github.com/iancoleman/strcase)
  5. [![Go Report Card](https://goreportcard.com/badge/github.com/iancoleman/strcase)](https://goreportcard.com/report/github.com/iancoleman/strcase)
  6. strcase is a go package for converting string case to various cases (e.g. [snake case](https://en.wikipedia.org/wiki/Snake_case) or [camel case](https://en.wikipedia.org/wiki/CamelCase)) to see the full conversion table below.
  7. ## Example
  8. ```go
  9. s := "AnyKind of_string"
  10. ```
  11. | Function | Result |
  12. |-------------------------------------------|----------------------|
  13. | `ToSnake(s)` | `any_kind_of_string` |
  14. | `ToSnakeWithIgnore(s, '.')` | `any_kind.of_string` |
  15. | `ToScreamingSnake(s)` | `ANY_KIND_OF_STRING` |
  16. | `ToKebab(s)` | `any-kind-of-string` |
  17. | `ToScreamingKebab(s)` | `ANY-KIND-OF-STRING` |
  18. | `ToDelimited(s, '.')` | `any.kind.of.string` |
  19. | `ToScreamingDelimited(s, '.', '', true)` | `ANY.KIND.OF.STRING` |
  20. | `ToScreamingDelimited(s, '.', ' ', true)` | `ANY.KIND OF.STRING` |
  21. | `ToCamel(s)` | `AnyKindOfString` |
  22. | `ToLowerCamel(s)` | `anyKindOfString` |
  23. ## Install
  24. ```bash
  25. go get -u github.com/iancoleman/strcase
  26. ```
  27. ## Custom Acronyms for ToCamel && ToLowerCamel
  28. Often times text can contain specific acronyms which you need to be handled a certain way.
  29. Out of the box `strcase` treats the string "ID" as "Id" or "id" but there is no way to cater
  30. for every case in the wild.
  31. To configure your custom acronym globally you can use the following before running any conversion
  32. ```go
  33. import (
  34. "github.com/iancoleman/strcase"
  35. )
  36. func init() {
  37. // results in "Api" using ToCamel("API")
  38. // results in "api" using ToLowerCamel("API")
  39. strcase.ConfigureAcronym("API", "api")
  40. // results in "PostgreSQL" using ToCamel("PostgreSQL")
  41. // results in "postgreSQL" using ToLowerCamel("PostgreSQL")
  42. strcase.ConfigureAcronym("PostgreSQL", "PostgreSQL")
  43. }
  44. ```