-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.js
More file actions
30 lines (26 loc) · 779 Bytes
/
lib.js
File metadata and controls
30 lines (26 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// For an RFC 1123 (HTTP header date) date
function formatDate(date) {
return (date || new Date()).toGMTString()
}
// Translate size in bytes into a human easy format
// Example: 17314856 B into 17,31 MB
function humanSizeFormat(size) {
var formats = ['B', 'kB', 'MB', 'GB', 'TB'], pos = 0;
while (size >= 1000 && formats[pos + 1]) {
size = Math.round(size / 10) / 100;
++pos
}
return formatNumber(size) + ' ' + formats[pos]
}
// Translate standard javascript number format into
// the user's locale number format.
// Example: 17314856.4874 into 17.314.856,4874
function formatNumber(number) {
return (+number).toLocaleString()
}
// Export functions
module.exports = {
formatDate: formatDate,
humanSizeFormat: humanSizeFormat,
formatNumber: formatNumber
}