MCPcopy
hub / github.com/tdewolff/minify / ExampleM_Minify_custom

Function ExampleM_Minify_custom

minify_test.go:353–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

351////////////////////////////////////////////////////////////////
352
353func ExampleM_Minify_custom() {
354 m := New()
355 m.AddFunc("text/plain", func(m *M, w io.Writer, r io.Reader, _ map[string]string) error {
356 // remove all newlines and spaces
357 rb := bufio.NewReader(r)
358 for {
359 line, err := rb.ReadString('\n')
360 if err != nil && err != io.EOF {
361 return err
362 }
363 if _, errws := io.WriteString(w, strings.ReplaceAll(line, " ", "")); errws != nil {
364 return errws
365 }
366 if err == io.EOF {
367 break
368 }
369 }
370 return nil
371 })
372
373 in := "Because my coffee was too cold, I heated it in the microwave."
374 out, err := m.String("text/plain", in)
375 if err != nil {
376 panic(err)
377 }
378 fmt.Println(out)
379 // Output: Becausemycoffeewastoocold,Iheateditinthemicrowave.
380}
381
382func ExampleM_Reader() {
383 b := bytes.NewReader([]byte("input"))

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
AddFuncMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…