Documentation
¶
Overview ¶
Package js holds what the port needs of JavaScript's own behaviour, so that every value the SDK writes, compares, or counts is written, compared, and counted the same way here: numbers as Number.prototype.toString prints them, JSON.stringify and JSON.parse (objects keep JavaScript's key order), string lengths and cuts in UTF-16 code units, the characters \s matches, and Date's calendar arithmetic.
Index ¶
- Constants
- func ArrayIndex(key string) (uint32, bool)
- func BeyondDates(ms int64) string
- func CivilFromDays(z int64) (int64, int64, int64)
- func CloneValue(v any) any
- func Cut16Lone(s string, max int) string
- func DateUTC(year, month, day, hour, minute, second, ms int64) int64
- func DaysFromCivil(y, m, d int64) int64
- func FloorDiv(a, b int64) int64
- func FormatNumber(n float64) string
- func FromUnits(u []uint16) string
- func Head16(s string, n int) string
- func Head16Lone(s string, n int) string
- func ISOString(ms int64) string
- func ISOTime(ms int64) (string, bool)
- func IsInteger(n float64) bool
- func IsSpace(r rune) bool
- func Length16(s string) int
- func Length16Lone(s string) int
- func Mod(a, b int64) int64
- func Number(text string) float64
- func Parse(text string) (any, error)
- func Quote(s string) string
- func Slice16(s string, start, end int) string
- func Slice16Lone(s string, start, end int) string
- func Stamp(ms int64) string
- func Stringify(v any) string
- func StringifyLone(v any) string
- func Tail16(s string, n int) string
- func Tail16Lone(s string, n int) string
- func Trim(s string) string
- func TrimEnd(s string) string
- func Units(s string) []uint16
- func ValueOf(v Valuer) any
- func WellFormed(s string) string
- type Object
- type Valuer
Constants ¶
const ( FirstDateMs int64 = -62_135_596_800_000 LastDateMs int64 = 253_402_300_799_999 )
FirstDateMs is the first millisecond written as a date, 0001-01-01T00:00:00.000Z, and LastDateMs the last, 9999-12-31T23:59:59.999Z.
const MaxSafeInteger = 1<<53 - 1
MaxSafeInteger is Number.MAX_SAFE_INTEGER.
const Whitespace = `\t\n\v\f\r \x{a0}\x{1680}\x{2000}-\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}\x{feff}`
Whitespace is the character class JavaScript's \s matches, and what String.prototype.trim removes: WhiteSpace and LineTerminator, written for a Go character class.
Variables ¶
This section is empty.
Functions ¶
func ArrayIndex ¶
ArrayIndex reports whether a key is an array index, which JavaScript orders before every other key.
func BeyondDates ¶ added in v0.8.0
BeyondDates is the words that stand in for a time ISOTime does not write: "before 0001-01-01 00:00:00 UTC" or "after 9999-12-31 23:59:59 UTC".
func CivilFromDays ¶
CivilFromDays is the date of a day counted from 1970-01-01: year, month (1 to 12) and day.
func Cut16Lone ¶ added in v0.10.0
Cut16Lone is the SDK's cut() for text that may hold a lone half (Slice16Lone): at most max code units, one fewer when the unit at max - 1 is a high surrogate (a pair's first half, or a lone one), so it never ends on a high surrogate it cut from its pair or left behind at the cut.
func DateUTC ¶
DateUTC is Date.UTC(year, month, day, hour, minute, second, ms) with a 0-based month, every field free to overflow into the next, as Date.UTC allows.
func DaysFromCivil ¶
DaysFromCivil is the days since 1970-01-01 of a proleptic Gregorian date, month 1 to 12.
func FormatNumber ¶
FormatNumber is String(n): the shortest digits that read back as n, in plain notation from 1e-7 up to 1e21 and exponential notation outside it, as Number.prototype.toString writes them.
func FromUnits ¶
FromUnits is the text of UTF-16 code units; a lone surrogate becomes U+FFFD, as it does once JavaScript writes it out as UTF-8.
func Head16Lone ¶
Head16Lone is s.slice(0, n), keeping a lone half (Slice16Lone).
func ISOString ¶
ISOString is new Date(ms).toISOString(): "2026-01-05T09:30:00.000Z", with a signed six-digit year outside 0 to 9999.
func ISOTime ¶ added in v0.8.0
ISOTime is ISOString for a time from the year 1 through 9999, and false for any other. A start read from another process's row, or a damaged one, can be any number; outside those years it is not written as a date at all.
func Length16Lone ¶ added in v0.10.0
Length16Lone is Length16 for text that may hold a lone half of a surrogate pair as its WTF-8 bytes (Slice16Lone), counting that half as the one code unit it is.
func Number ¶ added in v0.11.0
Number is Number(text): trimmed as String.prototype.trim trims, then decimal, 0x, 0o, or 0b, Infinity, or NaN; "" (or only whitespace) is 0.
func Parse ¶
Parse is JSON.parse: objects as *Object in JavaScript's key order (a key given twice keeps its first place and its last value), numbers as float64. A lone surrogate escape (\ud800) becomes U+FFFD.
func Slice16 ¶
Slice16 is s.slice(start, end) in UTF-16 code units, with JavaScript's clamping (a negative index counts from the end). A cut through a surrogate pair keeps the lone half, which is written here as U+FFFD, the character it becomes once written out as UTF-8, so a stored or hashed result is the same bytes.
func Slice16Lone ¶
Slice16Lone is Slice16 keeping the lone half of a surrogate pair the cut goes through, as JavaScript keeps it, for text that goes into a JSON body: the half is held as its three WTF-8 bytes (ED A0..BF 80..BF), which StringifyLone writes as \ud83d, as JSON.stringify does. Anything else that reads the result sees three bytes that are not UTF-8.
func Stamp ¶ added in v0.8.0
Stamp is ISOString, or BeyondDates for a time outside the years 1 to 9999.
func Stringify ¶
Stringify is JSON.stringify: the same bytes for the same value. A number that is not finite is null, as JavaScript writes it.
func StringifyLone ¶
StringifyLone is Stringify for a value whose strings may hold a lone surrogate kept by Slice16Lone: each is written as JSON.stringify writes one (\ud83d), so a body cut through a surrogate pair is the SDK's bytes. Its strings must otherwise be UTF-8 (WellFormed), since the three bytes that hold a lone surrogate are not.
func Tail16Lone ¶
Tail16Lone is s.slice(-n), keeping a lone half (Slice16Lone).
func ValueOf ¶ added in v0.11.0
ValueOf is v's JSON value, for the packages that read a cronwatch type's value (whose JSValue method is deprecated, to be unexported at 1.0).
func WellFormed ¶
WellFormed is the text with every byte that is not UTF-8 replaced by U+FFFD, as a JavaScript string decoded from those bytes has it.
Types ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is a JavaScript object: keys in JavaScript's order, which is every key that is an array index (a canonical whole number below 2^32 - 1) in ascending order, then every other key in the order it was first set. The zero value is an empty object.