feedbaby-client
Version:
Client for the FeedBaby App
32 lines (31 loc) • 992 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class AuthParameters {
static validPassphrase(passphrase) {
return /^[a-z0-9]+$/i.test(passphrase);
}
validate(auth) {
if (!AuthParameters.validPassphrase(auth.passphrase)) {
throw new Error('Passphrase can only contain letters and numbers');
}
}
create(auth) {
this.validate(auth);
return {
"passphrase": auth.passphrase,
"dob_year": `${auth.dateOfBirth.getFullYear()}`,
"dob_month": AuthParameters.paddedMonth(auth.dateOfBirth),
"dob_day": AuthParameters.paddedDay(auth.dateOfBirth),
};
}
static pad(value) {
return ('0' + value).slice(-2);
}
static paddedMonth(date) {
return AuthParameters.pad(date.getMonth() + 1);
}
static paddedDay(date) {
return AuthParameters.pad(date.getDate());
}
}
exports.AuthParameters = AuthParameters;