lib/object.js
function calculate_sizeof(input, weak_map) {

		var bytes,
		    type = typeof input,
		    key;

		if (type == 'string') {
			return input.length * 2;
		} else if (type == 'number') {
			return 8;
		} else if (type == 'boolean') {
			return 4;
		} else if (type == 'symbol') {
			return (input.toString().length - 8) * 2;
		} else if (input == null) {
			return 0;
		}

		// If this has already been seen, skip the actual value
		if (weak_map.get(input)) {
			return 0;
		}

		weak_map.set(input, true);

		if (typeof input[Blast.sizeofSymbol] == 'function') {
			try {
				return input[Blast.sizeofSymbol]();
			} catch (err) {
				// Continue;
			}
		}

		bytes = 0;

		if (Array.isArray(input)) {
			type = 'array';
		} else if (Blast.isNode && Buffer.isBuffer(input)) {
			return input.length;
		}

		for (key in input) {

			// Skip properties coming from the prototype
			if (!Object.hasOwnProperty.call(input, key)) {
				continue;
			}

			// Each entry is a reference to a certain place in the memory,
			// on 64bit devices this will be 8 bytes
			bytes += 8;

			if (type == 'array' && Number(key) > -1) {
				// Don't count array indices
			} else {
				bytes += key.length * 2;
			}

			bytes += calculate_sizeof(input[key], weak_map);
		}

		return bytes;
	}
function calculate_sizeof(input, weak_map) {

		var bytes,
		    type = typeof input,
		    key;

		if (type == 'string') {
			return input.length * 2;
		} else if (type == 'number') {
			return 8;
		} else if (type == 'boolean') {
			return 4;
		} else if (type == 'symbol') {
			return (input.toString().length - 8) * 2;
		} else if (input == null) {
			return 0;
		}

		// If this has already been seen, skip the actual value
		if (weak_map.get(input)) {
			return 0;
		}

		weak_map.set(input, true);

		if (typeof input[Blast.sizeofSymbol] == 'function') {
			try {
				return input[Blast.sizeofSymbol]();
			} catch (err) {
				// Continue;
			}
		}

		bytes = 0;

		if (Array.isArray(input)) {
			type = 'array';
		} else if (Blast.isNode && Buffer.isBuffer(input)) {
			return input.length;
		}

		for (key in input) {

			// Skip properties coming from the prototype
			if (!Object.hasOwnProperty.call(input, key)) {
				continue;
			}

			// Each entry is a reference to a certain place in the memory,
			// on 64bit devices this will be 8 bytes
			bytes += 8;

			if (type == 'array' && Number(key) > -1) {
				// Don't count array indices
			} else {
				bytes += key.length * 2;
			}

			bytes += calculate_sizeof(input[key], weak_map);
		}

		return bytes;
	}
function calculate_sizeof ( input , weak_map ) { var bytes , type = typeof input , key ; if ( type == 'string' ) { return input . length * 2 ; } else if ( type == 'number' ) { return 8 ; } else if ( type == 'boolean' ) { return 4 ; } else if ( type == 'symbol' ) { return ( input . toString ( ) . length - 8 ) * 2 ; } else if ( input == null ) { return 0 ; } // If this has already been seen, skip the actual value if ( weak_map . get ( input ) ) { return 0 ; } weak_map . set ( input , true ) ; if ( typeof input [ Blast . sizeofSymbol ] == 'function' ) { try { return input [ Blast . sizeofSymbol ] ( ) ; } catch ( err ) { // Continue; } } bytes = 0 ; if ( Array . isArray ( input ) ) { type = 'array' ; } else if ( Blast . isNode && Buffer . isBuffer ( input ) ) { return input . length ; } for ( key in input ) { // Skip properties coming from the prototype if ( ! Object . hasOwnProperty . call ( input , key ) ) { continue ; } // Each entry is a reference to a certain place in the memory, // on 64bit devices this will be 8 bytes bytes += 8 ; if ( type == 'array' && Number ( key ) > - 1 ) { // Don't count array indices } else { bytes += key . length * 2 ; } bytes += calculate_sizeof ( input [ key ] , weak_map ) ; } return bytes ; }
Calculate the size of a variable

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.6.0
@version  0.6.0

@param    {Mixed}    input
@param    {WeakMap}  weak_map

@return   {Number}
Calculate the size of a variable