# Using utility methods in Calculators

**URL:** <https://community.synatic.com/t/using-utility-methods-in-calculators/185>\
**Category:** Calculators\
**Tags:** calculator, helper-functions\
**Created:** [February 17, 2022, 12:41pm UTC](https://community.synatic.com/t/using-utility-methods-in-calculators/185 "2022-02-17T12:41:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![navessa](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.synatic.com/navessa/32/58_2.png) [@navessa](https://community.synatic.com/u/navessa)\
**Post date:** [February 17, 2022, 12:41pm UTC](https://community.synatic.com/t/using-utility-methods-in-calculators/185/1 "2022-02-17T12:41:25Z")

</div>

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:

```auto
  '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](https://community.synatic.com/t/byte-buffers-in-calculators/60)

[Using DayJS in Calculators](https://community.synatic.com/t/using-dayjs-in-calculators/48)

[Miscellaneous Calculator Functions](https://community.synatic.com/t/miscellaneous-calculator-functions/64)
