"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validatePackageName=void 0;const e=require("../../../util/similar"),a=require("../../../common/Constants"),r=require("../../../common/message"),s=/^(?:@([^/]+?)[/])?([^/]+?)$/,o=[a.Constants.MyModules,"node_modules","favicon.ico"];exports.validatePackageName=function(a,t=!1){if(!a||!a.length)throw new Error((0,r.format)(r.Messages.Validator.FieldEmptyError,{fieldName:"name"}));const i=function(e){const a=[];e.match(/^\./)&&a.push(r.Messages.Validator.NameStartWithPeriodError);e.match(/^_/)&&a.push(r.Messages.Validator.NameStartWithUnderscoreError);e.trim()!==e&&a.push(r.Messages.Validator.NameContainsSpacesError);o.forEach((function(s){e.toLowerCase()===s&&a.push((0,r.format)(r.Messages.Validator.NameIsBlackListError,{value:`${s}`}))})),e.length>128&&a.push((0,r.format)(r.Messages.Validator.NameLengthError,{length:"128"}));e.toLowerCase()!==e&&a.push(r.Messages.Validator.NameCapitalError);/[~'!()*]/.test(e.split("/").slice(-1)[0])&&a.push(r.Messages.Validator.NameWithSpecialCharsError);0===a.length&&(s.test(e)||a.push(r.Messages.Validator.NameInvalidError));return a}(a);if(null==t||t||e.similar.forEach((function(e){a.toLowerCase()===e&&i.push((0,r.format)(r.Messages.Validator.NameIsCoreModuleError,{value:`${e}`}))})),0!==i.length)throw new Error(i.join("\n"))};