helpers

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsNonBMPCodePoint added in v0.14.19

func ContainsNonBMPCodePoint(text string) bool

func ContainsNonBMPCodePointUTF16 added in v0.14.19

func ContainsNonBMPCodePointUTF16(text []uint16) bool

This does "ContainsNonBMPCodePoint(UTF16ToString(text))" without any allocations

func DecodeWTF8Rune added in v0.14.19

func DecodeWTF8Rune(s string) (rune, int)

This is a clone of "utf8.DecodeRuneInString" that has been modified to decode using WTF-8 instead. See https://simonsapin.github.io/wtf-8/ for more info.

func EncodeStringAsPercentEscapedDataURL added in v0.16.0

func EncodeStringAsPercentEscapedDataURL(mimeType string, text string) (string, bool)

See "scripts/dataurl-escapes.html" for how this was derived

func EncodeStringAsShortestDataURL added in v0.19.1

func EncodeStringAsShortestDataURL(mimeType string, text string) string

Returns the shorter of either a base64-encoded or percent-escaped data URL

func EscapeClosingTag added in v0.13.10

func EscapeClosingTag(text string, slashTag string) string

func GlobPatternToString added in v0.19.0

func GlobPatternToString(pattern []GlobPart) string

func HashCombine added in v0.11.19

func HashCombine(seed uint32, hash uint32) uint32

From: http://boost.sourceforge.net/doc/html/boost/hash_combine.html

func HashCombineString added in v0.11.19

func HashCombineString(seed uint32, text string) uint32

func IsInsideNodeModules added in v0.11.20

func IsInsideNodeModules(path string) bool

func MimeTypeByExtension added in v0.10.0

func MimeTypeByExtension(ext string) string

This is used instead of Go's built-in "mime.TypeByExtension" function because that function is broken on Windows: https://github.com/golang/go/issues/32350.

func PrettyPrintedStack added in v0.14.1

func PrettyPrintedStack() string

func QuoteForJSON added in v0.14.50

func QuoteForJSON(text string, asciiOnly bool) []byte

func QuoteSingle added in v0.16.2

func QuoteSingle(text string, asciiOnly bool) []byte

func StringArrayArraysEqual added in v0.19.2

func StringArrayArraysEqual(a [][]string, b [][]string) bool

func StringArrayToQuotedCommaSeparatedString added in v0.14.36

func StringArrayToQuotedCommaSeparatedString(a []string) string

func StringArraysEqual added in v0.14.35

func StringArraysEqual(a []string, b []string) bool

func StringToUTF16 added in v0.14.19

func StringToUTF16(text string) []uint16

func UTF16EqualsString added in v0.14.19

func UTF16EqualsString(text []uint16, str string) bool

Does "UTF16ToString(text) == str" without a temporary allocation

func UTF16EqualsUTF16 added in v0.14.19

func UTF16EqualsUTF16(a []uint16, b []uint16) bool

func UTF16ToString added in v0.14.19

func UTF16ToString(text []uint16) string

func UTF16ToStringWithValidation added in v0.14.19

func UTF16ToStringWithValidation(text []uint16) (string, uint16, bool)

Types

type BitSet added in v0.11.5

type BitSet struct {
	// contains filtered or unexported fields
}

func NewBitSet added in v0.11.5

func NewBitSet(bitCount uint) BitSet

func (BitSet) Equals added in v0.11.5

func (bs BitSet) Equals(other BitSet) bool

func (BitSet) HasBit added in v0.11.5

func (bs BitSet) HasBit(bit uint) bool

func (BitSet) SetBit added in v0.11.5

func (bs BitSet) SetBit(bit uint)

func (BitSet) String added in v0.11.5

func (bs BitSet) String() string

type F64 added in v0.20.1

type F64 struct {
	// contains filtered or unexported fields
}

This wraps float64 math operations. Why does this exist? The Go compiler contains some optimizations to take advantage of "fused multiply and add" (FMA) instructions on certain processors. These instructions lead to different output on those processors, which means esbuild's output is no longer deterministic across all platforms. From the Go specification itself (https://go.dev/ref/spec#Floating_point_operators):

An implementation may combine multiple floating-point operations into a
single fused operation, possibly across statements, and produce a result
that differs from the value obtained by executing and rounding the
instructions individually. An explicit floating-point type conversion
rounds to the precision of the target type, preventing fusion that would
discard that rounding.

For instance, some architectures provide a "fused multiply and add" (FMA)
instruction that computes x*y + z without rounding the intermediate result
x*y.

Therefore we need to add explicit type conversions such as "float64(x)" to prevent optimizations that break correctness. Rather than adding them on a case-by-case basis as real correctness issues are discovered, we instead preemptively force them to be added everywhere by using this wrapper type for all floating-point math.

func Lerp added in v0.20.1

func Lerp(a F64, b F64, t F64) F64

func Max2 added in v0.20.1

func Max2(a F64, b F64) F64

func Max3 added in v0.20.1

func Max3(a F64, b F64, c F64) F64

func Min2 added in v0.20.1

func Min2(a F64, b F64) F64

func Min3 added in v0.20.1

func Min3(a F64, b F64, c F64) F64

func NewF64 added in v0.20.1

func NewF64(a float64) F64

func (F64) Abs added in v0.20.1

func (a F64) Abs() F64

func (F64) Add added in v0.20.1

func (a F64) Add(b F64) F64

func (F64) AddConst added in v0.20.1

func (a F64) AddConst(b float64) F64

func (F64) Atan2 added in v0.20.1

func (a F64) Atan2(b F64) F64

func (F64) Cbrt added in v0.20.1

func (a F64) Cbrt() F64

func (F64) Ceil added in v0.20.1

