UNPKG

git-cat-file

Version:

Pure JavaScript `git cat-file -p` for node.js

42 lines (41 loc) 1.35 kB
"use strict"; /** * https://github.com/kawanet/git-cat-file */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getFileMode = void 0; class FileMode { constructor(mode) { this.mode = mode; switch (mode) { case 33261 /* OctalMode.executable */: case 33261 /* OctalMode.executable */ & 0o777: this.isExecutable = true; /* falls through */ case 33188 /* OctalMode.file */: case 33188 /* OctalMode.file */ & 0o777: this.isFile = true; break; case 40960 /* OctalMode.symlink */: this.isSymlink = true; break; case 57344 /* OctalMode.submodule */: this.isSubmodule = true; break; case 16384 /* OctalMode.directory */: this.isDirectory = true; break; default: throw new TypeError(`Unknown mode: ${mode ? mode.toString(8) : mode}`); } } toString() { return (0o1000000 | this.mode).toString(8).substr(-6); } } const cachedMode = {}; function getFileMode(mode) { const modeNum = parseInt(mode, 8); return cachedMode[modeNum] || (cachedMode[modeNum] = new FileMode(modeNum)); } exports.getFileMode = getFileMode;