Skip to content

Commit

Permalink
Merge pull request #3
Browse files Browse the repository at this point in the history
[API] Validate Email Unicode Ranges
  • Loading branch information
MichelineMedhat authored Aug 26, 2019
2 parents 8abfb23 + 1707a13 commit b1476f4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 108 deletions.
37 changes: 27 additions & 10 deletions api/functions/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
const functions = require('firebase-functions');

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.emailValidation = functions.https.onRequest((request, response) => {
response.status(200).json({
message: 'It worked!'
})
});
const functions = require("firebase-functions");
const unicodeRange = require("unicode-range");

exports.emailValidation = functions.https.onRequest((request, response) => {

var email = request.query.email.toString();

var getRange = c => unicodeRange("U+" + c.charCodeAt(0).toString(16));
var range = getRange(email);
var isConsistent = ![...email].some(c => getRange(c) !== range);

var rangesRTL = [
"Arabic",
"Imperial Aramaic",
"Old Turkic",
"Hebrew",
"Old Persian"
];
var isRTL = rangesRTL.some(r => r === range)

response.json({
range: isConsistent ? range : "MIXED",
isRTL: isConsistent ? isRTL : "MIXED",
isConsistent
});

});
Loading

0 comments on commit b1476f4

Please sign in to comment.