func (a F64) Ceil() F64

func (F64) Cos added in v0.20.1

func (a F64) Cos() F64

func (F64) Cubed added in v0.20.1

func (a F64) Cubed() F64

func (F64) Div added in v0.20.1

func (a F64) Div(b F64) F64

func (F64) DivConst added in v0.20.1

func (a F64) DivConst(b float64) F64

func (F64) Floor added in v0.20.1

func (a F64) Floor() F64

func (F64) IsNaN added in v0.20.1

func (a F64) IsNaN() bool

func (F64) Log2 added in v0.20.1

func (a F64) Log2() F64

func (F64) Mul added in v0.20.1

func (a F64) Mul(b F64) F64

func (F64) MulConst added in v0.20.1

func (a F64) MulConst(b float64) F64

func (F64) Neg added in v0.20.1

func (a F64) Neg() F64

func (F64) Pow added in v0.20.1

func (a F64) Pow(b F64) F64

func (F64) PowConst added in v0.20.1

func (a F64) PowConst(b float64) F64

func (F64) Round added in v0.20.1

func (a F64) Round() F64

func (F64) Sin added in v0.20.1

func (a F64) Sin() F64

func (F64) Sqrt added in v0.20.1

func (a F64) Sqrt() F64

func (F64) Squared added in v0.20.1

func (a F64) Squared() F64

func (F64) Sub added in v0.20.1

func (a F64) Sub(b F64) F64

func (F64) SubConst added in v0.20.1

func (a F64) SubConst(b float64) F64

func (F64) Value added in v0.20.1

func (a F64) Value() float64

func (F64) WithSignFrom added in v0.20.1

func (a F64) WithSignFrom(b F64) F64

type GlobPart added in v0.19.0

type GlobPart struct {
	Prefix   string
	Wildcard GlobWildcard
}

func ParseGlobPattern added in v0.19.0

func ParseGlobPattern(text string) (pattern []GlobPart)

The returned array will always be at least one element. If there are no wildcards then it will be exactly one element, and if there are wildcards then it will be more than one element.

type GlobWildcard added in v0.19.0

type GlobWildcard uint8
const (
	GlobNone GlobWildcard = iota
	GlobAllExceptSlash
	GlobAllIncludingSlash
)

type Joiner added in v0.9.4

type Joiner struct {
	// contains filtered or unexported fields
}

This provides an efficient way to join lots of big string and byte slices together. It avoids the cost of repeatedly reallocating as the buffer grows by measuring exactly how big the buffer should be and then allocating once. This is a measurable speedup.

func (*Joiner) AddBytes added in v0.9.4

func (j *Joiner) AddBytes(data []byte)

func (*Joiner) AddString added in v0.9.4

func (j *Joiner) AddString(data string)

func (*Joiner) Contains added in v0.11.23

func (j *Joiner) Contains(s string, b []byte) bool

func (*Joiner) Done added in v0.9.4

func (j *Joiner) Done() []byte

func (*Joiner) EnsureNewlineAtEnd added in v0.9.4

func (j *Joiner) EnsureNewlineAtEnd()

func (*Joiner) LastByte added in v0.9.4

func (j *Joiner) LastByte() byte

func (*Joiner) Length added in v0.9.4

func (j *Joiner) Length() uint32

type Serializer added in v0.14.18

type Serializer struct {
	// contains filtered or unexported fields
}

Each call to "Enter(i)" doesn't start until "Leave(i-1)" is called

func MakeSerializer added in v0.14.18

func MakeSerializer(count int) Serializer

func (*Serializer) Enter added in v0.14.18

func (s *Serializer) Enter(i int)

func (*Serializer) Leave added in v0.14.18

func (s *Serializer) Leave(i int)

type ThreadSafeWaitGroup added in v0.16.3

type ThreadSafeWaitGroup struct {
	// contains filtered or unexported fields
}

Go's "sync.WaitGroup" is not thread-safe. Specifically it's not safe to call "Add" concurrently with "Wait", which is problematic because we have a case where we would like to do that.

This is a simple alternative implementation of "sync.WaitGroup" that is thread-safe and that works for our purposes. We don't need to worry about multiple waiters so the implementation can be very simple.

func MakeThreadSafeWaitGroup added in v0.16.3

func MakeThreadSafeWaitGroup() *ThreadSafeWaitGroup

func (*ThreadSafeWaitGroup) Add added in v0.16.3

func (wg *ThreadSafeWaitGroup) Add(delta int32)

func (*ThreadSafeWaitGroup) Done added in v0.16.3

func (wg *ThreadSafeWaitGroup) Done()

func (*ThreadSafeWaitGroup) Wait added in v0.16.3

func (wg *ThreadSafeWaitGroup) Wait()

type Timer added in v0.11.13

type Timer struct {
	// contains filtered or unexported fields
}

func (*Timer) Begin added in v0.11.13

func (t *Timer) Begin(name string)

func (*Timer) End added in v0.11.13

func (t *Timer) End(name string)

func (*Timer) Fork added in v0.11.13

func (t *Timer) Fork() *Timer

func (*Timer) Join added in v0.11.13

func (t *Timer) Join(other *Timer)

func (*Timer) Log added in v0.11.13

func (t *Timer) Log(log logger.Log)

type TypoDetector added in v0.14.12

type TypoDetector struct {
	// contains filtered or unexported fields
}

func MakeTypoDetector added in v0.14.12

func MakeTypoDetector(valid []string) TypoDetector

func (TypoDetector) MaybeCorrectTypo added in v0.14.12

func (detector TypoDetector) MaybeCorrectTypo(typo string) (string, bool)

Jump to

Keyboard shortcuts

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