mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 21:16:34 +02:00
Run linter
This commit is contained in:
parent
179542897c
commit
056ece0238
|
@ -1,5 +1,3 @@
|
||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a string of random chars
|
* Generates a string of random chars
|
||||||
* @param {Number} length Length of the string to generate
|
* @param {Number} length Length of the string to generate
|
||||||
|
@ -23,7 +21,10 @@ export const generateChars = function(length) {
|
||||||
* @return {String} Unique Id
|
* @return {String} Unique Id
|
||||||
*/
|
*/
|
||||||
export const generateId = function(element, prefix) {
|
export const generateId = function(element, prefix) {
|
||||||
let id = element.id || (element.name && (`${element.name}-${generateChars(2)}`)) || generateChars(4);
|
let id =
|
||||||
|
element.id ||
|
||||||
|
(element.name && `${element.name}-${generateChars(2)}`) ||
|
||||||
|
generateChars(4);
|
||||||
id = id.replace(/(:|\.|\[|\]|,)/g, '');
|
id = id.replace(/(:|\.|\[|\]|,)/g, '');
|
||||||
id = prefix + id;
|
id = prefix + id;
|
||||||
|
|
||||||
|
@ -56,10 +57,14 @@ export const isType = function(type, obj) {
|
||||||
* @param {Object} obj Object to be tested
|
* @param {Object} obj Object to be tested
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
export const isElement = o => (
|
export const isElement = o =>
|
||||||
typeof HTMLElement === 'object' ? o instanceof HTMLElement : // DOM2
|
typeof HTMLElement === 'object'
|
||||||
o && typeof o === 'object' && o !== null && o.nodeType === 1 && typeof o.nodeName === 'string'
|
? o instanceof HTMLElement // DOM2
|
||||||
);
|
: o &&
|
||||||
|
typeof o === 'object' &&
|
||||||
|
o !== null &&
|
||||||
|
o.nodeType === 1 &&
|
||||||
|
typeof o.nodeName === 'string';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges unspecified amount of objects into new object
|
* Merges unspecified amount of objects into new object
|
||||||
|
@ -78,12 +83,12 @@ export const extend = function() {
|
||||||
for (const prop in obj) {
|
for (const prop in obj) {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
||||||
// If deep merge and property is an object, merge properties
|
// If deep merge and property is an object, merge properties
|
||||||
if (isType('Object', obj[prop])) {
|
if (isType('Object', obj[prop])) {
|
||||||
extended[prop] = extend(true, extended[prop], obj[prop]);
|
extended[prop] = extend(true, extended[prop], obj[prop]);
|
||||||
} else {
|
} else {
|
||||||
extended[prop] = obj[prop];
|
extended[prop] = obj[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,7 +180,8 @@ export const isScrolledIntoView = (el, parent, direction = 1) => {
|
||||||
|
|
||||||
if (direction > 0) {
|
if (direction > 0) {
|
||||||
// In view from bottom
|
// In view from bottom
|
||||||
isVisible = (parent.scrollTop + parent.offsetHeight) >= (el.offsetTop + el.offsetHeight);
|
isVisible =
|
||||||
|
parent.scrollTop + parent.offsetHeight >= el.offsetTop + el.offsetHeight;
|
||||||
} else {
|
} else {
|
||||||
// In view from top
|
// In view from top
|
||||||
isVisible = el.offsetTop >= parent.scrollTop;
|
isVisible = el.offsetTop >= parent.scrollTop;
|
||||||
|
@ -190,7 +196,8 @@ export const isScrolledIntoView = (el, parent, direction = 1) => {
|
||||||
* @return {String} Sanitised string
|
* @return {String} Sanitised string
|
||||||
*/
|
*/
|
||||||
export const stripHTML = html =>
|
export const stripHTML = html =>
|
||||||
html.replace(/&/g, '&')
|
html
|
||||||
|
.replace(/&/g, '&')
|
||||||
.replace(/>/g, '&rt;')
|
.replace(/>/g, '&rt;')
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/"/g, '"');
|
.replace(/"/g, '"');
|
||||||
|
@ -224,7 +231,7 @@ export const strToEl = (function() {
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
};
|
};
|
||||||
}());
|
})();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the width of a passed input based on its value and passes
|
* Determines the width of a passed input based on its value and passes
|
||||||
|
@ -351,33 +358,39 @@ export const reduceToValues = (items, key = 'value') => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch properties from object
|
* Fetch properties from object
|
||||||
* @param {Object} object Related object
|
* @param {Object} object Related object
|
||||||
* @param {String} properties Properties from object
|
* @param {String} properties Properties from object
|
||||||
*/
|
*/
|
||||||
export const fetchFromObject = function (object, properties){
|
export const fetchFromObject = (object, properties) => {
|
||||||
const index = properties.indexOf('.');
|
const index = properties.indexOf('.');
|
||||||
|
|
||||||
if (index > -1){
|
if (index > -1) {
|
||||||
return fetchFromObject(object[properties.substring(0, index)], properties.substr(index + 1));
|
return fetchFromObject(
|
||||||
|
object[properties.substring(0, index)],
|
||||||
|
properties.substr(index + 1),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return object[properties];
|
return object[properties];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isIE11 = () => {
|
export const isIE11 = () => {
|
||||||
return !!(navigator.userAgent.match(/Trident/) && navigator.userAgent.match(/rv[ :]11/));
|
return !!(
|
||||||
|
navigator.userAgent.match(/Trident/) &&
|
||||||
|
navigator.userAgent.match(/rv[ :]11/)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const existsInArray = (array, value) => {
|
export const existsInArray = (array, value) => {
|
||||||
return array.some((item) => {
|
return array.some(item => {
|
||||||
if (isType('String', value)) {
|
if (isType('String', value)) {
|
||||||
return item.value === value.trim();
|
return item.value === value.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.value === value;
|
return item.value === value;
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue