Using utility methods in Calculators

The below are some utils methods that can be used in a Calculator step.

Datatype conversion

You can convert a value to a different datatype:

let newValue = utils.convert(val, toType, format);

Objects

You can copy an object:

let newObj = utils.copy(obj);

You can hash an object with an algorithm:

let HashObj = utils.crypto.createHash(algorithm, options);

You can create an HMAC for an object:

let HmacObj = utils.crypto.createHmac(algorithm, key, options);

You can create a cryptographically artificial random data with the byte size:

let RandomData = utils.crypto.randomBytes(size);

You can merge a source object to a destination object:

let MergeObj = utils.merge(a, b, options);

Schemas:

You can generate a schema from a JSON object:

let newSchema = utils.schema.generateSchemaFromJSON(obj);

You can flatten a schema:

let newSchema = utils.schema.flattenSchema(schema, options);

You can validate a schema in a document:

let validateSchema = utils.schema.validate(document, schema, coerce, showAllErrors);

You can merge schemas:

let mergeSchema = utils.schema.mergeSchemas(schemas);

Escape XML Entities

You can escape XML entities by replacing them:

let safeXML= utils.escapeXml(xmlString);

Exclude Empty Arrays:

return Object.entries(input.record.fieldName).length = 0

Convert runDate to an epoch time:

input.parameters.fromDate = utils.dayjs(input.runInfo.lastRun).valueOf()

The following are a list of Utils functions that can be used:

  'concatBuffer',
  'constructor',      'convert',                'copy',
  'createBuffer',     'createReadableStream',   'cryptoCreateHash',
  'cryptoCreateHmac', 'dayjs',                  'deepEqual',
  'duration',         'escapeXml',              'flattenSchema',
  'formatDate',       'generateSchemaFromJSON', 'generateUUID',
  'hasOwnProperty',   'hash',                   'isArray',
  'isAssigned',       'isBoolean',              'isBuffer',
  'isDate',           'isEmptyObject',          'isFloat',
  'isInteger',        'isNumber',               'isObject',
  'isPrototypeOf',    'isString',               'jsonGet',
  'jsonSet',          'jsonWalk',               'jwtSign',
  'jwtVerify',        'mergeObjects',           'mergeSchemas',
  'parseAddress',     'propertyIsEnumerable',   'randomBytes',
  'round',            'toLocaleString',         'toString',
  'toposort',         'validateSchema',         'valueOf',
  'xsdToJsonSchema'

Byte buffers in Calculators

Using DayJS in Calculators

Miscellaneous Calculator Functions