MCPcopy Create free account
hub / github.com/PolymathNetwork/polymath-core / _cast

Function _cast

CLI/commands/helpers/csv.js:5–24  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

3const web3Utils = require('web3-utils');
4
5function _cast(obj) {
6 if (/^(\-|\+)?([1-9]+[0-9]*)$/.test(obj)) { // Int
7 obj = parseInt(obj);
8 }
9 else if (/^[+-]?([0-9]*[.])?[0-9]+$/.test(obj)) { // Float
10 obj = parseFloat(obj);
11 }
12 else if (/^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/.test(obj)) { // Datetime
13 var matches = /^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/.exec(obj);
14 var composedDate = new Date(matches[3], matches[1] - 1, matches[2]);
15 var timestampDate = composedDate.getTime();
16 obj = timestampDate / 1000;
17 }
18 else if (obj.toLowerCase() === "true" || obj.toLowerCase() === "false") { // Boolean
19 obj = JSON.parse(obj.toLowerCase());
20 } else if (web3Utils.isAddress(obj)) {
21 obj = web3Utils.toChecksumAddress(obj);
22 }
23 return obj;
24}
25
26function parse(_csvFilePath, _batchSize) {
27 // Read file

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected