Return Sequelize Array from String or String Array After Filtering

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












My main concern is if this is the most efficient way to filter, and subsequently search for, the three type of values.



Here are my helper methods and their return data type:



_.email.isValidText(string) : boolean
_.strings.isValid(string) : boolean
_.strings.isDigits(string) : boolean
_.uuid.isValidUid(string) : boolean
_.strings.toLowerCase(string || string) : string || string


I'm trying to validate between three types of values:



SMTP/Email Address
10-digit Phone Number
prefixed 10-digit Phone Number (uid.xxxxxxxxxx)


The _d is a soft delete field (timestamp) which indicates when / if the row was deleted.



function getByAddress (valueOrValues, done) 
valueOrValues = .concat(valueOrValues).filter(_.strings.isValid).map(_.strings.toLowerCase);
var email = valueOrValues.filter(_.email.isValidText);
var outgoing = valueOrValues.filter(_.strings.isDigits);
var incoming = valueOrValues.filter(function(v)
var parts = v.split('.');
return (parts.length === 2 && _.uuid.isValidUid(parts[0]) && _.strings.isDigits(parts[1]));
);
var valid = .concat(email, outgoing, incoming);
var invalid = valueOrValues.filter(function(v)
return (valid.indexOf(v) < 0);
);

if (invalid.length > 0) return done('create : invalid values supplied');

models.mailbox_address.findAll(
where :
address : $in : .concat(email, outgoing, incoming) ,
_d : $eq : null ,

)
.then(function(items)
return done(null, items);
)
.catch(function(err)
return done(err);
);







share|improve this question





















  • Please edit the question to clarify what the code accomplishes, with examples. Also retitle the question to state the task accomplished by the code, rather than your main concern about the code. See How to Ask.
    – 200_success
    Feb 7 at 19:36










  • @200_success : done
    – G. Deward
    Feb 7 at 19:43
















up vote
0
down vote

favorite












My main concern is if this is the most efficient way to filter, and subsequently search for, the three type of values.



Here are my helper methods and their return data type:



_.email.isValidText(string) : boolean
_.strings.isValid(string) : boolean
_.strings.isDigits(string) : boolean
_.uuid.isValidUid(string) : boolean
_.strings.toLowerCase(string || string) : string || string


I'm trying to validate between three types of values:



SMTP/Email Address
10-digit Phone Number
prefixed 10-digit Phone Number (uid.xxxxxxxxxx)


The _d is a soft delete field (timestamp) which indicates when / if the row was deleted.



function getByAddress (valueOrValues, done) 
valueOrValues = .concat(valueOrValues).filter(_.strings.isValid).map(_.strings.toLowerCase);
var email = valueOrValues.filter(_.email.isValidText);
var outgoing = valueOrValues.filter(_.strings.isDigits);
var incoming = valueOrValues.filter(function(v)
var parts = v.split('.');
return (parts.length === 2 && _.uuid.isValidUid(parts[0]) && _.strings.isDigits(parts[1]));
);
var valid = .concat(email, outgoing, incoming);
var invalid = valueOrValues.filter(function(v)
return (valid.indexOf(v) < 0);
);

if (invalid.length > 0) return done('create : invalid values supplied');

models.mailbox_address.findAll(
where :
address : $in : .concat(email, outgoing, incoming) ,
_d : $eq : null ,

)
.then(function(items)
return done(null, items);
)
.catch(function(err)
return done(err);
);







share|improve this question





















  • Please edit the question to clarify what the code accomplishes, with examples. Also retitle the question to state the task accomplished by the code, rather than your main concern about the code. See How to Ask.
    – 200_success
    Feb 7 at 19:36










  • @200_success : done
    – G. Deward
    Feb 7 at 19:43












up vote
0
down vote

favorite









up vote
0
down vote

favorite











My main concern is if this is the most efficient way to filter, and subsequently search for, the three type of values.



Here are my helper methods and their return data type:



_.email.isValidText(string) : boolean
_.strings.isValid(string) : boolean
_.strings.isDigits(string) : boolean
_.uuid.isValidUid(string) : boolean
_.strings.toLowerCase(string || string) : string || string


