Update utils.js

This commit is contained in:
valhalla-creator 2025-05-22 21:18:52 +01:00 committed by GitHub
parent 973a788c21
commit 9245ba4a5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,17 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { Session } from 'meteor/session';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Tracker } from 'meteor/tracker';
import { $ } from 'meteor/jquery';
import { Meteor } from 'meteor/meteor';
// Create Utils as a global object and export it
export const Utils = {
// Initialize global Utils first
if (typeof window.Utils === 'undefined') {
window.Utils = {};
}
// Create Utils object
const Utils = {
setBackgroundImage(url) {
const currentBoard = Utils.getCurrentBoard();
if (currentBoard.backgroundImageURL !== undefined) {
@ -16,12 +26,19 @@ export const Utils = {
// This helps with date parsing in non-English languages
normalizeDigits(str) {
if (!str) return str;
const persian = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
const arabic = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
for (let i = 0; i < 10; i++) {
str = str.replace(persian[i], i).replace(arabic[i], i);
}
return str;
// Convert Persian and Arabic numbers to English
const persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
const arabicNumbers = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
return str.split('')
.map(c => {
const pIndex = persianNumbers.indexOf(c);
const aIndex = arabicNumbers.indexOf(c);
if (pIndex >= 0) return pIndex.toString();
if (aIndex >= 0) return aIndex.toString();
return c;
})
.join('');
},
/** returns the current board id
* <li> returns the current board id or the board id of the popup card if set
@ -592,8 +609,11 @@ export const Utils = {
},
};
// Make Utils available globally for legacy code
window.Utils = Utils;
// Update global Utils with all methods
Object.assign(window.Utils, Utils);
// Export for ES modules
export { Utils };
// A simple tracker dependency that we invalidate every time the window is
// resized. This is used to reactively re-calculate the popup position in case