mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
3dcf85d5e4
refs: 23b383bedf
- @tryghost/error constructors take an object, not a string - the expectation is that message, context & help should all be set
- This does the bare minimum and just ensures message is set correctly
27 lines
730 B
JavaScript
27 lines
730 B
JavaScript
const ValueObject = require('./shared/ValueObject');
|
|
const InvalidOfferName = require('../errors').InvalidOfferName;
|
|
|
|
/** @extends ValueObject<string> */
|
|
class OfferName extends ValueObject {
|
|
/** @param {unknown} name */
|
|
static create(name) {
|
|
if (!name || typeof name !== 'string') {
|
|
throw new InvalidOfferName({
|
|
message: 'Offer `name` must be a string.'
|
|
});
|
|
}
|
|
|
|
if (name.length > 40) {
|
|
throw new InvalidOfferName({
|
|
message: 'Offer `name` can be a maximum of 40 characters.'
|
|
});
|
|
}
|
|
|
|
return new OfferName(name.trim());
|
|
}
|
|
|
|
static InvalidOfferName = InvalidOfferName;
|
|
}
|
|
|
|
module.exports = OfferName;
|