ext

package module
v0.0.0-...-440f624 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: AGPL-3.0 Imports: 2 Imported by: 3

README

ext

Go Reference Go Report Card

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.

Example

package main

import "github.com/speedyhoon/ext"

func main() {
	println("favicon" + ext.ICO)
	// Output: favicon.ico
	
	println(ext.EqualFold("index.htM", ext.HTM))
	// Output: true
	
	println(ext.Is("index.htm", ext.HTM))
	// Output: true
	
	println(ext.IsGo("main.go"))
	// Output: true
	
	println(ext.IsGoTest("val_test.go"))
	// Output: true
	
	println(ext.Replace("val_test.go", ext.GoTest, ext.Go))
	// Output: val.go
	
	println(ext.ReplaceFold("val_TEST.GO", ext.GoTest, ext.Go))
	// Output: val.go
}

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

Examples

Constants

View Source
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
)
View Source
const (
	GoTest = "_test" + Go
)

Variables

This section is empty.

Functions

func Del

func Del(path string) string

Del removes the path's file extension. If a path contains several extensions, then only the last one is removed.

func EqualFold

func EqualFold(path, ext string) bool

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

func Is(path, ext string) bool

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

func IsAny(path string, extensions ...string) bool

IsAny returns true if the path ends with any of the file extensions or filename suffixes.

func IsAnyFold

func IsAnyFold(path string, extensions ...string) bool

IsAnyFold returns true if the path ends with any of the file extensions or filename suffixes, ignoring case.

func IsGo

func IsGo(path string) bool

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

func IsGoTest(path string) bool

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

func Replace(path, old, new string) string

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

func ReplaceFold(path, old, new string) string

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.

Jump to

Keyboard shortcuts

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