object to convert X-10 house codes from numbers to strings and back
488249
function HouseCode(houseCode) {
	this.raw = null;

	switch (typeof houseCode) {
	case "string":
		if (houseCode !== "" && houseCode.length === 1) {
			var index = houseCode.charCodeAt(0) - 65;
			if ((index >= 0) && (index <= (deviceCodes.length - 1))) {
				this.raw = deviceCodes[index];
			} else {
				throw new Error("House code string out of range.");
			}
		} else {
			throw new Error("Invalid house code.");
		}
		break;
	default:
		if (deviceCodes.indexOf(houseCode) !== -1) {
			this.raw = houseCode;
		} else {
			throw new Error("House code number out of range.");
		}
		break;
	}
	return this.raw;
}
861139
function numberToString (x) { // avoids scientific notation for too large and too small numbers

    if (isString (x)) return x

    if (Math.abs (x) < 1.0) {
        const s = x.toString ()
        const e = parseInt (s.split ('e-')[1])
        const neg = (s[0] === '-')
        if (e) {
            x *= Math.pow (10, e-1)
            x = (neg ? '-' : '') + '0.' + (new Array (e)).join ('0') + x.toString ().substring (neg ? 3 : 2)
        }
    } else {
        let e = parseInt (x.toString ().split ('+')[1])
        if (e > 20) {
            e -= 20
            x /= Math.pow (10, e)
            x += (new Array (e+1)).join ('0')
        }
    }
    return x.toString ()
}
726706
def tostr(object, encoding=None):
    
    if isinstance(object, basestring):
        if encoding is None:
            return object
        else:
            return object.encode(encoding)
    if isinstance(object, tuple):
        s = ['(']
        for item in object:
            if isinstance(item, basestring):
                s.append(item)
            else:
                s.append(tostr(item))
            s.append(', ')
        s.append(')')
        return ''.join(s)
    if isinstance(object, list):
        s = ['[']
        for item in object:
            if isinstance(item, basestring):
                s.append(item)
            else:
                s.append(tostr(item))
            s.append(', ')
        s.append(']')
        return ''.join(s)
    if isinstance(object, dict):
        s = ['{']
        for item in object.items():
            if isinstance(item[0], basestring):
                s.append(item[0])
            else:
                s.append(tostr(item[0]))
            s.append(' = ')
            if isinstance(item[1], basestring):
                s.append(item[1])
            else:
                s.append(tostr(item[1]))
            s.append(', ')
        s.append('}')
        return ''.join(s)
    try:
        return unicode(object)
    except:
        return str(object)
639266
def to_str(opts={})
      @unique_table = {}
      @count_objects = 0
      @object_refs = 0

      @written_object_count = 0
      @object_table = []

      @offsets = []

      binary_str = "bplist00"

      @object_refs = count_object_refs(opts[:root])

      opts[:root].to_binary(self)

      next_offset = 8
      offsets = @object_table.map do |object|
        offset = next_offset
        next_offset += object.bytesize
        offset
      end
      binary_str << @object_table.join

      table_offset = next_offset
      offset_size = Binary.bytes_needed(table_offset)

      if offset_size < 8
        # Fast path: encode the entire offset array at once.
        binary_str << offsets.pack((%w(C n N N)[offset_size - 1]) + '*')
      else
        # Slow path: host may be little or big endian, must pack each offset
        # separately.
        offsets.each do |offset|
          binary_str << "#{Binary.pack_it_with_size(offset_size,offset)}"
        end
      end

      binary_str << [offset_size, object_ref_size(@object_refs)].pack("x6CC")
      binary_str << [@object_table.size].pack("x4N")
      binary_str << [0].pack("x4N")
      binary_str << [table_offset].pack("x4N")

      binary_str
    end
