-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparameter.js.html
More file actions
370 lines (326 loc) · 13 KB
/
parameter.js.html
File metadata and controls
370 lines (326 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: parameter.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: parameter.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { getElements, isNullOrUndefined, toWKT } from './utils';
/**
* @module opensearch/parameter
*/
const typeRE = /{([a-zA-Z:]+)([?]?)}/;
function parseType(value) {
const match = typeRE.exec(value);
if (match) {
return match[1];
}
return null;
}
function isMandatory(value) {
return typeRE.exec(value)[2] !== '?';
}
function eoValueToString(value, isDate = false) {
const convertDate = (dateValue) => {
if (dateValue instanceof Date) {
return dateValue.toISOString();
}
return value;
};
if (typeof value === 'string') {
return value;
} else if (typeof value === 'number') {
return value.toString();
} else if (isDate && value instanceof Date) {
return convertDate(value);
} else if (Array.isArray(value)) {
if (isDate) {
return `{${value.map(convertDate).join(',')}}`;
}
return `{${value.join(',')}}`;
}
let left = null;
let right = null;
if (Object.prototype.hasOwnProperty.call(value, 'min')) {
left = `[${isDate ? convertDate(value.min) : value.min}`;
} else if (Object.prototype.hasOwnProperty.call(value, 'minExclusive')) {
left = `]${isDate ? convertDate(value.minExclusive) : value.minExclusive}`;
}
if (Object.prototype.hasOwnProperty.call(value, 'max')) {
right = `${isDate ? convertDate(value.max) : value.max}]`;
} else if (Object.prototype.hasOwnProperty.call(value, 'maxExclusive')) {
right = `${isDate ? convertDate(value.maxExclusive) : value.maxExclusive}[`;
}
if (left !== null && right !== null) {
return `${left},${right}`;
} else if (left !== null) {
return left;
}
return right;
}
/**
* Class to describe a single OpenSearch URL parameter.
*/
export class OpenSearchParameter {
/**
* Class to describe a single OpenSearch URL parameter.
* @param {string} type The type of the parameter
* @param {string} name The name of the parameter
* @param {boolean} mandatory Whether the parameter is mandatory
* @param {object[]} [options=null] The possible values for this parameter
* @param {string} options[].label The label of the option
* @param {string} options[].value The value of the option
* @param {Number} [minExclusive=undefined] The minimum value allowed for this
parameter (exclusive)
* @param {Number} [maxExclusive=undefined] The maximum value allowed for this
parameter (exclusive)
* @param {Number} [minInclusive=undefined] The minimum value allowed for this
parameter (inclusive)
* @param {Number} [maxInclusive=undefined] The maximum value allowed for this
parameter (inclusive)
*/
constructor(type, name, mandatory, options = null,
minExclusive = undefined, maxExclusive = undefined,
minInclusive = undefined, maxInclusive = undefined) {
this._type = type;
this._name = name;
this._mandatory = mandatory;
this._options = options;
this._minExclusive = minExclusive;
this._maxExclusive = maxExclusive;
this._minInclusive = minInclusive;
this._maxInclusive = maxInclusive;
}
/**
* The type of the parameter
* @readonly
*/
get type() {
return this._type;
}
/**
* The name of the parameter
* @readonly
*/
get name() {
return this._name;
}
/**
* Whether the parameter is mandatory
* @readonly
*/
get mandatory() {
return this._mandatory;
}
/**
* The possible values for this parameter
* @readonly
*/
get options() {
return this._options;
}
/**
* The minimum value allowed for this parameter (exclusive)
* @readonly
*/
get minExclusive() {
return this._minExclusive;
}
/**
* The maximum value allowed for this parameter (exclusive)
* @readonly
*/
get maxExclusive() {
return this._maxExclusive;
}
/**
* The minimum value allowed for this parameter (inclusive)
* @readonly
*/
get minInclusive() {
return this._minInclusive;
}
/**
* The maximum value allowed for this parameter (inclusive)
* @readonly
*/
get maxInclusive() {
return this._maxInclusive;
}
/**
* Combines this parameter with the values of another parameter.
* @param {OpenSearchParameter} other the other parameter
* @returns {OpenSearchParameter} the combined parameter
*/
combined(other) {
return new OpenSearchParameter(
this.type, this.name,
isNullOrUndefined(this.mandatory) ? other.mandatory : this.mandatory,
isNullOrUndefined(this.options) ? other.options : this.options,
isNullOrUndefined(this.minExclusive) ? other.minExclusive : this.minExclusive,
isNullOrUndefined(this.maxExclusive) ? other.maxExclusive : this.maxExclusive,
isNullOrUndefined(this.minInclusive) ? other.minInclusive : this.minInclusive,
isNullOrUndefined(this.maxInclusive) ? other.maxInclusive : this.maxInclusive
);
}
/**
* Serialize the given value according to the internal type to be sent in a
* request.
* @param {Number|string|Date|array|object} value The value to serialize. The
* allowed types depend on the
* internal type.
* @returns {string} the serialized value.
*/
serializeValue(value) {
switch (this.type) {
case 'time:start':
case 'time:end':
if (value instanceof Date) {
return value.toISOString();
}
break;
case 'geo:box':
if (Array.isArray(value)) {
return value.join(',');
}
break;
case 'geo:geometry':
return toWKT(value);
case 'eo:orbitNumber':
case 'eo:track':
case 'eo:frame':
case 'eo:cloudCover':
case 'eo:snowCover':
case 'eo:startTimeFromAscendingNode':
case 'eo:completionTimeFromAscendingNode':
case 'eo:illuminationAzimuthAngle':
case 'eo:illuminationZenithAngle':
case 'eo:illuminationElevationAngle':
case 'eo:minimumIncidenceAngle':
case 'eo:maximumIncidenceAngle':
case 'eo:dopplerFrequency':
case 'eo:incidenceAngleVariation':
return eoValueToString(value);
case 'eo:availabilityTime':
case 'eo:creationDate':
case 'eo:modificationDate':
case 'eo:processingDate':
return eoValueToString(value, true);
default:
break;
}
return value;
}
/**
* Constructs a new OpenSearchParameter from a DOM-Node.
* @param {DOMNode} node the node to create the parameter from.
* @returns {OpenSearchParameter} the constructed parameters object.
*/
static fromNode(node) {
const type = parseType(node.getAttribute('value'));
const name = node.getAttribute('name');
const mandatory = node.hasAttribute('minimum')
? node.getAttribute('minimum') !== '0' : undefined;
const minExclusive = node.hasAttribute('minExclusive')
? parseInt(node.getAttribute('minExclusive'), 10)
: undefined;
const maxExclusive = node.hasAttribute('maxExclusive')
? parseInt(node.getAttribute('maxExclusive'), 10)
: undefined;
const minInclusive = node.hasAttribute('minInclusive')
? parseInt(node.getAttribute('minInclusive'), 10)
: undefined;
const maxInclusive = node.hasAttribute('maxInclusive')
? parseInt(node.getAttribute('maxInclusive'), 10)
: undefined;
const optionNodes = getElements(node, 'parameters', 'Option');
let options;
if (optionNodes.length) {
options = optionNodes.map(optionNode => ({
label: optionNode.getAttribute('label'),
value: optionNode.getAttribute('value'),
}));
}
return new OpenSearchParameter(
type, name, mandatory, options, minExclusive, maxExclusive, minInclusive, maxInclusive
);
}
/**
* Constructs a new OpenSearchParameter from a key value pair (e.g: from the
* query part of a KVP-URL). Returns null, when the value could not be parsed.
* @param {DOMNode} key the key of the key-value-pair.
* @param {DOMNode} value the value of the key-value-pair.
* @returns {OpenSearchParameter|null} the constructed parameters object.
*/
static fromKeyValuePair(key, value) {
const type = parseType(value);
if (type) {
return new OpenSearchParameter(
type, key, isMandatory(value)
);
}
return null;
}
/**
* Serialize the parameter to a simple object.
* @returns {object} The serialized parameter
*/
serialize() {
const values = {
type: this._type,
name: this._name,
mandatory: this._mandatory,
options: this._options,
};
if (typeof this._minExclusive !== 'undefined') {
values.minExclusive = this._minExclusive;
}
if (typeof this._maxExclusive !== 'undefined') {
values.maxExclusive = this._maxExclusive;
}
if (typeof this._minInclusive !== 'undefined') {
values.minInclusive = this._minInclusive;
}
if (typeof this._maxInclusive !== 'undefined') {
values.maxInclusive = this._maxInclusive;
}
return values;
}
/**
* Deserialize a parameter from a simple object.
* @param {object} values The serialized parameter
* @returns {OpenSearchParameter} The deserialized parameter
*/
static deserialize(values) {
return new OpenSearchParameter(
values.type, values.name, values.mandatory, values.options,
values.minExclusive, values.maxExclusive, values.minInclusive, values.maxInclusive
);
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-opensearch.html">opensearch</a></li><li><a href="module-opensearch_config.html">opensearch/config</a></li><li><a href="module-opensearch_error.html">opensearch/error</a></li><li><a href="module-opensearch_formats.html">opensearch/formats</a></li><li><a href="module-opensearch_formats_atom.html">opensearch/formats/atom</a></li><li><a href="module-opensearch_formats_geojson.html">opensearch/formats/geojson</a></li><li><a href="module-opensearch_formats_rss.html">opensearch/formats/rss</a></li><li><a href="module-opensearch_formats_suggestions-json.html">opensearch/formats/suggestions-json</a></li><li><a href="module-opensearch_paginator.html">opensearch/paginator</a></li><li><a href="module-opensearch_parameter.html">opensearch/parameter</a></li><li><a href="module-opensearch_search.html">opensearch/search</a></li><li><a href="module-opensearch_url.html">opensearch/url</a></li><li><a href="module-opensearch_utils.html">opensearch/utils</a></li></ul><h3>Classes</h3><ul><li><a href="module-opensearch_formats_atom-AtomFormat.html">AtomFormat</a></li><li><a href="module-opensearch_formats_geojson-GeoJSONFormat.html">GeoJSONFormat</a></li><li><a href="module-opensearch_formats_rss-RSSFormat.html">RSSFormat</a></li><li><a href="module-opensearch_formats_suggestions-json-SuggestionsJSONFormat.html">SuggestionsJSONFormat</a></li><li><a href="module-opensearch_paginator.OpenSearchPaginator.html">OpenSearchPaginator</a></li><li><a href="module-opensearch_paginator-PagedSearchProgressEmitter.html">PagedSearchProgressEmitter</a></li><li><a href="module-opensearch_parameter.OpenSearchParameter.html">OpenSearchParameter</a></li><li><a href="module-opensearch_url.OpenSearchUrl.html">OpenSearchUrl</a></li><li><a href="OpenSearchDescription.html">OpenSearchDescription</a></li><li><a href="OpenSearchService.html">OpenSearchService</a></li></ul><h3>Events</h3><ul><li><a href="module-opensearch_paginator-PagedSearchProgressEmitter.html#event:error">error</a></li><li><a href="module-opensearch_paginator-PagedSearchProgressEmitter.html#event:page">page</a></li><li><a href="module-opensearch_paginator-PagedSearchProgressEmitter.html#event:success">success</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-opensearch_formats.FormatInterface.html">FormatInterface</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 10 2018 13:14:22 GMT+0100 (CET)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>