For this you should create a class and define its methods as static.
Example Class:
class DateHelper {
static converterTextForDate(text) {
if(!/\d{4}-\d{2}-\d{2}/.test(text)) {
throw new Error('Should be in the format aaaa-mm-dd');
}
return new Date(...texto.split('-').map((item, index)
=> item - index % 2));
}
}
How to use it ?
DateHelper.converterTextForDate(this._inputData.value);
How to don’t allow new instances of this class ?
You can return a error in the constructor of this class. Example :
constructor() {
throw new Error('You can't use instances of this class');
}