lodash#reject JavaScript Examples
The following examples show how to use
lodash#reject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From holo-schedule with MIT License | 5 votes |
initOnce = async () => {
global.workflows = workflows
global.store = store
global.alarm = alarm
await store.init()
await alarm.init(store)
await i18n.init(store)
await workflows.init()
if (isStartUp) {
// Use new state
await clearCachedEndedLives()
await setIsPopupFirstRun(true)
console.log('[background]States have been cleared.')
}
requests.onSuccessRequest.addEventListener(() => {
const lastSuccessRequestTime = getLastSuccessRequestTime() ?? getUnix()
const timestamp = getUnix()
if (timestamp - lastSuccessRequestTime > 60 * 5) {
clearCachedEndedLives()
}
setLastSuccessRequestTime(timestamp)
})
store.subscribe(ENDED_LIVES, async (lives, prevLives) => workflows.syncHotnesses(
reject(differenceBy(lives, prevLives, 'id'), 'hotnesses'),
))
browser.alarms.onAlarm.addListener(handleAlarm)
browser.alarms.create(ALARM_NAME, { periodInMinutes: 1 })
browser.runtime.sendMessage('background alive').catch(err => {
if (err.message.startsWith('Could not establish connection.')) {
console.log('[background]on message error. Keep calm, this error is in expect.')
} else {
console.log('[background]on message error', err.message)
}
})
}
Example #2
Source File: ValidateInput.js From SESTA-FMS with GNU Affero General Public License v3.0 | 5 votes |
validateInput = (value, inputValidations = {}, type = "text") => {
let errors = [];
const emailRegex = new RegExp(
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
const phoneRegex = new RegExp(
/^\s*(?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *[x/#]{1}(\d+))?\s*$/
);
const passRegx = new RegExp("^(?=.*[a-zA-Z])(?=.*[0-9])(?=.{8,})");
// handle i18n
const requiredError = { id: "components.Input.error.validation.required" };
mapKeys(inputValidations, (validationValue, validationKey) => {
switch (validationKey) {
case "max":
if (parseInt(value, 10) > validationValue.value) {
errors.push(validationValue.message);
}
break;
case "maxLength":
if (value.length > validationValue.value) {
errors.push(validationValue.message);
}
break;
case "min":
if (parseInt(value, 10) < validationValue.value) {
errors.push(validationValue.message);
}
break;
case "minLength":
if (value.length < validationValue.value) {
errors.push(validationValue.message);
}
break;
case "required":
if (value.length === 0) {
errors.push(validationValue.message);
}
break;
case "regex":
if (!new RegExp(validationValue.value).test(value)) {
errors.push(validationValue.message);
}
break;
case "validatePasswordRegex":
if (value.length !== 0 && !passRegx.test(value)) {
errors.push(validationValue.message);
}
break;
case "email":
if (value.length !== 0 && !emailRegex.test(value)) {
errors.push(validationValue.message);
}
break;
case "phone":
if (value.length !== 0 && !phoneRegex.test(value)) {
errors.push(validationValue.message);
}
break;
default:
errors = [];
}
});
if (type === "email" && !emailRegex.test(value)) {
errors.push("Not an email");
}
if (includes(errors, requiredError)) {
errors = reject(errors, (error) => error !== requiredError);
}
return errors;
}