|
|
|
@ -108,31 +108,46 @@ const getAvailableRollupForUiType = (type: string) => {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getFileName = ({ |
|
|
|
|
name, |
|
|
|
|
count, |
|
|
|
|
ext |
|
|
|
|
}) => `${name}${count ? `(${count})` : ''}${ext? `${ext}` : ''}` |
|
|
|
|
const getFileName = ({ name, count, ext }) => |
|
|
|
|
`${name}${count ? `(${count})` : ''}${ext ? `${ext}` : ''}`; |
|
|
|
|
|
|
|
|
|
// add count before extension if duplicate name found
|
|
|
|
|
function populateUniqueFileName( |
|
|
|
|
fileName: string, |
|
|
|
|
attachments: string[] |
|
|
|
|
) { |
|
|
|
|
return fileName.replace(/^(.+?)(?:\((\d+)\))?(\.(?:tar|min)\.(?:\w{2,4})|\.\w+)$/, (fileName,name, count, ext) =>{ |
|
|
|
|
let genFileName = fileName; |
|
|
|
|
let c = count || 1; |
|
|
|
|
|
|
|
|
|
// iterate until a unique name
|
|
|
|
|
while (attachments.some((fn) => fn === genFileName)) { |
|
|
|
|
genFileName = getFileName({ |
|
|
|
|
name, |
|
|
|
|
ext, |
|
|
|
|
count: c++ |
|
|
|
|
}); |
|
|
|
|
function populateUniqueFileName(fileName: string, attachments: string[]) { |
|
|
|
|
return fileName.replace( |
|
|
|
|
/^(.+?)(?:\((\d+)\))?(\.(?:tar|min)\.(?:\w{2,4})|\.\w+)$/, |
|
|
|
|
(fileName, name, count, ext) => { |
|
|
|
|
let genFileName = fileName; |
|
|
|
|
let c = count || 1; |
|
|
|
|
|
|
|
|
|
// iterate until a unique name
|
|
|
|
|
while (attachments.some((fn) => fn === genFileName)) { |
|
|
|
|
genFileName = getFileName({ |
|
|
|
|
name, |
|
|
|
|
ext, |
|
|
|
|
count: c++, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return genFileName; |
|
|
|
|
} |
|
|
|
|
return genFileName; |
|
|
|
|
}); |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function roundUpToPrecision(number: number, precision: number = 0) { |
|
|
|
|
precision = |
|
|
|
|
precision == null |
|
|
|
|
? 0 |
|
|
|
|
: precision >= 0 |
|
|
|
|
? Math.min(precision, 292) |
|
|
|
|
: Math.max(precision, -292); |
|
|
|
|
if (precision) { |
|
|
|
|
// Shift with exponential notation to avoid floating-point issues.
|
|
|
|
|
// See [MDN](https://mdn.io/round#Examples) for more details.
|
|
|
|
|
let pair = `${number}e`.split('e'); |
|
|
|
|
const value = Math.round(Number(`${pair[0]}e${+pair[1] + precision}`)); |
|
|
|
|
pair = `${value}e`.split('e'); |
|
|
|
|
return +`${pair[0]}e${+pair[1] - precision}`; |
|
|
|
|
} |
|
|
|
|
return Math.round(number); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export { |
|
|
|
@ -145,4 +160,5 @@ export {
|
|
|
|
|
stringifyRolesObj, |
|
|
|
|
getAvailableRollupForUiType, |
|
|
|
|
populateUniqueFileName, |
|
|
|
|
roundUpToPrecision, |
|
|
|
|
}; |
|
|
|
|