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

Function validatePointOptions

src/point.js:36–77  ·  view source on GitHub ↗
(options, updating)

Source from the content-addressed store, hash-verified

34}
35
36function validatePointOptions(options, updating) {
37 const context = updating ? 'update()' : 'add()';
38
39 if (!updating || (updating && objectHasProperty(options, 'time'))) {
40 if (!isValidTime(options.time)) {
41 // eslint-disable-next-line max-len
42 throw new TypeError('peaks.points.' + context + ': time should be a numeric value');
43 }
44 }
45
46 if (options.time < 0) {
47 // eslint-disable-next-line max-len
48 throw new RangeError('peaks.points.' + context + ': time should not be negative');
49 }
50
51 if (objectHasProperty(options, 'labelText') && !isString(options.labelText)) {
52 throw new TypeError('peaks.points.' + context + ': labelText must be a string');
53 }
54
55 if (objectHasProperty(options, 'editable') && !isBoolean(options.editable)) {
56 throw new TypeError('peaks.points.' + context + ': editable must be true or false');
57 }
58
59 if (objectHasProperty(options, 'color') &&
60 !isString(options.color) &&
61 !isLinearGradientColor(options.color)) {
62 // eslint-disable-next-line max-len
63 throw new TypeError('peaks.points.' + context + ': color must be a string or a valid linear gradient object');
64 }
65
66 invalidOptions.forEach(function(name) {
67 if (objectHasProperty(options, name)) {
68 throw new Error('peaks.points.' + context + ': invalid option name: ' + name);
69 }
70 });
71
72 pointOptions.forEach(function(name) {
73 if (objectHasProperty(options, '_' + name)) {
74 throw new Error('peaks.points.' + context + ': invalid option name: _' + name);
75 }
76 });
77}
78
79/**
80 * A point is a single instant of time, with associated label and color.

Callers 2

waveform-points.jsFile · 0.90
point.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