From b6b5bf49c215aeeceb46e5932dfe6812e645dbf7 Mon Sep 17 00:00:00 2001 From: scottbea Date: Wed, 2 Sep 2015 12:40:25 -0500 Subject: [PATCH] Adding value normalization to ensure all values bound to slots are lowercase and trimmed. More work will be done in the future for handling the stripping or conversion of various special characters such as # or percent. --- lib/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 6d75e81..f7a0b3a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,9 +15,13 @@ var spoken = require('spoken-numbers'); function GrammarGenerator() { //(function constructor(self) {})(this); } +GrammarGenerator.prototype.normalizeTextValue = function (value) { + return (value + '').toLocaleLowerCase().trim(); +}; GrammarGenerator.prototype.replaceTopicReferenceWithValue = function (model, topicReference, value) { + var self = this; var topicReferenceToken = '{' + topicReference + '}'; - var valueToken = '{' + value + '|' + topicReference + '}'; + var valueToken = '{' + self.normalizeTextValue(value) + ' | ' + topicReference + '}'; return model.replace(topicReferenceToken, valueToken); }; GrammarGenerator.prototype.getNextTopicReference = function (model) {