mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
* Update typography rule to disallow curly quotes with auto-fix - Reverse typography rule to detect and flag curly quotes instead of straight quotes - Add auto-fixer that converts curly quotes to straight quotes - Fix auto-fixer to properly escape quotes when they match string delimiters * Fix quotation marks in error messages and formatting strings across multiple files - Standardize quotation marks from curly to straight in error messages and string formatting for consistency. - Update various components and utility files to ensure proper string handling and improve readability. * Standardize quotation marks across multiple files - Replace curly quotes with straight quotes in various documentation and code files for consistency and improved readability. - Update error messages, comments, and documentation to ensure uniformity in string formatting. * Standardize month formatting across multiple components - Update month formatting strings from "MMMM 'yy" to "MMMM ''yy" in various components and utility files for consistency. - Ensure uniformity in how months are displayed throughout the application. * Refactor typography rule to enhance curly quote handling - Simplify the error reporting mechanism for curly quotes by creating a shared fix function. - Update test cases to include various curly quote scenarios for improved coverage. - Ensure consistent handling of curly quotes in formatting functions across multiple files. * Refactor typography handling and update tests for curly quotes - Replace curly quotes with their Unicode equivalents in typography rule and related test cases for consistency. - Remove unnecessary eslint-disable comments to improve code clarity. - Ensure proper handling of quotes in arithmetic and utility tests to align with updated typography standards. * Update VRT screenshots Auto-generated by VRT workflow PR: #6454 * Fix: Correct typo in budget cell notification message Co-authored-by: matiss <matiss@mja.lv> * Update VRT screenshots Auto-generated by VRT workflow PR: #6454 * Temporarily disable i18n string extraction workflow --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
import * as fs from '../../platform/server/fs';
|
|
import { handlers } from '../main';
|
|
|
|
export async function uniqueBudgetName(
|
|
initialName: string = 'My Finances',
|
|
): Promise<string> {
|
|
const budgets = await handlers['get-budgets']();
|
|
let idx = 1;
|
|
|
|
// If there is a conflict, keep appending an index until there is no
|
|
// conflict and we have a unique name
|
|
let newName = initialName;
|
|
while (budgets.find(file => file.name === newName)) {
|
|
newName = `${initialName} ${idx}`;
|
|
idx++;
|
|
}
|
|
|
|
return newName;
|
|
}
|
|
|
|
export async function validateBudgetName(
|
|
name: string,
|
|
): Promise<{ valid: boolean; message?: string }> {
|
|
const trimmedName = name.trim();
|
|
const uniqueName = await uniqueBudgetName(trimmedName);
|
|
let message: string | null = null;
|
|
|
|
if (trimmedName === '') message = 'Budget name cannot be blank';
|
|
if (trimmedName.length > 100) {
|
|
message = 'Budget name is too long (max length 100)';
|
|
}
|
|
if (uniqueName !== trimmedName) {
|
|
message = `"${name}" already exists, try "${uniqueName}" instead`;
|
|
}
|
|
|
|
return message ? { valid: false, message } : { valid: true };
|
|
}
|
|
|
|
export async function idFromBudgetName(name: string): Promise<string> {
|
|
let id = name.replace(/( |[^A-Za-z0-9])/g, '-') + '-' + uuidv4().slice(0, 7);
|
|
|
|
// Make sure the id is unique. There's a chance one could already
|
|
// exist (although very unlikely now that we append unique
|
|
// characters onto the id)
|
|
let index = 0;
|
|
|
|
let budgetDir = fs.getBudgetDir(id);
|
|
while (await fs.exists(budgetDir)) {
|
|
index++;
|
|
budgetDir = fs.getBudgetDir(id + index.toString());
|
|
}
|
|
|
|
// If a suffix was added, update the id
|
|
if (index > 0) {
|
|
id = id + index.toString();
|
|
}
|
|
|
|
return id;
|
|
}
|