UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

69 lines (67 loc) 2.61 kB
/* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2007-2023 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ export const siteInputMaxLength = 4000; export const siteNameMaxLength = 255; export const siteIdMaxLength = 50; export const siteIdExist = (sites, value) => { return Boolean(sites && sites.find((site) => site.id === value)); }; export const siteNameExist = (sites, value) => { return Boolean(sites && sites.find((site) => site.name === value)); }; export function getSiteIdFromSiteName(siteName) { let siteId = siteName .replace(/[^a-zA-Z0-9_\s-]/g, '') .replace(/[_\s]/g, '-') .toLowerCase(); if (siteId.startsWith('0') || siteId.startsWith('-') || siteId.startsWith('_')) { siteId = siteId.replace(/0|-|_/, ''); } // Site id max length differs from the site name max length, so the id needs to be trimmed to // its max length return siteId.substring(0, siteIdMaxLength); } export function cleanupSiteId(siteId) { return siteId .replace(/[^a-zA-Z0-9_\s-]/g, '') .replace(/[_\s]/g, '-') .toLowerCase(); } export function cleanupGitBranch(branch) { return ( branch .replace(/\s+|[~^:?*[@\\]/g, '') // It cannot have two or more consecutive dots anywhere. .replace(/\.{2,}/g, '.') // It cannot have two or more consecutive slashes anywhere. .replace(/\/{2,}/g, '/') ); }