https://github.com/flytam/filenamify
Convert a string to a valid safe filename on Golang
https://github.com/flytam/filenamify
convert filenamify filepath golang valid
Last synced: about 2 months ago
JSON representation
Convert a string to a valid safe filename on Golang
- Host: GitHub
- URL: https://github.com/flytam/filenamify
- Owner: flytam
- License: mit
- Created: 2020-02-06T12:55:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-07T08:59:33.000Z (almost 2 years ago)
- Last Synced: 2025-08-15T05:36:35.224Z (8 months ago)
- Topics: convert, filenamify, filepath, golang, valid
- Language: Go
- Size: 19.5 KB
- Stars: 41
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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(``,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(``)
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