Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elr-utility-lib

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elr-utility-lib - npm Package Compare versions

Comparing version 1.0.6 to 2.0.0

.nyc_output/adb255f4042b554ea0691a9037a49064.json

741

dist/main.js

@@ -9,10 +9,2 @@ 'use strict';

var $ = require('jquery');
if (!Number.isNan) {
Number.isNan = function (num) {
return num !== num;
};
}
var elrUtilities = function elrUtilities() {

@@ -46,24 +38,24 @@ var self = {

// validates United States phone number patterns
phone: /^((?:\d{3}[)-.])?(?:[\s]?\d{3})(?:[\-\.]?\d{4})(?:[xX]\d+)?)$/i,
alphaNumDash: /^[a-z\d- ]*$/i,
phone: /^(?:\d{10})|^((?:\()?(?:\d{3}[)-.])?(?:[\s]?\d{3})(?:[\-\.]?\d{4})(?:[xX]\d+)?)$/i,
slug: /^[a-z\d-]*$/i,
tags: /<[a-z]+.*>.*<\/[a-z]+>/i,
// matched all major cc
creditCard: new RegExp('^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$'),
creditCard: /^(?:3[47]\d{2}([\ \-]?)\d{6}\1\d|(?:(?:4\d|5[1-5]|65)\d{2}|6011)([\ \-]?)\d{4}\2\d{4}\2)\d{4}$/,
cvv: /^[0-9]{3,4}$/,
// mm/dd/yyyy
monthDayYear: new RegExp('^(?:[0]?[1-9]|[1][012]|[1-9])[-\/.](?:[0]?[1-9]|[12][0-9]|[3][01])[-\/.][0-9]{4}$'),
monthDayYear: /^(?:[0]?[1-9]|[1][012]|[1-9])[-\/.](?:[0]?[1-9]|[12][0-9]|[3][01])[-\/.][0-9]{4}$/,
// 00:00pm
time: new RegExp('^(?:[12][012]:|[0]?[0-9]:)[012345][0-9](?:\/:[012345][0-9])?(?:am|pm)$', 'i'),
hour: /^(\\d+)/,
minute: /:(\\d+)/,
time: /(?:^(?:[12][012]:|[0]?[0-9]:)[012345][0-9](?::[012345][0-9])?(?:am|pm)$)|(?:^(?:(?:1[0-9])|(?:2[0-3])|(?:0?[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?$)/i,
hour: /^([12][012])(?=:)|^([0]?[0-9])(?=:)|^(1[0-5])(?=:)|^(2[0-3])(?=:)/,
minute: /:(0[0-9])|:([1-5][0-9])/,
ampm: /(am|pm|AM|PM)$/,
longDate: new RegExp('^(?:[a-z]*[\\.,]?\\s)?[a-z]*\\.?\\s(?:[3][01],?\\s|[012][1-9],?\\s|[1-9],?\\s)[0-9]{4}$', 'i'),
shortDate: new RegExp('((?:[0]?[1-9]|[1][012]|[1-9])[-\/.](?:[0]?[1-9]|[12][0-9]|[3][01])[-\/.][0-9]{4})'),
longTime: new RegExp('((?:[12][012]:|[0]?[0-9]:)[012345][0-9](?:\\:[012345][0-9])?(?:am|pm)?)', 'i'),
longMonth: new RegExp('\b(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)'),
dateNumber: new RegExp('[\\s\/\\-\\.](?:([3][01]),?[\\s\/\\-\\.]?|([012][1-9]),?[\\s\/\\-\\.]?|([1-9]),?[\\s\/\\-\\.]?)'),
year: new RegExp('([0-9]{4})'),
dateKeywords: new RegExp('^(yesterday|today|tomorrow)', 'i'),
timeKeywords: new RegExp('^(noon|midnight)', 'i'),
singleSpace: new RegExp('\\s'),
longDate: /^(?:[a-z]*[\.,]?\s)?[a-z]*\.?\s(?:[3][01],?\s|[012][1-9],?\s|[1-9],?\s)[0-9]{4}$/i,
// shortDate: this.monthDayYear,
longTime: /((?:[12][012]:|[0]?[0-9]:)[012345][0-9](?::[012345][0-9])?(?:am|pm)?)/i,
longMonth: /\b(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)/,
dateNumber: /[\s\/\-\.](?:([3][01]),?[\s\/\-\.]?|([012][1-9]),?[\s\/\-\.]?|([1-9]),?[\s\/\-\.]?)/,
year: /([0-9]{4})/,
dateKeywords: /^(yesterday|today|tomorrow)/i,
timeKeywords: /^(noon|midnight)/i,
singleSpace: /\s/,

@@ -109,14 +101,2 @@ // sort patterns

},
// filters an array using a callback function
// exclude(arr, fn) {
// let list = [];
// for (let i = 0; i < arr.length; i++) {
// if (fn(arr[i])) {
// list.push(arr[i]);
// }
// }
// return list;
// };
isDate: function isDate(val) {

@@ -132,3 +112,3 @@ return this.patterns.sortMonthDayYear.test(val) ? true : false;

isTime: function isTime(val) {
return this.patterns.sortTime.test(val) ? true : false;
return this.patterns.time.test(val) ? true : false;
},

@@ -141,3 +121,2 @@ getDataTypes: function getDataTypes(values) {

var types = [];
type = type || null;

@@ -168,6 +147,7 @@ if (type) {

},
generateRandomString: function generateRandomString(length, charset) {
generateRandomString: function generateRandomString() {
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
var charset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var str = '';
length = length || 10;
charset = charset || 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

@@ -189,3 +169,3 @@ for (var i = 0, n = charset.length; i < length; i++) {

if (str) {
return str.length < reqLength ? true : false;
return str.length <= reqLength ? true : false;
}

@@ -195,18 +175,6 @@

},
getText: function getText(elems) {
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' ';
var text = [];
self.each(elems, function () {
var val = this.innerText || this.textContent;
text.push(self.trim(val));
});
return text.join(separator);
},
getTextArray: function getTextArray(elems) {
var arr = [];
self.each(elems, function () {
this.each(elems, function () {
var val = this.innerText || this.textContent;

@@ -218,39 +186,22 @@ arr.push(val);

},
getText: function getText(elems) {
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' ';
return this.getTextArray(elems).join(separator);
},
getValue: function getValue(field) {
var value = self.trim(field.value);
var value = this.trim(field.value);
if (value.length > 0) {
return value;
} else {
return null;
}
},
getColumnList: function getColumnList(columnNum, $listItems) {
var $list = [];
self.each($listItems, function (k, v) {
$list.push($(v).find('td').eq(columnNum));
return $list;
});
return $list;
return null;
},
getListValues: function getListValues($list) {
var values = [];
self.each($list, function (k, v) {
values.push(self.trim($(v).text()).toLowerCase());
return values;
});
return values;
},
// removes leading 'the' or 'a' from a string
cleanAlpha: function cleanAlpha(str, ignoreWords) {
ignoreWords = ignoreWords || ['the', 'a'];
cleanAlpha: function cleanAlpha(str) {
var ignoreWords = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['the', 'a'];
self.each(ignoreWords, function () {
this.each(ignoreWords, function () {
var re = new RegExp('^' + this + '\\s', 'i');

@@ -271,8 +222,8 @@ str = str.replace(re, '');

// debounce
throttle: function throttle(fn, threshold, scope) {
throttle: function throttle(fn, scope) {
var threshold = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 500;
var last = void 0;
var deferTimer = void 0;
threshold = threshold || 500;
return function () {

@@ -296,123 +247,6 @@ var context = scope || this;

},
clearElement: function clearElement($el, speed) {
speed = speed || 300;
$el.fadeOut(speed, function () {
$(this).remove();
});
},
clearForm: function clearForm($fields) {
$fields.each(function () {
var $that = $(this);
if ($that.attr('type') === 'checkbox') {
$that.prop('checked', false);
} else {
$that.val('');
}
});
},
cleanString: function cleanString(str, re) {
var reg = new RegExp(re, 'i');
return self.trim(str.replace(reg, ''));
return this.trim(str.replace(reg, ''));
},
getFormData: function getFormData($form) {
// get form data and return an object
// need to remove dashes from ids
var formInput = {};
var $fields = $form.find(':input').not('button').not(':checkbox');
var $checkboxes = $form.find('input:checked');
if ($checkboxes.length !== 0) {
(function () {
var boxIds = [];
$checkboxes.each(function () {
boxIds.push($(this).attr('id'));
});
boxIds = self.unique(boxIds);
self.each(boxIds, function () {
var checkboxValues = [];
var $boxes = $form.find('input:checked#' + this);
$boxes.each(function () {
checkboxValues.push(self.trim($(this).val()));
});
formInput[this] = checkboxValues;
return;
});
})();
}
self.each($fields, function () {
var $that = $(this);
var id = $that.attr('id');
var formInput = [];
var input = void 0;
if (self.trim($that.val()) === '') {
input = null;
} else {
input = self.trim($that.val());
}
if (input) {
formInput[id] = input;
}
return;
});
return formInput;
},
// wrapper for creating jquery objects
createElement: function createElement(tagName) {
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return $('<' + tagName + '></' + tagName + '>', attrs);
},
toTop: function toTop($content, speed) {
$content.stop().animate({
'scrollTop': $content.position().top
}, speed, 'swing');
},
killEvent: function killEvent($el, eventType) {
var selector = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
if (selector === null) {
$el.on(eventType, function (e) {
e.stopPropagation();
});
}
$el.on(eventType, selector, function (e) {
e.stopPropagation();
});
},
// scrollEvent($el, offset, cb) {
// // TODO: finish thie function
// if ($(document).scrollTop() > $(window).height()) {
// cb();
// }
// },
scrollToView: function scrollToView($el) {
var speed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 300;
var showElement = function showElement(speed) {
var scroll = $(document).scrollTop();
var height = $(window).height();
if (scroll > height) {
$el.fadeIn(speed);
} else if (scroll < height) {
$el.fadeOut(speed);
}
};
$(window).on('scroll', self.throttle(showElement, 100));
},
strToArray: function strToArray(str) {

@@ -422,4 +256,4 @@ var arr = [];

self.each(splitStr, function () {
arr.push(self.trim(this));
this.each(splitStr, function () {
arr.push(this.trim(this));
});

@@ -441,7 +275,7 @@

},
inArray: function inArray(arr, item, i) {
return arr == null ? -1 : arr.indexOf(item, i);
inArray: function inArray(arr, item, startIndex) {
return arr === null ? -1 : arr.indexOf(item, startIndex);
},
// create an array of unique items from a list
// create an array of items from a list
toArray: function toArray(items) {

@@ -452,3 +286,3 @@ var unique = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

self.each(items, function () {
this.each(items, function () {
arr.push(this.textContent);

@@ -467,4 +301,6 @@

// create object keys with arrays for each value in an array
createArrays: function createArrays(obj, list) {
self.each(list, function () {
createArrays: function createArrays(list) {
var obj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.each(list, function () {
obj[this] = [];

@@ -480,3 +316,3 @@ });

self.each(obj, function () {
this.each(obj, function () {
arr = arr.concat(this);

@@ -487,474 +323,53 @@ });

},
// test for alpha values and perform alpha sort
sortValues: function sortValues(a, b) {
compareAlpha: function compareAlpha(a, b) {
var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'ascending';
if (this.patterns.alpha.test(a)) {
if (a < b) {
return dir === 'ascending' ? -1 : 1;
} else if (a > b) {
return dir === 'ascending' ? 1 : -1;
} else if (a === b) {
return 0;
}
if (a < b) {
return dir === 'ascending' ? -1 : 1;
} else if (a > b) {
return dir === 'ascending' ? 1 : -1;
}
return dir === 'ascending' ? a - b : b - a;
return 0;
},
sortComplexList: function sortComplexList(types, listItems) {
compare: function compare(a, b) {
var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'ascending';
var that = this;
var sortLists = {};
// create sortList arrays
that.createArrays(sortLists, types);
// add list items to sortLists arrays
that.each(types, function () {
var type = this;
that.each(listItems, function () {
var listItem = this;
var val = that.trim($(listItem).text());
if (that['is' + that.capitalize(type)].call(that, val)) {
sortLists[type].push(listItem);
} else {
return;
}
});
that.each(sortLists[type], function () {
var val = $(this).text();
$(listItems).each(function (k) {
var listVal = $(this).text();
if (listVal === val) {
listItems.splice(k, 1);
}
});
});
});
// sort sortLists arrays
that.each(sortLists, function (key) {
that['sort' + that.capitalize(key)](sortLists[key], dir);
});
// that.each(types, function() {
// let type = this;
// that.each(sortLists[type], function(k, v) {
// console.log($(v).text() + ':' + type);
// });
// });
return that.concatArrays(sortLists);
return dir === 'ascending' ? a - b : b - a;
},
sortDate: function sortDate($items, dir) {
var _this2 = this;
var sort = function sort(a, b) {
if (_this2.isDate(_this2.trim($(a).text())) && _this2.isDate(_this2.trim($(b).text()))) {
a = new Date(_this2.patterns.sortMonthDayYear.exec(_this2.trim($(a).text())));
b = new Date(_this2.patterns.sortMonthDayYear.exec(_this2.trim($(b).text())));
}
// test for alpha values and perform alpha sort
sortValues: function sortValues(a, b) {
var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'ascending';
return _this2.sortValues(a, b, dir);
};
if (this.patterns.alpha.test(a)) {
return this.compareAlpha(a, b, dir);
}
return $items.sort(sort);
return this.compare(a, b, dir);
},
// converts a time string to 24hr time
parseTime: function parseTime(time) {
var minutes = this.patterns.minute.exec(time)[1];
var ampm = this.patterns.ampm.exec(time)[1].toLowerCase();
var hour = parseInt(this.patterns.hour.exec(time)[1], 10);
to24hr: function to24hr(hour, minutes, ampm) {
if (ampm === 'am') {
hour = hour.toString();
var hourStr = hour.toString();
if (hour === '12') {
hour = '00';
} else if (hour.length === 1) {
hour = '0' + hour;
}
return hour + ':' + minutes;
} else if (ampm === 'pm') {
return hour + 12 + ':' + minutes;
return hourStr === '12' ? '00:' + minutes : '0' + hourStr + ':' + minutes;
// if 12pm
} else if (hour === 12) {
return '12:' + minutes;
}
return 'should be am or pm';
// if pm after 12
return hour + 12 + ':' + minutes;
},
sortTime: function sortTime($items, dir) {
var _this3 = this;
parseTime: function parseTime(time) {
if (this.patterns.time.test(time) && this.patterns.ampm.test(time)) {
var minutes = this.patterns.minute.exec(time)[2];
var hour = parseInt(this.patterns.hour.exec(time)[0], 10);
var ampm = this.patterns.ampm.exec(time)[0].toLowerCase();
var sort = function sort(a, b) {
var time1 = _this3.patterns.sortTime.exec(_this3.trim($(a).text()))[0];
var time2 = _this3.patterns.sortTime.exec(_this3.trim($(b).text()))[0];
if (_this3.isTime(_this3.trim($(a).text())) && _this3.isTime(_this3.trim($(b).text()))) {
a = new Date('04-22-2014 ' + _this3.parseTime(time1));
b = new Date('04-22-2014 ' + _this3.parseTime(time2));
}
return _this3.sortValues(a, b, dir);
};
return $items.sort(sort);
},
sortAlpha: function sortAlpha($items, dir) {
var _this4 = this;
var sort = function sort(a, b) {
a = _this4.cleanAlpha(_this4.trim($(a).text()), ['the', 'a']).toLowerCase();
b = _this4.cleanAlpha(_this4.trim($(b).text()), ['the', 'a']).toLowerCase();
return _this4.sortValues(a, b, dir);
};
return $items.sort(sort);
},
sortNumber: function sortNumber($items, dir) {
var _this5 = this;
var sort = function sort(a, b) {
a = parseFloat(_this5.trim($(a).text()));
b = parseFloat(_this5.trim($(b).text()));
return _this5.sortValues(a, b, dir);
};
return $items.sort(sort);
},
sortColumnDate: function sortColumnDate($listItems, dir, columnNum) {
var _this6 = this;
var sort = function sort(a, b) {
a = _this6.trim($(a).find('td').eq(columnNum).text());
b = _this6.trim($(b).find('td').eq(columnNum).text());
if (_this6.isDate(a) && _this6.isDate(b)) {
a = new Date(_this6.patterns.monthDayYear.exec(a));
b = new Date(_this6.patterns.monthDayYear.exec(b));
return _this6.sortValues(a, b, dir);
}
return;
};
return $listItems.sort(sort);
},
sortColumnTime: function sortColumnTime($listItems, dir, columnNum) {
var _this7 = this;
var sort = function sort(a, b) {
a = _this7.trim($(a).find('td').eq(columnNum).text());
b = _this7.trim($(b).find('td').eq(columnNum).text());
if (_this7.isTime(a) && _this7.isTime(b)) {
a = new Date('04-22-2014 ' + _this7.parseTime(_this7.patterns.monthDayYear.exec(a)));
b = new Date('04-22-2014 ' + _this7.parseTime(_this7.patterns.monthDayYear.exec(b)));
} else {
return;
}
return _this7.sortValues(a, b, dir);
};
return $listItems.sort(sort);
},
sortColumnAlpha: function sortColumnAlpha($listItems, dir, columnNum) {
var _this8 = this;
var ignoreWords = ['a', 'the'];
var sort = function sort(a, b) {
a = _this8.cleanAlpha(_this8.trim($(a).find('td').eq(columnNum).text()), ignoreWords).toLowerCase();
b = _this8.cleanAlpha(_this8.trim($(b).find('td').eq(columnNum).text()), ignoreWords).toLowerCase();
return _this8.sortValues(a, b, dir);
};
return $listItems.sort(sort);
},
sortColumnNumber: function sortColumnNumber($listItems, dir, columnNum) {
var _this9 = this;
var sort = function sort(a, b) {
a = parseFloat(_this9.trim($(a).find('td').eq(columnNum).text()));
b = parseFloat(_this9.trim($(b).find('td').eq(columnNum).text()));
return _this9.sortValues(a, b, dir);
};
return $listItems.sort(sort);
},
scrollSpy: function scrollSpy($nav, $content, el, activeClass) {
var scroll = $(document).scrollTop();
var $links = $nav.find('a[href^="#"]');
var positions = this.findPositions($content, el);
this.each(positions, function (index, value) {
if (scroll === 0) {
$nav.find('a.' + activeClass).removeClass(activeClass);
$links.eq(0).addClass(activeClass);
} else if (value < scroll) {
// if value is less than scroll add activeClass to link with the same index
$nav.find('a.' + activeClass).removeClass(activeClass);
$links.eq(index).addClass(activeClass);
}
});
},
getPosition: function getPosition(height, $obj) {
if (height > 200) {
return $obj.position().top - $obj.height() / 4;
return this.to24hr(hour, minutes, ampm);
}
return $obj.position().top - $obj.height() / 2;
},
findPositions: function findPositions($content, el) {
var $sections = $content.find(el);
var positions = [];
// populate positions array with the position of the top of each section element
$sections.each(function (index) {
var $that = $(this);
var length = $sections.length;
var position = void 0;
// the first element's position should always be 0
if (index === 0) {
position = 0;
} else if (index === length - 1) {
// subtract the bottom container's full height so final scroll value is equivalent
// to last container's position
position = self.getPosition($that.height, $that);
} else {
// for all other elements correct position by only subtracting half of its height
// from its top position
position = $that.position().top - $that.height() / 4;
}
// correct for any elements _that may have a negative position value
if (position < 0) {
positions.push(0);
} else {
positions.push(position);
}
});
return positions;
},
// forces link to open in a new tab
openInTab: function openInTab($links) {
$links.on('click', function (e) {
e.preventDefault();
window.open($(this).attr('href'), '_blank');
});
},
isMobile: function isMobile() {
var mobileWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 568;
return $(window).width() <= mobileWidth ? true : false;
},
// assigns a random class to an element.
// useful for random backgrounds/styles
randomClass: function randomClass($el) {
var classList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
this.each(classList, function (index, value) {
$el.removeClass(value);
});
$el.addClass(classList[Math.floor(Math.random() * classList.length)]);
},
// smooth scroll to section of page
// put id of section in href attr of link
gotoSection: function gotoSection() {
var section = $(this).attr('href').split('#').pop();
$('body, html').stop().animate({
'scrollTop': $('#' + section).position().top
});
return false;
},
closest: function closest(el, selector) {
var firstEl = el[0];
var matchesSelector = firstEl.matches || firstEl.msMatchesSelector;
var els = [];
var closestEl = void 0;
while (firstEl) {
if (matchesSelector.call(firstEl, selector)) {
break;
}
firstEl = firstEl.parentElement;
}
els.push(closestEl);
return els;
},
// checkCollectionLength(collection) {
// // make sure an element with the index exists in the collection
// if (collection.length < index + 1) {
// console.log('There is no element with that index');
// return false;
// }
// return true;
// },
// get element in the collection with the provided index
eq: function eq(collection, index) {
var els = [];
var parent = self.parent(collection).length > 1 ? self.parent(collection)[0] : self.parent(collection);
console.log(parent);
var checkCollectionLength = function checkCollectionLength(collection) {
// make sure an element with the index exists in the collection
if (collection.length < index + 1) {
console.log('There is no element with that index');
return false;
}
return true;
};
var children = checkCollectionLength(collection) ? parent[0].children : null;
els.push(children[index]);
return els;
},
// get the index of the provided element
index: function index(el) {
var parent = self.parent(el);
return Array.prototype.indexOf.call(parent[0].children, el[0]);
},
matches: function matches(el, selector) {
var matchesSelector = el.matches || el.msMatchesSelector;
if (matchesSelector.call(el, selector)) {
return el;
} else {
return null;
}
},
// get elements not matching the given criteria
not: function not(collection, filter) {
var filtered = [];
for (var i = 0; i < collection.length; i++) {
if (!self.matches(collection[i], filter)) {
filtered.push(collection[i]);
}
}
return filtered;
},
even: function even(collection) {
var filtered = [];
for (var i = 0; i < collection.length; i++) {
if ((self.index([collection[i]]) + 1) % 2 === 0) {
filtered.push(collection[i]);
}
}
return filtered;
},
odd: function odd(collection) {
var filtered = [];
for (var i = 0; i < collection.length; i++) {
if ((self.index([collection[i]]) + 1) % 2 !== 0) {
filtered.push(collection[i]);
}
}
return filtered;
},
// get the data value from the given element
data: function data(el, dataName) {
var data = el[0].dataset[dataName];
if (typeof data !== 'undefined') {
return data;
}
console.log('there is no data attribute with this name');
return;
},
// get the first element in the collection
first: function first(collection) {
return collection[0];
},
// get the last element in the collection
last: function last(collection) {
if (collection.length > 1) {
return collection[collection.length - 1];
}
return collection[0];
},
// returns parent of the first element if a collection is provided
parent: function parent(el) {
var selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
// get the parent elements for each element in the collection
// if they are the same parent only return a single item
var parents = [];
for (var i = 0; i < el.length; i++) {
if (selector) {
parents.push(self.matches(el[i].parentNode, selector));
} else {
parents.push(el[i].parentNode);
}
}
return self.unique(parents);
},
// return all of the element's parents through the entire dom tree
parents: function parents(el) {
var selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var firstEl = el[0];
var parents = [];
while (firstEl) {
if (firstEl.tagName && typeof firstEl.tagName !== 'undefined' && firstEl.tagName !== 'HTML') {
parents.push(firstEl.parentNode);
}
firstEl = el.parentNode;
}
return parents;
return null;
}

@@ -961,0 +376,0 @@ };

{
"name": "elr-utility-lib",
"description": "JavaScript Utility Library",
"version": "1.0.6",
"version": "2.0.0",
"author": "Elizabeth Rogers",

@@ -11,4 +11,3 @@ "bugs": {

"dependencies": {
"babel-runtime": "^6.0.0",
"jquery": "^3.1.1"
"babel-runtime": "^6.0.0"
},

@@ -20,2 +19,4 @@ "devDependencies": {

"chai-arrays": "0.0.1",
"chai-jquery": "^2.0.0",
"chai-shallow-deep-equal": "^1.4.4",
"chai-subset": "^1.3.0",

@@ -39,3 +40,3 @@ "codecov": "^1.0.1",

"keywords": [
"javascript, jquery, utility, ui"
"javascript, utility, array"
],

@@ -48,10 +49,24 @@ "license": "SEE LICENSE IN LICENSE.md",

},
"config": {
"ghooks": {
"pre-commit": "gulp"
}
},
"nyc": {
"check-coverage": true,
"branches": 0,
"functions": 0,
"lines": 0,
"statements": 0,
"include": [
"src/*.js"
]
},
"scripts": {
"build": "build",
"test": "nyc mocha --compilers js:babel-core/register",
"test watch": "nyc mocha watch --compilers js:babel-core/register",
"cover": "nyc --reporter=lcov npm t",
"check-coverage": "nyc check-coverage --statements 0 --branches 0 --functions 0 --lines 0",
"test": "nyc mocha test/test.js --compilers js:babel-core/register",
"test watch": "nyc mocha test/test.js watch --compilers js:babel-core/register",
"cover": "nyc --reporter=lcov npm test",
"report-coverage": "cat ./coverage/lcov.info | codecov"
}
}

@@ -5,2 +5,4 @@ # elr-utility-lib

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![codecov](https://codecov.io/gh/Beth3346/elr-utility-lib/branch/master/graph/badge.svg)](https://codecov.io/gh/Beth3346/elr-utility-lib)
[![npm](https://img.shields.io/npm/dm/elr-utility-lib.svg?style=flat)]()

@@ -22,3 +24,2 @@ JavaScript Utility Library

- [babel-runtime](https://github.com/babel/babel/tree/master/packages): babel selfContained runtime
- [jquery](https://github.com/jquery/jquery): JavaScript library for DOM operations

@@ -25,0 +26,0 @@ ## Dev Dependencies

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc