Documentation
¶
Overview ¶
Package stringutil Exports common rune utilities for parsing and emitting javascript
Index ¶
- Constants
- func AddUTF8ByteOrderMark(text string) string
- func CodePointToSurrogatePair(ch rune) (high rune, low rune)
- func CombineSurrogatePairs(s string) string
- func ContainsNonASCII(s string) bool
- func DecodeJSStringRune(s string) (rune, int)
- func EncodeJSStringRune(ch rune) string
- func EncodeURI(s string) string
- func EquateStringCaseInsensitive(a, b string) bool
- func EquateStringCaseSensitive(a, b string) bool
- func GetStringComparer(ignoreCase bool) func(a, b string) Comparison
- func GetStringEqualityComparer(ignoreCase bool) func(a, b string) bool
- func GuessIndentation(lines []string) int
- func HasPrefix(s string, prefix string, caseSensitive bool) bool
- func HasPrefixAndSuffixWithoutOverlap(s string, prefix string, suffix string, caseSensitive bool) bool
- func HasSuffix(s string, suffix string, caseSensitive bool) bool
- func IsASCIILetter(ch rune) bool
- func IsDigit(ch rune) bool
- func IsHexDigit(ch rune) bool
- func IsHighSurrogate(ch rune) bool
- func IsLineBreak(ch rune) bool
- func IsLowSurrogate(ch rune) bool
- func IsOctalDigit(ch rune) bool
- func IsSurrogate(ch rune) bool
- func IsUnicodeIdentifierPart(ch rune) bool
- func IsUnicodeIdentifierStart(ch rune) bool
- func IsWhiteSpaceLike(ch rune) bool
- func IsWhiteSpaceSingleLine(ch rune) bool
- func LowerFirstChar(str string) string
- func RemoveByteOrderMark(text string) string
- func SplitLines(text string) []string
- func StripQuotes(name string) string
- func SurrogatePairToCodePoint(high rune, low rune) rune
- func ToLowerJS(str string) string
- func ToUpperJS(str string) string
- func TruncateByRunes(str string, maxLength int) string
- func UnquoteString(str string) string
- type Comparison
Constants ¶
const ( // SurrogateLowStart is the boundary between the high and low halves of the // UTF-16 surrogate range. unicode/utf16 only exposes IsSurrogate for the // whole range, so this split point is defined here to distinguish the two. SurrogateLowStart = 0xDC00 )
Variables ¶
This section is empty.
Functions ¶
func AddUTF8ByteOrderMark ¶
func CodePointToSurrogatePair ¶ added in v0.22.0
func CombineSurrogatePairs ¶ added in v0.22.0
CombineSurrogatePairs canonicalizes a JS-string value produced by concatenation, merging any adjacent high+low surrogate sentinel pair (as written by EncodeJSStringRune) into the single supplementary code point they represent. This mirrors how concatenating two UTF-16 code units forms a surrogate pair in a JavaScript string. It must be applied wherever separately scanned string values are joined, since each half is only a lone surrogate until it meets its partner. Strings without a lone-surrogate sentinel (the common case) are returned unchanged.
func ContainsNonASCII ¶ added in v0.22.0
func DecodeJSStringRune ¶ added in v0.22.0
func EncodeJSStringRune ¶ added in v0.22.0
func GetStringComparer ¶
func GetStringComparer(ignoreCase bool) func(a, b string) Comparison
func GuessIndentation ¶
func IsASCIILetter ¶
func IsHexDigit ¶
func IsHighSurrogate ¶ added in v0.22.0
func IsLineBreak ¶
func IsLowSurrogate ¶ added in v0.22.0
func IsOctalDigit ¶
func IsSurrogate ¶ added in v0.22.0
func IsUnicodeIdentifierPart ¶ added in v0.22.0
IsUnicodeIdentifierPart reports whether ch may appear after the first character of an ECMAScript identifier, i.e. whether it has the Unicode ID_Continue (or Other_ID_Continue) property, which also includes ID_Start.
func IsUnicodeIdentifierStart ¶ added in v0.22.0
IsUnicodeIdentifierStart reports whether ch may begin an ECMAScript identifier, i.e. whether it has the Unicode ID_Start (or Other_ID_Start) property. The range table is generated; see generate-unicode-data.mts.
func IsWhiteSpaceLike ¶
func IsWhiteSpaceSingleLine ¶
func LowerFirstChar ¶
func RemoveByteOrderMark ¶
func SplitLines ¶
func StripQuotes ¶
func SurrogatePairToCodePoint ¶ added in v0.22.0
func TruncateByRunes ¶
func UnquoteString ¶
Types ¶
type Comparison ¶
type Comparison = int
const ( ComparisonLessThan Comparison = -1 ComparisonEqual Comparison = 0 ComparisonGreaterThan Comparison = 1 )
func CompareStringsCaseInsensitive ¶
func CompareStringsCaseInsensitive(a string, b string) Comparison
func CompareStringsCaseInsensitiveEslintCompatible ¶
func CompareStringsCaseInsensitiveEslintCompatible(a, b string) Comparison
CompareStringsCaseInsensitiveEslintCompatible performs a case-insensitive comparison using toLowerCase() instead of toUpperCase() for ESLint compatibility.
`CompareStringsCaseInsensitive` transforms letters to uppercase for unicode reasons, while eslint's `sort-imports` rule transforms letters to lowercase. Which one you choose affects the relative order of letters and ASCII characters 91-96, of which `_` is a valid character in an identifier. So if we used `CompareStringsCaseInsensitive` for import sorting, TypeScript and eslint would disagree about the correct case-insensitive sort order for `__String` and `Foo`. Since eslint's whole job is to create consistency by enforcing nitpicky details like this, it makes way more sense for us to just adopt their convention so users can have auto-imports without making eslint angry.
func CompareStringsCaseInsensitiveThenSensitive ¶
func CompareStringsCaseInsensitiveThenSensitive(a, b string) Comparison
func CompareStringsCaseSensitive ¶
func CompareStringsCaseSensitive(a string, b string) Comparison