als-path-tree
Version:
A Node.js library for managing a virtual file system structure, offering functionalities for file and directory operations with a shared storage system.
50 lines (44 loc) • 2.21 kB
JavaScript
class Options {
static options = {
logger: console,
thresholdRating: 3,
thresholdPercentage: 20,
maxStoreTime: 1000 * 60 * 60 * 24,
weights: {
accessCount: 5, // Чем больше обращений, тем выше приоритет
lastAccess: -3, // Чем старше дата последнего обращения, тем ниже приоритет
size: -1, // Чем больше размер файла, тем ниже приоритет
}
}
constructor() {}
get logger() { return Options.options.logger }
get thresholdRating() { return Options.options.thresholdRating }
get thresholdPercentage() { return Options.options.thresholdPercentage }
get maxStoreTime() { return Options.options.maxStoreTime }
get weights() { return Options.options.weights }
set logger(logger) {
const methods = ['log', 'warn', 'error']
if (typeof logger !== 'object') throw new Error(`logger must be object with methods ${methods.join}.`)
for (const methodName of methods) {
if (typeof logger[methodName] !== 'function') throw new Error(`logger must to include method ${methodName} as function.`)
}
Options.options.logger = logger
}
set thresholdRating(value) {
if (typeof value !== 'number' || value > 100 || value < 1) throw new Error('Threshold rating must be a number between 1 and 100.');
Options.options.thresholdRating = value
}
set thresholdPercentage(value) {
if (typeof value !== 'number' || value > 100 || value < 1) throw new Error('Threshold percentage must be a number between 1 and 100.');
Options.options.thresholdPercentage = value
}
set maxStoreTime(value) {
if (typeof value !== 'number' || value < 1000 * 60) throw new Error('maxStoreTime must be a number between larger than 1000*60 (minute).');
Options.options.maxStoreTime = value
}
set weights(obj={}) {
const keys = ['accessCount', 'lastAccess', 'size']
keys.forEach(key => {if(typeof obj[key] === 'number') Options.options.weights[key] = obj[key]})
}
}
module.exports = new Options()