@cloudcmd/formatify 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog +5 -0
- package/README.md +2 -0
- package/lib/formatify.js +18 -6
- package/lib/shorttime.js +9 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -48,12 +48,14 @@ formatify(files);
|
|
|
48
48
|
date: '12.01.2017',
|
|
49
49
|
owner: 0,
|
|
50
50
|
mode: 'rw- rw- r--',
|
|
51
|
+
time: '10:30:30',
|
|
51
52
|
}, {
|
|
52
53
|
name: 'readify.js',
|
|
53
54
|
size: '1.59kb',
|
|
54
55
|
date: '12.01.2017',
|
|
55
56
|
owner: 0,
|
|
56
57
|
mode: 'rw- rw- r--',
|
|
58
|
+
time: '10:30:30',
|
|
57
59
|
}];
|
|
58
60
|
```
|
|
59
61
|
|
package/lib/formatify.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import format from 'format-io';
|
|
2
2
|
import shortdate from 'shortdate';
|
|
3
|
+
import {shorttime} from './shorttime.js';
|
|
3
4
|
|
|
4
5
|
const {assign} = Object;
|
|
5
6
|
const {isArray} = Array;
|
|
@@ -8,7 +9,7 @@ export const formatify = (files) => {
|
|
|
8
9
|
check(files);
|
|
9
10
|
|
|
10
11
|
return files
|
|
11
|
-
.map(
|
|
12
|
+
.map(createReplaceDate())
|
|
12
13
|
.map(replaceMode)
|
|
13
14
|
.map(replaceSize);
|
|
14
15
|
};
|
|
@@ -18,15 +19,26 @@ function check(files) {
|
|
|
18
19
|
throw Error('files should be an array!');
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const createReplaceDate = () => (stat) => {
|
|
23
|
+
if (!stat.date)
|
|
24
|
+
return {
|
|
25
|
+
...stat,
|
|
26
|
+
date: '',
|
|
27
|
+
time: '',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const date = shortdate(stat.date, {
|
|
23
31
|
order: 'little',
|
|
24
32
|
});
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
const time = shorttime(stat.date);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...stat,
|
|
27
38
|
date,
|
|
28
|
-
|
|
29
|
-
}
|
|
39
|
+
time,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
30
42
|
|
|
31
43
|
function replaceMode(stat) {
|
|
32
44
|
const octal = Number(stat.mode).toString(8);
|
package/lib/shorttime.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const maybeAddZero = (a) => a >= 10 ? a : `0${a}`;
|
|
2
|
+
|
|
3
|
+
export function shorttime(date) {
|
|
4
|
+
const hours = date.getHours();
|
|
5
|
+
const minutes = date.getMinutes();
|
|
6
|
+
const seconds = date.getSeconds();
|
|
7
|
+
|
|
8
|
+
return `${maybeAddZero(hours)}:${maybeAddZero(minutes)}:${maybeAddZero(seconds)}`;
|
|
9
|
+
}
|