Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static validateAge(input) {
// Try to recognize the input as a number. This works for responses such as "twelve" as well as "12".
try {
// Attempt to convert the Recognizer result to an integer. This works for "a dozen", "twelve", "12", and so on.
// The recognizer returns a list of potential recognition results, if any.
const results = Recognizers.recognizeNumber(input, Recognizers.Culture.English);
let output;
results.forEach(result => {
// result.resolution is a dictionary, where the "value" entry contains the processed string.
const value = result.resolution.value;
if (value) {
const age = parseInt(value);
if (!isNaN(age) && age >= 18 && age <= 120) {
output = { success: true, age: age };
return;
}
}
});
return output || { success: false, message: 'Please enter an age between 18 and 120.' };
} catch (error) {
return {
success: false,
var Recognizers = require('@microsoft/recognizers-text-suite');
// Use English for the Recognizers culture
const defaultCulture = Recognizers.Culture.English;
// Start Sample
showIntro();
runRecognition();
// Read from Console and recognize
function runRecognition() {
var stdin = process.openStdin();
// Read the text to recognize
write('Enter the text to recognize: ');
stdin.addListener('data', function (e) {
var input = e.toString().trim();
if (input) {
// Exit
var recognizeNumber = (query) => Recognizers.recognizeNumber(query, Recognizers.Culture.English);
var recognizeDate = (query) => Recognizers.recognizeDateTime(query, Recognizers.Culture.English);
var recognizeDate = (query) => Recognizers.recognizeDateTime(query, Recognizers.Culture.English);
var recognizeBoolean = (query) => Recognizers.recognizeBoolean(query, Recognizers.Culture.English);