mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move string utils to shared module
This commit is contained in:
@ -7,7 +7,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument } from '../../slash-commands/SlashC
|
|||||||
import { enumIcons } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { enumIcons } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
import { enumTypes, SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
import { enumTypes, SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
|
||||||
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
||||||
import { uuidv4 } from '../../utils.js';
|
import { collapseSpaces, getUniqueName, uuidv4 } from '../../utils.js';
|
||||||
|
|
||||||
const MODULE_NAME = 'connection-manager';
|
const MODULE_NAME = 'connection-manager';
|
||||||
const NONE = '<None>';
|
const NONE = '<None>';
|
||||||
@ -71,8 +71,6 @@ const profilesProvider = () => [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const escapeArgument = (a) => a.replace(/"/g, '\\"').replace(/\|/g, '\\|');
|
const escapeArgument = (a) => a.replace(/"/g, '\\"').replace(/\|/g, '\\|');
|
||||||
const collapseSpaces = (s) => s.replace(/\s+/g, ' ').trim();
|
|
||||||
const makeUnique = (s, f, i) => { if (!f(s)) { return s; } else { while (f(`${s} (${i})`)) { i++; } return `${s} (${i})`; } };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the best match for the search value.
|
* Finds the best match for the search value.
|
||||||
@ -150,7 +148,7 @@ async function createConnectionProfile(forceName = null) {
|
|||||||
const profileForDisplay = makeFancyProfile(profile);
|
const profileForDisplay = makeFancyProfile(profile);
|
||||||
const template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay });
|
const template = await renderExtensionTemplateAsync(MODULE_NAME, 'profile', { profile: profileForDisplay });
|
||||||
const checkName = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
|
const checkName = (n) => extension_settings.connectionManager.profiles.some(p => p.name === n);
|
||||||
const suggestedName = makeUnique(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), checkName, 1);
|
const suggestedName = getUniqueName(collapseSpaces(`${profile.api ?? ''} ${profile.model ?? ''} - ${profile.preset ?? ''}`), checkName);
|
||||||
const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 });
|
const name = forceName ?? await callGenericPopup(template, POPUP_TYPE.INPUT, suggestedName, { rows: 2 });
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
@ -1436,6 +1436,15 @@ export function uuidv4() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collapses multiple spaces in a strings into one.
|
||||||
|
* @param {string} s String to process
|
||||||
|
* @returns {string} String with collapsed spaces
|
||||||
|
*/
|
||||||
|
export function collapseSpaces(s) {
|
||||||
|
return s.replace(/\s+/g, ' ').trim();
|
||||||
|
}
|
||||||
|
|
||||||
function postProcessText(text, collapse = true) {
|
function postProcessText(text, collapse = true) {
|
||||||
// Remove carriage returns
|
// Remove carriage returns
|
||||||
text = text.replace(/\r/g, '');
|
text = text.replace(/\r/g, '');
|
||||||
|
Reference in New Issue
Block a user