Utility
Math, lodash, buffers, HTML parsing, console logging.
console.debug
Section titled “console.debug”Write the given message to the sandbox log (debug-level). Prefixed by ‘D:’ in the sandbox logs
Signature
console.debug(msg, [args])Parameters
msg· `string`- The message to log
args· `*` · optional- Optional values to format into the message.
Returns
void
Example
console.debug('short message');console.error
Section titled “console.error”Write the given message to the sandbox log (error-level). Prefixed by ‘E:’ in the sandbox logs
Signature
console.error(msg, [args])Parameters
msg· `string`- The message to log
args· `*` · optional- Optional values to format into the message.
Returns
void
Example
console.error('short message');console.get
Section titled “console.get”Returns the log message entries
Signature
console.get()Returns
Array.<string>— - An array of log messages
Example
var logger = console.get();logger.log('raw message');console.info
Section titled “console.info”Write the given message to the sandbox log (info-level). Prefixed by ‘I:’ in the sandbox logs
Signature
console.info(msg, [args])Parameters
msg· `string`- The message to log
args· `*` · optional- Optional values to format into the message.
Returns
void
Example
console.info('short message');console.warn
Section titled “console.warn”Write the given message to the sandbox log (warning-level). Prefixed by ‘W:’ in the sandbox logs
Signature
console.warn(msg, [args])Parameters
msg· `string`- The message to log
args· `*` · optional- Optional values to format into the message.
Returns
void
Example
console.warn('short message');D._unsafe.buffer.alloc
Section titled “D._unsafe.buffer.alloc”Allocates a new buffer of size bytes. If fill is undefined, the Buffer will be zero-filled. A TypeError will be thrown if size is not a number. If size is larger than buffer.constants.MAX_LENGTH or smaller than 0, ERR_INVALID_OPT_VALUE is thrown.
Signature
D._unsafe.buffer.alloc(length, [fill], [encoding])Parameters
length· `integer`- The desired length of the new Buffer.
fill· `string` | `Buffer` | `Unit8Array` | `integer` · optional- A value to pre-fill the new Buffer with.
encoding· `string` · optional, default `utf8`- If fill is a string, this is its encoding.
Returns
Buffer
Example
D._unsafe.buffer.alloc(8,'1') - returns '11111111'D._unsafe.buffer.concat
Section titled “D._unsafe.buffer.concat”Returns a new Buffer which is the result of concatenating all the Buffer instances in the list together. If the list has no items, or if the length is 0, then a new zero-length Buffer is returned. If length is not provided, it is calculated from the Buffer instances in list by adding their lengths. If length is provided, it is coerced to an unsigned integer. If the combined length of the Buffers in data list exceeds length, the result is truncated to length.
Signature
D._unsafe.buffer.concat(data, length)Parameters
data· `Array.` | `Array. ` - List of Buffer or Uint8Array instances to concatenate.
length· `integer`- Total length of the Buffer instances in list when concatenated.
Returns
Buffer
Example
var combined = D._unsafe.buffer.concat([buf1, buf2]);D._unsafe.buffer.from
Section titled “D._unsafe.buffer.from”Allocates a new Buffer using multiple types of input data (array, arrayBuffer, buffer, object, string)
Signature
D._unsafe.buffer.from(data, [offsetOrEncoding], [length])Parameters
data· `string` | `Array.` | `Buffer` - The input bytes. Strings are decoded using the second argument's encoding.
offsetOrEncoding· `integer` | `string` · optional, default `0 | utf8`- Index of first byte to expose or encoding of string
length· `integer` · optional- Number of bytes to expose.
Returns
Buffer
Example
var buf = D._unsafe.buffer.from('48656c6c6f', 'hex'); // "Hello"D.math.percent
Section titled “D.math.percent”Percentage Calculating Function
Signature
D.math.percent(actual, maximum)Parameters
actual· `number`- The actual number
maximum· `number`- The maximum number
Returns
number— - The Percentage
Example
D.math.percent(7, 10) // returns 70D.htmlParse
Section titled “D.htmlParse”Html Parser Library
Signature
D.htmlParse(content, [options], [isDocument])Parameters
content· `string` | `Node` | `Array.` | `Buffer` - Markup to be loaded.
options· `Object` · optional- Options for the created instance (see [https://cheerio.js.org/interfaces/CheerioOptions.html](https://cheerio.js.org/interfaces/CheerioOptions.html))
isDocument· `boolean` · optional, default `true`- Allows parser to be switched to fragment mode.
Returns
Object— - The loaded document (see https://cheerio.js.org/interfaces/CheerioAPI.html)
Example
D.htmlParse()