-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] Validate Email Unicode Ranges
- Loading branch information
Showing
3 changed files
with
77 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
|
||
}); |
Oops, something went wrong.