UNPKG

cluedin-widget

Version:

This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.

155 lines (125 loc) 3.53 kB
var moment = require('moment'); var addPixel = function (value) { if (!value) { return; } return value + ' px'; }; var formatMinutesFromSeconds = function (seconds) { if (!seconds) { return; } return '~' + Math.floor(seconds / 60) + ' min.'; }; var formatReadingTime = function (wordCound) { if (!wordCound) { return; } return '~' + Math.floor(wordCound / 250) + ' min.'; }; var getPresentationTime = function (wordCound) { if (!wordCound) { return; } var readingTime = Math.floor(wordCound / 250); return Math.floor(readingTime * 3); }; var formatPresentationTime = function (wordCound) { if (!wordCound) { return; } return '~' + getPresentationTime(wordCound) + ' min.'; }; var bytesToSize = function (bytes) { if (!bytes) { return; } if (typeof bytes === 'string') { bytes = parseInt(bytes, 10); } var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes === 0) { return '0 Byte'; } var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; }; module.exports = { formatNumberM: function (value) { if (!value) { return; } var intValue = parseInt(value,10); if(intValue < 1000000) { return intValue.toLocaleString(); } else { return (intValue/1000).toFixed(2) + 'm'; } }, formatNumberAbbreviation: function (value) { if (!value) { return; } var value = parseInt(value, 10); if (value && value <= 10000) { return value.toLocaleString(); } if (value && value >= 10000 && value < 1000000) { value = value / 1000; return (value.toFixed(2) + 'K'); } if (value && value >= 1000000 && value < 1000000000) { value = value / 1000000; return (value.toFixed(2) + 'M'); } if (value && value >= 1000000000) { value = value / 1000000000; return (value.toFixed(2) + 'G') } return value; }, formatNumberKmB: function (value) { if (!value) { return; } var value = parseInt(value, 10); if (value && value <= 1000) { return value.toLocaleString(); } if (value && value >= 1000 && value < 1000000) { value = value / 1000; return (value.toFixed(2) + 'K'); } if (value && value >= 1000000 && value < 1000000000) { value = value / 1000000; return (value.toFixed(2) + 'm'); } if (value && value >= 1000000000) { value = value / 1000000000; return (value.toFixed(2) + 'B') } return value; }, formatDate: function (value) { if (!value) { return; } return moment(value).format('MMMM Do YYYY, h:mm:ss a'); }, /** * @return {string} */ YesOrNo: function (value) { if (!value) { return ''; } return "True" !== value ? 'No' : 'Yes'; }, addPixel: addPixel, formatMinutesFromSeconds: formatMinutesFromSeconds, formatReadingTime: formatReadingTime, formatPresentationTime: formatPresentationTime, getPresentationTime: getPresentationTime, bytesToSize: bytesToSize };