@socketsecurity/lib
Version:
Core utilities and infrastructure for Socket.dev security tools
97 lines (96 loc) • 2.93 kB
JavaScript
;
/* Socket Lib - Built with esbuild */
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var sorts_exports = {};
__export(sorts_exports, {
compareSemver: () => compareSemver,
compareStr: () => compareStr,
localeCompare: () => localeCompare,
naturalCompare: () => naturalCompare,
naturalSorter: () => naturalSorter
});
module.exports = __toCommonJS(sorts_exports);
let _localeCompare;
// @__NO_SIDE_EFFECTS__
function localeCompare(x, y) {
if (_localeCompare === void 0) {
_localeCompare = new Intl.Collator().compare;
}
return _localeCompare(x, y);
}
let _naturalCompare;
// @__NO_SIDE_EFFECTS__
function naturalCompare(x, y) {
if (_naturalCompare === void 0) {
_naturalCompare = new Intl.Collator(
// The `undefined` locale means it uses the default locale of the user's
// environment.
void 0,
{
// Enables numeric sorting: numbers in strings are compared by value,
// e.g. 'file2' comes before 'file10' as numbers and not 'file10' before
// 'file2' as plain text.
numeric: true,
// Makes the comparison case-insensitive and ignores diacritics, e.g.
// 'a', 'A', and 'á' are treated as equivalent.
sensitivity: "base"
}
).compare;
}
return _naturalCompare(x, y);
}
let _naturalSorter;
// @__NO_SIDE_EFFECTS__
function naturalSorter(arrayToSort) {
if (_naturalSorter === void 0) {
const fastSort = require("./external/fast-sort");
_naturalSorter = fastSort.createNewSortInstance({
comparer: naturalCompare
});
}
return _naturalSorter(arrayToSort);
}
// @__NO_SIDE_EFFECTS__
function compareStr(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
}
// @__NO_SIDE_EFFECTS__
function compareSemver(a, b) {
const semver = require("./external/semver");
const validA = semver.valid(a);
const validB = semver.valid(b);
if (!validA && !validB) {
return 0;
}
if (!validA) {
return -1;
}
if (!validB) {
return 1;
}
return semver.compare(a, b);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
compareSemver,
compareStr,
localeCompare,
naturalCompare,
naturalSorter
});