Spaces:
Runtime error
Runtime error
File size: 1,602 Bytes
56b6519 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
// Filename whitelist validation for template creation
function validFilename(filename) {
const regex = /^[\p{Letter}\p{Mark}0-9 \[\]'()_-]+$/iu;
return regex.test(filename);
}
exports.validFilename = validFilename;
// Escape XML special entities when using {@RawXML} in template generation
function escapeXMLEntities(input) {
var XML_CHAR_MAP = { '<': '<', '>': '>', '&': '&' };
var standardEncode = input.replace(/[<>&]/g, function (ch) {
return XML_CHAR_MAP[ch];
});
return standardEncode;
}
exports.escapeXMLEntities = escapeXMLEntities;
// Convert number to 3 digits format if under 100
function lPad(number) {
if (number <= 99) {
number = ('00' + number).slice(-3);
}
return `${number}`;
}
exports.lPad = lPad;
function escapeRegex(regex) {
return regex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
exports.escapeRegex = escapeRegex;
function generateUUID() {
return require('crypto').randomBytes(32).toString('hex');
}
exports.generateUUID = generateUUID;
var getObjectPaths = (obj, prefix = '') =>
Object.keys(obj).reduce((res, el) => {
if (Array.isArray(obj[el])) {
return [...res, prefix + el];
} else if (typeof obj[el] === 'object' && obj[el] !== null) {
return [...res, ...getObjectPaths(obj[el], prefix + el + '.')];
}
return [...res, prefix + el];
}, []);
exports.getObjectPaths = getObjectPaths;
function getSockets(io, room) {
var result = [];
io.sockets.sockets.forEach(data => {
if (data.rooms.has(room)) {
result.push(data);
}
});
return result;
}
exports.getSockets = getSockets;
|