UNPKG

@hahnpro/ms-speech-sdk

Version:
1 lines 4.37 kB
{"version":3,"sources":["src/sdk/PropertyCollection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,UAAU,CAA4B;IAE9C;;;;;;;;;;;OAWG;IACI,WAAW,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM;IAsBrF;;;;;;;OAOG;IACI,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAoBjE;;;;;;OAMG;IACI,KAAK,IAAI,kBAAkB;IAWlC;;;;;;OAMG;IACI,OAAO,CAAC,qBAAqB,EAAE,kBAAkB,GAAG,IAAI;IAS/D;;;;;;OAMG;IACH,IAAW,IAAI,IAAI,MAAM,EAAE,CAE1B;CACJ","file":"PropertyCollection.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { PropertyId } from \"./Exports.js\";\n\n/**\n * Represents collection of properties and their values.\n * @class PropertyCollection\n */\nexport class PropertyCollection {\n private privKeys: string[] = [] as string[];\n private privValues: string[] = [] as string[];\n\n /**\n * Returns the property value in type String.\n * Currently only String, int and bool are allowed.\n * If the name is not available, the specified defaultValue is returned.\n * @member PropertyCollection.prototype.getProperty\n * @function\n * @public\n * @param {string} key - The parameter name.\n * @param {string | number | boolean} def - The default value which is returned if the parameter\n * is not available in the collection.\n * @returns {string} value of the parameter.\n */\n public getProperty(key: PropertyId | string, def?: string | number | boolean): string {\n let keyToUse: string;\n\n if (typeof key === \"string\") {\n keyToUse = key;\n } else {\n keyToUse = PropertyId[key];\n }\n\n for (let n = 0; n < this.privKeys.length; n++) {\n if (this.privKeys[n] === keyToUse) {\n return this.privValues[n];\n }\n }\n\n if (def === undefined) {\n return undefined;\n }\n\n return String(def);\n }\n\n /**\n * Sets the String value of the parameter specified by name.\n * @member PropertyCollection.prototype.setProperty\n * @function\n * @public\n * @param {string} key - The parameter name.\n * @param {string} value - The value of the parameter.\n */\n public setProperty(key: string | PropertyId, value: string): void {\n let keyToUse: string;\n\n if (typeof key === \"string\") {\n keyToUse = key;\n } else {\n keyToUse = PropertyId[key];\n }\n\n for (let n = 0; n < this.privKeys.length; n++) {\n if (this.privKeys[n] === keyToUse) {\n this.privValues[n] = value;\n return;\n }\n }\n\n this.privKeys.push(keyToUse);\n this.privValues.push(value);\n }\n\n /**\n * Clones the collection.\n * @member PropertyCollection.prototype.clone\n * @function\n * @public\n * @returns {PropertyCollection} A copy of the collection.\n */\n public clone(): PropertyCollection {\n const clonedMap = new PropertyCollection();\n\n for (let n = 0; n < this.privKeys.length; n++) {\n clonedMap.privKeys.push(this.privKeys[n]);\n clonedMap.privValues.push(this.privValues[n]);\n }\n\n return clonedMap;\n }\n\n /**\n * Merges this set of properties into another, no overwrites.\n * @member PropertyCollection.prototype.mergeTo\n * @function\n * @public\n * @param {PropertyCollection} destinationCollection - The collection to merge into.\n */\n public mergeTo(destinationCollection: PropertyCollection): void {\n this.privKeys.forEach((key: string | PropertyId): void => {\n if (destinationCollection.getProperty(key, undefined) === undefined) {\n const value = this.getProperty(key);\n destinationCollection.setProperty(key, value);\n }\n });\n }\n\n /**\n * Get the keys in Property Collection.\n * @member PropertyCollection.prototype.keys\n * @function\n * @public\n * @returns {string []} Keys in the collection.\n */\n public get keys(): string[] {\n return this.privKeys;\n }\n}\n"]}