Open gabe565 opened 1 year ago
I was just looking for a code-shortener-as-a-library and found this project, which is just what I was hoping for! My usecase includes code generation and I was hoping for a library rather than a command. Anything holding up this PR from being merged?
I would also love to see this merged.
Description
Refactor codebase to add a
shorten
package. This allows other projects to use this library and closes #34.Some notes:
pkg
is preferred for things that should be public. I could easily move topkg/shorten
. I opted to keep the imports shorter, but let me know if you have a different preference!shorten
package could be moved to their own packages ininternal
. Again, I don't mind doing the refactoring if you'd prefer that.shorten.DefaultConfig()
which returns ashorten.Config
struct that matches the default flag values. I have also changedshorten.New()
so that config is an optional parameter. If not passed, the default config is used.shorten.New()
,shorten.DefaultConfig()
, andShortener.Shorten()
are exposed.Unfortunately, this PR required some major refactoring and will create merge conflicts with any other open PRs.
Let me know if you have any suggestions!
Example: Usage in another project
main.go
```go package main import ( "fmt" "github.com/segmentio/golines/shorten" ) var code = `package main var myMap = map[string]string{"key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4", "key5", "value5"} ` func main() { shortener := shorten.New() out, err := shortener.Shorten([]byte(code)) if err != nil { panic(err) } fmt.Print(string(out)) } ```Todo