836386
function transformPropertiesToCamelCase (object) {
  var output = {}

  for (var _key in object) {
    if (typeof object === 'string') { return object.replace(' !important', '') }
    var key = _key
    var value = object[_key]
    if (~key.indexOf('-')) {
      var splittedKeys = key.split('-')
      splittedKeys = splittedKeys.map(function (v, i) {
        return i > 0
        // UCFIRST if ! first element
        ? v.charAt(0).toUpperCase() + v.substr(1) : v
      })
      key = splittedKeys.join('')
    }
    output[key] = transformPropertiesToCamelCase(value)
  }
  return output
}
38011
def arbitrary_object_to_string(a_thing):
    """"""
    # is it None?
    if a_thing is None:
        return ''
    # is it already a string?
    if isinstance(a_thing, six.string_types):
        return a_thing
    if six.PY3 and isinstance(a_thing, six.binary_type):
        try:
            return a_thing.decode('utf-8')
        except UnicodeDecodeError:
            pass
    # does it have a to_str function?
    try:
        return a_thing.to_str()
    except (AttributeError, KeyError, TypeError):
        # AttributeError - no to_str function?
        # KeyError - DotDict has no to_str?
        # TypeError - problem converting
        # nope, no to_str function
        pass
    # is this a type proxy?
    try:
        return arbitrary_object_to_string(a_thing.a_type)
    except (AttributeError, KeyError, TypeError):
        #
        # nope, no a_type property
        pass
    # is it a built in?
    try:
        return known_mapping_type_to_str[a_thing]
    except (KeyError, TypeError):
        # nope, not a builtin
        pass
    # is it something from a loaded module?
    try:
        if a_thing.__module__ not in ('__builtin__', 'builtins', 'exceptions'):
            if a_thing.__module__ == "__main__":
                module_name = (
                    sys.modules['__main__']
                    .__file__[:-3]
                    .replace('/', '.')
                    .strip('.')
                )
            else:
                module_name = a_thing.__module__
            return "%s.%s" % (module_name, a_thing.__name__)
    except AttributeError:
        # nope, not one of these
        pass
    # maybe it has a __name__ attribute?
    try:
        return a_thing.__name__
    except AttributeError:
        # nope, not one of these
        pass
    # punt and see what happens if we just cast it to string
    return str(a_thing)
77593
function fromCodePoint(cp) {
        return (cp < 0x10000) ? String.fromCharCode(cp) :
            String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
            String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
    }
558597
function (num) {
  for (var ext = '', i = 0; i < 4; i++) {
    ext = String.fromCharCode(num & 0xFF) + ext
    num >>= 8
  }
  return ext
}
283367
private Object convertStringToNearestObjectType(String value) {
    switch (value) {
      case "true":
        return true;
      case "false":
        return false;
      default: {
        if (NumberUtils.isParsable(value)) {
          return Integer.parseInt(value);
        }
        return value;
      }
    }
  }
67133
def _encode_numbers(self, obj):
        """"""

        # strict checks first - for speed
        if obj.__class__ is int:
            if abs(obj) > JAVASCRIPT_MAXINT:
                raise ValueError('Number out of range: {!r}'.format(obj))
            return str(obj)

        if obj.__class__ is float:
            if isnan(obj):
                raise ValueError('NaN is not supported')
            if isinf(obj):
                raise ValueError('Infinity is not supported')
            return repr(obj)

        # more in-depth class analysis last
        if isinstance(obj, int):
            obj = int(obj)
            if abs(obj) > JAVASCRIPT_MAXINT:
                raise ValueError('Number out of range: {!r}'.format(obj))
            return str(obj)

        if isinstance(obj, float):
            if isnan(obj):
                raise ValueError('NaN is not supported')
            if isinf(obj):
                raise ValueError('Infinity is not supported')
            return repr(obj)

        if isinstance(obj, Decimal):
            return '"' + str(obj) + '"'

        # for complex and other Numbers
        return self._encode(self.default(obj))
