nav-new-publication-cli
Version:
Add new publication to the navigator web project
34 lines (33 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkDomain = exports.checkName = exports.checkArn = exports.checkNotEmpty = exports.stripSpace = void 0;
const constants_1 = require("./constants");
const stripSpace = (str) => str.replace(/\s/, '').toLowerCase();
exports.stripSpace = stripSpace;
const checkNotEmpty = (value) => value === '' ? 'Cannot be empty' : true;
exports.checkNotEmpty = checkNotEmpty;
const checkArn = (value) => {
const empty = (0, exports.checkNotEmpty)(value);
if (empty !== true)
return empty;
return constants_1.arnRegex.test(value) ? true : 'Invalid certificateArn';
};
exports.checkArn = checkArn;
const checkName = (existingPublications) => (value) => {
const pubCheck = existingPublications.reduce((check, { title }) => {
return (0, exports.stripSpace)(title) === (0, exports.stripSpace)(value);
}, false);
if (pubCheck)
return 'This publication already exists, please check before proceeding';
return (0, exports.checkNotEmpty)(value);
};
exports.checkName = checkName;
const checkDomain = (value) => {
const empty = (0, exports.checkNotEmpty)(value);
if (empty !== true)
return empty;
if (value.includes('http://') || value.includes("www."))
return 'should not include http or www';
return constants_1.urlRegex.test(value) ? true : 'Invalid domain';
};
exports.checkDomain = checkDomain;