/** * @class ep.i18n * */ /* * @copyright © Copyright 2006-2010, epages GmbH, All Rights Reserved. * * @module ep.i18n * * @revision $Revision: 1.7 $ */ define("ep/i18n", [ "jquery", "ep", "jquery/i18n" ], function ($, ep){ $.extend((ep.i18n = {}),{ /** * Format a number as Bytes. * * The `ep.i18n.formatBytes()` method uses the `jQuery.i18n.formatNumber()` method to format the givn value and * add the correct unit (Byte, kB, MB, GB). * * + default adds '''Byte''' * + value is bigger or equal ''1024'' and smaller than ''1048576'' adds '''kb''' * + value is bigger or equal ''1048576'' and smaller than ''1073741824'' adds '''MB''Ã' * + value is bigger or equal ''1073741824'' adds '''GB''' * * ### Examples * Format an number with default options. * * JavaScript: * * ep.i18n.formatBytes( 12000 ); * * Results: * * 11.72 kB * * Format an number with 4 after decimal places. * * JavaScript: * * ep.i18n.formatBytes( 10240, 4 ); * * Results: * * 10.0000 kB * * Format an number with 2 after decimal places and german language settings. * * JavaScript: * * ep.i18n.formatBytes( 10240, 2, {region: 'de'} ); * * Results: * * 10,00 kB * * * ### Dependencies * * + `ep` * + `jQuery.i18n` * * @param {Number} value A number to format. * @param {Integer} [decimals] A count of after decimal places. * @param {Object} [options] A map of key/values settings like the options of jQuery.i18n.formatNumber(). * * @method formatBytes * @static * @member ep.i18n * * @since 6.11.0 */ formatBytes: function( value, decimals, options ){ if( typeof decimals !== 'number' ){ if( !options ){ options = decimals; } decimals = 2; } var unit = 'Byte'; if( value >= 1073741824 ) { value /= 1073741824; unit = 'GB'; } else if( value >= 1048576 ) { value /= 1048576; unit = 'MB'; } else if( value >= 1024 ) { value /= 1024; unit = 'kB'; } return $.i18n.formatNumber( value, 'n'+decimals, options ) + ' ' + unit; } }); return ep; });