Compare commits
No commits in common. "3546ab52d156083b02a7f2700a9d8a02fa05ffb0" and "1d235af8765ac500e735179334630976b599147d" have entirely different histories.
3546ab52d1
...
1d235af876
3 changed files with 3 additions and 98 deletions
|
|
@ -1,14 +1,5 @@
|
||||||
# Changelog
|
# 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
|
## [0.0.3] - 2025-03-11
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package nomino
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -106,56 +105,26 @@ func Incremental() Generator {
|
||||||
return IncrementalWithStartAndStep(0, 1)
|
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
|
// IncrementalWithStart generates a name that is a series of integers starting at the specified number
|
||||||
func IncrementalWithStart(start int) Generator {
|
func IncrementalWithStart(start int) Generator {
|
||||||
return IncrementalWithStartAndStep(start, 1)
|
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
|
// 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 {
|
func IncrementalWithStep(step int) Generator {
|
||||||
return IncrementalWithStartAndStep(0, step)
|
return IncrementalWithStartAndStep(0, step)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncrementalFormatWithStep generates a name that is a series of integers, starting at 0, and increasing the specified number each time,
|
// InrementalWithStartAndStep 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 IncrementalWithStartAndStep(start, 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
|
next := start
|
||||||
return func(*Config) (string, error) {
|
return func(*Config) (string, error) {
|
||||||
out := cb(next)
|
out := strconv.Itoa(next)
|
||||||
next += step
|
next += step
|
||||||
return out, nil
|
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
|
// ErrMissingOriginal is the error returned by Slug if there is no filename
|
||||||
var ErrMissingOriginal = errors.New("missing original filename")
|
var ErrMissingOriginal = errors.New("missing original filename")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,61 +91,6 @@ func ExampleIncrementalWithStartAndStep() {
|
||||||
// foo_46.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() {
|
func ExampleSlug() {
|
||||||
conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy"))
|
conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy"))
|
||||||
str, _ := Make(conf)
|
str, _ := Make(conf)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue