UNPKG

@socketsecurity/lib

Version:

Core utilities and infrastructure for Socket.dev security tools

106 lines (103 loc) 3.69 kB
"use strict"; /** * Bundled from validate-npm-package-name * This is a zero-dependency bundle created by esbuild. */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; // node_modules/.pnpm/validate-npm-package-name@6.0.2/node_modules/validate-npm-package-name/lib/index.js var require_lib = __commonJS({ "node_modules/.pnpm/validate-npm-package-name@6.0.2/node_modules/validate-npm-package-name/lib/index.js"(exports2, module2) { "use strict"; var { builtinModules: builtins } = require("module"); var scopedPackagePattern = new RegExp("^(?:@([^/]+?)[/])?([^/]+?)$"); var exclusionList = [ "node_modules", "favicon.ico" ]; function validate(name) { var warnings = []; var errors = []; if (name === null) { errors.push("name cannot be null"); return done(warnings, errors); } if (name === void 0) { errors.push("name cannot be undefined"); return done(warnings, errors); } if (typeof name !== "string") { errors.push("name must be a string"); return done(warnings, errors); } if (!name.length) { errors.push("name length must be greater than zero"); } if (name.startsWith(".")) { errors.push("name cannot start with a period"); } if (name.match(/^_/)) { errors.push("name cannot start with an underscore"); } if (name.trim() !== name) { errors.push("name cannot contain leading or trailing spaces"); } exclusionList.forEach(function(excludedName) { if (name.toLowerCase() === excludedName) { errors.push(excludedName + " is not a valid package name"); } }); if (builtins.includes(name.toLowerCase())) { warnings.push(name + " is a core module name"); } if (name.length > 214) { warnings.push("name can no longer contain more than 214 characters"); } if (name.toLowerCase() !== name) { warnings.push("name can no longer contain capital letters"); } if (/[~'!()*]/.test(name.split("/").slice(-1)[0])) { warnings.push(`name can no longer contain special characters ("~'!()*")`); } if (encodeURIComponent(name) !== name) { var nameMatch = name.match(scopedPackagePattern); if (nameMatch) { var user = nameMatch[1]; var pkg = nameMatch[2]; if (pkg.startsWith(".")) { errors.push("name cannot start with a period"); } if (encodeURIComponent(user) === user && encodeURIComponent(pkg) === pkg) { return done(warnings, errors); } } errors.push("name can only contain URL-friendly characters"); } return done(warnings, errors); } __name(validate, "validate"); var done = /* @__PURE__ */ __name(function(warnings, errors) { var result = { validForNewPackages: errors.length === 0 && warnings.length === 0, validForOldPackages: errors.length === 0, warnings, errors }; if (!result.warnings.length) { delete result.warnings; } if (!result.errors.length) { delete result.errors; } return result; }, "done"); module2.exports = validate; } }); // src/external/validate-npm-package-name.js module.exports = require_lib();