@cloudcmd/formatify 2.0.1 → 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 +19 -0
- package/README.md +4 -0
- package/lib/formatify.js +26 -13
- package/lib/shorttime.js +9 -0
- package/package.json +11 -11
package/ChangeLog
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
2026.03.20, v3.1.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- b7efee2 @cloudcmd/formatify: add ability to return time (coderaiser/cloudcmd#230)
|
|
5
|
+
|
|
6
|
+
2026.03.17, v3.0.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- ef0d29b @cloudcmd/formatify: export: default -> named
|
|
10
|
+
- 42be3e4 @cloudcmd/formatify: migrate to ESM
|
|
11
|
+
- 563ac54 @cloudcmd/formatify: drop support of node < 22
|
|
12
|
+
- c188667 @cloudcmd/formatify: try-catch v4.0.9
|
|
13
|
+
- 441ca8f @cloudcmd/formatify: supertape v12.10.5
|
|
14
|
+
- e821920 @cloudcmd/formatify: putout v42.2.3
|
|
15
|
+
- 8bd76a4 @cloudcmd/formatify: madrun v13.0.1
|
|
16
|
+
- 4a7d093 @cloudcmd/formatify: eslint-plugin-putout v31.1.1
|
|
17
|
+
- e941576 @cloudcmd/formatify: eslint v10.0.3
|
|
18
|
+
- b0c23f3 @cloudcmd/formatify: superc8 v12.3.1
|
|
19
|
+
|
|
1
20
|
2024.08.16, v2.0.1
|
|
2
21
|
|
|
3
22
|
fix:
|
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ npm i @cloudcmd/formatify --save
|
|
|
24
24
|
## Examples
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
|
+
import {formatify} from '@cloudcmd/formatify';
|
|
28
|
+
|
|
27
29
|
const files = [{
|
|
28
30
|
name: 'sortify.js',
|
|
29
31
|
size: 3538,
|
|
@@ -46,12 +48,14 @@ formatify(files);
|
|
|
46
48
|
date: '12.01.2017',
|
|
47
49
|
owner: 0,
|
|
48
50
|
mode: 'rw- rw- r--',
|
|
51
|
+
time: '10:30:30',
|
|
49
52
|
}, {
|
|
50
53
|
name: 'readify.js',
|
|
51
54
|
size: '1.59kb',
|
|
52
55
|
date: '12.01.2017',
|
|
53
56
|
owner: 0,
|
|
54
57
|
mode: 'rw- rw- r--',
|
|
58
|
+
time: '10:30:30',
|
|
55
59
|
}];
|
|
56
60
|
```
|
|
57
61
|
|
package/lib/formatify.js
CHANGED
|
@@ -1,37 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
import format from 'format-io';
|
|
2
|
+
import shortdate from 'shortdate';
|
|
3
|
+
import {shorttime} from './shorttime.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
+
const {assign} = Object;
|
|
6
|
+
const {isArray} = Array;
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
export const formatify = (files) => {
|
|
7
9
|
check(files);
|
|
8
10
|
|
|
9
11
|
return files
|
|
10
|
-
.map(
|
|
12
|
+
.map(createReplaceDate())
|
|
11
13
|
.map(replaceMode)
|
|
12
14
|
.map(replaceSize);
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
function check(files) {
|
|
16
|
-
if (!
|
|
18
|
+
if (!isArray(files))
|
|
17
19
|
throw Error('files should be an array!');
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const createReplaceDate = () => (stat) => {
|
|
23
|
+
if (!stat.date)
|
|
24
|
+
return {
|
|
25
|
+
...stat,
|
|
26
|
+
date: '',
|
|
27
|
+
time: '',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const date = shortdate(stat.date, {
|
|
22
31
|
order: 'little',
|
|
23
32
|
});
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
const time = shorttime(stat.date);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...stat,
|
|
26
38
|
date,
|
|
27
|
-
|
|
28
|
-
}
|
|
39
|
+
time,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
29
42
|
|
|
30
43
|
function replaceMode(stat) {
|
|
31
44
|
const octal = Number(stat.mode).toString(8);
|
|
32
45
|
const mode = format.permissions.symbolic(octal);
|
|
33
46
|
|
|
34
|
-
return
|
|
47
|
+
return assign(stat, {
|
|
35
48
|
mode,
|
|
36
49
|
});
|
|
37
50
|
}
|
|
@@ -39,7 +52,7 @@ function replaceMode(stat) {
|
|
|
39
52
|
function replaceSize(stat) {
|
|
40
53
|
const size = format.size(stat.size);
|
|
41
54
|
|
|
42
|
-
return
|
|
55
|
+
return assign(stat, {
|
|
43
56
|
size,
|
|
44
57
|
});
|
|
45
58
|
}
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcmd/formatify",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "format directory content",
|
|
7
7
|
"homepage": "http://github.com/cloudcmd/formatify",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git://github.com/cloudcmd/formatify.git"
|
|
10
|
+
"url": "git+https://github.com/cloudcmd/formatify.git"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"lint": "madrun lint",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"main": "lib/formatify.js",
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">=22"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"c8": "^10.1.2",
|
|
43
42
|
"coveralls": "^3.0.0",
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"eslint-plugin-putout": "^
|
|
46
|
-
"madrun": "^
|
|
43
|
+
"eslint": "^10.0.3",
|
|
44
|
+
"eslint-plugin-putout": "^31.1.1",
|
|
45
|
+
"madrun": "^13.0.1",
|
|
47
46
|
"mkdirp": "^3.0.1",
|
|
48
47
|
"nodemon": "^3.1.4",
|
|
49
|
-
"putout": "^
|
|
50
|
-
"
|
|
51
|
-
"
|
|
48
|
+
"putout": "^42.2.3",
|
|
49
|
+
"superc8": "^12.3.1",
|
|
50
|
+
"supertape": "^12.10.5",
|
|
51
|
+
"try-catch": "^4.0.9"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|