PythonMonkey   v0.8.2 (dev)
Loading...
Searching...
No Matches
util.js File Reference

Functions

function join (output, separator)
 
function isError (e)
 
function isDate (o)
 
function isSet (o)
 
function isMap (o)
 
function isDataView (o)
 
function isExternal (o)
 
function objectToString (o)
 
function getConstructorOf (obj)
 
function colour (colourCode, val)
 
function strEscape (str)
 
function tryStringify (arg)
 
function format (f)
 
function inspect (obj, opts=undefined)
 
Object defineProperty (inspect, 'defaultOptions', { get() { return inspectDefaultOptions;}, set(options) { if(options===null||typeof options !=='object') { throw new TypeError('"options" must be an object');} Object.assign(inspectDefaultOptions, options);} })
 
function stylizeWithColor (str, styleType)
 
function stylizeNoColor (str, styleType)
 
function formatValue (ctx, value, recurseTimes, ln)
 

Variables

const internalBinding = require('internal-binding')
 
 const
 
const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom')
 
const kPending = 0
 
const kFulfilled = 1
 
const kRejected = 2
 
const inspectDefaultOptions
 
const propertyIsEnumerable = Object.prototype.propertyIsEnumerable
 
const regExpToString = RegExp.prototype.toString
 
const dateToISOString = Date.prototype.toISOString
 
let CIRCULAR_ERROR_MESSAGE
 
const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/
 
const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c]/g
 
const colorRegExp = /\u001b\[\d\d?m/g
 
const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/
 
const numberRegExp = /^(0|[1-9][0-9]*)$/
 
const meta
 
const escapeFn = (str) => meta[str.charCodeAt(0)]
 
inspect custom = customInspectSymbol
 
inspect colors
 
inspect styles
 

Detailed Description

Node.js-style util.inspect implementation, largely based on https://github.com/nodejs/node/blob/v8.17.0/lib/util.js.

Author
Tom Tang xmade.nosp@m.r@di.nosp@m.strib.nosp@m.utiv.nosp@m.e.net.nosp@m.work
Date
June 2023

Function Documentation

◆ colour()

function colour (   colourCode,
  val 
)

Return String(val) surrounded by appropriate ANSI escape codes to change the console text colour.

◆ defineProperty()

Object defineProperty ( inspect  ,
'defaultOptions'  ,
{ get() { return inspectDefaultOptions;}, set(options) { if(options===null||typeof options !=='object') { throw new TypeError('"options" must be an object');} Object.assign(inspectDefaultOptions, options);} }   
)

◆ format()

function format (   f)

◆ formatValue()

function formatValue (   ctx,
  value,
  recurseTimes,
  ln 
)

Format an instance of Error. Error is the only type which is typically displayed using two different colours – the stack gets darker at the bottom where it's less relevant.

Parameters
ctx{object} inspect context - lets us know if we're using colors or not
error{object} instance of Error to inspect

◆ getConstructorOf()

function getConstructorOf (   obj)

◆ inspect()

function inspect (   obj,
  opts = undefined 
)

Echos the value of a value. Tries to print the value out in the best way possible given the different types.

Parameters
{Object}obj The object to print out.
{Object}opts Optional options object that alters the output.

◆ isDataView()

function isDataView (   o)
Returns
{o is DataView}

◆ isDate()

function isDate (   o)
Returns
{o is Date}

◆ isError()

function isError (   e)
Returns
{o is Error}

◆ isExternal()

function isExternal (   o)

V8 IsJSExternalObject

◆ isMap()

function isMap (   o)
Returns
{o is Map}

◆ isSet()

function isSet (   o)
Returns
{o is Set}

◆ join()

function join (   output,
  separator 
)
Parameters
{string[]}output
{string}separator

◆ objectToString()

function objectToString (   o)

◆ strEscape()

function strEscape (   str)

◆ stylizeNoColor()

function stylizeNoColor (   str,
  styleType 
)

◆ stylizeWithColor()

function stylizeWithColor (   str,
  styleType 
)

◆ tryStringify()

function tryStringify (   arg)

Variable Documentation

◆ CIRCULAR_ERROR_MESSAGE

let CIRCULAR_ERROR_MESSAGE

◆ colorRegExp

const colorRegExp = /\u001b\[\d\d?m/g

◆ colors

inspect colors
Initial value:
= Object.assign(Object.create(null), {
'bold': [1, 22],
'italic': [3, 23],
'underline': [4, 24],
'inverse': [7, 27],
'white': [37, 39],
'grey': [90, 39],
'black': [30, 39],
'blue': [34, 39],
'cyan': [36, 39],
'green': [32, 39],
'magenta': [35, 39],
'red': [31, 39],
'yellow': [33, 39]
})

◆ const

const
Initial value:
{
isAnyArrayBuffer,
isPromise,
isRegExp,
isTypedArray,
getPromiseDetails,
getProxyDetails,
} = internalBinding('utils')
const internalBinding
Definition util.js:12

◆ custom

inspect custom = customInspectSymbol

◆ customInspectSymbol

const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom')

◆ dateToISOString

const dateToISOString = Date.prototype.toISOString

◆ escapeFn

const escapeFn = (str) => meta[str.charCodeAt(0)]

◆ inspectDefaultOptions

const inspectDefaultOptions
Initial value:
= Object.seal({
showHidden: false,
depth: 2,
colors: true,
customInspect: true,
showProxy: true,
maxArrayLength: 100,
breakLength: 60
})
inspect colors
Definition util.js:395

◆ internalBinding

const internalBinding = require('internal-binding')

◆ keyStrRegExp

const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/

◆ kFulfilled

const kFulfilled = 1

@type {PromiseState.Fulfilled}

◆ kPending

const kPending = 0

@type {PromiseState.Pending}

◆ kRejected

const kRejected = 2

@type {PromiseState.Rejected}

◆ meta

const meta
Initial value:
= [
'\\u0000', '\\u0001', '\\u0002', '\\u0003', '\\u0004',
'\\u0005', '\\u0006', '\\u0007', '\\b', '\\t',
'\\n', '\\u000b', '\\f', '\\r', '\\u000e',
'\\u000f', '\\u0010', '\\u0011', '\\u0012', '\\u0013',
'\\u0014', '\\u0015', '\\u0016', '\\u0017', '\\u0018',
'\\u0019', '\\u001a', '\\u001b', '\\u001c', '\\u001d',
'\\u001e', '\\u001f', '', '', '',
'', '', '', '', "\\'", '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '\\\\'
]

◆ numberRegExp

const numberRegExp = /^(0|[1-9][0-9]*)$/

◆ propertyIsEnumerable

const propertyIsEnumerable = Object.prototype.propertyIsEnumerable

◆ regExpToString

const regExpToString = RegExp.prototype.toString

◆ strEscapeSequencesRegExp

const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/

◆ strEscapeSequencesReplacer

const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c]/g

◆ styles

inspect styles
Initial value:
= Object.assign(Object.create(null), {
'special': 'cyan',
'number': 'yellow',
'boolean': 'yellow',
'undefined': 'grey',
'null': 'bold',
'string': 'green',
'symbol': 'green',
'date': 'magenta',
'regexp': 'red',
'error2': 'grey',
})