mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
30 lines
857 B
JavaScript
30 lines
857 B
JavaScript
const ValueObject = require('./shared/ValueObject');
|
|
const InvalidOfferTitle = require('../errors').InvalidOfferTitle;
|
|
|
|
/** @extends ValueObject<string> */
|
|
class OfferTitle extends ValueObject {
|
|
/** @param {unknown} title */
|
|
static create(title) {
|
|
if (title === null || title === undefined) {
|
|
return new OfferTitle('');
|
|
}
|
|
if (typeof title !== 'string') {
|
|
throw new InvalidOfferTitle({
|
|
message: 'Offer `display_title` must be a string.'
|
|
});
|
|
}
|
|
|
|
if (title.length > 191) {
|
|
throw new InvalidOfferTitle({
|
|
message: 'Offer `display_title` can be a maximum of 191 characters.'
|
|
});
|
|
}
|
|
|
|
return new OfferTitle(title.trim());
|
|
}
|
|
|
|
static InvalidOfferTitle = InvalidOfferTitle;
|
|
}
|
|
|
|
module.exports = OfferTitle;
|