fix(bytes): change Bytes function to accept string input but return a byte slice

The old method signature was just nonsensical, as you would always be
providing indented values via a string literal. So it makes much more
sense to have all methods accept a string argument, and then return
different types.

This also allows use of a `Bytesf` method.

This is technically a breaking change, but I'm classifying it as a
bugfix cause the old method signature was basically useless.
This commit is contained in:
2020-12-14 14:29:35 +00:00
parent d79e413e8e
commit 5dbdbbf341
3 changed files with 43 additions and 36 deletions

View File

@@ -7,11 +7,11 @@ import (
)
func ExampleBytes() {
b := undent.Bytes([]byte(`
b := undent.Bytes(`
{
"hello": "world"
}`,
))
)
fmt.Println(string(b))
// Output:
@@ -20,6 +20,20 @@ func ExampleBytes() {
// }
}
func ExampleBytesf() {
s := undent.Bytesf(`
{
"hello": "%s"
}`,
"world",
)
fmt.Println(string(s))
// Output:
// {
// "hello": "world"
// }
}
func ExampleString() {
s := undent.String(`
{