Comparing version 1.0.4 to 1.1.0
@@ -103,3 +103,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
\******************/ | ||
/*! exports provided: VERSION, isEmpty, isArray, isNumber, isString, isObject, isBoolean, getQuery, getNumbers, getScrollbarWidth, getCookie, getOffset, getType, setQuery, setCookie, removeCookie, clone, invertObject, first, formatNumber, debounce, scrollTo, uniq, default */ | ||
/*! exports provided: VERSION, isEmpty, isArray, isNumber, isString, isObject, isBoolean, isEqual, getQuery, getNumbers, getScrollbarWidth, getCookie, getOffset, getType, setQuery, setCookie, removeCookie, decodeHtml, clone, invertObject, first, formatNumber, debounce, scrollTo, uniq, default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -134,52 +134,58 @@ | ||
/* harmony import */ var _lib_getQuery__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./lib/getQuery */ "./lib/getQuery.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getQuery", function() { return _lib_getQuery__WEBPACK_IMPORTED_MODULE_9__["default"]; }); | ||
/* harmony import */ var _lib_isEqual__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./lib/isEqual */ "./lib/isEqual.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isEqual", function() { return _lib_isEqual__WEBPACK_IMPORTED_MODULE_9__["default"]; }); | ||
/* harmony import */ var _lib_getNumbers__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./lib/getNumbers */ "./lib/getNumbers.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getNumbers", function() { return _lib_getNumbers__WEBPACK_IMPORTED_MODULE_10__["default"]; }); | ||
/* harmony import */ var _lib_getQuery__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./lib/getQuery */ "./lib/getQuery.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getQuery", function() { return _lib_getQuery__WEBPACK_IMPORTED_MODULE_10__["default"]; }); | ||
/* harmony import */ var _lib_getScrollbarWidth__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./lib/getScrollbarWidth */ "./lib/getScrollbarWidth.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getScrollbarWidth", function() { return _lib_getScrollbarWidth__WEBPACK_IMPORTED_MODULE_11__["default"]; }); | ||
/* harmony import */ var _lib_getNumbers__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./lib/getNumbers */ "./lib/getNumbers.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getNumbers", function() { return _lib_getNumbers__WEBPACK_IMPORTED_MODULE_11__["default"]; }); | ||
/* harmony import */ var _lib_getCookie__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./lib/getCookie */ "./lib/getCookie.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getCookie", function() { return _lib_getCookie__WEBPACK_IMPORTED_MODULE_12__["default"]; }); | ||
/* harmony import */ var _lib_getScrollbarWidth__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./lib/getScrollbarWidth */ "./lib/getScrollbarWidth.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getScrollbarWidth", function() { return _lib_getScrollbarWidth__WEBPACK_IMPORTED_MODULE_12__["default"]; }); | ||
/* harmony import */ var _lib_getOffset__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./lib/getOffset */ "./lib/getOffset.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getOffset", function() { return _lib_getOffset__WEBPACK_IMPORTED_MODULE_13__["default"]; }); | ||
/* harmony import */ var _lib_getCookie__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./lib/getCookie */ "./lib/getCookie.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getCookie", function() { return _lib_getCookie__WEBPACK_IMPORTED_MODULE_13__["default"]; }); | ||
/* harmony import */ var _lib_getType__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./lib/getType */ "./lib/getType.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getType", function() { return _lib_getType__WEBPACK_IMPORTED_MODULE_14__["default"]; }); | ||
/* harmony import */ var _lib_getOffset__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./lib/getOffset */ "./lib/getOffset.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getOffset", function() { return _lib_getOffset__WEBPACK_IMPORTED_MODULE_14__["default"]; }); | ||
/* harmony import */ var _lib_setQuery__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./lib/setQuery */ "./lib/setQuery.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setQuery", function() { return _lib_setQuery__WEBPACK_IMPORTED_MODULE_15__["default"]; }); | ||
/* harmony import */ var _lib_getType__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./lib/getType */ "./lib/getType.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getType", function() { return _lib_getType__WEBPACK_IMPORTED_MODULE_15__["default"]; }); | ||
/* harmony import */ var _lib_setCookie__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./lib/setCookie */ "./lib/setCookie.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setCookie", function() { return _lib_setCookie__WEBPACK_IMPORTED_MODULE_16__["default"]; }); | ||
/* harmony import */ var _lib_setQuery__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./lib/setQuery */ "./lib/setQuery.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setQuery", function() { return _lib_setQuery__WEBPACK_IMPORTED_MODULE_16__["default"]; }); | ||
/* harmony import */ var _lib_removeCookie__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./lib/removeCookie */ "./lib/removeCookie.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeCookie", function() { return _lib_removeCookie__WEBPACK_IMPORTED_MODULE_17__["default"]; }); | ||
/* harmony import */ var _lib_setCookie__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./lib/setCookie */ "./lib/setCookie.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setCookie", function() { return _lib_setCookie__WEBPACK_IMPORTED_MODULE_17__["default"]; }); | ||
/* harmony import */ var _lib_clone__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./lib/clone */ "./lib/clone.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "clone", function() { return _lib_clone__WEBPACK_IMPORTED_MODULE_18__["default"]; }); | ||
/* harmony import */ var _lib_removeCookie__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./lib/removeCookie */ "./lib/removeCookie.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeCookie", function() { return _lib_removeCookie__WEBPACK_IMPORTED_MODULE_18__["default"]; }); | ||
/* harmony import */ var _lib_invertObject__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./lib/invertObject */ "./lib/invertObject.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "invertObject", function() { return _lib_invertObject__WEBPACK_IMPORTED_MODULE_19__["default"]; }); | ||
/* harmony import */ var _lib_decondeHtml__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./lib/decondeHtml */ "./lib/decondeHtml.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "decodeHtml", function() { return _lib_decondeHtml__WEBPACK_IMPORTED_MODULE_19__["default"]; }); | ||
/* harmony import */ var _lib_first__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./lib/first */ "./lib/first.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "first", function() { return _lib_first__WEBPACK_IMPORTED_MODULE_20__["default"]; }); | ||
/* harmony import */ var _lib_clone__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./lib/clone */ "./lib/clone.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "clone", function() { return _lib_clone__WEBPACK_IMPORTED_MODULE_20__["default"]; }); | ||
/* harmony import */ var _lib_formatNumber__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./lib/formatNumber */ "./lib/formatNumber.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "formatNumber", function() { return _lib_formatNumber__WEBPACK_IMPORTED_MODULE_21__["default"]; }); | ||
/* harmony import */ var _lib_invertObject__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./lib/invertObject */ "./lib/invertObject.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "invertObject", function() { return _lib_invertObject__WEBPACK_IMPORTED_MODULE_21__["default"]; }); | ||
/* harmony import */ var _lib_debounce__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./lib/debounce */ "./lib/debounce.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "debounce", function() { return _lib_debounce__WEBPACK_IMPORTED_MODULE_22__["default"]; }); | ||
/* harmony import */ var _lib_first__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./lib/first */ "./lib/first.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "first", function() { return _lib_first__WEBPACK_IMPORTED_MODULE_22__["default"]; }); | ||
/* harmony import */ var _lib_scrollTo__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./lib/scrollTo */ "./lib/scrollTo.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "scrollTo", function() { return _lib_scrollTo__WEBPACK_IMPORTED_MODULE_23__["default"]; }); | ||
/* harmony import */ var _lib_formatNumber__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./lib/formatNumber */ "./lib/formatNumber.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "formatNumber", function() { return _lib_formatNumber__WEBPACK_IMPORTED_MODULE_23__["default"]; }); | ||
/* harmony import */ var _lib_uniq__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./lib/uniq */ "./lib/uniq.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "uniq", function() { return _lib_uniq__WEBPACK_IMPORTED_MODULE_24__["default"]; }); | ||
/* harmony import */ var _lib_debounce__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./lib/debounce */ "./lib/debounce.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "debounce", function() { return _lib_debounce__WEBPACK_IMPORTED_MODULE_24__["default"]; }); | ||
/* harmony import */ var _lib_scrollTo__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ./lib/scrollTo */ "./lib/scrollTo.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "scrollTo", function() { return _lib_scrollTo__WEBPACK_IMPORTED_MODULE_25__["default"]; }); | ||
/* harmony import */ var _lib_uniq__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ./lib/uniq */ "./lib/uniq.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "uniq", function() { return _lib_uniq__WEBPACK_IMPORTED_MODULE_26__["default"]; }); | ||
/** | ||
@@ -221,2 +227,4 @@ * Chober.js - is a collection of useful methods that are used by programmers every day. | ||
/** | ||
@@ -249,18 +257,20 @@ * Set version to constant. | ||
isBoolean: _lib_isBoolean__WEBPACK_IMPORTED_MODULE_8__["default"], | ||
getQuery: _lib_getQuery__WEBPACK_IMPORTED_MODULE_9__["default"], | ||
getNumbers: _lib_getNumbers__WEBPACK_IMPORTED_MODULE_10__["default"], | ||
getScrollbarWidth: _lib_getScrollbarWidth__WEBPACK_IMPORTED_MODULE_11__["default"], | ||
getCookie: _lib_getCookie__WEBPACK_IMPORTED_MODULE_12__["default"], | ||
getOffset: _lib_getOffset__WEBPACK_IMPORTED_MODULE_13__["default"], | ||
getType: _lib_getType__WEBPACK_IMPORTED_MODULE_14__["default"], | ||
setQuery: _lib_setQuery__WEBPACK_IMPORTED_MODULE_15__["default"], | ||
setCookie: _lib_setCookie__WEBPACK_IMPORTED_MODULE_16__["default"], | ||
removeCookie: _lib_removeCookie__WEBPACK_IMPORTED_MODULE_17__["default"], | ||
clone: _lib_clone__WEBPACK_IMPORTED_MODULE_18__["default"], | ||
invertObject: _lib_invertObject__WEBPACK_IMPORTED_MODULE_19__["default"], | ||
first: _lib_first__WEBPACK_IMPORTED_MODULE_20__["default"], | ||
formatNumber: _lib_formatNumber__WEBPACK_IMPORTED_MODULE_21__["default"], | ||
debounce: _lib_debounce__WEBPACK_IMPORTED_MODULE_22__["default"], | ||
scrollTo: _lib_scrollTo__WEBPACK_IMPORTED_MODULE_23__["default"], | ||
uniq: _lib_uniq__WEBPACK_IMPORTED_MODULE_24__["default"] | ||
isEqual: _lib_isEqual__WEBPACK_IMPORTED_MODULE_9__["default"], | ||
getQuery: _lib_getQuery__WEBPACK_IMPORTED_MODULE_10__["default"], | ||
getNumbers: _lib_getNumbers__WEBPACK_IMPORTED_MODULE_11__["default"], | ||
getScrollbarWidth: _lib_getScrollbarWidth__WEBPACK_IMPORTED_MODULE_12__["default"], | ||
getCookie: _lib_getCookie__WEBPACK_IMPORTED_MODULE_13__["default"], | ||
getOffset: _lib_getOffset__WEBPACK_IMPORTED_MODULE_14__["default"], | ||
getType: _lib_getType__WEBPACK_IMPORTED_MODULE_15__["default"], | ||
setQuery: _lib_setQuery__WEBPACK_IMPORTED_MODULE_16__["default"], | ||
setCookie: _lib_setCookie__WEBPACK_IMPORTED_MODULE_17__["default"], | ||
removeCookie: _lib_removeCookie__WEBPACK_IMPORTED_MODULE_18__["default"], | ||
decodeHtml: _lib_decondeHtml__WEBPACK_IMPORTED_MODULE_19__["default"], | ||
clone: _lib_clone__WEBPACK_IMPORTED_MODULE_20__["default"], | ||
invertObject: _lib_invertObject__WEBPACK_IMPORTED_MODULE_21__["default"], | ||
first: _lib_first__WEBPACK_IMPORTED_MODULE_22__["default"], | ||
formatNumber: _lib_formatNumber__WEBPACK_IMPORTED_MODULE_23__["default"], | ||
debounce: _lib_debounce__WEBPACK_IMPORTED_MODULE_24__["default"], | ||
scrollTo: _lib_scrollTo__WEBPACK_IMPORTED_MODULE_25__["default"], | ||
uniq: _lib_uniq__WEBPACK_IMPORTED_MODULE_26__["default"] | ||
}); | ||
@@ -323,5 +333,3 @@ }; | ||
* @example | ||
* window.addEventListener('scroll', debounce(() => { | ||
* console.log(Math.random()); | ||
* }, 100)); | ||
* window.addEventListener('scroll', debounce(() => console.log(Math.random()), 100)) | ||
*/ | ||
@@ -355,2 +363,32 @@ function debounce(func, delay) { | ||
/***/ "./lib/decondeHtml.js": | ||
/*!****************************!*\ | ||
!*** ./lib/decondeHtml.js ***! | ||
\****************************/ | ||
/*! exports provided: default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/** | ||
* Decode a string that has special HTML entities | ||
* | ||
* @since 1.1.0 | ||
* @param {String} html Html to decode. | ||
* @returns {String} | ||
* | ||
* @example | ||
* decodeHtml('<h1>Hi my friend!</h1>') | ||
* // => '<h1>Hi my friend!</h1>' | ||
*/ | ||
function decodeHtml(html) { | ||
var text = document.createElement('textarea'); | ||
text.innerHTML = html; | ||
return text.value; | ||
} | ||
/* harmony default export */ __webpack_exports__["default"] = (decodeHtml); | ||
/***/ }), | ||
/***/ "./lib/first.js": | ||
@@ -385,7 +423,2 @@ /*!**********************!*\ | ||
var number = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
if (!array) { | ||
throw new Error('[chober]: array is not passed.'); | ||
} | ||
return Object(_isArray__WEBPACK_IMPORTED_MODULE_0__["default"])(array) ? array.slice(0, number) : []; | ||
@@ -424,8 +457,3 @@ } | ||
var symbol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' '; | ||
if (!number) { | ||
throw new Error('[chober]: number is not passed.'); | ||
} | ||
return String(number).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, "$1".concat(symbol)); | ||
return String(number || 0).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, "$1".concat(symbol)); | ||
} | ||
@@ -497,3 +525,3 @@ | ||
if (!string) { | ||
throw new Error('[chober]: string or number is not passed.'); | ||
return ''; | ||
} | ||
@@ -575,3 +603,3 @@ | ||
* @since 0.1.0 | ||
* @param {Array} arrayFields Fields that must be an arrays. | ||
* @param {?Array} arrayFields Fields that must be arrays. | ||
* @returns {Object} | ||
@@ -581,3 +609,2 @@ * | ||
* // http://github.com/?value=test&field=hi&field=hello | ||
* | ||
* getQuery() | ||
@@ -738,2 +765,3 @@ * // => { value: 'test', field: ['hi', 'hello'] } | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -772,2 +800,3 @@ * @example | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -836,2 +865,37 @@ * @example | ||
/***/ "./lib/isEqual.js": | ||
/*!************************!*\ | ||
!*** ./lib/isEqual.js ***! | ||
\************************/ | ||
/*! exports provided: default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/** | ||
* Checking is equal items. | ||
* | ||
* @since 1.1.0 | ||
* @param {Any} firstItem First item to check. | ||
* @param {Any} secondItem Second item to check. | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
* isEqual([], []) | ||
* // => true | ||
* | ||
* isEqual({ test: 'value' }, { test: 'value' }) | ||
* // => true | ||
* | ||
* isEqual(true, false) | ||
* // => false | ||
*/ | ||
function isEqual(firstItem, secondItem) { | ||
return JSON.stringify(firstItem) === JSON.stringify(secondItem); | ||
} | ||
/* harmony default export */ __webpack_exports__["default"] = (isEqual); | ||
/***/ }), | ||
/***/ "./lib/isNumber.js": | ||
@@ -853,2 +917,3 @@ /*!*************************!*\ | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -887,2 +952,3 @@ * @example | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -921,2 +987,3 @@ * @example | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -1054,3 +1121,3 @@ * @example | ||
/* harmony import */ var _isEmpty__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./isEmpty */ "./lib/isEmpty.js"); | ||
/* harmony import */ var _getType__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./getType */ "./lib/getType.js"); | ||
/* harmony import */ var _isArray__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./isArray */ "./lib/isArray.js"); | ||
/* harmony import */ var _uniq__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./uniq */ "./lib/uniq.js"); | ||
@@ -1067,4 +1134,7 @@ | ||
* @since 0.3.0 | ||
* @param {Object} object Object to parse in url. | ||
* @param {?Boolean} isSaveOldQuery Whether to save the old query. Default: false. | ||
* @param {Object} query Object to parse in url. | ||
* @param {?Object} params Object with params. | ||
* @param {?Boolean} params.isSaveOld Does save old query. Default: false. | ||
* @param {?Boolean} params.isSaveHash Does save hash. Default: true. | ||
* @param {?Boolean} params.isSaveEmptyFields Does save empty fields. Default: false. | ||
* | ||
@@ -1078,13 +1148,25 @@ * @example | ||
* | ||
* // https://github.com/?test=value&field=test | ||
* setQuery({ test: 'field' }, true) | ||
* // => https://github.com/?test=value&test=field&field=test | ||
* // /?test=value&field=test | ||
* setQuery({ test: 'field' }, { isSaveOld: true }) | ||
* // => /?test=value&test=field&field=test | ||
* | ||
* // /?test=value#someHash | ||
* setQuery({ test: 'value' }, { isSaveHash: false }) | ||
* // => /?test=value | ||
*/ | ||
function setQuery(query) { | ||
var isSaveOldQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$isSaveOld = _ref.isSaveOld, | ||
isSaveOld = _ref$isSaveOld === void 0 ? false : _ref$isSaveOld, | ||
_ref$isSaveHash = _ref.isSaveHash, | ||
isSaveHash = _ref$isSaveHash === void 0 ? true : _ref$isSaveHash, | ||
_ref$isSaveEmptyField = _ref.isSaveEmptyFields, | ||
isSaveEmptyFields = _ref$isSaveEmptyField === void 0 ? false : _ref$isSaveEmptyField; | ||
var localQuery = query || {}; | ||
var oldQuery = isSaveOldQuery && Object(_getQuery__WEBPACK_IMPORTED_MODULE_2__["default"])(); | ||
var oldQuery = isSaveOld && Object(_getQuery__WEBPACK_IMPORTED_MODULE_2__["default"])(); | ||
var mergedQueries = Object.entries(localQuery).concat(Object.entries(oldQuery)); | ||
var newQueryObject = isSaveOldQuery && !Object(_isEmpty__WEBPACK_IMPORTED_MODULE_3__["default"])(oldQuery) ? mergedQueries.reduce(function (newQuery, field) { | ||
var hash = isSaveHash && window.location.href.split('#')[1]; | ||
var newQueryObject = isSaveOld && !Object(_isEmpty__WEBPACK_IMPORTED_MODULE_3__["default"])(oldQuery) ? mergedQueries.reduce(function (newQuery, field) { | ||
var fieldName = field[0]; | ||
@@ -1096,4 +1178,4 @@ var fieldValue = field[1]; | ||
var textValue = newQuery[fieldName] === fieldValue ? fieldValue : [newQuery[fieldName], fieldValue]; | ||
var arrayValue = Object(_getType__WEBPACK_IMPORTED_MODULE_4__["default"])(newQuery[fieldName]) === 'array' ? Object(_uniq__WEBPACK_IMPORTED_MODULE_5__["default"])(newQuery[fieldName].concat(fieldValue)) : textValue; | ||
var newValue = Object(_getType__WEBPACK_IMPORTED_MODULE_4__["default"])(fieldValue) === 'array' ? Object(_uniq__WEBPACK_IMPORTED_MODULE_5__["default"])(fieldValue.concat(newQuery[fieldName])) : arrayValue; | ||
var arrayValue = Object(_isArray__WEBPACK_IMPORTED_MODULE_4__["default"])(newQuery[fieldName]) ? Object(_uniq__WEBPACK_IMPORTED_MODULE_5__["default"])(newQuery[fieldName].concat(fieldValue)) : textValue; | ||
var newValue = Object(_isArray__WEBPACK_IMPORTED_MODULE_4__["default"])(fieldValue) ? Object(_uniq__WEBPACK_IMPORTED_MODULE_5__["default"])(fieldValue.concat(newQuery[fieldName])) : arrayValue; | ||
return _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_1___default()({}, newQuery, _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()({}, fieldName, newValue)); | ||
@@ -1106,6 +1188,21 @@ } | ||
if (key === '&') return ''; | ||
var fieldValue = key && newQueryObject[key] ? "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(newQueryObject[key])) : ''; | ||
return Array.isArray(newQueryObject[key]) ? newQueryObject[key].map(function (value) { | ||
return value && key ? "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value)) : ''; | ||
}).join('&') : fieldValue; | ||
var value = newQueryObject[key]; | ||
var fieldValue; | ||
if (isSaveEmptyFields) { | ||
fieldValue = key ? "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value)) : ''; | ||
} else { | ||
fieldValue = key && value ? "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value)) : ''; | ||
} | ||
return Object(_isArray__WEBPACK_IMPORTED_MODULE_4__["default"])(value) ? value.map(function (arrayValue) { | ||
if (isSaveEmptyFields) { | ||
return key ? "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(arrayValue)) : ''; | ||
} | ||
return key && arrayValue ? "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(arrayValue)) : ''; | ||
}).filter(function (queryItem) { | ||
return queryItem; | ||
}) // Remove empty queries | ||
.join('&') : fieldValue; | ||
}).filter(function (queryItem) { | ||
@@ -1115,3 +1212,3 @@ return queryItem; | ||
.join('&'); | ||
window.history.pushState({}, document.title, newQueryString ? "?".concat(decodeURIComponent(newQueryString)) : window.location.href.split('?')[0]); | ||
window.history.pushState({}, document.title, newQueryString ? "?".concat(decodeURIComponent(newQueryString)).concat(hash ? "#".concat(hash) : '') : window.location.href.split('?')[0].split('#')[0] + (hash ? "#".concat(hash) : '')); | ||
} | ||
@@ -1132,7 +1229,9 @@ | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */ var _isArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./isArray */ "./lib/isArray.js"); | ||
/** | ||
* Remove same values. | ||
* Remove same values from array. | ||
* | ||
* @since 0.3.0 | ||
* @param {Array} array Array of strings. | ||
* @param {Array} array Array of values. | ||
* @return {Array} | ||
@@ -1143,11 +1242,26 @@ * | ||
* // => ['test', 'field'] | ||
* | ||
* uniq([{ test: 'value' }, { test: 'value' }]) | ||
* // => [{ test: 'value' }] | ||
* | ||
* uniq([['someValue'], ['someOtherValue'], ['someValue']]) | ||
* // => [['someValue'], ['someOtherValue']] | ||
*/ | ||
function uniq(array) { | ||
if (!array) { | ||
throw new Error('[chober]: array is not passed.'); | ||
function uniq() { | ||
var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
if (!Object(_isArray__WEBPACK_IMPORTED_MODULE_0__["default"])(array)) { | ||
throw new Error('[chober]: param must to be an array.'); | ||
} | ||
return array.filter(function (item, index, currentArray) { | ||
var arrayOfStrings = array.map(function (item) { | ||
return JSON.stringify(item); | ||
}); | ||
var filteredArray = arrayOfStrings.filter(function (item, index, currentArray) { | ||
return currentArray.indexOf(item) === index; | ||
}); | ||
return filteredArray.map(function (item) { | ||
return JSON.parse(item); | ||
}); | ||
} | ||
@@ -1270,3 +1384,3 @@ | ||
module.exports = {"name":"chober","version":"1.0.4","description":"Chober.js - is a collection of methods that are used by programmers every day. We decided to put all the methods together so as not to copy them from project to project.","main":"dist/chober.js","scripts":{"prod":"webpack --env production --config webpack.config.js","dev":"webpack --env development --config webpack.config.js","watch":"webpack --env development --config webpack.config.js --watch","build":"npm run docs && npm run prod && npm run dev","docs":"jsdoc2md --template README.hbs --files lib/*.js > docs/README.md","docs-server":"docsify serve docs -p 35730"},"repository":{"type":"git","url":"git+https://github.com/BrooonS/chober.js.git"},"keywords":["webpack","js","javascript","library","es6","commonjs","methods","chober","isEmpty","isArray","isNumber","isString","isObject","isBoolean","getQuery","getNumbers","getScrollbarWidth","getCookie","getOffset","getType","setQuery","setCookie","removeCookie","clone","invertObject","first","formatNumber","debounce","scrollTo","uniq"],"author":"Valery Strelets","license":"MIT","bugs":{"url":"https://github.com/BrooonS/chober.js/issues"},"homepage":"https://github.com/BrooonS/chober.js#readme","devDependencies":{"@babel/core":"^7.1.2","@babel/plugin-proposal-object-rest-spread":"^7.0.0","@babel/plugin-transform-object-assign":"^7.0.0","@babel/plugin-transform-runtime":"^7.1.0","@babel/preset-env":"^7.1.0","@babel/runtime":"^7.1.2","babel-eslint":"^10.0.1","babel-loader":"^8.0.4","docsify-cli":"^4.2.1","eslint":"^5.6.1","eslint-config-airbnb":"^17.1.0","eslint-loader":"^2.1.1","eslint-plugin-import":"^2.14.0","eslint-plugin-jsx-a11y":"^6.1.2","eslint-plugin-react":"^7.11.1","jsdoc-to-markdown":"^4.0.1","uglifyjs-webpack-plugin":"^2.0.1","webpack":"^4.20.2","webpack-cli":"^3.1.2"}}; | ||
module.exports = {"name":"chober","version":"1.1.0","description":"Chober.js - is a collection of methods that are used by programmers every day. We decided to put all the methods together so as not to copy them from project to project.","main":"dist/chober.js","scripts":{"prod":"webpack --env production --config webpack.config.js","dev":"webpack --env development --config webpack.config.js","watch":"webpack --env development --config webpack.config.js --watch","build":"npm run docs && npm run prod && npm run dev","docs":"jsdoc2md --template README.hbs --files lib/*.js > docs/README.md","docs-server":"docsify serve docs -p 35730"},"repository":{"type":"git","url":"git+https://github.com/BrooonS/chober.js.git"},"keywords":["webpack","js","javascript","library","es6","commonjs","methods","chober","isEmpty","isArray","isNumber","isString","isObject","isBoolean","isEqual","getQuery","getNumbers","getScrollbarWidth","getCookie","getOffset","getType","setQuery","setCookie","removeCookie","decodeHtml","clone","invertObject","first","formatNumber","debounce","scrollTo","uniq"],"author":"Valery Strelets","license":"MIT","bugs":{"url":"https://github.com/BrooonS/chober.js/issues"},"homepage":"https://github.com/BrooonS/chober.js#readme","devDependencies":{"@babel/core":"^7.1.2","@babel/plugin-proposal-object-rest-spread":"^7.0.0","@babel/plugin-transform-object-assign":"^7.0.0","@babel/plugin-transform-runtime":"^7.1.0","@babel/preset-env":"^7.1.0","@babel/runtime":"^7.1.2","babel-eslint":"^10.0.1","babel-loader":"^8.0.4","docsify-cli":"^4.2.1","eslint":"^5.6.1","eslint-config-airbnb":"^17.1.0","eslint-loader":"^2.1.1","eslint-plugin-import":"^2.14.0","eslint-plugin-jsx-a11y":"^6.1.2","eslint-plugin-react":"^7.11.1","jsdoc-to-markdown":"^4.0.1","uglifyjs-webpack-plugin":"^2.0.1","webpack":"^4.23.1","webpack-cli":"^3.1.2"}}; | ||
@@ -1273,0 +1387,0 @@ /***/ }) |
@@ -1,2 +0,2 @@ | ||
!function webpackUniversalModuleDefinition(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("_c",[],r):"object"==typeof exports?exports._c=r():e._c=r()}("undefined"!=typeof self?self:this,function(){return function(t){var n={};function __webpack_require__(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return t[e].call(r.exports,r,r.exports,__webpack_require__),r.l=!0,r.exports}return __webpack_require__.m=t,__webpack_require__.c=n,__webpack_require__.d=function(e,r,t){__webpack_require__.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.t=function(r,e){if(1&e&&(r=__webpack_require__(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(__webpack_require__.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)__webpack_require__.d(t,n,function(e){return r[e]}.bind(null,n));return t},__webpack_require__.n=function(e){var r=e&&e.__esModule?function getDefault(){return e.default}:function getModuleExports(){return e};return __webpack_require__.d(r,"a",r),r},__webpack_require__.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=5)}([function(e,r){e.exports=function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}},function(e,r,t){var o=t(0);e.exports=function _objectSpread(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(e){o(r,e,t[e])})}return r}},function(e,r){function _extends(){return e.exports=_extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},_extends.apply(this,arguments)}e.exports=_extends},function(e,r){e.exports=function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}},function(e){e.exports={a:"1.0.4"}},function(e,r,t){"use strict";t.r(r);var n=t(2),o=t.n(n),i=t(3),c=t.n(i),u=t(4);var a=function isEmpty(e){return!(e&&(e.length||Object.keys(e).length))};var f=function getType(e){return Object.prototype.toString.call(e).replace(/^\[object (.+)\]$/,"$1").toLowerCase()};var s=function isArray(e){return"array"===f(e)};var l=function isNumber(e){return"number"===f(e)};var p=function isString(e){return"string"===f(e)};var d=function isObject(e){return"object"===f(e)};var b=function isBoolean(e){return"boolean"===f(e)},_=t(0),h=t.n(_),w=t(1),y=t.n(w);var v=function getQuery(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],r=window.location.search.substr(1),n={};return r?(e.length&&o()(n,e.reduce(function(e,r){return y()({},e,h()({},r,[]))},{})),r.split("&").forEach(function(e){if(e){var t=e.split("=");Object.prototype.hasOwnProperty.call(n,t[0])&&(s(n[t[0]])?n[t[0]].push(t[1]):n[t[0]]=[n[t[0]],t[1]]),s(n[t[0]])?n[t[0]].forEach(function(e,r){n[t[0]][r]=decodeURIComponent(e)}):n[t[0]]=decodeURIComponent(t[1])}}),n):{}};var g=function getNumbers(e){if(!e)throw new Error("[chober]: string or number is not passed.");return String(e).replace(/\D+/g,"")};var m=function getScrollbarWidth(){return window.innerWidth-document.documentElement.clientWidth};var O=function getCookie(e){if(!e)throw new Error("[chober]: key is not passed.");var r="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===r.length?r.pop().split(";").shift():""};var j=function getOffset(e){if(!e)throw new Error("[chober]: selector is not passed.");var r=document.querySelector(e).getBoundingClientRect(),t=window.pageXOffset,n=window.pageYOffset;return{x:r.left+t,y:r.top+n,left:r.left+t,top:r.top+n,right:r.right+t,bottom:r.bottom+n}};var k=function uniq(e){if(!e)throw new Error("[chober]: array is not passed.");return e.filter(function(e,r,t){return t.indexOf(e)===r})};var C=function setQuery(e){var r=1<arguments.length&&void 0!==arguments[1]&&arguments[1],t=e||{},n=r&&v(),o=Object.entries(t).concat(Object.entries(n)),i=r&&!a(n)?o.reduce(function(e,r){var t=r[0],n=r[1];if(Object.prototype.hasOwnProperty.call(e,t)){var o=e[t]===n?n:[e[t],n],i="array"===f(e[t])?k(e[t].concat(n)):o,c="array"===f(n)?k(n.concat(e[t])):i;return y()({},e,h()({},t,c))}return y()({},e,h()({},t,n))},{}):t,c=Object.keys(i).map(function(r){if("&"===r)return"";var e=r&&i[r]?"".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(i[r])):"";return Array.isArray(i[r])?i[r].map(function(e){return e&&r?"".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(e)):""}).join("&"):e}).filter(function(e){return e}).join("&");window.history.pushState({},document.title,c?"?".concat(decodeURIComponent(c)):window.location.href.split("?")[0])};var x=function setCookie(e,r){var t=2<arguments.length&&void 0!==arguments[2]&&arguments[2];if(!e&&!r)throw new Error("[chober]: key or value is not passed.");var n=t&&(new Date).getTime()+t,o=t&&new Date(n).toUTCString(),i="".concat(e,"=").concat(r,"; path=/"),c="; expires=".concat(o);document.cookie=t?i:i+c};var S=function removeCookie(e){if(!e)throw new Error("[chober]: key is not passed.");document.cookie="".concat(e,"=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;")};var E=function clone(e){if(!e)throw new Error("[chober]: nothing to clone.");return e&&JSON.parse(JSON.stringify(e))};var q=function invertObject(e){if(!e)throw new Error("[chober]: object is not passed.");return e&&Object.entries(e).reduce(function(e,r){return y()({},e,h()({},r[1],r[0]))},{})};var T=function first(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;if(!e)throw new Error("[chober]: array is not passed.");return s(e)?e.slice(0,r):[]};var N=function formatNumber(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:" ";if(!e)throw new Error("[chober]: number is not passed.");return String(e).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g,"$1".concat(r))};var P=function debounce(n,o){var i=this;if(!n&&!o)throw new Error("[chober]: function or delay is not passed.");var c=null;return function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];c&&clearTimeout(c),c=setTimeout(function onComplete(){n.apply(i,r),c=null},o)}};var I=function scrollTo(e){if(!e)throw new Error("[chober]: element is not passed.");e.scrollIntoView({behavior:"smooth"})};t.d(r,"VERSION",function(){return R}),t.d(r,"isEmpty",function(){return a}),t.d(r,"isArray",function(){return s}),t.d(r,"isNumber",function(){return l}),t.d(r,"isString",function(){return p}),t.d(r,"isObject",function(){return d}),t.d(r,"isBoolean",function(){return b}),t.d(r,"getQuery",function(){return v}),t.d(r,"getNumbers",function(){return g}),t.d(r,"getScrollbarWidth",function(){return m}),t.d(r,"getCookie",function(){return O}),t.d(r,"getOffset",function(){return j}),t.d(r,"getType",function(){return f}),t.d(r,"setQuery",function(){return C}),t.d(r,"setCookie",function(){return x}),t.d(r,"removeCookie",function(){return S}),t.d(r,"clone",function(){return E}),t.d(r,"invertObject",function(){return q}),t.d(r,"first",function(){return T}),t.d(r,"formatNumber",function(){return N}),t.d(r,"debounce",function(){return P}),t.d(r,"scrollTo",function(){return I}),t.d(r,"uniq",function(){return k}); | ||
!function webpackUniversalModuleDefinition(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("_c",[],t):"object"==typeof exports?exports._c=t():e._c=t()}("undefined"!=typeof self?self:this,function(){return function(n){var r={};function __webpack_require__(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,__webpack_require__),t.l=!0,t.exports}return __webpack_require__.m=n,__webpack_require__.c=r,__webpack_require__.d=function(e,t,n){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.t=function(t,e){if(1&e&&(t=__webpack_require__(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)__webpack_require__.d(n,r,function(e){return t[e]}.bind(null,r));return n},__webpack_require__.n=function(e){var t=e&&e.__esModule?function getDefault(){return e.default}:function getModuleExports(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=5)}([function(e,t){e.exports=function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t,n){var o=n(0);e.exports=function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(e){o(t,e,n[e])})}return t}},function(e,t){function _extends(){return e.exports=_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(this,arguments)}e.exports=_extends},function(e,t){e.exports=function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e){e.exports={a:"1.1.0"}},function(e,t,n){"use strict";n.r(t);var r=n(2),o=n.n(r),i=n(3),c=n.n(i),u=n(4);var _=function isEmpty(e){return!(e&&(e.length||Object.keys(e).length))};var a=function getType(e){return Object.prototype.toString.call(e).replace(/^\[object (.+)\]$/,"$1").toLowerCase()};var b=function isArray(e){return"array"===a(e)};var f=function isNumber(e){return"number"===a(e)};var s=function isString(e){return"string"===a(e)};var l=function isObject(e){return"object"===a(e)};var d=function isBoolean(e){return"boolean"===a(e)};var p=function isEqual(e,t){return JSON.stringify(e)===JSON.stringify(t)},v=n(0),m=n.n(v),h=n(1),y=n.n(h);var g=function getQuery(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=window.location.search.substr(1),r={};return t?(e.length&&o()(r,e.reduce(function(e,t){return y()({},e,m()({},t,[]))},{})),t.split("&").forEach(function(e){if(e){var n=e.split("=");Object.prototype.hasOwnProperty.call(r,n[0])&&(b(r[n[0]])?r[n[0]].push(n[1]):r[n[0]]=[r[n[0]],n[1]]),b(r[n[0]])?r[n[0]].forEach(function(e,t){r[n[0]][t]=decodeURIComponent(e)}):r[n[0]]=decodeURIComponent(n[1])}}),r):{}};var w=function getNumbers(e){return e?String(e).replace(/\D+/g,""):""};var O=function getScrollbarWidth(){return window.innerWidth-document.documentElement.clientWidth};var j=function getCookie(e){if(!e)throw new Error("[chober]: key is not passed.");var t="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===t.length?t.pop().split(";").shift():""};var k=function getOffset(e){if(!e)throw new Error("[chober]: selector is not passed.");var t=document.querySelector(e).getBoundingClientRect(),n=window.pageXOffset,r=window.pageYOffset;return{x:t.left+n,y:t.top+r,left:t.left+n,top:t.top+r,right:t.right+n,bottom:t.bottom+r}};var S=function uniq(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];if(!b(e))throw new Error("[chober]: param must to be an array.");return e.map(function(e){return JSON.stringify(e)}).filter(function(e,t,n){return n.indexOf(e)===t}).map(function(e){return JSON.parse(e)})};var C=function setQuery(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=t.isSaveOld,r=void 0!==n&&n,o=t.isSaveHash,i=void 0===o||o,c=t.isSaveEmptyFields,u=void 0!==c&&c,a=e||{},f=r&&g(),s=Object.entries(a).concat(Object.entries(f)),l=i&&window.location.href.split("#")[1],d=r&&!_(f)?s.reduce(function(e,t){var n=t[0],r=t[1];if(Object.prototype.hasOwnProperty.call(e,n)){var o=e[n]===r?r:[e[n],r],i=b(e[n])?S(e[n].concat(r)):o,c=b(r)?S(r.concat(e[n])):i;return y()({},e,m()({},n,c))}return y()({},e,m()({},n,r))},{}):a,p=Object.keys(d).map(function(t){if("&"===t)return"";var e,n=d[t];return e=u?t?"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(n)):"":t&&n?"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(n)):"",b(n)?n.map(function(e){return u?t?"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e)):"":t&&e?"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e)):""}).filter(function(e){return e}).join("&"):e}).filter(function(e){return e}).join("&");window.history.pushState({},document.title,p?"?".concat(decodeURIComponent(p)).concat(l?"#".concat(l):""):window.location.href.split("?")[0].split("#")[0]+(l?"#".concat(l):""))};var x=function setCookie(e,t){var n=2<arguments.length&&void 0!==arguments[2]&&arguments[2];if(!e&&!t)throw new Error("[chober]: key or value is not passed.");var r=n&&(new Date).getTime()+n,o=n&&new Date(r).toUTCString(),i="".concat(e,"=").concat(t,"; path=/"),c="; expires=".concat(o);document.cookie=n?i:i+c};var E=function removeCookie(e){if(!e)throw new Error("[chober]: key is not passed.");document.cookie="".concat(e,"=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;")};var q=function decodeHtml(e){var t=document.createElement("textarea");return t.innerHTML=e,t.value};var N=function clone(e){if(!e)throw new Error("[chober]: nothing to clone.");return e&&JSON.parse(JSON.stringify(e))};var T=function invertObject(e){if(!e)throw new Error("[chober]: object is not passed.");return e&&Object.entries(e).reduce(function(e,t){return y()({},e,m()({},t[1],t[0]))},{})};var I=function first(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;return b(e)?e.slice(0,t):[]};var R=function formatNumber(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:" ";return String(e||0).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g,"$1".concat(t))};var P=function debounce(r,o){var i=this;if(!r&&!o)throw new Error("[chober]: function or delay is not passed.");var c=null;return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];c&&clearTimeout(c),c=setTimeout(function onComplete(){r.apply(i,t),c=null},o)}};var U=function scrollTo(e){if(!e)throw new Error("[chober]: element is not passed.");e.scrollIntoView({behavior:"smooth"})};n.d(t,"VERSION",function(){return M}),n.d(t,"isEmpty",function(){return _}),n.d(t,"isArray",function(){return b}),n.d(t,"isNumber",function(){return f}),n.d(t,"isString",function(){return s}),n.d(t,"isObject",function(){return l}),n.d(t,"isBoolean",function(){return d}),n.d(t,"isEqual",function(){return p}),n.d(t,"getQuery",function(){return g}),n.d(t,"getNumbers",function(){return w}),n.d(t,"getScrollbarWidth",function(){return O}),n.d(t,"getCookie",function(){return j}),n.d(t,"getOffset",function(){return k}),n.d(t,"getType",function(){return a}),n.d(t,"setQuery",function(){return C}),n.d(t,"setCookie",function(){return x}),n.d(t,"removeCookie",function(){return E}),n.d(t,"decodeHtml",function(){return q}),n.d(t,"clone",function(){return N}),n.d(t,"invertObject",function(){return T}),n.d(t,"first",function(){return I}),n.d(t,"formatNumber",function(){return R}),n.d(t,"debounce",function(){return P}),n.d(t,"scrollTo",function(){return U}),n.d(t,"uniq",function(){return S}); | ||
/** | ||
@@ -10,2 +10,2 @@ * Chober.js - is a collection of useful methods that are used by programmers every day. | ||
*/ | ||
var R=u.a;r.default=new function Chober(){c()(this,Chober),o()(this,{VERSION:R,isEmpty:a,isArray:s,isNumber:l,isString:p,isObject:d,isBoolean:b,getQuery:v,getNumbers:g,getScrollbarWidth:m,getCookie:O,getOffset:j,getType:f,setQuery:C,setCookie:x,removeCookie:S,clone:E,invertObject:q,first:T,formatNumber:N,debounce:P,scrollTo:I,uniq:k})}}])}); | ||
var M=u.a;t.default=new function Chober(){c()(this,Chober),o()(this,{VERSION:M,isEmpty:_,isArray:b,isNumber:f,isString:s,isObject:l,isBoolean:d,isEqual:p,getQuery:g,getNumbers:w,getScrollbarWidth:O,getCookie:j,getOffset:k,getType:a,setQuery:C,setCookie:x,removeCookie:E,decodeHtml:q,clone:N,invertObject:T,first:I,formatNumber:R,debounce:P,scrollTo:U,uniq:S})}}])}); |
![logo](_media/logo.png) | ||
# Chober <small>1.0.4</small> | ||
# Chober <small>1.1.0</small> | ||
@@ -5,0 +5,0 @@ > Is a collection of useful methods. |
@@ -34,3 +34,3 @@ # Chober.js | ||
<!-- With version --> | ||
<script src="https://cdn.jsdelivr.net/npm/chober@1.0.4/dist/chober.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/chober@1.1.0/dist/chober.min.js"></script> | ||
``` | ||
@@ -152,6 +152,27 @@ | ||
```JS | ||
window.addEventListener('scroll', debounce(() => { console.log(Math.random()); }, 100)); | ||
window.addEventListener('scroll', debounce(() => console.log(Math.random()), 100)) | ||
``` | ||
<a href="https://github.com/BrooonS/chober/tree/master/lib/debounce.js" target="_blank">Source code</a> | ||
* * * | ||
### decodeHtml | ||
Decode a string that has special HTML entities | ||
#### Since | ||
- 1.1.0 | ||
#### Params | ||
- `html` | ||
- Type: `String` | ||
- Description: *Html to decode.* | ||
#### Returns | ||
- `String` | ||
#### Example | ||
```JS | ||
decodeHtml('<h1>Hi my friend!</h1>') // => '<h1>Hi my friend!</h1>' | ||
``` | ||
<a href="https://github.com/BrooonS/chober/tree/master/lib/decodeHtml.js" target="_blank">Source code</a> | ||
* * * | ||
### first | ||
@@ -278,3 +299,3 @@ | ||
- Type: `Array` | ||
- Description: *Fields that must be an arrays.* | ||
- Description: *Fields that must be arrays.* | ||
@@ -286,3 +307,3 @@ #### Returns | ||
```JS | ||
// http://github.com/?value=test&field=hi&field=hello getQuery() // => { value: 'test', field: ['hi', 'hello'] } | ||
// http://github.com/?value=test&field=hi&field=hello getQuery() // => { value: 'test', field: ['hi', 'hello'] } | ||
``` | ||
@@ -358,2 +379,4 @@ <a href="https://github.com/BrooonS/chober/tree/master/lib/getQuery.js" target="_blank">Source code</a> | ||
#### Returns | ||
- `Boolean` | ||
@@ -378,2 +401,4 @@ #### Example | ||
#### Returns | ||
- `Boolean` | ||
@@ -407,2 +432,26 @@ #### Example | ||
* * * | ||
### isEqual | ||
Checking is equal items. | ||
#### Since | ||
- 1.1.0 | ||
#### Params | ||
- `firstItem` | ||
- Type: `Any` | ||
- Description: *First item to check.* | ||
- `secondItem` | ||
- Type: `Any` | ||
- Description: *Second item to check.* | ||
#### Returns | ||
- `Boolean` | ||
#### Example | ||
```JS | ||
isEqual([], []) // => true isEqual({ test: 'value' }, { test: 'value' }) // => true isEqual(true, false) // => false | ||
``` | ||
<a href="https://github.com/BrooonS/chober/tree/master/lib/isEqual.js" target="_blank">Source code</a> | ||
* * * | ||
### isNumber | ||
@@ -420,2 +469,4 @@ | ||
#### Returns | ||
- `Boolean` | ||
@@ -440,2 +491,4 @@ #### Example | ||
#### Returns | ||
- `Boolean` | ||
@@ -460,2 +513,4 @@ #### Example | ||
#### Returns | ||
- `Boolean` | ||
@@ -539,8 +594,17 @@ #### Example | ||
#### Params | ||
- `object` | ||
- `query` | ||
- Type: `Object` | ||
- Description: *Object to parse in url.* | ||
- `isSaveOldQuery` | ||
- `params` | ||
- Type: `Object` | ||
- Description: *Object with params.* | ||
- `params.isSaveOld` | ||
- Type: `Boolean` | ||
- Description: *Whether to save the old query. Default: false.* | ||
- Description: *Does save old query. Default: false.* | ||
- `params.isSaveHash` | ||
- Type: `Boolean` | ||
- Description: *Does save hash. Default: true.* | ||
- `params.isSaveEmptyFields` | ||
- Type: `Boolean` | ||
- Description: *Does save empty fields. Default: false.* | ||
@@ -550,3 +614,3 @@ | ||
```JS | ||
setQuery({ test: 'value' }) // => /?test=value setQuery({ test: ['12', '34'] }) // => /?test=12&test=34 // https://github.com/?test=value&field=test setQuery({ test: 'field' }, true) // => https://github.com/?test=value&test=field&field=test | ||
setQuery({ test: 'value' }) // => /?test=value setQuery({ test: ['12', '34'] }) // => /?test=12&test=34 // /?test=value&field=test setQuery({ test: 'field' }, { isSaveOld: true }) // => /?test=value&test=field&field=test // /?test=value#someHash setQuery({ test: 'value' }, { isSaveHash: false }) // => /?test=value | ||
``` | ||
@@ -557,3 +621,3 @@ <a href="https://github.com/BrooonS/chober/tree/master/lib/setQuery.js" target="_blank">Source code</a> | ||
Remove same values. | ||
Remove same values from array. | ||
@@ -566,3 +630,3 @@ #### Since | ||
- Type: `Array` | ||
- Description: *Array of strings.* | ||
- Description: *Array of values.* | ||
@@ -574,3 +638,3 @@ #### Returns | ||
```JS | ||
uniq(['test', 'field', 'test']) // => ['test', 'field'] | ||
uniq(['test', 'field', 'test']) // => ['test', 'field'] uniq([{ test: 'value' }, { test: 'value' }]) // => [{ test: 'value' }] uniq([['someValue'], ['someOtherValue'], ['someValue']]) // => [['someValue'], ['someOtherValue']] | ||
``` | ||
@@ -577,0 +641,0 @@ <a href="https://github.com/BrooonS/chober/tree/master/lib/uniq.js" target="_blank">Source code</a> |
@@ -21,2 +21,3 @@ /** | ||
import isBoolean from './lib/isBoolean'; | ||
import isEqual from './lib/isEqual'; | ||
import getQuery from './lib/getQuery'; | ||
@@ -31,2 +32,3 @@ import getNumbers from './lib/getNumbers'; | ||
import removeCookie from './lib/removeCookie'; | ||
import decodeHtml from './lib/decondeHtml'; | ||
import clone from './lib/clone'; | ||
@@ -58,2 +60,3 @@ import invertObject from './lib/invertObject'; | ||
isBoolean, | ||
isEqual, | ||
getQuery, | ||
@@ -68,2 +71,3 @@ getNumbers, | ||
removeCookie, | ||
decodeHtml, | ||
clone, | ||
@@ -91,2 +95,3 @@ invertObject, | ||
isBoolean, | ||
isEqual, | ||
getQuery, | ||
@@ -101,2 +106,3 @@ getNumbers, | ||
removeCookie, | ||
decodeHtml, | ||
clone, | ||
@@ -103,0 +109,0 @@ invertObject, |
@@ -10,5 +10,3 @@ /** | ||
* @example | ||
* window.addEventListener('scroll', debounce(() => { | ||
* console.log(Math.random()); | ||
* }, 100)); | ||
* window.addEventListener('scroll', debounce(() => console.log(Math.random()), 100)) | ||
*/ | ||
@@ -15,0 +13,0 @@ function debounce(func, delay) { |
@@ -19,6 +19,2 @@ import isArray from './isArray'; | ||
function first(array, number = 1) { | ||
if (!array) { | ||
throw new Error('[chober]: array is not passed.'); | ||
} | ||
return isArray(array) ? array.slice(0, number) : []; | ||
@@ -25,0 +21,0 @@ } |
@@ -17,9 +17,5 @@ /** | ||
function formatNumber(number, symbol = ' ') { | ||
if (!number) { | ||
throw new Error('[chober]: number is not passed.'); | ||
} | ||
return String(number).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, `$1${symbol}`); | ||
return String(number || 0).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, `$1${symbol}`); | ||
} | ||
export default formatNumber; |
@@ -14,3 +14,3 @@ /** | ||
if (!string) { | ||
throw new Error('[chober]: string or number is not passed.'); | ||
return ''; | ||
} | ||
@@ -17,0 +17,0 @@ |
@@ -7,3 +7,3 @@ import isArray from './isArray'; | ||
* @since 0.1.0 | ||
* @param {Array} arrayFields Fields that must be an arrays. | ||
* @param {?Array} arrayFields Fields that must be arrays. | ||
* @returns {Object} | ||
@@ -13,3 +13,2 @@ * | ||
* // http://github.com/?value=test&field=hi&field=hello | ||
* | ||
* getQuery() | ||
@@ -16,0 +15,0 @@ * // => { value: 'test', field: ['hi', 'hello'] } |
@@ -8,2 +8,3 @@ import getType from './getType'; | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -10,0 +11,0 @@ * @example |
@@ -8,2 +8,3 @@ import getType from './getType'; | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -10,0 +11,0 @@ * @example |
@@ -8,2 +8,3 @@ import getType from './getType'; | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -10,0 +11,0 @@ * @example |
@@ -8,2 +8,3 @@ import getType from './getType'; | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -10,0 +11,0 @@ * @example |
@@ -8,2 +8,3 @@ import getType from './getType'; | ||
* @param {Any} item Item to check. | ||
* @returns {Boolean} | ||
* | ||
@@ -10,0 +11,0 @@ * @example |
import getQuery from './getQuery'; | ||
import isEmpty from './isEmpty'; | ||
import getType from './getType'; | ||
import isArray from './isArray'; | ||
import uniq from './uniq'; | ||
@@ -10,4 +10,7 @@ | ||
* @since 0.3.0 | ||
* @param {Object} object Object to parse in url. | ||
* @param {?Boolean} isSaveOldQuery Whether to save the old query. Default: false. | ||
* @param {Object} query Object to parse in url. | ||
* @param {?Object} params Object with params. | ||
* @param {?Boolean} params.isSaveOld Does save old query. Default: false. | ||
* @param {?Boolean} params.isSaveHash Does save hash. Default: true. | ||
* @param {?Boolean} params.isSaveEmptyFields Does save empty fields. Default: false. | ||
* | ||
@@ -21,11 +24,20 @@ * @example | ||
* | ||
* // https://github.com/?test=value&field=test | ||
* setQuery({ test: 'field' }, true) | ||
* // => https://github.com/?test=value&test=field&field=test | ||
* // /?test=value&field=test | ||
* setQuery({ test: 'field' }, { isSaveOld: true }) | ||
* // => /?test=value&test=field&field=test | ||
* | ||
* // /?test=value#someHash | ||
* setQuery({ test: 'value' }, { isSaveHash: false }) | ||
* // => /?test=value | ||
*/ | ||
function setQuery(query, isSaveOldQuery = false) { | ||
function setQuery(query, { | ||
isSaveOld = false, | ||
isSaveHash = true, | ||
isSaveEmptyFields = false, | ||
} = {}) { | ||
const localQuery = query || {}; | ||
const oldQuery = isSaveOldQuery && getQuery(); | ||
const oldQuery = isSaveOld && getQuery(); | ||
const mergedQueries = Object.entries(localQuery).concat(Object.entries(oldQuery)); | ||
const newQueryObject = isSaveOldQuery && !isEmpty(oldQuery) | ||
const hash = isSaveHash && window.location.href.split('#')[1]; | ||
const newQueryObject = isSaveOld && !isEmpty(oldQuery) | ||
? mergedQueries.reduce((newQuery, field) => { | ||
@@ -40,6 +52,6 @@ const fieldName = field[0]; | ||
: [newQuery[fieldName], fieldValue]; | ||
const arrayValue = getType(newQuery[fieldName]) === 'array' | ||
const arrayValue = isArray(newQuery[fieldName]) | ||
? uniq(newQuery[fieldName].concat(fieldValue)) | ||
: textValue; | ||
const newValue = getType(fieldValue) === 'array' | ||
const newValue = isArray(fieldValue) | ||
? uniq(fieldValue.concat(newQuery[fieldName])) | ||
@@ -64,9 +76,25 @@ : arrayValue; | ||
const fieldValue = key && newQueryObject[key] | ||
? `${encodeURIComponent(key)}=${encodeURIComponent(newQueryObject[key])}` | ||
: ''; | ||
const value = newQueryObject[key]; | ||
let fieldValue; | ||
return Array.isArray(newQueryObject[key]) | ||
? newQueryObject[key] | ||
.map(value => (value && key ? `${encodeURIComponent(key)}=${encodeURIComponent(value)}` : '')) | ||
if (isSaveEmptyFields) { | ||
fieldValue = key | ||
? `${encodeURIComponent(key)}=${encodeURIComponent(value)}` | ||
: ''; | ||
} else { | ||
fieldValue = key && value | ||
? `${encodeURIComponent(key)}=${encodeURIComponent(value)}` | ||
: ''; | ||
} | ||
return isArray(value) | ||
? value | ||
.map((arrayValue) => { | ||
if (isSaveEmptyFields) { | ||
return key ? `${encodeURIComponent(key)}=${encodeURIComponent(arrayValue)}` : ''; | ||
} | ||
return key && arrayValue ? `${encodeURIComponent(key)}=${encodeURIComponent(arrayValue)}` : ''; | ||
}) | ||
.filter(queryItem => queryItem) // Remove empty queries | ||
.join('&') | ||
@@ -82,4 +110,4 @@ : fieldValue; | ||
newQueryString | ||
? `?${decodeURIComponent(newQueryString)}` | ||
: window.location.href.split('?')[0], | ||
? `?${decodeURIComponent(newQueryString)}${hash ? `#${hash}` : ''}` | ||
: window.location.href.split('?')[0].split('#')[0] + (hash ? `#${hash}` : ''), | ||
); | ||
@@ -86,0 +114,0 @@ } |
@@ -0,6 +1,8 @@ | ||
import isArray from './isArray'; | ||
/** | ||
* Remove same values. | ||
* Remove same values from array. | ||
* | ||
* @since 0.3.0 | ||
* @param {Array} array Array of strings. | ||
* @param {Array} array Array of values. | ||
* @return {Array} | ||
@@ -11,13 +13,21 @@ * | ||
* // => ['test', 'field'] | ||
* | ||
* uniq([{ test: 'value' }, { test: 'value' }]) | ||
* // => [{ test: 'value' }] | ||
* | ||
* uniq([['someValue'], ['someOtherValue'], ['someValue']]) | ||
* // => [['someValue'], ['someOtherValue']] | ||
*/ | ||
function uniq(array) { | ||
if (!array) { | ||
throw new Error('[chober]: array is not passed.'); | ||
function uniq(array = []) { | ||
if (!isArray(array)) { | ||
throw new Error('[chober]: param must to be an array.'); | ||
} | ||
return array | ||
.filter((item, index, currentArray) => currentArray | ||
.indexOf(item) === index); | ||
const arrayOfStrings = array.map(item => JSON.stringify(item)); | ||
const filteredArray = arrayOfStrings.filter((item, index, currentArray) => currentArray | ||
.indexOf(item) === index); | ||
return filteredArray.map(item => JSON.parse(item)); | ||
} | ||
export default uniq; |
{ | ||
"name": "chober", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Chober.js - is a collection of methods that are used by programmers every day. We decided to put all the methods together so as not to copy them from project to project.", | ||
@@ -33,2 +33,3 @@ "main": "dist/chober.js", | ||
"isBoolean", | ||
"isEqual", | ||
"getQuery", | ||
@@ -43,2 +44,3 @@ "getNumbers", | ||
"removeCookie", | ||
"decodeHtml", | ||
"clone", | ||
@@ -76,5 +78,5 @@ "invertObject", | ||
"uglifyjs-webpack-plugin": "^2.0.1", | ||
"webpack": "^4.20.2", | ||
"webpack": "^4.23.1", | ||
"webpack-cli": "^3.1.2" | ||
} | ||
} |
@@ -31,3 +31,3 @@ # Chober.js | ||
<!-- With version --> | ||
<script src="https://cdn.jsdelivr.net/npm/chober@1.0.4/dist/chober.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/chober@1.1.0/dist/chober.min.js"></script> | ||
``` | ||
@@ -34,0 +34,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
218838
41
1912