recently-modified-files 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Codecov Status][codecov-image]][codecov-url]
6
6
  [![Standard][standard-image]][standard-url]
7
7
 
8
- > Gets a list of recently modified files
8
+ > Gets a list of recently modified files in a dir
9
9
 
10
10
  ## Install
11
11
 
@@ -19,25 +19,35 @@ npm install --save recently-modified-files
19
19
  import rmf from 'recently-modified-files'
20
20
  ```
21
21
 
22
- ### `rmf(path, fn)`
22
+ ### `rmf(dir, fn)`
23
23
 
24
24
  **params**
25
25
 
26
- - `path` {string} The path to test for files
26
+ - `dir` {string} The dir to test for files
27
27
  - `fn` {Function} Callback, the arguments are
28
28
  - `err` {Error} Possible exception or null
29
29
  - `files` {Array} An array with the names of the files where the first one is the most recently modified file or an empty array when there are no files
30
30
 
31
- ### `const filenames = rmf.sync(path)`
31
+ ### `const filenames = rmf.sync(dir)`
32
32
 
33
33
  **params**
34
34
 
35
- - `path` {string} The path to test for files
35
+ - `dir` {string} The path to test for files
36
36
 
37
37
  **return**
38
38
 
39
39
  An array of strings with the filenames on `path` in descending order with respect to the modified time
40
40
 
41
+ ### `rmf.promise(dir)`
42
+
43
+ **params**
44
+
45
+ - `dir` {string} The path to test for files
46
+
47
+ **return**
48
+
49
+ A native promise, note that it's required that `global.Promise` is defined
50
+
41
51
  **NOTE: the test to check if a file is a file is by calling `stat.isFile()` which means that folders/symlinks are ignored**
42
52
 
43
53
  ## License
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "recently-modified-files",
3
- "version": "0.1.0",
4
- "description": "Gets the most recent modified file on a given path",
3
+ "version": "0.1.2",
4
+ "description": "Gets the most recent modified file on a dir",
5
5
  "license": "MIT",
6
- "author": {
7
- "name": "Mauricio Poppe",
8
- "email": "mauricio.poppe@gmail.com",
9
- "url": "http://maurizzzio.com"
10
- },
6
+ "author": "Mauricio Poppe (https://mauriciopoppe.com)",
11
7
  "main": "dist/index.js",
12
8
  "jsnext:main": "src/index.js",
13
9
  "keywords": [
@@ -15,14 +11,10 @@
15
11
  "file",
16
12
  "recently modified"
17
13
  ],
18
- "repository": "maurizzzio/recently-modified-files",
14
+ "repository": "mauriciopoppe/recently-modified-files",
19
15
  "scripts": {
20
- "clean": "rimraf dist/ && mkdirp dist/",
21
- "lint": "standard",
22
- "prebuild": "npm run clean -s && npm run lint -s",
23
16
  "build": "babel src/index.js --out-file dist/index.js",
24
17
  "build:watch": "npm run build -- --watch",
25
- "preversion": "npm run build",
26
18
  "test": "ava",
27
19
  "test:watch": "npm test -- --watch",
28
20
  "coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov"
package/src/index.js CHANGED
@@ -13,7 +13,7 @@ function fmr (stats, files) {
13
13
  return onlyFiles.map(stat => stat.filename)
14
14
  }
15
15
 
16
- export default (dir, cb) => {
16
+ export default function asynch (dir, cb) {
17
17
  stat(dir, (err, stats, files) => {
18
18
  if (err) return cb(err)
19
19
  return cb(null, fmr(stats, files))
@@ -25,3 +25,12 @@ export function sync (dir) {
25
25
  var stats = files.map(file => fs.statSync(path.join(dir, file)))
26
26
  return fmr(stats, files)
27
27
  }
28
+
29
+ export function promise (dir) {
30
+ return new Promise((resolve, reject) => {
31
+ asynch(dir, (err, files) => {
32
+ if (err) reject(err)
33
+ else resolve(files)
34
+ })
35
+ })
36
+ }
package/dist/index.js DELETED
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sync = sync;
7
-
8
- var _fs = require('fs');
9
-
10
- var _fs2 = _interopRequireDefault(_fs);
11
-
12
- var _path = require('path');
13
-
14
- var _path2 = _interopRequireDefault(_path);
15
-
16
- var _folderStat = require('folder-stat');
17
-
18
- var _folderStat2 = _interopRequireDefault(_folderStat);
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- function fmr(stats, files) {
23
- var onlyFiles = stats.map(function (stat, i) {
24
- stat.filename = files[i];
25
- return stat;
26
- }).filter(function (stat) {
27
- return stat.isFile();
28
- });
29
- onlyFiles.sort(function (a, b) {
30
- return b.mtime - a.mtime;
31
- });
32
- return onlyFiles.map(function (stat) {
33
- return stat.filename;
34
- });
35
- }
36
-
37
- exports.default = function (dir, cb) {
38
- (0, _folderStat2.default)(dir, function (err, stats, files) {
39
- if (err) return cb(err);
40
- return cb(null, fmr(stats, files));
41
- });
42
- };
43
-
44
- function sync(dir) {
45
- var files = _fs2.default.readdirSync(dir);
46
- var stats = files.map(function (file) {
47
- return _fs2.default.statSync(_path2.default.join(dir, file));
48
- });
49
- return fmr(stats, files);
50
- }