Documentation
Parsers
Parsing utilities exposed to CYBERQUEST scripts through CQ.Parsers.
Overview
The CQ.Parsers namespace provides parsing utilities for use in customizable CYBERQUEST scripts, including Data Transformation Service (DTS) and alert scripts.
Available members
| Access path | Exported utility |
|---|---|
CQ.Parsers.fast_xml_parser | fast_xml_parser |
CQ.Parsers.string2Bytes | bytes |
CQ.Parsers.urlParse | urlParse |
CQ.Parsers.csvjson | csvjson |
CQ.Parsers.getObjectFromDirtyJsonString | getObjectFromDirtyJsonString |
Usage
fast_xml_parser
Validate XML, Parse XML to JS/JSON and vice versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback.
Access the package as CQ.Parsers.fast_xml_parser.
const xml = "<event><id>42</id></event>";
const validation = CQ.Parsers.fast_xml_parser.validate(xml);
const event = CQ.Parsers.fast_xml_parser.parse(xml);
validate(xml) reports whether an XML string is valid. parse(xml, options) returns the parsed JavaScript value; pass parser options as the optional second argument.
| Method | Parameters | Returns |
|---|---|---|
validate(xml) | xml (string). | Validation result from fast-xml-parser. |
parse(xml, options) | XML string and optional parser-options object. | Parsed JavaScript value. |
For more information on fast_xml_parser click here.
string2Bytes
Utility to parse a string bytes (ex: 1TB) to bytes (1099511627776) and vice-versa.
Access it as CQ.Parsers.string2Bytes.
const bytes = CQ.Parsers.string2Bytes("1TB");
const displayValue = CQ.Parsers.string2Bytes.format(bytes);
Call the utility with a size string to obtain a byte count. Use .format(bytes) to produce a readable size string.
| Call | Parameters | Returns |
|---|---|---|
string2Bytes(value) | Human-readable size string such as "1TB". | Numeric byte count, or the package’s invalid-input result. |
string2Bytes.format(value, options) | Byte count and optional formatting options. | Human-readable size string. |
For more information on bytes click here.
urlParse
Parse a URL with CQ.Parsers.urlParse:
const parsedUrl = CQ.Parsers.urlParse("https://example.com:8443/path?source=api");
parsedUrl.hostname; // "example.com"
parsedUrl.port; // "8443"
parsedUrl.pathname; // "/path"
The first parameter is the URL string or URL-like value. Package-supported optional parameters may provide a base URL and parsing behavior. The call returns a parsed URL object.
For more information on urlParse click here.
csvjson
CSV conversion helpers are available as CQ.Parsers.csvjson.
const rows = CQ.Parsers.csvjson.toObject("name,score\nAda,10");
const csv = CQ.Parsers.csvjson.toCSV(rows);
| Method | Parameters | Returns |
|---|---|---|
toObject(csv, options) | CSV string and optional conversion settings. | Array of row objects. |
toCSV(rows, options) | Array of objects and optional conversion settings. | CSV string. |
For more information on csvjson, click here.
getObjectFromDirtyJsonString
Extracts a JSON object from a string that contains surrounding non-JSON text. It returns null when no object can be extracted.
const value = CQ.Parsers.getObjectFromDirtyJsonString(
"Remote response: {\"status\": \"ok\"}"
);
The function accepts one string and returns the extracted object. It returns null when it cannot extract an object.
For more information on getObjectFromDirtyJsonString, click here.