3 const parameters
= new Map();
5 * De-duplicating factory of minimal-objects to track the named-parameter parts of path definitions.
7 * @property {String} parameter
9 class PathParameter
extends null {
10 constructor(parameter
) {
11 if (!parameter
|| typeof(parameter
) !== 'string') {
12 throw new RangeError('parameter must be string');
14 if (parameters
.has(parameter
)) {
15 return parameters
.get(parameter
);
17 const pathParameter
= Object
.create(PathParameter
.prototype);
18 pathParameter
.parameter
= parameter
;
19 parameters
.set(parameter
, pathParameter
);
20 Object
.freeze(pathParameter
);
28 return `{${this.constructor.name} ${this.parameter}}`;
32 * Clear the de-duplication table, for tests.
35 this.parameters
.clear();
38 PathParameter
.parameters
= parameters
;
40 module
.exports
= PathParameter
;