@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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2026.03.20, v3.1.0
2
+
3
+ feature:
4
+ - b7efee2 @cloudcmd/formatify: add ability to return time (coderaiser/cloudcmd#230)
5
+
1
6
  2026.03.17, v3.0.0
2
7
 
3
8
  feature:
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(replaceDate)
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
- function replaceDate(stat) {
22
- const date = !stat.date ? '' : shortdate(stat.date, {
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
- return assign(stat, {
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);
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcmd/formatify",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "format directory content",