From 61a51996992facd1f115bff535f8d101a7a8a35b Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 17:39:42 -0500 Subject: [PATCH 1/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20Timestamp?= =?UTF-8?q?=20Generator=20to=20single=20function=20with=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen_ts.go | 59 +++++++++++++++++++++++++++++++++++++++++ gen_ts_examples_test.go | 38 ++++++++++++++++++++++++++ gen_ts_test.go | 15 +++++++++++ generators.go | 42 ----------------------------- generators_test.go | 26 +----------------- 5 files changed, 113 insertions(+), 67 deletions(-) create mode 100644 gen_ts.go create mode 100644 gen_ts_examples_test.go create mode 100644 gen_ts_test.go diff --git a/gen_ts.go b/gen_ts.go new file mode 100644 index 0000000..4d0e13d --- /dev/null +++ b/gen_ts.go @@ -0,0 +1,59 @@ +package nomino + +import "time" + +// FileTimestamp is the default format for WithTimestamp and WithTime +const FileTimestamp string = "2006-01-02T15-04-05-0700" + +// FileTimestampNoTZ is the default format for WithTimestampUTC and WithTimeUTC +const FileTimestampNoTZ string = "2006-01-02T15-04-05" + +type timestampConf struct { + format string + ts time.Time + utc bool +} + +// TimestampOption provides options for the Timestamp Generator +type TimestampOption func(c *timestampConf) + +// Timestamp generates a a date and time. By default, it uses the current time, and will. +// be formatted accourding to FileTimestamp +func Timestamp(opts ...TimestampOption) Generator { + c := timestampConf{format: FileTimestamp, ts: time.Now()} + for _, opt := range opts { + opt(&c) + } + + if c.utc { + c.ts = c.ts.UTC() + } + + return func(*Config) (string, error) { + return c.ts.Format(c.format), nil + } +} + +// TSFormat sets the format for the generated name. +// Consult time.Time.Format for details on the format. +func TSFormat(format string) TimestampOption { + return func(c *timestampConf) { + c.format = format + } +} + +// TSTime sets the time for the generated name. +// By default, it uses the current time. +func TSTime(t time.Time) TimestampOption { + return func(c *timestampConf) { + c.ts = t + } +} + +// TSUTC uses the time in UTC, while also stripping the timezone from the format. +func TSUTC() TimestampOption { + return func(c *timestampConf) { + c.utc = true + c.format = FileTimestampNoTZ + } +} diff --git a/gen_ts_examples_test.go b/gen_ts_examples_test.go new file mode 100644 index 0000000..0dcc0b6 --- /dev/null +++ b/gen_ts_examples_test.go @@ -0,0 +1,38 @@ +package nomino_test + +import ( + "fmt" + "time" + + "codeberg.org/danjones000/nomino" +) + +func ExampleTimestamp_withTime() { + tz, _ := time.LoadLocation("America/New_York") + ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) + gen := nomino.Timestamp(nomino.TSTime(ts)) + conf := nomino.NewConfig(nomino.WithGenerator(gen)) + s, _ := nomino.Make(conf) + fmt.Println(s) + // Output: 2009-01-20T12-05-00-0500.txt +} + +func ExampleTimestamp_withFormat() { + tz, _ := time.LoadLocation("America/New_York") + ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) + gen := nomino.Timestamp(nomino.TSTime(ts), nomino.TSFormat("2006#01#02<>15|04|05-0700")) + conf := nomino.NewConfig(nomino.WithGenerator(gen)) + s, _ := nomino.Make(conf) + fmt.Println(s) + // Output: 2009#01#20<>12|05|00-0500.txt +} + +func ExampleTimestamp_withUTC() { + tz, _ := time.LoadLocation("America/New_York") + ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) + gen := nomino.Timestamp(nomino.TSTime(ts), nomino.TSUTC()) + conf := nomino.NewConfig(nomino.WithGenerator(gen)) + s, _ := nomino.Make(conf) + fmt.Println(s) + // Output: 2009-01-20T17-05-00.txt +} diff --git a/gen_ts_test.go b/gen_ts_test.go new file mode 100644 index 0000000..2997702 --- /dev/null +++ b/gen_ts_test.go @@ -0,0 +1,15 @@ +package nomino + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestTimestamp(t *testing.T) { + n := time.Now() + st, err := Timestamp()(nil) + assert.NoError(t, err) + assert.Equal(t, n.Format(FileTimestamp), st) +} diff --git a/generators.go b/generators.go index 8685662..a1b2b52 100644 --- a/generators.go +++ b/generators.go @@ -8,7 +8,6 @@ import ( "fmt" "hash" "strconv" - "time" "github.com/google/uuid" "github.com/gosimple/slug" @@ -65,46 +64,6 @@ func UUID() Generator { return uuidGen } -// FileTimestamp is the default format for WithTimestamp and WithTime -const FileTimestamp string = "2006-01-02_03-05-06-0700" - -// Timestamp generates a a date and time for the current time. -// It is formatted accourding to FileTimestamp -func Timestamp() Generator { - return TimestampWithFormat(FileTimestamp) -} - -// TimestampWithFormat generates a date and time for the current time with the supplied format. -func TimestampWithFormat(f string) Generator { - return FormattedTime(time.Now(), FileTimestamp) -} - -// Time generates a date and time for the supplied time. -// It is formatted accourding to FileTimestamp -func Time(t time.Time) Generator { - return FormattedTime(t, FileTimestamp) -} - -// FormattedTime generates a date and time for the supplied time with the supplied format. -func FormattedTime(t time.Time, f string) Generator { - return func(*Config) (string, error) { - return t.Format(f), nil - } -} - -// 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. -func TimestampUTC() Generator { - return TimeUTC(time.Now()) -} - -// TimeUTC generates a date and time for the supplied time in UTC without a timezone in the format. -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) @@ -136,7 +95,6 @@ func IncrementalWithStep(step int) Generator { 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) { diff --git a/generators_test.go b/generators_test.go index c6b3bbe..330b169 100644 --- a/generators_test.go +++ b/generators_test.go @@ -2,9 +2,7 @@ package nomino import ( "errors" - "fmt" "testing" - "time" "github.com/google/uuid" "github.com/stretchr/testify/assert" @@ -85,28 +83,6 @@ func TestUUIDFail(t *testing.T) { assert.Equal(t, errors.New("sorry"), err) } -func TestTimestamp(t *testing.T) { - n := time.Now() - st, err := Timestamp()(nil) - assert.NoError(t, err) - assert.Equal(t, n.Format(FileTimestamp), st) -} - -func TestTime(t *testing.T) { - d := time.Date(1986, time.March, 28, 12, 0, 0, 0, time.UTC) - - 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()(nil) - 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) @@ -138,6 +114,6 @@ func TestHashMissingOriginal(t *testing.T) { } func TestHashTypeStringer(t *testing.T) { - s := fmt.Sprintf("%s", MD5) + s := MD5.String() assert.Equal(t, "MD5", s) } From 63d538d889fc8bfd65466c51b8db82e1f3b85ba3 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 18:09:07 -0500 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20TS*=20to=20Timestam?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen_ts.go | 12 ++++++------ gen_ts_examples_test.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gen_ts.go b/gen_ts.go index 4d0e13d..abb4181 100644 --- a/gen_ts.go +++ b/gen_ts.go @@ -34,24 +34,24 @@ func Timestamp(opts ...TimestampOption) Generator { } } -// TSFormat sets the format for the generated name. +// TimestampFormat sets the format for the generated name. // Consult time.Time.Format for details on the format. -func TSFormat(format string) TimestampOption { +func TimestampFormat(format string) TimestampOption { return func(c *timestampConf) { c.format = format } } -// TSTime sets the time for the generated name. +// TimestampTime sets the time for the generated name. // By default, it uses the current time. -func TSTime(t time.Time) TimestampOption { +func TimestampTime(t time.Time) TimestampOption { return func(c *timestampConf) { c.ts = t } } -// TSUTC uses the time in UTC, while also stripping the timezone from the format. -func TSUTC() TimestampOption { +// TimestampUTC uses the time in UTC, while also stripping the timezone from the format. +func TimestampUTC() TimestampOption { return func(c *timestampConf) { c.utc = true c.format = FileTimestampNoTZ diff --git a/gen_ts_examples_test.go b/gen_ts_examples_test.go index 0dcc0b6..527728d 100644 --- a/gen_ts_examples_test.go +++ b/gen_ts_examples_test.go @@ -10,7 +10,7 @@ import ( func ExampleTimestamp_withTime() { tz, _ := time.LoadLocation("America/New_York") ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) - gen := nomino.Timestamp(nomino.TSTime(ts)) + gen := nomino.Timestamp(nomino.TimestampTime(ts)) conf := nomino.NewConfig(nomino.WithGenerator(gen)) s, _ := nomino.Make(conf) fmt.Println(s) @@ -20,7 +20,7 @@ func ExampleTimestamp_withTime() { func ExampleTimestamp_withFormat() { tz, _ := time.LoadLocation("America/New_York") ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) - gen := nomino.Timestamp(nomino.TSTime(ts), nomino.TSFormat("2006#01#02<>15|04|05-0700")) + gen := nomino.Timestamp(nomino.TimestampTime(ts), nomino.TimestampFormat("2006#01#02<>15|04|05-0700")) conf := nomino.NewConfig(nomino.WithGenerator(gen)) s, _ := nomino.Make(conf) fmt.Println(s) @@ -30,7 +30,7 @@ func ExampleTimestamp_withFormat() { func ExampleTimestamp_withUTC() { tz, _ := time.LoadLocation("America/New_York") ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) - gen := nomino.Timestamp(nomino.TSTime(ts), nomino.TSUTC()) + gen := nomino.Timestamp(nomino.TimestampTime(ts), nomino.TimestampUTC()) conf := nomino.NewConfig(nomino.WithGenerator(gen)) s, _ := nomino.Make(conf) fmt.Println(s) From 586fe4f1deee3de760c61841b714dd7880380bc0 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 18:33:30 -0500 Subject: [PATCH 3/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20Incremental?= =?UTF-8?q?=20Generator=20to=20single=20function=20with=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen_int.go | 55 ++++++++++++++++ gen_int_examples_test.go | 121 ++++++++++++++++++++++++++++++++++ generators.go | 55 ---------------- generators_examples_test.go | 127 ------------------------------------ 4 files changed, 176 insertions(+), 182 deletions(-) create mode 100644 gen_int.go create mode 100644 gen_int_examples_test.go diff --git a/gen_int.go b/gen_int.go new file mode 100644 index 0000000..aeb6076 --- /dev/null +++ b/gen_int.go @@ -0,0 +1,55 @@ +package nomino + +import ( + "fmt" + "strconv" +) + +type incConf struct { + start int + step int + cb func(int) string +} + +// IncrementalOption sets an option for the Incremental Generator +type IncrementalOption func(c *incConf) + +// Incremental generates a name that is a series of integers. +// By default it begins at 0 and increments by 1 each time. +func Incremental(opts ...IncrementalOption) Generator { + c := incConf{step: 1, cb: strconv.Itoa} + for _, opt := range opts { + opt(&c) + } + + next := c.start + return func(*Config) (string, error) { + out := c.cb(next) + next += c.step + return out, nil + } +} + +// IncrementalStart sets the starting integer for Incremental +func IncrementalStart(start int) IncrementalOption { + return func(c *incConf) { + c.start = start + } +} + +// IncrementalStepsets the step by which Incremental increases with each invocation. +func IncrementalStep(step int) IncrementalOption { + return func(c *incConf) { + c.step = step + } +} + +// IncrementalFormatsets the format for the number generated by Incremental. +// It will be formatted with Printf. This is mostly likely useful with a format like "%02d" +func IncrementalFormat(format string) IncrementalOption { + return func(c *incConf) { + c.cb = func(i int) string { + return fmt.Sprintf(format, i) + } + } +} diff --git a/gen_int_examples_test.go b/gen_int_examples_test.go new file mode 100644 index 0000000..f3e61c7 --- /dev/null +++ b/gen_int_examples_test.go @@ -0,0 +1,121 @@ +package nomino_test + +import ( + "fmt" + + "codeberg.org/danjones000/nomino" +) + +func ExampleIncremental() { + conf := nomino.NewConfig( + nomino.WithPrefix("foo"), + nomino.WithGenerator(nomino.Incremental()), + ) + + str, _ := nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + // Output: + // foo_0.txt + // foo_1.txt + // foo_2.txt +} + +func ExampleIncrementalStart() { + conf := nomino.NewConfig( + nomino.WithPrefix("foo"), + nomino.WithGenerator(nomino.Incremental( + nomino.IncrementalStart(42), + )), + ) + + str, _ := nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + // Output: + // foo_42.txt + // foo_43.txt + // foo_44.txt +} + +func ExampleIncrementalStep() { + conf := nomino.NewConfig( + nomino.WithPrefix("foo"), + nomino.WithGenerator(nomino.Incremental( + nomino.IncrementalStep(2), + )), + ) + + str, _ := nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + // Output: + // foo_0.txt + // foo_2.txt + // foo_4.txt +} + +func ExampleIncremental_withStartAndStep() { + conf := nomino.NewConfig( + nomino.WithPrefix("foo"), + nomino.WithGenerator(nomino.Incremental( + nomino.IncrementalStart(42), + nomino.IncrementalStep(2), + )), + ) + + str, _ := nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + // Output: + // foo_42.txt + // foo_44.txt + // foo_46.txt +} + +func ExampleIncrementalFormat() { + conf := nomino.NewConfig( + nomino.WithPrefix("foo"), + nomino.WithGenerator(nomino.Incremental( + nomino.IncrementalFormat("%03d"), + )), + ) + + str, _ := nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + str, _ = nomino.Make(conf) + fmt.Println(str) + + // Output: + // foo_000.txt + // foo_001.txt + // foo_002.txt +} diff --git a/generators.go b/generators.go index a1b2b52..2a12236 100644 --- a/generators.go +++ b/generators.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "hash" - "strconv" "github.com/google/uuid" "github.com/gosimple/slug" @@ -64,60 +63,6 @@ func UUID() Generator { return uuidGen } -// Incremental generates a name that is a series of integers starting at 0 -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) -} - -// 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 := 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 11cfae2..85563f9 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -19,133 +19,6 @@ func ExampleWithGenerator_custom_generator() { // 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 -} - -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 1d0f2238b3a9e8ea99afbefe12039dbc8deac814 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 19:50:24 -0500 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=9A=9A=20Move=20Slug/Hash=20Generator?= =?UTF-8?q?s=20to=20own=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen_file.go | 81 +++++++++++++++++++++++++++++++++++++ gen_file_examples_test.go | 66 ++++++++++++++++++++++++++++++ gen_file_test.go | 42 +++++++++++++++++++ generators.go | 77 ----------------------------------- generators_examples_test.go | 46 --------------------- generators_test.go | 35 ---------------- hashtype_string.go | 8 ++-- 7 files changed, 193 insertions(+), 162 deletions(-) create mode 100644 gen_file.go create mode 100644 gen_file_examples_test.go create mode 100644 gen_file_test.go diff --git a/gen_file.go b/gen_file.go new file mode 100644 index 0000000..ef239cb --- /dev/null +++ b/gen_file.go @@ -0,0 +1,81 @@ +package nomino + +import ( + "crypto/md5" + "crypto/sha1" + "crypto/sha256" + "errors" + "fmt" + "hash" + + "github.com/gosimple/slug" +) + +// 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. +// If a language is specified, that may affect the resulting slug. +func Slug(lang ...string) Generator { + ret := slug.Make + if len(lang) > 0 { + ret = func(in string) string { + return slug.MakeLang(in, lang[0]) + } + } + return func(c *Config) (string, error) { + name, err := getOriginal(c) + return ret(name), err + } +} + +// HashingFunc is a function that generates a hash.Hash +type HashingFunc func() hash.Hash + +//go:generate stringer -type=HashType -trimprefix=Hash + +// HashType represents a particular hashing algorithm +type HashType uint8 + +const ( + HashMD5 HashType = iota + 1 + HashSHA1 + HashSHA256 +) + +// ErrInvalidHashType is returned by the Hash generator when an invalid HashType is passed +var ErrInvalidHashType = errors.New("invalid hash type") + +var hashMap = map[HashType]HashingFunc{ + HashMD5: md5.New, + HashSHA1: sha1.New, + HashSHA256: sha256.New, +} + +// Hash generates a name from a hash of the filename. +// When this is used, the original filename will be removed from the final filename. +func Hash(t HashType) Generator { + f, ok := hashMap[t] + return func(c *Config) (string, error) { + if !ok { + return "", fmt.Errorf("%w: %s", ErrInvalidHashType, t) + } + name, err := getOriginal(c) + if err != nil { + return "", err + } + hs := f() + hs.Write([]byte(name)) + return fmt.Sprintf("%x", hs.Sum(nil)), nil + } +} diff --git a/gen_file_examples_test.go b/gen_file_examples_test.go new file mode 100644 index 0000000..3d8036f --- /dev/null +++ b/gen_file_examples_test.go @@ -0,0 +1,66 @@ +package nomino_test + +import ( + "fmt" + + "codeberg.org/danjones000/nomino" +) + +func ExampleSlug() { + conf := nomino.NewConfig( + nomino.WithOriginal("My name is Jimmy"), + nomino.WithGenerator(nomino.Slug()), + ) + str, _ := nomino.Make(conf) + fmt.Println(str) + + // Output: my-name-is-jimmy.txt +} + +func ExampleSlug_withLang() { + conf := nomino.NewConfig( + nomino.WithOriginal("Diese & Dass"), + nomino.WithGenerator(nomino.Slug("de")), + ) + + str, _ := nomino.Make(conf) + fmt.Println(str) + + // Output: diese-und-dass.txt +} + +func ExampleHash_mD5() { + conf := nomino.NewConfig( + nomino.WithOriginal("foobar"), + nomino.WithGenerator( + nomino.Hash(nomino.HashMD5), + ), + ) + str, _ := nomino.Make(conf) + fmt.Println(str) + // Output: 3858f62230ac3c915f300c664312c63f.txt +} + +func ExampleHash_sHA1() { + conf := nomino.NewConfig( + nomino.WithOriginal("foobar"), + nomino.WithGenerator( + nomino.Hash(nomino.HashSHA1), + ), + ) + str, _ := nomino.Make(conf) + fmt.Println(str) + // Output: 8843d7f92416211de9ebb963ff4ce28125932878.txt +} + +func ExampleHash_sHA256() { + conf := nomino.NewConfig( + nomino.WithOriginal("foobar"), + nomino.WithGenerator( + nomino.Hash(nomino.HashSHA256), + ), + ) + str, _ := nomino.Make(conf) + fmt.Println(str) + // Output: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.txt +} diff --git a/gen_file_test.go b/gen_file_test.go new file mode 100644 index 0000000..0d03d16 --- /dev/null +++ b/gen_file_test.go @@ -0,0 +1,42 @@ +package nomino + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +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) +} + +func TestHashBadHash(t *testing.T) { + conf := NewConfig(WithOriginal("foobar"), WithGenerator(Hash(0))) + st, err := conf.generator(&conf) + assert.Equal(t, "", st) + assert.ErrorIs(t, err, ErrInvalidHashType) + assert.ErrorContains(t, err, "invalid hash type: HashType(0)") +} + +func TestHashMissingOriginal(t *testing.T) { + conf := NewConfig(WithGenerator(Hash(HashMD5))) + st, err := conf.generator(&conf) + assert.Equal(t, "", st) + assert.ErrorIs(t, err, ErrMissingOriginal) +} + +func TestHashTypeStringer(t *testing.T) { + s := HashMD5.String() + assert.Equal(t, "MD5", s) +} diff --git a/generators.go b/generators.go index 2a12236..25cd36e 100644 --- a/generators.go +++ b/generators.go @@ -1,15 +1,9 @@ package nomino import ( - "crypto/md5" - "crypto/sha1" - "crypto/sha256" "errors" - "fmt" - "hash" "github.com/google/uuid" - "github.com/gosimple/slug" ) // Generator is a function that returns the "random" portion of the returned filename. @@ -62,74 +56,3 @@ func uuidGen(*Config) (string, error) { func UUID() Generator { return uuidGen } - -// 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 - } -} - -// HashingFunc is a function that generates a hash.Hash -type HashingFunc func() hash.Hash - -//go:generate stringer -type=HashType - -// HashType represents a particular hashing algorithm -type HashType uint8 - -const ( - MD5 HashType = iota + 1 - SHA1 - SHA256 -) - -// ErrInvalidHashType is returned by the Hash generator when an invalid HashType is passed -var ErrInvalidHashType = errors.New("invalid hash type") - -var hashMap = map[HashType]HashingFunc{ - MD5: md5.New, - SHA1: sha1.New, - SHA256: sha256.New, -} - -// Hash generates a name from a hash of the filename. -// When this is used, the original filename will be removed from the final filename. -func Hash(t HashType) Generator { - f, ok := hashMap[t] - return func(c *Config) (string, error) { - if !ok { - return "", fmt.Errorf("%w: %s", ErrInvalidHashType, t) - } - name, err := getOriginal(c) - if err != nil { - return "", err - } - hs := f() - hs.Write([]byte(name)) - return fmt.Sprintf("%x", hs.Sum(nil)), nil - } -} diff --git a/generators_examples_test.go b/generators_examples_test.go index 85563f9..d46ebef 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -18,49 +18,3 @@ func ExampleWithGenerator_custom_generator() { // hello.txt // hello } - -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 -} - -func ExampleHash_mD5() { - conf := NewConfig( - WithOriginal("foobar"), - WithGenerator(Hash(MD5)), - ) - str, _ := Make(conf) - fmt.Println(str) - // Output: 3858f62230ac3c915f300c664312c63f.txt -} - -func ExampleHash_sHA1() { - conf := NewConfig( - WithOriginal("foobar"), - WithGenerator(Hash(SHA1)), - ) - str, _ := Make(conf) - fmt.Println(str) - // Output: 8843d7f92416211de9ebb963ff4ce28125932878.txt -} - -func ExampleHash_sHA256() { - conf := NewConfig( - WithOriginal("foobar"), - WithGenerator(Hash(SHA256)), - ) - str, _ := Make(conf) - fmt.Println(str) - // Output: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.txt -} diff --git a/generators_test.go b/generators_test.go index 330b169..7886ded 100644 --- a/generators_test.go +++ b/generators_test.go @@ -82,38 +82,3 @@ func TestUUIDFail(t *testing.T) { _, err := UUID()(nil) assert.Equal(t, errors.New("sorry"), err) } - -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) -} - -func TestHashBadHash(t *testing.T) { - conf := NewConfig(WithOriginal("foobar"), WithGenerator(Hash(0))) - st, err := conf.generator(&conf) - assert.Equal(t, "", st) - assert.ErrorIs(t, err, ErrInvalidHashType) - assert.ErrorContains(t, err, "invalid hash type: HashType(0)") -} - -func TestHashMissingOriginal(t *testing.T) { - conf := NewConfig(WithGenerator(Hash(MD5))) - st, err := conf.generator(&conf) - assert.Equal(t, "", st) - assert.ErrorIs(t, err, ErrMissingOriginal) -} - -func TestHashTypeStringer(t *testing.T) { - s := MD5.String() - assert.Equal(t, "MD5", s) -} diff --git a/hashtype_string.go b/hashtype_string.go index 16aa752..a4ce423 100644 --- a/hashtype_string.go +++ b/hashtype_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=HashType"; DO NOT EDIT. +// Code generated by "stringer -type=HashType -trimprefix=Hash"; DO NOT EDIT. package nomino @@ -8,9 +8,9 @@ func _() { // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. var x [1]struct{} - _ = x[MD5-1] - _ = x[SHA1-2] - _ = x[SHA256-3] + _ = x[HashMD5-1] + _ = x[HashSHA1-2] + _ = x[HashSHA256-3] } const _HashType_name = "MD5SHA1SHA256" From bd448eb5db729217771cf2867fb8e53610d01289 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 20:12:22 -0500 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=9A=9A=20Move=20remaining=20examples?= =?UTF-8?q?=20to=20nomino=5Ftest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators_examples_test.go | 21 ++++++++++++++------- make_examples_test.go | 10 +++++++--- options_examples_test.go | 20 ++++++++++++-------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/generators_examples_test.go b/generators_examples_test.go index d46ebef..3e63db3 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -1,17 +1,24 @@ -package nomino +package nomino_test -import "fmt" +import ( + "fmt" -func ExampleWithGenerator_custom_generator() { - gen := func(*Config) (string, error) { + "codeberg.org/danjones000/nomino" +) + +func ExampleWithGenerator_customGenerator() { + gen := func(*nomino.Config) (string, error) { return "hello", nil } - option := WithGenerator(gen) + option := nomino.WithGenerator(gen) - str, _ := Make(NewConfig(option)) + str, _ := nomino.Make(nomino.NewConfig(option)) fmt.Println(str) - str, _ = Make(NewConfig(option, WithoutExtension())) + str, _ = nomino.Make(nomino.NewConfig( + option, + nomino.WithoutExtension(), + )) fmt.Println(str) // Output: diff --git a/make_examples_test.go b/make_examples_test.go index 07c85ba..be09fc5 100644 --- a/make_examples_test.go +++ b/make_examples_test.go @@ -1,9 +1,13 @@ -package nomino +package nomino_test -import "fmt" +import ( + "fmt" + + "codeberg.org/danjones000/nomino" +) func ExampleMake_basic() { // Use default config - out, _ := Make(NewConfig()) + out, _ := nomino.Make(nomino.NewConfig()) fmt.Println(out) } diff --git a/options_examples_test.go b/options_examples_test.go index 0c4e669..b60171f 100644 --- a/options_examples_test.go +++ b/options_examples_test.go @@ -1,11 +1,15 @@ -package nomino +package nomino_test -import "fmt" +import ( + "fmt" + + "codeberg.org/danjones000/nomino" +) func ExampleWithOriginalSlug() { - st, _ := Make(NewConfig( - WithOriginalSlug("Hello, World"), - WithGenerator(Incremental()), + st, _ := nomino.Make(nomino.NewConfig( + nomino.WithOriginalSlug("Hello, World"), + nomino.WithGenerator(nomino.Incremental()), )) fmt.Println(st) @@ -13,9 +17,9 @@ func ExampleWithOriginalSlug() { } func ExampleWithOriginalSlugLang() { - st, _ := Make(NewConfig( - WithOriginalSlugLang("Diese & Dass", "de"), - WithGenerator(Incremental()), + st, _ := nomino.Make(nomino.NewConfig( + nomino.WithOriginalSlugLang("Diese & Dass", "de"), + nomino.WithGenerator(nomino.Incremental()), )) fmt.Println(st) From 9402d807043cc1668eb62deb42d650e2db52d062 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 21:22:29 -0500 Subject: [PATCH 6/8] =?UTF-8?q?=E2=9C=85=20Examples=20for=20everything?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen_ts_examples_test.go | 13 +++++-- generators_examples_test.go | 38 +++++++++++++++++++ options_examples_test.go | 76 +++++++++++++++++++++++++++++++++++++ options_test.go | 48 ----------------------- 4 files changed, 124 insertions(+), 51 deletions(-) delete mode 100644 options_test.go diff --git a/gen_ts_examples_test.go b/gen_ts_examples_test.go index 527728d..2f49392 100644 --- a/gen_ts_examples_test.go +++ b/gen_ts_examples_test.go @@ -7,7 +7,14 @@ import ( "codeberg.org/danjones000/nomino" ) -func ExampleTimestamp_withTime() { +func ExampleTimestamp() { + gen := nomino.Timestamp() + conf := nomino.NewConfig(nomino.WithGenerator(gen)) + s, _ := nomino.Make(conf) + fmt.Println(s) +} + +func ExampleTimestampTime() { tz, _ := time.LoadLocation("America/New_York") ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) gen := nomino.Timestamp(nomino.TimestampTime(ts)) @@ -17,7 +24,7 @@ func ExampleTimestamp_withTime() { // Output: 2009-01-20T12-05-00-0500.txt } -func ExampleTimestamp_withFormat() { +func ExampleTimestampFormat() { tz, _ := time.LoadLocation("America/New_York") ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) gen := nomino.Timestamp(nomino.TimestampTime(ts), nomino.TimestampFormat("2006#01#02<>15|04|05-0700")) @@ -27,7 +34,7 @@ func ExampleTimestamp_withFormat() { // Output: 2009#01#20<>12|05|00-0500.txt } -func ExampleTimestamp_withUTC() { +func ExampleTimestampUTC() { tz, _ := time.LoadLocation("America/New_York") ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz) gen := nomino.Timestamp(nomino.TimestampTime(ts), nomino.TimestampUTC()) diff --git a/generators_examples_test.go b/generators_examples_test.go index 3e63db3..c9d8710 100644 --- a/generators_examples_test.go +++ b/generators_examples_test.go @@ -25,3 +25,41 @@ func ExampleWithGenerator_customGenerator() { // hello.txt // hello } + +func ExampleMultiGeneratorInOrder() { + gen1 := func(*nomino.Config) (string, error) { + return "hello", nil + } + gen2 := func(*nomino.Config) (string, error) { + return "goodbye", nil + } + gen := nomino.MultiGeneratorInOrder(gen1, gen2) + option := nomino.WithGenerator(gen) + + str, _ := nomino.Make(nomino.NewConfig(option)) + fmt.Println(str) + + str, _ = nomino.Make(nomino.NewConfig(option)) + fmt.Println(str) + + str, _ = nomino.Make(nomino.NewConfig(option)) + fmt.Println(str) + + // Output: + // hello.txt + // goodbye.txt + // hello.txt +} + +func ExampleUUID() { + option := nomino.WithGenerator(nomino.UUID()) + + str, _ := nomino.Make(nomino.NewConfig(option)) + fmt.Println(str) + + str, _ = nomino.Make(nomino.NewConfig(option)) + fmt.Println(str) + + str, _ = nomino.Make(nomino.NewConfig(option)) + fmt.Println(str) +} diff --git a/options_examples_test.go b/options_examples_test.go index b60171f..8263fe9 100644 --- a/options_examples_test.go +++ b/options_examples_test.go @@ -6,6 +6,82 @@ import ( "codeberg.org/danjones000/nomino" ) +func ExampleWithExtension() { + st, _ := nomino.Make(nomino.NewConfig( + nomino.WithExtension("xml"), + nomino.WithGenerator(nomino.Incremental()), + )) + + fmt.Println(st) + // Output: 0.xml +} + +func ExampleWithoutExtension() { + st, _ := nomino.Make(nomino.NewConfig( + nomino.WithoutExtension(), + nomino.WithGenerator(nomino.Incremental()), + )) + + fmt.Println(st) + // Output: 0 +} + +func ExampleWithPrefix() { + conf := nomino.NewConfig( + nomino.WithPrefix("pref"), + nomino.WithGenerator(nomino.Incremental()), + ) + st, _ := nomino.Make(conf) + fmt.Println(st) + + st, _ = nomino.Make(conf) + fmt.Println(st) + // Output: + // pref_0.txt + // pref_1.txt +} + +func ExampleWithSeparator() { + conf := nomino.NewConfig( + nomino.WithPrefix("pref"), + nomino.WithSeparator("---"), + nomino.WithGenerator(nomino.Incremental()), + ) + st, _ := nomino.Make(conf) + fmt.Println(st) + + st, _ = nomino.Make(conf) + fmt.Println(st) + // Output: + // pref---0.txt + // pref---1.txt +} + +func ExampleWithSuffix() { + conf := nomino.NewConfig( + nomino.WithSuffix("suff"), + nomino.WithGenerator(nomino.Incremental()), + ) + st, _ := nomino.Make(conf) + fmt.Println(st) + + st, _ = nomino.Make(conf) + fmt.Println(st) + // Output: + // 0_suff.txt + // 1_suff.txt +} + +func ExampleWithOriginal() { + st, _ := nomino.Make(nomino.NewConfig( + nomino.WithOriginal("Hello, World"), + nomino.WithGenerator(nomino.Incremental()), + )) + + fmt.Println(st) + // Output: 0_Hello, World.txt +} + func ExampleWithOriginalSlug() { st, _ := nomino.Make(nomino.NewConfig( nomino.WithOriginalSlug("Hello, World"), diff --git a/options_test.go b/options_test.go deleted file mode 100644 index 6aded3a..0000000 --- a/options_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package nomino - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestWithOriginal(t *testing.T) { - var c Config - name := "foobar" - WithOriginal(name)(&c) - assert.Equal(t, name, c.original) -} - -func TestWithPrefix(t *testing.T) { - var c Config - pref := "draft" - WithPrefix(pref)(&c) - assert.Equal(t, pref, c.prefix) -} - -func TestWithSuffix(t *testing.T) { - var c Config - suff := "out" - WithSuffix(suff)(&c) - assert.Equal(t, suff, c.suffix) -} - -func TestWithoutExtension(t *testing.T) { - c := Config{extension: ".foobar"} - WithoutExtension()(&c) - assert.Equal(t, "", c.extension) -} - -func TestWithExtension(t *testing.T) { - var c Config - ext := "yaml" - WithExtension(ext)(&c) - assert.Equal(t, "."+ext, c.extension) -} - -func TestWithSeparator(t *testing.T) { - var c Config - sep := "---" - WithSeparator(sep)(&c) - assert.Equal(t, sep, c.separator) -} From db2f12522dcdc3e791d0d3b5a8d5532b8220f0fc Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 21:46:30 -0500 Subject: [PATCH 7/8] =?UTF-8?q?=E2=9C=A8=20Add=20extra=20Options=20to=20Ma?= =?UTF-8?q?ke?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make.go | 14 ++++++++++---- make_examples_test.go | 17 +++++++++++++++++ make_test.go | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/make.go b/make.go index 538c7e0..640ec39 100644 --- a/make.go +++ b/make.go @@ -5,12 +5,21 @@ import "fmt" // Make generates a random filename. The behavior can be controlled by specifying Options // 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) { +func Make(conf Config, opts ...Option) (string, error) { + for _, opt := range opts { + opt(&conf) + } + name, err := conf.generator(&conf) if err != nil { return "", err } + seperateConf(&conf) + return fmt.Sprintf("%s%s%s%s%s", conf.prefix, name, conf.original, conf.suffix, conf.extension), nil +} + +func seperateConf(conf *Config) { if conf.prefix != "" { conf.prefix += conf.separator } @@ -19,8 +28,5 @@ func Make(conf Config) (string, error) { } if conf.suffix != "" { conf.suffix = conf.separator + conf.suffix - } - - return fmt.Sprintf("%s%s%s%s%s", conf.prefix, name, conf.original, conf.suffix, conf.extension), nil } diff --git a/make_examples_test.go b/make_examples_test.go index be09fc5..88b8521 100644 --- a/make_examples_test.go +++ b/make_examples_test.go @@ -11,3 +11,20 @@ func ExampleMake_basic() { out, _ := nomino.Make(nomino.NewConfig()) fmt.Println(out) } + +func ExampleMake_withExtraOptions() { + gen := nomino.Incremental() + conf := nomino.NewConfig( + nomino.WithGenerator(gen), + nomino.WithPrefix("pre"), + ) + + st, _ := nomino.Make(conf, nomino.WithOriginal("foobar")) + fmt.Println(st) + st, _ = nomino.Make(conf, nomino.WithOriginal("baz")) + fmt.Println(st) + + // Output: + // pre_0_foobar.txt + // pre_1_baz.txt +} diff --git a/make_test.go b/make_test.go index ffdecee..0970c48 100644 --- a/make_test.go +++ b/make_test.go @@ -66,3 +66,18 @@ func TestMakeDoesntChangeConf(t *testing.T) { assert.Equal(t, "foo.txt", st) assert.NoError(t, err) } + +func TestMakeOptsDoesntChangeConf(t *testing.T) { + gen := Incremental() + conf := NewConfig(WithGenerator(gen), WithPrefix("pre")) + + st, err := Make(conf, WithOriginal("foobar")) + assert.Equal(t, "", conf.original) + assert.Equal(t, "pre_0_foobar.txt", st) + assert.NoError(t, err) + + st, err = Make(conf, WithOriginal("baz")) + assert.Equal(t, "", conf.original) + assert.Equal(t, "pre_1_baz.txt", st) + assert.NoError(t, err) +} From 46a40031dd6dc2ab9af0ef858299bd62bb823a2f Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 14 Mar 2025 21:56:12 -0500 Subject: [PATCH 8/8] =?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 | 14 ++++++++++++++ README.md | 2 ++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c597e7d..0611f05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +### [0.3.0] - 2025-03-14 + +#### Features + +- Simplified multiple Generator functions to single function with options +- Added a lot of examples for docs +- Can add extra Options to Make + +Multiple breaking changes around Generators. + +#### Bugs + +- Fixed date formats + ### [0.2.1] - 2025-03-14 #### Features diff --git a/README.md b/README.md index f08b801..09b7bb7 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ The purpose of nomino is to generate (probably random) filenames, for example, i It takes a lot of inspiration (although no actual code) from [Onym](https://github.com/Blaspsoft/onym). +Note that this is still not at a stable release. There will be breaking changes between minor releases until it reaches 1.0.0. Patch releases shouldn't contain breaking changes however. Once it reaches 1.0.0, breaking changes will only happen between major releases. + ## TODO I'll fill this out more in depth later.