1
1
'use strict' ;
2
2
3
3
/**
4
- * Represents Metadata as a name and value pair.
4
+ * Represents Metadata as a key and value pair.
5
5
* @example
6
6
* var metadata = require('./metadata');
7
7
* ...
8
8
*
9
- * var header1 = new metadata("name1 ", "value1");
9
+ * var metadata1 = new metadata("key1 ", "value1");
10
10
*/
11
11
class Metadata {
12
12
13
13
/**
14
14
* Creates a new instance of the Metadata class.
15
15
* @constructor
16
- * @param {string } name , The name of your custom header.
16
+ * @param {string } key , The key of your custom header.
17
17
* @param {string } value, The value of your custom header.
18
18
* @example
19
- * var header1 = Metadata("name1 ", "value1");
19
+ * var metadata1 = Metadata("key1 ", "value1");
20
20
*
21
21
*/
22
- constructor ( name , value ) {
23
- this . setName ( name ) ;
22
+ constructor ( key , value ) {
23
+ this . setKey ( key ) ;
24
24
this . setValue ( value ) ;
25
25
}
26
26
27
27
/**
28
- * Sets the Metadata Name .
28
+ * Sets the Metadata Key .
29
29
* @param {string } value
30
30
*/
31
- setName ( value ) {
31
+ setKey ( value ) {
32
32
if ( typeof value === 'undefined' || ! value ) {
33
33
return ;
34
34
}
35
35
if ( typeof value !== 'string' ) {
36
- throw new Error ( "Invalid custom header name , type of 'string' was expected." ) ;
36
+ throw new Error ( "Invalid metadata , type of 'string' was expected." ) ;
37
37
}
38
38
/**
39
- * The Metadata Name .
39
+ * The Metadata Key .
40
40
*/
41
- this . name = value ;
41
+ this . key = value ;
42
42
}
43
43
44
44
/**
@@ -62,23 +62,23 @@ class Metadata {
62
62
* A quick check to ensure that the Metadata is valid.
63
63
*/
64
64
isValid ( ) {
65
- if ( ( ! this . name && this . name !== "" ) && ( ! this . value && this . value !== "" ) )
65
+ if ( ( ! this . key && this . key !== "" ) && ( ! this . value && this . value !== "" ) )
66
66
return false ;
67
67
return true ;
68
68
}
69
69
/**
70
70
* String representation of the Metadata class.
71
71
*/
72
72
toString ( ) {
73
- return `${ this . name } , ${ this . value } ` ;
73
+ return `${ this . key } , ${ this . value } ` ;
74
74
}
75
75
/**
76
76
* JSON string representation of the Metadata class.
77
77
*/
78
78
toJSON ( ) {
79
79
80
80
return {
81
- name : this . name ,
81
+ key : this . key ,
82
82
value : this . value
83
83
} ;
84
84
0 commit comments