UNPKG

@enonic/mock-xp

Version:

Mock Enonic XP API JavaScript Library

26 lines (25 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortZipEntries = sortZipEntries; function sortZipEntries(entries, options) { if (options === void 0) { options = {}; } var _a = options.prioritizeShorter, prioritizeShorter = _a === void 0 ? true : _a, _b = options.prioritizeDirectories, prioritizeDirectories = _b === void 0 ? false : _b, _c = options.excludePattern, excludePattern = _c === void 0 ? null : _c, _d = options.caseInsensitive, caseInsensitive = _d === void 0 ? false : _d; return entries.sort(function (a, b) { if (prioritizeDirectories && a.isDirectory !== b.isDirectory) { return a.isDirectory ? -1 : 1; } if (excludePattern) { var aHasPattern = a.entryName.includes(excludePattern); var bHasPattern = b.entryName.includes(excludePattern); if (aHasPattern !== bHasPattern) { return aHasPattern ? 1 : -1; } } if (prioritizeShorter && a.entryName.length !== b.entryName.length) { return a.entryName.length - b.entryName.length; } return caseInsensitive ? a.entryName.localeCompare(b.entryName, undefined, { sensitivity: 'base' }) : a.entryName.localeCompare(b.entryName); }); }