✨ Add IncrementalStep* Generators
This commit is contained in:
parent
1d235af876
commit
9d8737079f
2 changed files with 89 additions and 3 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue