Skip to main content

Module js

Module js 

Source
Expand description

JavaScript string and number semantics that pi’s texts depend on: string lengths and slices count UTF-16 code units, and toFixed and Math.round round halves up.

Functions§

byte_index
The byte offset of UTF-16 index units in text: the start of the first character at or after it, or the end of the text.
decode_utf8_stream
TextDecoder.decode(bytes, {stream: true}): appends bytes to pending and decodes what is complete. A character cut off at the end stays pending; invalid bytes become U+FFFD.
errno
Node’s code and description for an I/O error of kind, such as ("ENOENT", "no such file or directory").
len
text.length.
node_error
The message Node gives a failed file system call, such as ENOENT: no such file or directory, access '/a/b'.
round
Math.round(value).
slice
text.slice(start, end) with indices in UTF-16 code units, clamped to the text. A surrogate pair cut in half becomes U+FFFD.
to_fixed
value.toFixed(digits): the exact value rounded half up.
utf16_index
The UTF-16 index of byte offset byte in text, as JavaScript indexes strings; an offset inside a character counts from its start.