readify 10.0.0 → 11.0.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 +28 -0
- package/README.md +5 -2
- package/lib/readdir.js +34 -27
- package/lib/readify.js +20 -24
- package/package.json +13 -15
package/ChangeLog
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
2026.03.17, v11.0.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 7a5a512 readify: drop support of node < 22
|
|
5
|
+
- affeb7e readify: migrate to ESM
|
|
6
|
+
- e7ae40e readdir: get rid of mock-require
|
|
7
|
+
- b460323 readify: export: default -> named
|
|
8
|
+
- f0ea5c7 readify: get rid of mock-require
|
|
9
|
+
- aebe67e readify: try-to-catch v4.0.5
|
|
10
|
+
- d177938 readify: try-catch v4.0.9
|
|
11
|
+
- beb6869 readify: supertape v12.10.5
|
|
12
|
+
- f7e52c0 readify: putout v42.2.3
|
|
13
|
+
- 9ebc9e9 readify: madrun v13.0.1
|
|
14
|
+
- 7a10046 readify: eslint-plugin-putout v31.1.1
|
|
15
|
+
- 519aaba readify: eslint v10.0.3
|
|
16
|
+
- 611e819 readify: @cloudcmd/formatify v3.0.0
|
|
17
|
+
- 8cf2542 readify: superc8 v12.3.1
|
|
18
|
+
- 22a59d7 readify: putout v37.1.0
|
|
19
|
+
- e59d19f readify: eslint-plugin-putout v23.3.0
|
|
20
|
+
|
|
21
|
+
2024.08.16, v10.0.1
|
|
22
|
+
|
|
23
|
+
feature:
|
|
24
|
+
- cba73a1 readify: @cloudcmd/formatify v2.0.0
|
|
25
|
+
- 76b6045 readify: putout v36.0.3
|
|
26
|
+
- a4597a1 readify: eslint v9.9.0
|
|
27
|
+
- 0511e66 readify: c8 v10.1.2
|
|
28
|
+
|
|
1
29
|
2024.03.29, v10.0.0
|
|
2
30
|
|
|
3
31
|
feature:
|
package/README.md
CHANGED
|
@@ -32,8 +32,9 @@ npm i readify
|
|
|
32
32
|
## Examples
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
import {readify} from 'readify';
|
|
36
|
+
|
|
37
|
+
const {tryToCatch} = require('try-to-catch');
|
|
37
38
|
|
|
38
39
|
const [error, data] = await tryToCatch(readify, '/');
|
|
39
40
|
console.log(data);
|
|
@@ -53,6 +54,7 @@ console.log(data);
|
|
|
53
54
|
readify('/', {
|
|
54
55
|
type: 'raw',
|
|
55
56
|
}).then(console.log);
|
|
57
|
+
|
|
56
58
|
// output
|
|
57
59
|
({
|
|
58
60
|
path: '/',
|
|
@@ -71,6 +73,7 @@ readify('/', {
|
|
|
71
73
|
sort: 'size',
|
|
72
74
|
order: 'desc',
|
|
73
75
|
}).then(console.log);
|
|
76
|
+
|
|
74
77
|
// output
|
|
75
78
|
({
|
|
76
79
|
path: '/',
|
package/lib/readdir.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const tryToCatch = require('try-to-catch');
|
|
7
|
-
const superstat = require('superstat');
|
|
8
|
-
const currify = require('currify');
|
|
1
|
+
import {join, extname} from 'node:path';
|
|
2
|
+
import {readdir as _readdir} from 'node:fs/promises';
|
|
3
|
+
import currify from 'currify';
|
|
4
|
+
import {tryToCatch} from 'try-to-catch';
|
|
5
|
+
import _superstat from 'superstat';
|
|
9
6
|
|
|
10
7
|
const noop = () => {};
|
|
11
8
|
const {assign} = Object;
|
|
12
9
|
|
|
13
|
-
const stat = currify(async (dir, name) => {
|
|
10
|
+
const stat = currify(async (superstat, dir, name) => {
|
|
14
11
|
const full = join(dir, name);
|
|
15
12
|
const [, info = empty()] = await tryToCatch(superstat, full);
|
|
16
13
|
|
|
@@ -19,38 +16,48 @@ const stat = currify(async (dir, name) => {
|
|
|
19
16
|
});
|
|
20
17
|
});
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
export const readdir = async (dir, overrides = {}) => {
|
|
20
|
+
const {
|
|
21
|
+
readdir = _readdir,
|
|
22
|
+
superstat = _superstat,
|
|
23
|
+
} = overrides;
|
|
24
|
+
|
|
23
25
|
const names = await readdir(dir);
|
|
24
26
|
|
|
25
|
-
const statsPromises = names.map(stat(dir));
|
|
27
|
+
const statsPromises = names.map(stat(superstat, dir));
|
|
26
28
|
const stats = await Promise.all(statsPromises);
|
|
27
29
|
|
|
28
30
|
return stats.map(parseStat);
|
|
29
31
|
};
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
}
|
|
33
|
+
const empty = (name) => ({
|
|
34
|
+
name,
|
|
35
|
+
uid: 0,
|
|
36
|
+
mode: 0,
|
|
37
|
+
size: 0,
|
|
38
|
+
mtime: 0,
|
|
39
|
+
isDirectory: noop,
|
|
40
|
+
isSymbolicLink: noop,
|
|
41
|
+
});
|
|
42
42
|
|
|
43
43
|
function parseStat(stat) {
|
|
44
|
-
const {
|
|
44
|
+
const {
|
|
45
|
+
name,
|
|
46
|
+
size,
|
|
47
|
+
mtime,
|
|
48
|
+
mode,
|
|
49
|
+
uid,
|
|
50
|
+
} = stat;
|
|
51
|
+
|
|
45
52
|
const isDir = stat.isDirectory();
|
|
46
53
|
const isLink = stat.isSymbolicLink();
|
|
47
54
|
|
|
48
55
|
return {
|
|
49
56
|
name,
|
|
50
|
-
size
|
|
51
|
-
date:
|
|
52
|
-
owner:
|
|
53
|
-
mode
|
|
57
|
+
size,
|
|
58
|
+
date: mtime,
|
|
59
|
+
owner: uid,
|
|
60
|
+
mode,
|
|
54
61
|
type: getType({
|
|
55
62
|
name,
|
|
56
63
|
isDir,
|
package/lib/readify.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import format from 'format-io';
|
|
2
|
+
import currify from 'currify';
|
|
3
|
+
import {tryToCatch} from 'try-to-catch';
|
|
4
|
+
import sortify from '@cloudcmd/sortify';
|
|
5
|
+
import {formatify} from '@cloudcmd/formatify';
|
|
6
|
+
import _nicki from 'nicki';
|
|
7
|
+
import {readdir as _readdir} from './readdir.js';
|
|
2
8
|
|
|
3
|
-
const process = require('node:process');
|
|
4
9
|
const isUndefined = (a) => typeof a === 'undefined';
|
|
5
|
-
const format = require('format-io');
|
|
6
|
-
const currify = require('currify');
|
|
7
|
-
const tryToCatch = require('try-to-catch');
|
|
8
10
|
|
|
9
|
-
const sortify = require('@cloudcmd/sortify');
|
|
10
|
-
const formatify = require('@cloudcmd/formatify');
|
|
11
|
-
|
|
12
|
-
const WIN = process.platform === 'win32';
|
|
13
|
-
|
|
14
|
-
const readdir = require('./readdir');
|
|
15
|
-
const nicki = !WIN && require('nicki');
|
|
16
11
|
const replaceProperty = currify(_replaceProperty);
|
|
17
12
|
const ifRaw = currify(_ifRaw);
|
|
18
13
|
const isString = (a) => typeof a === 'string';
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async function readify(path, options = {}) {
|
|
15
|
+
export const readify = async (path, options = {}) => {
|
|
23
16
|
const {
|
|
24
17
|
type,
|
|
25
18
|
order,
|
|
26
19
|
sort = 'name',
|
|
20
|
+
nicki = _nicki,
|
|
21
|
+
readdir = _readdir,
|
|
27
22
|
} = options;
|
|
28
23
|
|
|
29
24
|
check({
|
|
@@ -38,8 +33,10 @@ async function readify(path, options = {}) {
|
|
|
38
33
|
const sorted = sortify({sort, order}, names);
|
|
39
34
|
const formated = ifRaw(type, formatify, sorted);
|
|
40
35
|
|
|
41
|
-
return await fillJSON(path, type, formated
|
|
42
|
-
|
|
36
|
+
return await fillJSON(path, type, formated, {
|
|
37
|
+
nicki,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
43
40
|
|
|
44
41
|
function check({path, type, sort, order}) {
|
|
45
42
|
if (!isString(path))
|
|
@@ -62,7 +59,7 @@ function _ifRaw(type, fn, a) {
|
|
|
62
59
|
return fn(a);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
async function fillJSON(dir, type, files) {
|
|
62
|
+
async function fillJSON(dir, type, files, {nicki}) {
|
|
66
63
|
const path = format.addSlashToEnd(dir);
|
|
67
64
|
|
|
68
65
|
if (type === 'raw')
|
|
@@ -71,7 +68,9 @@ async function fillJSON(dir, type, files) {
|
|
|
71
68
|
files,
|
|
72
69
|
};
|
|
73
70
|
|
|
74
|
-
const newFiles = await changeUIDToName(files
|
|
71
|
+
const newFiles = await changeUIDToName(files, {
|
|
72
|
+
nicki,
|
|
73
|
+
});
|
|
75
74
|
|
|
76
75
|
return {
|
|
77
76
|
path,
|
|
@@ -79,13 +78,10 @@ async function fillJSON(dir, type, files) {
|
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
async function changeUIDToName(files) {
|
|
83
|
-
if (!nicki)
|
|
84
|
-
return files;
|
|
85
|
-
|
|
81
|
+
async function changeUIDToName(files, {nicki}) {
|
|
86
82
|
const [e, names] = await tryToCatch(nicki);
|
|
87
83
|
|
|
88
|
-
if (e)
|
|
84
|
+
if (e || !names)
|
|
89
85
|
return files;
|
|
90
86
|
|
|
91
87
|
const replaceOwner = replaceProperty(names, 'owner');
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "readify",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Read directory content with file attributes: size, date, owner, mode",
|
|
7
7
|
"homepage": "http://github.com/coderaiser/readify",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git://github.com/coderaiser/readify.git"
|
|
10
|
+
"url": "git+https://github.com/coderaiser/readify.git"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"lint": "madrun lint",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"watcher": "madrun watcher"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@cloudcmd/formatify": "^
|
|
23
|
+
"@cloudcmd/formatify": "^3.0.0",
|
|
24
24
|
"@cloudcmd/sortify": "^2.0.0",
|
|
25
25
|
"currify": "^4.0.0",
|
|
26
26
|
"format-io": "^2.0.0",
|
|
27
27
|
"nicki": "^6.0.0",
|
|
28
28
|
"shortdate": "^2.0.0",
|
|
29
29
|
"superstat": "^2.0.0",
|
|
30
|
-
"try-to-catch": "^
|
|
30
|
+
"try-to-catch": "^4.0.5"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
33
33
|
"read",
|
|
@@ -44,19 +44,17 @@
|
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"main": "lib/readify.js",
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
47
|
+
"node": ">=22"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"
|
|
53
|
-
"eslint-plugin-putout": "^22.5.0",
|
|
54
|
-
"madrun": "^10.0.1",
|
|
55
|
-
"mock-require": "^3.0.2",
|
|
50
|
+
"eslint": "^10.0.3",
|
|
51
|
+
"eslint-plugin-putout": "^31.1.1",
|
|
52
|
+
"madrun": "^13.0.1",
|
|
56
53
|
"nodemon": "^3.1.0",
|
|
57
|
-
"putout": "^
|
|
58
|
-
"
|
|
59
|
-
"
|
|
54
|
+
"putout": "^42.2.3",
|
|
55
|
+
"superc8": "^12.3.1",
|
|
56
|
+
"supertape": "^12.10.5",
|
|
57
|
+
"try-catch": "^4.0.9"
|
|
60
58
|
},
|
|
61
59
|
"publishConfig": {
|
|
62
60
|
"access": "public"
|