暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 416B

123456789101112131415161718
  1. const { dirname, resolve } = require('path');
  2. const { readdirSync, statSync } = require('fs');
  3. module.exports = function (start, callback) {
  4. let dir = resolve('.', start);
  5. let tmp, stats = statSync(dir);
  6. if (!stats.isDirectory()) {
  7. dir = dirname(dir);
  8. }
  9. while (true) {
  10. tmp = callback(dir, readdirSync(dir));
  11. if (tmp) return resolve(dir, tmp);
  12. dir = dirname(tmp = dir);
  13. if (tmp === dir) break;
  14. }
  15. }