HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/.pm2/modules/pm2-logrotate/node_modules/pmx/lib/utils/autocast.js
(function() {
  /**
   * Common strings to cast
   */
  var common_strings = {
    'true': true,
    'false': false,
    'undefined': undefined,
    'null': null,
    'NaN': NaN
  };

  function process(key,value, o) {
    if (typeof(value) == 'object') return;
    o[key] = _cast(value);
  }

  function traverse(o,func) {
    for (var i in o) {
      func.apply(this,[i,o[i], o]);
      if (o[i] !== null && typeof(o[i])=="object") {
        //going on step down in the object tree!!
        traverse(o[i],func);
      }
    }
  }

  function _cast(s) {
    var key;

    // Don't cast Date objects
    if (s instanceof Date) return s;
    if (typeof s == 'boolean') return s;

    // Try to cast it to a number
    if ((key = +s) == key) return key;

    // Try to make it a common string
    for (key in common_strings) {
      if (s === key) return common_strings[key];
    }

    // Give up
    return s;
  }

  /**
   * Given a value, try and cast it
   */
  function autocast(s) {
    if (typeof(s) == 'object') {
      traverse(s, process);
      return s;
    }

    return _cast(s);
  };

  // export
  module.exports = autocast;
}());