nomino/options.go

70 lines
1.7 KiB
Go
Raw Normal View History

2025-03-07 16:26:24 -06:00
package nomino
2025-03-13 16:58:55 -05:00
import (
"strings"
"github.com/gosimple/slug"
)
2025-03-07 16:26:24 -06:00
// Option sets configuration parameters for [Config].
2025-03-10 14:52:50 -05:00
type Option func(c *Config)
2025-03-07 16:26:24 -06:00
2025-03-10 13:46:13 -05:00
// WithOriginal sets the original filename.
// This will be included in the generated name after the generated string and before the suffix.
2025-03-07 16:26:24 -06:00
func WithOriginal(o string) Option {
2025-03-10 14:52:50 -05:00
return func(c *Config) {
2025-03-11 16:42:39 -05:00
c.original = o
2025-03-07 16:26:24 -06:00
}
}
2025-03-13 16:58:55 -05:00
// WithOriginal sets the original filename as a slug.
// This should not be used with the [Slug] [Generator] (as it would be redundant).
2025-03-13 16:58:55 -05:00
func WithOriginalSlug(o string) Option {
return func(c *Config) {
c.original = slug.Make(o)
}
}
// WithOriginal sets the original filename as a slug, taking the language into account.
// This should not be used with the [Slug] [Generator] (as it would be redundant).
2025-03-13 16:58:55 -05:00
func WithOriginalSlugLang(o, lang string) Option {
return func(c *Config) {
c.original = slug.MakeLang(o, lang)
}
}
2025-03-10 13:46:13 -05:00
// WithPrefix sets a prefix for the generated name.
2025-03-07 16:26:24 -06:00
func WithPrefix(p string) Option {
2025-03-10 14:52:50 -05:00
return func(c *Config) {
2025-03-11 16:42:39 -05:00
c.prefix = p
2025-03-07 16:26:24 -06:00
}
}
2025-03-10 13:46:13 -05:00
// WithSuffix sets a suffix for the generated name. It will be included in the base name before the suffix.
2025-03-07 16:26:24 -06:00
func WithSuffix(s string) Option {
2025-03-10 14:52:50 -05:00
return func(c *Config) {
2025-03-11 16:42:39 -05:00
c.suffix = s
2025-03-07 16:26:24 -06:00
}
}
// WithoutExtension sets no extension for the generated filename. By default, it will be txt.
2025-03-07 16:26:24 -06:00
func WithoutExtension() Option {
2025-03-10 14:52:50 -05:00
return func(c *Config) {
2025-03-07 16:26:24 -06:00
c.extension = ""
}
}
2025-03-10 13:46:13 -05:00
// WithExtension sets the extension for the generated filename.
2025-03-07 16:26:24 -06:00
func WithExtension(ext string) Option {
2025-03-10 14:52:50 -05:00
return func(c *Config) {
2025-03-07 16:26:24 -06:00
c.extension = "." + strings.TrimPrefix(ext, ".")
}
}
2025-03-11 16:42:39 -05:00
// WithSeparator sets the separator for the generated filename.
func WithSeparator(sep string) Option {
return func(c *Config) {
c.separator = sep
}
}