perms-to-string.js 392 B

123456789101112131415161718192021
  1. 'use strict';
  2. module.exports = function permsToString(stat) {
  3. if (!stat.isDirectory || !stat.mode) {
  4. return '???!!!???';
  5. }
  6. const dir = stat.isDirectory() ? 'd' : '-';
  7. const mode = stat.mode.toString(8);
  8. return dir + mode.slice(-3).split('').map(n => [
  9. '---',
  10. '--x',
  11. '-w-',
  12. '-wx',
  13. 'r--',
  14. 'r-x',
  15. 'rw-',
  16. 'rwx',
  17. ][parseInt(n, 10)]).join('');
  18. };