File: //proc/thread-self/root/home/arjun/projects/buyercall/buyercall/assets/vue/utils/util.js
import { helpers } from 'vuelidate/lib/validators';
import _ from 'lodash';
const images = importAll(require.context('../../images/', false, /\.(png|jpe?g|svg|gif)$/));
const compare = importAll(require.context('../../images/compare/', false, /\.(png|jpe?g|svg|gif)$/));
const gifs = importAll(require.context('../../images/gifs/', false, /\.(png|jpe?g|svg|gif)$/));
const credit = importAll(require.context('../../images/credit-cards/', false, /\.(png|jpe?g|svg|gif)$/));
const landing_page = importAll(require.context('../../images/landing-page/', false, /\.(png|jpe?g|svg|gif)$/));
const mobile = importAll(require.context('../../images/mobile/', false, /\.(png|jpe?g|svg|gif)$/));
const onboarding = importAll(require.context('../../images/onboarding/', false, /\.(png|jpe?g|svg|gif)$/));
const theme = importAll(require.context('../../images/theme/', false, /\.(png|jpe?g|svg|gif)$/));
const theme_new = importAll(require.context('../../images/theme-new/', false, /\.(png|jpe?g|svg|gif)$/));
const theme_1 = importAll(require.context('../../images/theme/jquery.chosen', false, /\.(png|jpe?g|svg|gif)$/));
const theme_2 = importAll(require.context('../../images/theme/jquery.colorpicker', false, /\.(png|jpe?g|svg|gif)$/));
const theme_3 = importAll(require.context('../../images/theme/jquery.datatables', false, /\.(png|jpe?g|svg|gif)$/));
const theme_4 = importAll(require.context('../../images/theme/placeholders', false, /\.(png|jpe?g|svg|gif)$/));
const theme_avatar = importAll(require.context('../../images/theme/placeholders/avatars', false, /\.(png|jpe?g|svg|gif)$/));
const theme_layout = importAll(require.context('../../images/theme/placeholders/layout', false, /\.(png|jpe?g|svg|gif)$/));
const theme_photos = importAll(require.context('../../images/theme/placeholders/photos', false, /\.(png|jpe?g|svg|gif)$/));
function importAll(r) {
return r.keys().map(r);
}
/** TOASTERS */
const toastSuccess = message => ({
message,
type: 'success',
position: 'top-right',
duration: 5000,
});
const toastError = message => ({
message,
type: 'error',
position: 'top-right',
duration: 5000,
});
const toastInfo = message => ({
message,
type: 'info',
position: 'top-right',
duration: 5000,
});
const toastWarning = message => ({
message,
type: 'warning',
position: 'top-right',
duration: 5000,
});
export const toastConfig = {
toastSuccess,
toastError,
toastInfo,
toastWarning,
};
/** VALIDATIONS */
const regexValidator = param => value => {
if (value) {
return param.test(value);
}
return true;
};
const phoneNumerValidator = helpers.regex(
'phoneNumer',
/^(\+1)?[(]?\d{3}[)]?[(\s)?.-]?\d{3}[\s.-]?\d{4}$/,
);
const passwordvalidator = value => {
const required = !helpers.req(value);
const reg = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%^*#?&])[A-Za-z\d@$!%^*#?&]{8,}$/.test(
value,
);
return required || reg;
};
const domainValidator = value => {
const required = !helpers.req(value);
const reg = /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/.test(
value,
);
return required || reg;
};
export const formvalidation = {
phoneNumerValidator,
passwordvalidator,
domainValidator,
regexValidator,
};
const phoneNumerValidatorMessage = 'Must be a US phone number.';
const passwordvalidatorMessage =
'Must be a password with minimum eight characters, at least one letter, one number and one special character';
const domainvalidatorMessage = 'Please enter a valid domain name';
export const formvalidationMessages = {
phoneNumerValidatorMessage,
passwordvalidatorMessage,
domainvalidatorMessage,
};
export const serializeForm = function(form) {
for (var pair of form.entries()) {
console.log(pair[0] + ', ' + pair[1]);
}
};
export const isImage = fileType => {
if (
_.includes(
['image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/bmp'],
fileType,
)
) {
return true;
}
return false;
};
export const isFileWithinLimit = (fileSize, threshhold) => {
if (threshhold > fileSize) {
return true;
}
return false;
};
export const chunkArrayInGroups = (arr, size) => {
var myArray = [];
for (var i = 0; i < arr.length; i += size) {
myArray.push(arr.slice(i, i + size));
}
return myArray;
};
export const formatPhoneNumber = num => {
return num;
};