Fast text generator on a mask.
Written in Golang. I do not use regular expressions and the fastest. I covered tests and simple! Supporting recursive text generation rules.
go get github.com/liderman/text-generator
An example of a simple template text generation:
tg := textgenerator.New()
template := "Good {morning|day}!"
fmt.Print(tg.Generate(template))
// Displays: Good morning!
fmt.Print(tg.Generate(template))
// Displays: Good day!
An example of a complex generation template text:
tg := textgenerator.New()
template := "{Good {morning|evening|day}|Goodnight|Hello}, {friend|brother}! {How are you|What's new with you}?"
fmt.Print(tg.Generate(template))
// Displays: Good morning, friend! How are you?
fmt.Print(tg.Generate(template))
// Displays: Good day, brother! What's new with you?
fmt.Print(tg.Generate(template))
// Displays: Hello, friend! How are you?
...
- Need at least
go1.14
or newer.
- Without external dependencies
- Fast (does not use regular expressions)
- Simple
- Supports caching
- Covered with tests
You can read package documentation here.
Unit-tests:
go test -v -race ./...
Run linter:
docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.40 golangci-lint run -v
go test -test.bench . -benchmem -benchtime=10s
The test result on computer MacBook Pro 2020 (Intel Core i5):
goos: darwin
goarch: amd64
pkg: github.com/liderman/text-generator
BenchmarkGenerateEasyText-8 22446540 531 ns/op 200 B/op 8 allocs/op
BenchmarkGenerateComplexText-8 4721838 2552 ns/op 1351 B/op 24 allocs/op
PASS
ok github.com/liderman/text-generator 27.227s
- write code
- run
go fmt ./...
- run all linters and tests (see above)
- create a PR describing the changes
MIT
Konstantin Osipov [email protected]