321995
def base10_integer_to_basek_string(k, x):
    """"""
    if not (2 <= k <= max_k_labeled):
        raise ValueError("k must be in range [2, %d]: %s"
                         % (max_k_labeled, k))
    return ((x == 0) and numerals[0]) or \
        (base10_integer_to_basek_string(k, x // k).\
         lstrip(numerals[0]) + numerals[x % k])
920729
def to_hex_string(data):
    '''  '''
    if isinstance(data, int):
        return '%02X' % data
    return ':'.join([('%02X' % o) for o in data])
976597
def obj2str(obj):
    """"""
    if isinstance(obj, str_types):
        return obj.encode("utf-8")
    elif isinstance(obj, pathlib.Path):
        return obj2str(str(obj))
    elif isinstance(obj, (bool, int, float)):
        return str(obj).encode("utf-8")
    elif obj is None:
        return b"none"
    elif isinstance(obj, np.ndarray):
        return obj.tostring()
    elif isinstance(obj, tuple):
        return obj2str(list(obj))
    elif isinstance(obj, list):
        return b"".join(obj2str(o) for o in obj)
    elif isinstance(obj, dict):
        return obj2str(list(obj.items()))
    elif hasattr(obj, "identifier"):
        return obj2str(obj.identifier)
    elif isinstance(obj, h5py.Dataset):
        return obj2str(obj[0])
    else:
        raise ValueError("No rule to convert object '{}' to string.".
                         format(obj.__class__))
42698
def _decrypt_object(obj, translate_newlines=False):
    '''
    
    '''
    if salt.utils.stringio.is_readable(obj):
        return _decrypt_object(obj.getvalue(), translate_newlines)
    if isinstance(obj, six.string_types):
        try:
            return _decrypt_ciphertext(obj,
                                       translate_newlines=translate_newlines)
        except (fernet.InvalidToken, TypeError):
            return obj

    elif isinstance(obj, dict):
        for key, value in six.iteritems(obj):
            obj[key] = _decrypt_object(value,
                                       translate_newlines=translate_newlines)
        return obj
    elif isinstance(obj, list):
        for key, value in enumerate(obj):
            obj[key] = _decrypt_object(value,
                                       translate_newlines=translate_newlines)
        return obj
    else:
        return obj
335435
function objectToString(object, tabs) {
            var result = [];
            var keys = Object.keys(object);

            keys.forEach(function (key, keyIndex) {
                var line;
                var formatedKey;

                if (-1 < key.indexOf('@')) {
                    formatedKey = '\'' + key + '\'';
                } else {
                    formatedKey = key;
                }

                if (typeof object[key] === 'object') {
                    if (Array.isArray(object[key])) {
                        var newTabs = (tabs + 1);

                        line = getTabs(tabs) + '' + formatedKey + ': [';

                        object[key].forEach(function (item, itemIndex) {
                            if (typeof item === 'object') {
                                line += "\n" + getTabs(newTabs) + '{';
                                line += "\n" + objectToString(item, (newTabs + 1));
                                line += "\n" + getTabs(newTabs) + '}';
                            } else if (typeof item === 'string') {
                                line += "\n" + getTabs(newTabs) + '\'' + addslashes(item) + '\'';
                            } else if (typeof item === 'boolean') {
                                line += "\n" + getTabs(newTabs) + '' + item;
                            } else if (typeof item === 'number') {
                                line += "\n" + getTabs(newTabs) + '' + item;
                            }

                            if (itemIndex < (object[key].length - 1)) {
                                line += ',';
                            }
                        });

                        line += "\n" + getTabs(tabs) + ']';
                    } else {
                        line = getTabs(tabs) + '' + formatedKey + ': {' + "\n";
                        line += objectToString(object[key], (tabs + 1));
                        line += "\n" + getTabs(tabs) + '}';
                    }
                } else if (typeof object[key] === 'string') {
                    line = getTabs(tabs) + '' + formatedKey + ': \'' + addslashes(object[key]) + '\'';
                } else if (typeof object[key] === 'boolean') {
                    line = getTabs(tabs) + '' + formatedKey + ': ' + object[key];
                } else if (typeof object[key] === 'number') {
                    line = getTabs(tabs) + '' + formatedKey + ': ' + object[key];
                }

                if (keyIndex < (keys.length - 1)) {
                    line += ',';
                }

                result.push(line);
            });

            return result.join("\n");
        }
301275
def to_text_string(obj, encoding=None):
    """"""
    if PY2:
        # Python 2
        if encoding is None:
            return unicode(obj)
        else:
            return unicode(obj, encoding)
    else:
        # Python 3
        if encoding is None:
            return str(obj)
        elif isinstance(obj, str):
            # In case this function is not used properly, this could happen
            return obj
        else:
            return str(obj, encoding)
1287419
def x10_housecode(self):
        """"""
        housecode = None
        if self.is_x10:
            housecode = insteonplm.utils.byte_to_housecode(self.addr[1])
        return housecode