I'm trying to validate between three types of values:



SMTP/Email Address
10-digit Phone Number
prefixed 10-digit Phone Number (uid.xxxxxxxxxx)


The _d is a soft delete field (timestamp) which indicates when / if the row was deleted.



function getByAddress (valueOrValues, done) 
valueOrValues = .concat(valueOrValues).filter(_.strings.isValid).map(_.strings.toLowerCase);
var email = valueOrValues.filter(_.email.isValidText);
var outgoing = valueOrValues.filter(_.strings.isDigits);
var incoming = valueOrValues.filter(function(v)
var parts = v.split('.');
return (parts.length === 2 && _.uuid.isValidUid(parts[0]) && _.strings.isDigits(parts[1]));
);
var valid = .concat(email, outgoing, incoming);
var invalid = valueOrValues.filter(function(v)
return (valid.indexOf(v) < 0);
);

if (invalid.length > 0) return done('create : invalid values supplied');

models.mailbox_address.findAll(
where :
address : $in : .concat(email, outgoing, incoming) ,
_d : $eq : null ,

)
.then(function(items)
return done(null, items);
)
.catch(function(err)
return done(err);
);







share|improve this question













My main concern is if this is the most efficient way to filter, and subsequently search for, the three type of values.



Here are my helper methods and their return data type:



_.email.isValidText(string) : boolean
_.strings.isValid(string) : boolean
_.strings.isDigits(string) : boolean
_.uuid.isValidUid(string) : boolean
_.strings.toLowerCase(string || string) : string || string


I'm trying to validate between three types of values:



SMTP/Email Address
10-digit Phone Number
prefixed 10-digit Phone Number (uid.xxxxxxxxxx)


The _d is a soft delete field (timestamp) which indicates when / if the row was deleted.



function getByAddress (valueOrValues, done) 
valueOrValues = .concat(valueOrValues).filter(_.strings.isValid).map(_.strings.toLowerCase);
var email = valueOrValues.filter(_.email.isValidText);
var outgoing = valueOrValues.filter(_.strings.isDigits);
var incoming = valueOrValues.filter(function(v)
var parts = v.split('.');
return (parts.length === 2 && _.uuid.isValidUid(parts[0]) && _.strings.isDigits(parts[1]));
);
var valid = .concat(email, outgoing, incoming);
var invalid = valueOrValues.filter(function(v)
return (valid.indexOf(v) < 0);
);

if (invalid.length > 0) return done('create : invalid values supplied');

models.mailbox_address.findAll(
where :
address : $in : .concat(email, outgoing, incoming) ,
_d : $eq : null ,

)
.then(function(items)
return done(null, items);
)
.catch(function(err)
return done(err);
);









share|improve this question












share|improve this question




share|improve this question








edited Feb 7 at 19:43
























asked Feb 7 at 19:33









G. Deward

1945




1945











  • Please edit the question to clarify what the code accomplishes, with examples. Also retitle the question to state the task accomplished by the code, rather than your main concern about the code. See How to Ask.
    – 200_success
    Feb 7 at 19:36










  • @200_success : done
    – G. Deward
    Feb 7 at 19:43
















  • Please edit the question to clarify what the code accomplishes, with examples. Also retitle the question to state the task accomplished by the code, rather than your main concern about the code. See How to Ask.
    – 200_success
    Feb 7 at 19:36










  • @200_success : done
    – G. Deward
    Feb 7 at 19:43















Please edit the question to clarify what the code accomplishes, with examples. Also retitle the question to state the task accomplished by the code, rather than your main concern about the code. See How to Ask.
– 200_success
Feb 7 at 19:36




Please edit the question to clarify what the code accomplishes, with examples. Also retitle the question to state the task accomplished by the code, rather than your main concern about the code. See How to Ask.
– 200_success
Feb 7 at 19:36












@200_success : done
– G. Deward
Feb 7 at 19:43




@200_success : done
– G. Deward
Feb 7 at 19:43















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187046%2freturn-sequelize-array-from-string-or-string-array-after-filtering%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187046%2freturn-sequelize-array-from-string-or-string-array-after-filtering%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?