MCPcopy
hub / github.com/bbc/peaks.js / validateSegmentOptions

Function validateSegmentOptions

src/segment.js:45–110  ·  view source on GitHub ↗
(options, updating)

Source from the content-addressed store, hash-verified

43}
44
45function validateSegmentOptions(options, updating) {
46 const context = updating ? 'update()' : 'add()';
47
48 if (objectHasProperty(options, 'startTime') && !isValidTime(options.startTime)) {
49 // eslint-disable-next-line max-len
50 throw new TypeError('peaks.segments.' + context + ': startTime should be a valid number');
51 }
52
53 if (objectHasProperty(options, 'endTime') && !isValidTime(options.endTime)) {
54 // eslint-disable-next-line max-len
55 throw new TypeError('peaks.segments.' + context + ': endTime should be a valid number');
56 }
57
58 if (!updating) {
59 if (!objectHasProperty(options, 'startTime') || !objectHasProperty(options, 'endTime')) {
60 throw new TypeError('peaks.segments.' + context + ': missing startTime or endTime');
61 }
62 }
63
64 if (options.startTime < 0) {
65 // eslint-disable-next-line max-len
66 throw new RangeError('peaks.segments.' + context + ': startTime should not be negative');
67 }
68
69 if (options.endTime < 0) {
70 // eslint-disable-next-line max-len
71 throw new RangeError('peaks.segments.' + context + ': endTime should not be negative');
72 }
73
74 if (options.endTime < options.startTime) {
75 // eslint-disable-next-line max-len
76 throw new RangeError('peaks.segments.' + context + ': endTime should not be less than startTime');
77 }
78
79 if (objectHasProperty(options, 'labelText') && !isString(options.labelText)) {
80 throw new TypeError('peaks.segments.' + context + ': labelText must be a string');
81 }
82
83 if (objectHasProperty(options, 'editable') && !isBoolean(options.editable)) {
84 throw new TypeError('peaks.segments.' + context + ': editable must be true or false');
85 }
86
87 if (objectHasProperty(options, 'color') &&
88 !isString(options.color) &&
89 !isLinearGradientColor(options.color)) {
90 // eslint-disable-next-line max-len
91 throw new TypeError('peaks.segments.' + context + ': color must be a string or a valid linear gradient object');
92 }
93
94 if (objectHasProperty(options, 'borderColor') && !isString(options.borderColor)) {
95 // eslint-disable-next-line max-len
96 throw new TypeError('peaks.segments.' + context + ': borderColor must be a string');
97 }
98
99 invalidOptions.forEach(function(name) {
100 if (objectHasProperty(options, name)) {
101 throw new Error('peaks.segments.' + context + ': invalid option name: ' + name);
102 }

Callers 2

segment.jsFile · 0.85

Calls 5

objectHasPropertyFunction · 0.90
isValidTimeFunction · 0.90
isStringFunction · 0.90
isBooleanFunction · 0.90
isLinearGradientColorFunction · 0.90

Tested by

no test coverage detected