filenamify

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 5 Imported by: 37

README

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)
LICENSE

MIT

Documentation

Index

Constants

View Source
const MAX_FILENAME_LENGTH = 100

Variables

This section is empty.

Functions

func Filenamify

func Filenamify(str string, options Options) (string, error)

func FilenamifyV2

func FilenamifyV2(str string, optFuns ...func(options *Options)) (string, error)

func Path

func Path(filePath string, options Options) (string, error)

func PathV2

func PathV2(filePath string, optFuns ...func(options *Options)) (string, error)

Types

type Options

type Options struct {
	// String for substitution
	Replacement string
	// maxlength
	MaxLength int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL