UNPKG

@kobold/core

Version:

Kobold core

60 lines (45 loc) 1.65 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault"); var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property"); _Object$defineProperty(exports, "__esModule", { value: true }); exports.Path = void 0; var _lastIndexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/last-index-of")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty")); var _crc = require("./crc"); class Path { constructor(opts) { (0, _defineProperty2.default)(this, "category", void 0); (0, _defineProperty2.default)(this, "repository", void 0); (0, _defineProperty2.default)(this, "path", void 0); (0, _defineProperty2.default)(this, "_index", void 0); (0, _defineProperty2.default)(this, "_index2", void 0); this.category = opts.category; this.repository = opts.repository; this.path = opts.path; } get indexHash() { var _context; if (this._index) { return this._index; } const lastSlash = (0, _lastIndexOf.default)(_context = this.path).call(_context, '/'); const folder = this.path.substr(0, lastSlash); const file = this.path.substr(lastSlash + 1); const folderHash = (0, _crc.crc)(folder); const fileHash = (0, _crc.crc)(file); const index = folderHash << 32n | fileHash; this._index = index; return index; } get index2Hash() { if (this._index2) { return this._index2; } const index2 = (0, _crc.crc)(this.path); this._index2 = index2; return index2; } } exports.Path = Path;