package minify
import "github.com/tdewolff/minify"
Package minify relates MIME type to minifiers. Several minifiers are provided in the subpackages.
Index ¶
- Variables
- func Bytes(m Minifier, mediatype string, v []byte) ([]byte, error)
- func ContentType(b []byte) []byte
- func DataURI(m Minifier, dataURI []byte) []byte
- func Number(num []byte) []byte
- func String(m Minifier, mediatype string, v string) (string, error)
- type Func
- type Minifier
- type Minify
- func New() *Minify
- func (m *Minify) AddCmd(mediatype string, cmd *exec.Cmd)
- func (m *Minify) AddCmdRegexp(mediatype *regexp.Regexp, cmd *exec.Cmd)
- func (m *Minify) AddFunc(mediatype string, minifyFunc Func)
- func (m *Minify) AddFuncRegexp(mediatype *regexp.Regexp, minifyFunc Func)
- func (m Minify) Minify(mediatype string, w io.Writer, r io.Reader) error
Variables ¶
var Epsilon = 0.00001
Epsilon is the closest number to zero that is not considered to be zero.
ErrNotExist is returned when no minifier exists for a given mediatype.
Functions ¶
func Bytes ¶
Bytes minifies an array of bytes (safe for concurrent use). When an error occurs it return the original array and the error. It returns an error when no such mediatype exists (ErrNotExist) or any error occurred in the minifier function.
func ContentType ¶
ContentType minifies a given mediatype by removing all whitespace.
func DataURI ¶
DataURI minifies a data URI and calls a minifier by the specified mediatype. Specifications: https://www.ietf.org/rfc/rfc2397.txt.
func Number ¶
Number minifies a given byte slice containing a number (see parse.Number) and removes superfluous characters.
func String ¶
String minifies a string (safe for concurrent use). When an error occurs it return the original string and the error. It returns an error when no such mediatype exists (ErrNotExist) or any error occurred in the minifier function.
Types ¶
type Func ¶
Func is the function interface for minifiers. The Minifier parameter is used for embedded resources, such as JS within HTML. The mediatype string is for wildcard minifiers so they know what they minify and for parameter passing (charset for example).
type Minifier ¶
Minifier is the interface which all minifier functions accept as first parameter. It's used to extract parameter values of the mediatype and to recursively call other minifier functions.
type Minify ¶
type Minify struct {
// contains filtered or unexported fields
}
Minify holds a map of mediatype => function to allow recursive minifier calls of the minifier functions.
func New ¶
func New() *Minify
New returns a new Minify.
func (*Minify) AddCmd ¶
AddCmd adds a minify function to the mediatype => function map (unsafe for concurrent use) that executes a command to process the minification. It allows the use of external tools like ClosureCompiler, UglifyCSS, etc. for a specific mediatype. Be aware that running external tools will slow down minification a lot!
func (*Minify) AddCmdRegexp ¶
AddCmdRegexp adds a minify function to the mediatype => function map (unsafe for concurrent use) that executes a command to process the minification. It allows the use of external tools like ClosureCompiler, UglifyCSS, etc. for a specific mediatype regular expression. Be aware that running external tools will slow down minification a lot!
func (*Minify) AddFunc ¶
AddFunc adds a minify function to the mediatype => function map (unsafe for concurrent use). It allows one to implement a custom minifier for a specific mediatype.
func (*Minify) AddFuncRegexp ¶
AddFuncRegexp adds a minify function to the mediatype => function map (unsafe for concurrent use). It allows one to implement a custom minifier for a specific mediatype regular expression.
func (Minify) Minify ¶
Minify minifies the content of a Reader and writes it to a Writer (safe for concurrent use). An error is returned when no such mediatype exists (ErrNotExist) or when an error occurred in the minifier function. Mediatype may take the form of 'text/plain', 'text/*', '*/*' or 'text/plain; charset=UTF-8; version=2.0'.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd | |
cmd/minify | |
css | Package css minifies CSS3 following the specifications at http://www.w3.org/TR/css-syntax-3/. |
html | Package html minifies HTML5 following the specifications at http://www.w3.org/TR/html5/syntax.html. |
js | Package js minifies ECMAScript5.1 following the specifications at http://www.ecma-international.org/ecma-262/5.1/. |
json | Package json minifies JSON following the specifications at http://json.org/. |
svg | Package svg minifies SVG1.1 following the specifications at http://www.w3.org/TR/SVG11/. |
xml | Package xml minifies XML1.0 following the specifications at http://www.w3.org/TR/xml/. |
- Version
- v1.1.0 (latest)
- Published
- Nov 2, 2015
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 5 hours ago –
Tools for package owners.