UNPKG

node-hue-api

Version:
44 lines (43 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Placeholder = void 0; const ApiError_1 = require("../../ApiError"); class Placeholder { constructor(type, defaultName, name) { this._name = name || defaultName; this._type = type; } get name() { return this._name; } get typeDefinition() { return this._type; } set typeDefinition(type) { this._type = type; } inject(uri, parameters) { const placeholderText = `<${this.name}>`; if (uri.indexOf(placeholderText) > -1) { return uri.replace(placeholderText, this.getValue(parameters)); } return uri; } getValue(parameters) { const typeDefinition = this.typeDefinition; if (!typeDefinition) { throw new ApiError_1.ApiError('No type definition has been specified for placeholder'); } const parameter = parameters ? parameters[this.name] : undefined; const value = this._getParameterValue(parameter); return typeDefinition.getValue(value); } _getParameterValue(parameter) { return parameter; } toString() { const type = this.typeDefinition; return `${this.name}: { type:${type.type}, optional:${type.optional}, defaultValue:${type.defaultValue} }`; } } exports.Placeholder = Placeholder;