Added ToCSV

This commit is contained in:
Leon Mika 2023-10-17 22:13:53 +00:00
parent 19f092b899
commit dfb22d462e
2 changed files with 42 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package scriptx_test
import (
"regexp"
"testing"
"github.com/bitfield/script"
@ -42,3 +43,17 @@ func ExampleCSVColumn() {
// banana
// cherry
}
func ExampleToCSV() {
script.Slice([]string{
"letter fruit word",
"a apple alpha",
"b banana bravo",
"c cherry charlie",
}).Filter(scriptx.ToCSV(regexp.MustCompile(`\s+`))).Stdout()
// Output:
// letter,fruit,word
// a,apple,alpha
// b,banana,bravo
// c,cherry,charlie
}