From 67f472a2c648cd94b585ee6c2068da2a3485dd4f Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 13 Mar 2025 15:22:54 -0500 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20Add=20Incremental*=20Generators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators.go | 28 ++++++++++++++- generators_examples_test.go | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/generators.go b/generators.go index fdbdabd..7873107 100644 --- a/generators.go +++ b/generators.go @@ -2,6 +2,7 @@ package nomino import ( "errors" + "strconv" "time" "github.com/google/uuid" @@ -85,7 +86,7 @@ func FormattedTime(t time.Time, f string) Generator { } } -// FileTimestamp is the default format for WithTimestampUTC and WithTimeUTC +// FileTimestampNoTZ is the default format for WithTimestampUTC and WithTimeUTC const FileTimestampNoTZ string = "2006-01-02_03-05-06" // TimestampUTC generates a date and time for the current time in UTC without a timezone in the format. @@ -97,3 +98,28 @@ func TimestampUTC() Generator { func TimeUTC(t time.Time) Generator { return FormattedTime(t.UTC(), FileTimestampNoTZ) } + +// Incremental generates a name that is a series of integers starting at 0 +func Incremental() Generator { + return IncrementalWithStartAndStep(0, 1) +} + +// IncrementalWithStart generates a name that is a series of integers starting at the specified number +func IncrementalWithStart(start int) Generator { + return IncrementalWithStartAndStep(start, 1) +} + +// IncrementalWithStep generates a name that is a series of integers, starting at 0, and increasing the specified number each time +func IncrementalWithStep(step int) Generator { + return IncrementalWithStartAndStep(0, step) +} + +// InrementalWithStartAndStep generates a name that is a series of integers, starting at the specified number, and increasing the specified step each time +func IncrementalWithStartAndStep(start, step int) Generator { + next := start + return func() (string, error) { + out := strconv.Itoa(next) + next += step + return out, nil + } +} diff --git a/generators_examples_test.go b/generators_examples_test.go index 67d5995..ad7ef4c 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -18,3 +18,75 @@ func ExampleWithGenerator_custom_generator() { // hello.txt // hello } + +func ExampleIncremental() { + conf := NewConfig(WithPrefix("foo"), WithGenerator(Incremental())) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_0.txt + // foo_1.txt + // foo_2.txt +} + +func ExampleIncrementalWithStart() { + conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStart(42))) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_42.txt + // foo_43.txt + // foo_44.txt +} + +func ExampleIncrementalWithStep() { + conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStep(2))) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_0.txt + // foo_2.txt + // foo_4.txt +} + +func ExampleIncrementalWithStartAndStep() { + conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStartAndStep(42, 2))) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_42.txt + // foo_44.txt + // foo_46.txt +} From 921020d9fde0b35fb5fde7d38d590fd2ecbadb46 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 13 Mar 2025 15:36:30 -0500 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=A7=20Pass=20Config=20to=20generat?= =?UTF-8?q?or?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_test.go | 2 +- generators.go | 14 +++++++------- generators_examples_test.go | 2 +- generators_test.go | 38 ++++++++++++++++++------------------- make.go | 2 +- make_test.go | 4 ++-- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/config_test.go b/config_test.go index aeee9b8..adc35e6 100644 --- a/config_test.go +++ b/config_test.go @@ -10,7 +10,7 @@ import ( func TestNewConf(t *testing.T) { c := NewConfig() assert.Equal(t, ".txt", c.extension) - st, _ := c.generator() + st, _ := c.generator(&c) _, parseErr := uuid.Parse(st) assert.NoError(t, parseErr) } diff --git a/generators.go b/generators.go index 7873107..41b0674 100644 --- a/generators.go +++ b/generators.go @@ -11,7 +11,7 @@ import ( // Generator is a function that returns the "random" portion of the returned filename. // Technically, it doesn't necessarily need to be random, and could be based on time, or a counter, // for example. -type Generator func() (string, error) +type Generator func(conf *Config) (string, error) // WithGenerator sets the specified generator func WithGenerator(g Generator) Option { @@ -23,7 +23,7 @@ func WithGenerator(g Generator) Option { // ErrMissingGenerators is returned by a multi-generator if no generators are supplied. var ErrMissingGenerators = errors.New("no generators supplied") -func missingGen() (string, error) { +func missingGen(*Config) (string, error) { return "", ErrMissingGenerators } @@ -39,14 +39,14 @@ func MultiGeneratorInOrder(gens ...Generator) Generator { } var idx int - return func() (string, error) { - st, err := gens[idx]() + return func(c *Config) (string, error) { + st, err := gens[idx](c) idx = (idx + 1) % len(gens) return st, err } } -func uuidGen() (string, error) { +func uuidGen(*Config) (string, error) { u, err := uuid.NewRandom() if err != nil { return "", err @@ -81,7 +81,7 @@ func Time(t time.Time) Generator { // FormattedTime generates a date and time for the supplied time with the supplied format. func FormattedTime(t time.Time, f string) Generator { - return func() (string, error) { + return func(*Config) (string, error) { return t.Format(f), nil } } @@ -117,7 +117,7 @@ func IncrementalWithStep(step int) Generator { // InrementalWithStartAndStep generates a name that is a series of integers, starting at the specified number, and increasing the specified step each time func IncrementalWithStartAndStep(start, step int) Generator { next := start - return func() (string, error) { + return func(*Config) (string, error) { out := strconv.Itoa(next) next += step return out, nil diff --git a/generators_examples_test.go b/generators_examples_test.go index ad7ef4c..c089c3f 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -3,7 +3,7 @@ package nomino import "fmt" func ExampleWithGenerator_custom_generator() { - gen := func() (string, error) { + gen := func(*Config) (string, error) { return "hello", nil } option := WithGenerator(gen) diff --git a/generators_test.go b/generators_test.go index 7282656..8af03bc 100644 --- a/generators_test.go +++ b/generators_test.go @@ -10,10 +10,10 @@ import ( ) func TestWithGenerator(t *testing.T) { - g := func() (string, error) { return "abc", nil } + g := func(*Config) (string, error) { return "abc", nil } var c Config WithGenerator(g)(&c) - st, err := c.generator() + st, err := c.generator(&c) assert.NoError(t, err) assert.Equal(t, "abc", st) } @@ -22,49 +22,49 @@ func TestMultiGeneratorInOrder(t *testing.T) { st1 := "abc" st2 := "def" er1 := errors.New("oops") - g1 := func() (string, error) { return st1, nil } - g2 := func() (string, error) { return st2, nil } - g3 := func() (string, error) { return "", er1 } + g1 := func(*Config) (string, error) { return st1, nil } + g2 := func(*Config) (string, error) { return st2, nil } + g3 := func(*Config) (string, error) { return "", er1 } g := MultiGeneratorInOrder(g1, g2, g3) - st, err := g() + st, err := g(nil) assert.NoError(t, err) assert.Equal(t, st1, st) - st, err = g() + st, err = g(nil) assert.NoError(t, err) assert.Equal(t, st2, st) - st, err = g() + st, err = g(nil) assert.Zero(t, st) assert.ErrorIs(t, err, er1) - st, err = g() + st, err = g(nil) assert.NoError(t, err) assert.Equal(t, st1, st) } func TestMultiGeneratorInOrderOne(t *testing.T) { st1 := "abc" - g1 := func() (string, error) { return st1, nil } + g1 := func(*Config) (string, error) { return st1, nil } g := MultiGeneratorInOrder(g1) - st, err := g() + st, err := g(nil) assert.NoError(t, err) assert.Equal(t, st1, st) - st, err = g() + st, err = g(nil) assert.NoError(t, err) assert.Equal(t, st1, st) } func TestMultiGeneratorInOrderMissing(t *testing.T) { g := MultiGeneratorInOrder() - st, err := g() + st, err := g(nil) assert.Zero(t, st) assert.ErrorIs(t, err, ErrMissingGenerators) - st, err = g() + st, err = g(nil) assert.Zero(t, st) assert.ErrorIs(t, err, ErrMissingGenerators) } func TestUUID(t *testing.T) { - st, err := UUID()() + st, err := UUID()(nil) assert.NoError(t, err) _, parseErr := uuid.Parse(st) assert.NoError(t, parseErr) @@ -80,13 +80,13 @@ func TestUUIDFail(t *testing.T) { uuid.SetRand(badRead{}) defer uuid.SetRand(nil) - _, err := UUID()() + _, err := UUID()(nil) assert.Equal(t, errors.New("sorry"), err) } func TestTimestamp(t *testing.T) { n := time.Now() - st, err := Timestamp()() + st, err := Timestamp()(nil) assert.NoError(t, err) assert.Equal(t, n.Format(FileTimestamp), st) } @@ -94,14 +94,14 @@ func TestTimestamp(t *testing.T) { func TestTime(t *testing.T) { d := time.Date(1986, time.March, 28, 12, 0, 0, 0, time.UTC) - st, err := Time(d)() + st, err := Time(d)(nil) assert.NoError(t, err) assert.Equal(t, d.Format(FileTimestamp), st) } func TestTimestampUTC(t *testing.T) { n := time.Now() - st, err := TimestampUTC()() + st, err := TimestampUTC()(nil) assert.NoError(t, err) assert.Equal(t, n.UTC().Format(FileTimestampNoTZ), st) } diff --git a/make.go b/make.go index 3d15b4a..c2c222c 100644 --- a/make.go +++ b/make.go @@ -6,7 +6,7 @@ import "fmt" // In general, the final filename will be [prefix]_[generated_string]_[original_filename]_[suffix].[extension]. // If the name generator returns an error (generally, it shouldn't), that will be returned instead. func Make(conf Config) (string, error) { - name, err := conf.generator() + name, err := conf.generator(&conf) if err != nil { return "", err } diff --git a/make_test.go b/make_test.go index dffc981..8d98d45 100644 --- a/make_test.go +++ b/make_test.go @@ -8,7 +8,7 @@ import ( ) func TestMake(t *testing.T) { - genOpt := WithGenerator(func() (string, error) { return "abc", nil }) + genOpt := WithGenerator(func(*Config) (string, error) { return "abc", nil }) testcases := []struct { name string opts []Option @@ -47,7 +47,7 @@ func TestMake(t *testing.T) { func TestMakeErr(t *testing.T) { retErr := errors.New("oops") - conf := NewConfig(WithGenerator(func() (string, error) { return "foobar", retErr })) + conf := NewConfig(WithGenerator(func(*Config) (string, error) { return "foobar", retErr })) st, err := Make(conf) assert.Zero(t, st) assert.ErrorIs(t, err, retErr) From 1d235af8765ac500e735179334630976b599147d Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 13 Mar 2025 16:58:55 -0500 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20Add=20Slug=20Generator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators.go | 31 +++++++++++++++++++++++++++++++ generators_examples_test.go | 16 ++++++++++++++++ generators_test.go | 15 +++++++++++++++ go.mod | 2 ++ go.sum | 4 ++++ make_test.go | 12 ++++++++++++ options.go | 22 +++++++++++++++++++++- options_examples_test.go | 23 +++++++++++++++++++++++ 8 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 options_examples_test.go diff --git a/generators.go b/generators.go index 41b0674..e258716 100644 --- a/generators.go +++ b/generators.go @@ -6,6 +6,7 @@ import ( "time" "github.com/google/uuid" + "github.com/gosimple/slug" ) // Generator is a function that returns the "random" portion of the returned filename. @@ -123,3 +124,33 @@ func IncrementalWithStartAndStep(start, step int) Generator { return out, nil } } + +// ErrMissingOriginal is the error returned by Slug if there is no filename +var ErrMissingOriginal = errors.New("missing original filename") + +func getOriginal(c *Config) (string, error) { + if c.original == "" { + return "", ErrMissingOriginal + } + name := c.original + c.original = "" + return name, nil +} + +// Slug generates a name from the original filename. +// When this is used, the original filename will be removed from the final filename. +func Slug() Generator { + return func(c *Config) (string, error) { + name, err := getOriginal(c) + return slug.Make(name), err + } +} + +// SlugWithLang generates a name from the original filename, accounting for the given language. +// When this is used, the original filename will be removed from the final filename. +func SlugWithLang(lang string) Generator { + return func(c *Config) (string, error) { + name, err := getOriginal(c) + return slug.MakeLang(name, lang), err + } +} diff --git a/generators_examples_test.go b/generators_examples_test.go index c089c3f..bb9b4a8 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -90,3 +90,19 @@ func ExampleIncrementalWithStartAndStep() { // foo_44.txt // foo_46.txt } + +func ExampleSlug() { + conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy")) + str, _ := Make(conf) + fmt.Println(str) + + // Output: my-name-is-jimmy.txt +} + +func ExampleSlugWithLang() { + conf := NewConfig(WithGenerator(SlugWithLang("de")), WithOriginal("Diese & Dass")) + str, _ := Make(conf) + fmt.Println(str) + + // Output: diese-und-dass.txt +} diff --git a/generators_test.go b/generators_test.go index 8af03bc..fb28ce7 100644 --- a/generators_test.go +++ b/generators_test.go @@ -105,3 +105,18 @@ func TestTimestampUTC(t *testing.T) { assert.NoError(t, err) assert.Equal(t, n.UTC().Format(FileTimestampNoTZ), st) } + +func TestSlugMissingFilename(t *testing.T) { + conf := NewConfig(WithGenerator(Slug())) + st, err := conf.generator(&conf) + assert.Zero(t, st) + assert.ErrorIs(t, err, ErrMissingOriginal) +} + +func TestSlugRemovesOriginal(t *testing.T) { + conf := NewConfig(WithGenerator(Slug()), WithOriginal("Hello, World")) + st, err := conf.generator(&conf) + assert.Zero(t, conf.original) + assert.Equal(t, "hello-world", st) + assert.NoError(t, err) +} diff --git a/go.mod b/go.mod index de6af60..6917d49 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,13 @@ go 1.23.6 require ( github.com/google/uuid v1.6.0 + github.com/gosimple/slug v1.15.0 github.com/stretchr/testify v1.10.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gosimple/unidecode v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 14c872b..8638c59 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo= +github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ= +github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o= +github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= diff --git a/make_test.go b/make_test.go index 8d98d45..28096ce 100644 --- a/make_test.go +++ b/make_test.go @@ -52,3 +52,15 @@ func TestMakeErr(t *testing.T) { assert.Zero(t, st) assert.ErrorIs(t, err, retErr) } + +func TestMakeDoesntChangeConf(t *testing.T) { + gen := func(c *Config) (string, error) { + c.original = "" + return "foo", nil + } + conf := NewConfig(WithGenerator(gen), WithOriginal("foobar")) + st, err := Make(conf) + assert.Equal(t, "foobar", conf.original) + assert.Equal(t, "foo.txt", st) + assert.NoError(t, err) +} diff --git a/options.go b/options.go index b51b756..c7e0338 100644 --- a/options.go +++ b/options.go @@ -1,6 +1,10 @@ package nomino -import "strings" +import ( + "strings" + + "github.com/gosimple/slug" +) // Option sets configuration parameters for Config. type Option func(c *Config) @@ -13,6 +17,22 @@ func WithOriginal(o string) Option { } } +// WithOriginal sets the original filename as a slug. +// This should not be used with the Slug Generator (as it would be redundant) +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) +func WithOriginalSlugLang(o, lang string) Option { + return func(c *Config) { + c.original = slug.MakeLang(o, lang) + } +} + // WithPrefix sets a prefix for the generated name. func WithPrefix(p string) Option { return func(c *Config) { diff --git a/options_examples_test.go b/options_examples_test.go new file mode 100644 index 0000000..0c4e669 --- /dev/null +++ b/options_examples_test.go @@ -0,0 +1,23 @@ +package nomino + +import "fmt" + +func ExampleWithOriginalSlug() { + st, _ := Make(NewConfig( + WithOriginalSlug("Hello, World"), + WithGenerator(Incremental()), + )) + + fmt.Println(st) + // Output: 0_hello-world.txt +} + +func ExampleWithOriginalSlugLang() { + st, _ := Make(NewConfig( + WithOriginalSlugLang("Diese & Dass", "de"), + WithGenerator(Incremental()), + )) + + fmt.Println(st) + // Output: 0_diese-und-dass.txt +} From 9d8737079fe754bcae74f88d3f09710e15d3043b Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 11:19:20 -0500 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20Add=20IncrementalStep*=20Genera?= =?UTF-8?q?tors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators.go | 37 +++++++++++++++++++++++-- generators_examples_test.go | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/generators.go b/generators.go index e258716..4b98284 100644 --- a/generators.go +++ b/generators.go @@ -2,6 +2,7 @@ package nomino import ( "errors" + "fmt" "strconv" "time" @@ -105,26 +106,56 @@ func Incremental() Generator { return IncrementalWithStartAndStep(0, 1) } +// IncrementalFormat generates a name that is a series of integers starting at 0, formatted with Printf +// This is mostly likely useful with a format like "%02d" +func IncrementalFormat(format string) Generator { + return IncrementalFormatWithStartAndStep(0, 1, format) +} + // IncrementalWithStart generates a name that is a series of integers starting at the specified number func IncrementalWithStart(start int) Generator { return IncrementalWithStartAndStep(start, 1) } +// IncrementalFormatWithStart generates a name that is a series of integers starting at the specified number, formatted with Printf +func IncrementalFormatWithStart(start int, format string) Generator { + return IncrementalFormatWithStartAndStep(start, 1, format) +} + // IncrementalWithStep generates a name that is a series of integers, starting at 0, and increasing the specified number each time func IncrementalWithStep(step int) Generator { return IncrementalWithStartAndStep(0, step) } -// InrementalWithStartAndStep generates a name that is a series of integers, starting at the specified number, and increasing the specified step each time -func IncrementalWithStartAndStep(start, step int) Generator { +// IncrementalFormatWithStep generates a name that is a series of integers, starting at 0, and increasing the specified number each time, +// formatted with Printf +func IncrementalFormatWithStep(step int, format string) Generator { + return IncrementalFormatWithStartAndStep(0, step, format) +} + +func incrementalHelper(start, step int, cb func(int) string) Generator { next := start return func(*Config) (string, error) { - out := strconv.Itoa(next) + out := cb(next) next += step return out, nil } } +// InrementalWithStartAndStep generates a name that is a series of integers, starting at the specified number, +// and increasing the specified step each time +func IncrementalWithStartAndStep(start, step int) Generator { + return incrementalHelper(start, step, strconv.Itoa) +} + +// IncrementalFormatWithStartAndStep generates a name that is a series of integers, starting at the specified number, +// and increasing the specified step each time, formatted with Printf +func IncrementalFormatWithStartAndStep(start, step int, format string) Generator { + return incrementalHelper(start, step, func(i int) string { + return fmt.Sprintf(format, i) + }) +} + // ErrMissingOriginal is the error returned by Slug if there is no filename var ErrMissingOriginal = errors.New("missing original filename") diff --git a/generators_examples_test.go b/generators_examples_test.go index bb9b4a8..0275877 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -91,6 +91,61 @@ func ExampleIncrementalWithStartAndStep() { // foo_46.txt } +func ExampleIncrementalFormat() { + conf := NewConfig( + WithPrefix("foo"), + WithGenerator(IncrementalFormat("%03d")), + ) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_000.txt + // foo_001.txt + // foo_002.txt +} + +func ExampleIncrementalFormatWithStart() { + conf := NewConfig( + WithPrefix("foo"), + WithGenerator(IncrementalFormatWithStart(9, "%02d")), + ) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_09.txt + // foo_10.txt +} + +func ExampleIncrementalFormatWithStep() { + conf := NewConfig( + WithPrefix("foo"), + WithGenerator(IncrementalFormatWithStep(10, "%02d")), + ) + + str, _ := Make(conf) + fmt.Println(str) + + str, _ = Make(conf) + fmt.Println(str) + + // Output: + // foo_00.txt + // foo_10.txt +} + func ExampleSlug() { conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy")) str, _ := Make(conf) From 439fe482302e1ad8ee580c3dfbfbf80b6bac59a5 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 11:25:35 -0500 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9D=20Update=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80e3768..e1d7c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +### [0.2.0] - 2025-03-14 + +- Add `IncrementalFormat`* Generators +- Add `Slug`* Generators +- Add `WithOriginalSlug`* Options +- Change signature of `Generator` function + +Note that this last change **is** a breaking change from 0.0.3, but only for custom Generators. + ## [0.0.3] - 2025-03-11 ### Features