Skip to content

Convert a string to a valid safe filename on Golang

License

Notifications You must be signed in to change notification settings

flytam/filenamify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-filenamify

Build Status

Convert a string to a valid safe filename

Installation

$ go get github.com/flytam/filenamify

(optional) To run unit tests:

go test -v

Usage

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)

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

LICENSE

MIT

About

Convert a string to a valid safe filename on Golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages