Fix trim bug

This commit is contained in:
Dennis Eichhorn 2017-09-03 20:32:43 +02:00
parent 68b046a5fc
commit 560867ebfe
3 changed files with 18 additions and 3 deletions

View File

@ -66,10 +66,13 @@
this.recognition.onstart = function() {}
this.recognition.onresult = function(event) {
console.log(event.results[event.resultIndex][0].transcript);
let result = jsOMS.trim(event.results[event.resultIndex][0].transcript);
if(self.commands.hasOwnProperty(event.results[event.resultIndex][0].transcript)) {
self.commands[event.results[event.resultIndex][0].transcript]();
console.log('.' + result + '.');
if(self.commands.hasOwnProperty(result)) {
console.log('found');
self.commands[result]();
}
}

View File

@ -26,6 +26,8 @@
*/
jsOMS.trim = function(str, char)
{
char = typeof char === 'undefined' ? ' ' : char;
return jsOMS.ltrim(jsOMS.rtrim(str, char), char);
};
@ -43,6 +45,8 @@
*/
jsOMS.rtrim = function(str, char)
{
char = typeof char === 'undefined' ? ' ' : char;
return str.replace(new RegExp("[" + char + "]*$"), '');
};
@ -60,6 +64,8 @@
*/
jsOMS.ltrim = function(str, char)
{
char = typeof char === 'undefined' ? ' ' : char;
return str.replace(new RegExp("^[" + char + "]*"), '');
};

View File

@ -26,6 +26,8 @@
*/
jsOMS.trim = function(str, char)
{
char = typeof char === 'undefined' ? ' ' : char;
return jsOMS.ltrim(jsOMS.rtrim(str, char), char);
};
@ -43,6 +45,8 @@
*/
jsOMS.rtrim = function(str, char)
{
char = typeof char === 'undefined' ? ' ' : char;
return str.replace(new RegExp("[" + char + "]*$"), '');
};
@ -60,6 +64,8 @@
*/
jsOMS.ltrim = function(str, char)
{
char = typeof char === 'undefined' ? ' ' : char;
return str.replace(new RegExp("^[" + char + "]*"), '');
};