Documentation
¶
Overview ¶
Package ext provides helpful functions for checking and modifying file extensions and file suffixes. Plus a list of string constants for commonly used file extensions and file suffixes.
Index ¶
- Constants
- func Del(path string) string
- func EqualFold(path, ext string) bool
- func Is(path, ext string) bool
- func IsAny(path string, extensions ...string) bool
- func IsAnyFold(path string, extensions ...string) bool
- func IsGo(path string) bool
- func IsGoTest(path string) bool
- func Replace(path, old, new string) string
- func ReplaceFold(path, old, new string) string
Examples ¶
Constants ¶
const ( BMP = ".bmp" // Bitmap image CSS = ".css" // Cascading Style Sheet DB = ".db" // Database file Go = ".go" GoHTML = ".gohtml" // Go HTML template HTM = ".htm" // HyperText Markup Language HTML = ".html" ICO = ".ico" // Icon INI = ".ini" // Configuration ISS = ".iss" // Inno Setup script JPG = ".jpg" // JPEG image JS = ".js" // JavaScript JSON = ".json" // JavaScript Object Notation LOG = ".log" // Logging MD = ".md" // Markdown PDF = ".pdf" // Portable Document Format PNG = ".png" // Portable Network Graphic STYL = ".styl" // Stylus style sheet SVG = ".svg" // Scalable Vector Graphic TIFF = ".tiff" // Tagged Image File Format TXT = ".txt" // Text file WEBP = ".webp" // WebP image XHTML = ".xhtml" // Extensible Hypertext Markup Language YML = ".yml" // YAML source )
const (
GoTest = "_test" + Go
)
Variables ¶
This section is empty.
Functions ¶
func Del ¶
Del removes the path's file extension. If a path contains several extensions, then only the last one is removed.
func EqualFold ¶
EqualFold determines if the path's extension is the same as ext, ignoring case.
Example ¶
package main
import (
"fmt"
"github.com/speedyhoon/ext"
)
func main() {
fmt.Println(ext.EqualFold("my/path/index.htM", ext.HTM))
}
Output: true
func Is ¶
Is returns true if the path ends with a certain file extension or filename suffix.
Example ¶
package main
import (
"fmt"
"github.com/speedyhoon/ext"
)
func main() {
fmt.Println(ext.Is("my/path/index.htm", ext.HTM))
}
Output: true
func IsAny ¶
IsAny returns true if the path ends with any of the file extensions or filename suffixes.
func IsAnyFold ¶
IsAnyFold returns true if the path ends with any of the file extensions or filename suffixes, ignoring case.
func IsGo ¶
IsGo performs a case-sensitive check if a filepath ends with a `.go` file extension. IsGo is shorthand for ext.Is(path, ext.Go)
Example ¶
package main
import (
"fmt"
"github.com/speedyhoon/ext"
)
func main() {
fmt.Println(ext.IsGo("my/path/main.go"))
}
Output: true
func IsGoTest ¶
IsGoTest performs a case-sensitive check if a filepath ends with an `_test.go` file suffix. IsGoTest is shorthand for ext.Is(path, ext.GoTest)
Example ¶
package main
import (
"fmt"
"github.com/speedyhoon/ext"
)
func main() {
fmt.Println(ext.IsGoTest("my/path/val_test.go"))
}
Output: true
func Replace ¶
Replace performs a case-sensitive swap of path's file extension.
Example ¶
package main
import (
"fmt"
"github.com/speedyhoon/ext"
)
func main() {
fmt.Println(ext.Replace("my/path/val_test.go", ext.GoTest, ext.Go))
}
Output: my/path/val.go
func ReplaceFold ¶
ReplaceFold swaps a path's file extension ignoring case.
Example ¶
package main
import (
"fmt"
"github.com/speedyhoon/ext"
)
func main() {
fmt.Println(ext.ReplaceFold("my/path/val_TEST.GO", ext.GoTest, ext.Go))
}
Output: my/path/val.go
Types ¶
This section is empty.