https://github.com/dreamscached/sanity
📝 Fast extensible file name sanitizer that works in Windows/Linux
https://github.com/dreamscached/sanity
crossplatform file file-name filename go go-library golang library sanitizer string
Last synced: 8 months ago
JSON representation
📝 Fast extensible file name sanitizer that works in Windows/Linux
- Host: GitHub
- URL: https://github.com/dreamscached/sanity
- Owner: dreamscached
- License: mit
- Created: 2021-10-15T21:41:40.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-22T22:51:55.000Z (almost 4 years ago)
- Last Synced: 2025-01-01T20:45:16.534Z (9 months ago)
- Topics: crossplatform, file, file-name, filename, go, go-library, golang, library, sanitizer, string
- Language: Go
- Homepage: https://pkg.go.dev/github.com/dreamscached/sanity
- Size: 19.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sanity
Sanity is a fast and easily extensible file name (and in fact any other string) sanitizer.
## Usage
### Built-in rule set
Sanity provides a sensible default rule set for Windows and Linux file names that will be enough in most cases:
```go
package mainimport (
"fmt""github.com/dreamscached/sanity/filename"
)func main() {
// Prints 'con_.txt'
fmt.Println(filename.Windows.Sanitize("con.txt"))// Prints 'foobar'
fmt.Println(filename.Unix.Sanitize("foo\x00bar.txt"))
}
```### Creating custom rule sets
Sanity provides a clean and obvious way to create custom rule sets with Rule factory functions. For example, here's
Linux default file name rule set.```go
package mainimport (
"github.com/dreamscached/sanity"
"github.com/aquilax/truncate"
)var Unix = sanity.New(
sanity.Replace("/", " "),
sanity.StripRune(0x0),
sanity.Truncate(255, truncate.DEFAULT_OMISSION, truncate.PositionEnd),
)
```