File: README.md

package info (click to toggle)
golang-github-flytam-filenamify 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 84 kB
  • sloc: makefile: 2
file content (78 lines) | stat: -rw-r--r-- 1,544 bytes parent folder | download
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


[![Build Status](https://travis-ci.com/flytam/filenamify.svg?branch=master)](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