1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
## go-filenamify
[](https://travis-ci.com/flytam/filenamify)
Convert a string to a valid safe filename
#### Installation
```bash
$ go get github.com/flytam/filenamify
```
(optional) To run unit tests:
```bash
go test -v
```
#### Usage
```go
package main
import (
"github.com/flytam/filenamify"
"fmt"
)
func main() {
output,err :=filenamify.Filenamify(`<foo/bar>`,filenamify.Options{})
fmt.Println(output,err) // => foo!bar,nil
//---
output,err =filenamify.Filenamify(`foo:"bar"`,filenamify.Options{
Replacement:"🐴",
})
fmt.Println(output,err) // => foo🐴bar,nil
output,err =filenamify.FilenamifyV2(`<foo/bar>`)
fmt.Println(output,err) // => foo!bar,nil
//---
output,err =filenamify.FilenamifyV2(`foo:"bar"`,func(options *Options) {
options.Replacement = "🐴"
})
fmt.Println(output,err) // => foo🐴bar,nil
}
```
#### API
- `Filenamify(str string, options Options) (string, error)`
- `func Path(filePath string, options Options) (string, error)`
```go
type Options struct {
// String for substitution
Replacement string// default: "!"
// maxlength
MaxLength int// default: 100
}
```
FilenamifyV2 and PathV2 are added in v1.1.0
- `func FilenamifyV2(str string, optFuns ...func(options *Options)) (string, error)`
- `func PathV2(str string, optFuns ...func(options *Options)) (string, error)`
#### Related
- [Node-filenamify](https://github.com/sindresorhus/filenamify)
#### LICENSE
MIT
|