Socket
Socket
Sign inDemoInstall

chober

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.3 to 2.0.0

lib/formatQuery.js

4

dist/chober.min.js

@@ -1,2 +0,2 @@

!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("_c",[],n):"object"==typeof exports?exports._c=n():t._c=n()}("undefined"==typeof self?this:self,function(){return function(e){var r={};function o(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=e,o.c=r,o.d=function(t,n,e){o.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(n,t){if(1&t&&(n=o(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(o.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var r in n)o.d(e,r,function(t){return n[t]}.bind(null,r));return e},o.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(n,"a",n),n},o.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},o.p="",o(o.s=11)}([function(t,n){t.exports=function(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}},function(t,n,e){var o=e(0);t.exports=function(n){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.forEach(function(t){o(n,t,e[t])})}return n}},function(t,n,e){var r=e(5),o=e(6),i=e(7);t.exports=function(t){return r(t)||o(t)||i()}},function(t){t.exports={a:"1.3.3"}},function(t,n,e){var r=e(8),o=e(9),i=e(10);t.exports=function(t,n){return r(t)||o(t,n)||i()}},function(t,n){t.exports=function(t){if(Array.isArray(t)){for(var n=0,e=new Array(t.length);n<t.length;n++)e[n]=t[n];return e}}},function(t,n){t.exports=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}},function(t,n){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(t,n){t.exports=function(t){if(Array.isArray(t))return t}},function(t,n){t.exports=function(t,n){var e=[],r=!0,o=!1,i=void 0;try{for(var c,u=t[Symbol.iterator]();!(r=(c=u.next()).done)&&(e.push(c.value),!n||e.length!==n);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==u.return||u.return()}finally{if(o)throw i}}return e}},function(t,n){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(t,n,e){"use strict";e.r(n);var r=e(3);var y=function(t){return!(t&&(t.length||Object.keys(t).length))};var o=function(t){return Object.prototype.toString.call(t).replace(/^\[object (.+)\]$/,"$1").toLowerCase()};var b=function(t){return"array"===o(t)};var i=function(t){return"number"===o(t)};var c=function(t){return"string"===o(t)};var a=function(t){return"object"===o(t)};var u=function(t){return"boolean"===o(t)},f=e(0),h=e.n(f),l=e(1),m=e.n(l),s=e(2),g=e.n(s);var p=function(t){return"undefined"===o(t)},d="[Circular]";var v=function(n){if(p(n))throw new Error("[chober]: nothing to clone.");var e,r,o,i;try{return JSON.parse(JSON.stringify(n))}catch(t){if(a(n)){var c=(o=n,i=Object.keys(o).reduce(function(n,e){try{return JSON.stringify(o[e]),n}catch(t){return g()(n).concat([e])}},[]).reduce(function(t,n){return m()({},t,h()({},n,d))},o),JSON.parse(JSON.stringify(i)));if(!y(c))return c}if(b(n)){var u=(r=(e=n).reduce(function(n,t,e){try{return JSON.stringify(t),n}catch(t){return g()(n).concat([e])}},[]).reduce(function(t,n){return t[n]=d,t},e),JSON.parse(JSON.stringify(r)));if(!y(u))return u}throw new Error(t)}};var w=function(t,n){return JSON.stringify(v(t))===JSON.stringify(v(n))};var O=function(t){return null==t};var S=function(t){return"function"===o(t)},j=e(4),x=e.n(j);var E=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],n=window.location.search.substr(1),i={};return""===n?{}:(0!==t.length&&(i=t.reduce(function(t,n){return m()({},t,h()({},n,[]))},{})),n.split("&").forEach(function(t){if(t){var n=t.split("="),e=x()(n,2),r=e[0],o=e[1];Object.prototype.hasOwnProperty.call(i,r)&&(b(i[r])?i[r].push(o):i[r]=[i[r],o]),b(i[r])?i[r].forEach(function(t,n){i[r][n]=decodeURIComponent(t)}):i[r]=decodeURIComponent(o)}}),i)};var C=function(t){return p(t)||!c(t)?"":String(t).replace(/\D+/g,"")};var N=function(){return window.innerWidth-document.documentElement.clientWidth};var k=function(t){if(p(t))throw new Error("[chober]: key is not passed.");if(!c(t))throw new Error("[chober]: key must to be a string.");var n="; ".concat(document.cookie).split("; ".concat(t,"="));return 2===n.length?n.pop().split(";").shift():""};var I=function(t){if(p(t))throw new Error("[chober]: item is not passed.");var n=(c(t)?document.querySelector(t):t).getBoundingClientRect(),e=window.pageXOffset,r=window.pageYOffset;return{x:n.left+e,y:n.top+r,left:n.left+e,top:n.top+r,right:n.right+e,bottom:n.bottom+r}};var J=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];if(!b(t))throw new Error("[chober]: param must to be an array.");return v(t).map(function(t){return JSON.stringify(t)}).filter(function(t,n,e){return e.indexOf(t)===n}).map(function(t){return JSON.parse(t)})};var T=function e(t){return b(t)?t.reduce(function(t,n){return b(n)?t.concat(e(n)):t.concat(n)},[]):[]};var R=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},e=n.isSaveOld,r=void 0!==e&&e,o=n.isSaveHash,i=void 0===o||o,c=n.isSaveEmptyFields,u=void 0!==c&&c,f=Object.prototype.hasOwnProperty,a=t?Object.entries(t).reduce(function(t,n){var e=n[0],r=b(n[1])?J(T(n[1]).map(function(t){return String(t)})):n[1];return m()({},t,h()({},e,r))},{}):{},l=r&&E(),s=r&&Object.entries(a).concat(Object.entries(l)),p=i&&window.location.href.split("#")[1],d=r&&!y(l)?s.reduce(function(t,n){var e=n[0],r=n[1],o=f.call(t,e),i=f.call(l,e);if(!o||i)return o&&i?t:m()({},t,h()({},e,r));var c=t[e]===r?r:[t[e],r],u=b(t[e])?J(g()(t[e]).concat(g()(r))):c,a=b(r)?J(g()(r).concat(g()(t[e]))):u;return m()({},t,h()({},e,a))},{}):a,v=Object.keys(d).map(function(n){if("&"===n)return"";var t,e=d[n];return t=u?n?"".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(e)):"":n&&e?"".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(e)):"",b(e)?e.map(function(t){return u?n?"".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(t)):"":n&&t?"".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(t)):""}).filter(function(t){return t}).join("&"):t}).filter(function(t){return t}).join("&");window.history.pushState({},document.title,v?"?".concat(v).concat(p?"#".concat(p):""):window.location.href.split("?")[0].split("#")[0]+(p?"#".concat(p):""))};var U=function(t,n){var e=2<arguments.length&&void 0!==arguments[2]&&arguments[2];if(p(t)||p(n))throw new Error("[chober]: key or value is not passed.");var r=e&&(new Date).getTime()+e,o=e&&new Date(r).toUTCString(),i="".concat(t,"=").concat(n,"; path=/"),c="; expires=".concat(o);document.cookie=e?i:i+c};var P=function(t){if(p(t))throw new Error("[chober]: key is not passed.");document.cookie="".concat(t,"=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;")};var A=function(t){var n=document.createElement("textarea");return n.innerHTML=t,n.value};var _=function(t){if(p(t))throw new Error("[chober]: object is not passed.");return t&&Object.entries(t).reduce(function(t,n){return m()({},t,h()({},n[1],n[0]))},{})};var M=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;return b(t)?t.slice(0,n):[]};var D=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:" ";return String(t||0).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g,"$1".concat(n))};var q=function(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 t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];c&&clearTimeout(c),c=setTimeout(function(){r.apply(i,n),c=null},o)}};var $=function(t){if(p(t))throw new Error("[chober]: item is not passed.");(c(t)?document.querySelector(t):t).scrollIntoView({block:"center",behavior:"smooth",inline:"end"})},H=r.a;
!function(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?this:self,function(){return(n={},o.m=r=[function(e,t){e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}},function(e,t,r){var n=r(4),o=r(5),c=r(6);e.exports=function(e){return n(e)||o(e)||c()}},function(e,t,r){var n=r(7),o=r(8),c=r(9);e.exports=function(e,t){return n(e)||o(e,t)||c()}},function(e){e.exports=JSON.parse('{"a":"2.0.0"}')},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}},function(e,t){e.exports=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){var r=[],n=!0,o=!1,c=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,c=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw c}}return r}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t,r){"use strict";r.r(t);var n=r(3);var b=function(e){return!(e&&(e.length||Object.keys(e).length))};var o=function(e){return Object.prototype.toString.call(e).replace(/^\[object (.+)\]$/,"$1").toLowerCase()};var O=function(e){return"array"===o(e)};var a=function(e){return"number"===o(e)};var c=function(e){return"string"===o(e)};var u=function(e){return"object"===o(e)};var f=function(e){return"boolean"===o(e)},i=r(0),v=r.n(i),s=r(1),h=r.n(s);var p=function(e){return"undefined"===o(e)};function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}var y="[Circular]";var d=function(t){if(p(t))throw new Error("[chober]: nothing to clone.");function r(e){var t=Object.keys(e).reduce(function(t,r){try{return JSON.stringify(e[r]),t}catch(e){return[].concat(h()(t),[r])}},[]).reduce(function(e,t){return function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(r,!0).forEach(function(e){v()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({},e,v()({},t,y))},e);return JSON.parse(JSON.stringify(t))}var n,o;try{return JSON.parse(JSON.stringify(t))}catch(e){if(u(t)){var c=r(t);if(!b(c))return c}if(O(t)){var i=(o=(n=t).reduce(function(t,e,r){try{return JSON.stringify(e),t}catch(e){return[].concat(h()(t),[r])}},[]).reduce(function(e,t){return e[t]=y,e},n),JSON.parse(JSON.stringify(o)));if(!b(i))return i}throw new Error(e)}};function g(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function w(e,t){function r(e){var r=d(e);return u(r)?Object.keys(r).sort().reduce(function(e,t){return function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?g(r,!0).forEach(function(e){v()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):g(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({},e,v()({},t,r[t]))},{}):r}return JSON.stringify(r(e))===JSON.stringify(r(t))}var m=function(e){return null==e};function j(e){return"function"===o(e)}var P=r(2),S=r.n(P);function E(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function x(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?E(r,!0).forEach(function(e){v()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):E(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}var D=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.arrays,r=void 0===t?[]:t,n=e.isParse,o=void 0===n||n,c=window.location.search.substr(1),i={};if(""===c)return{};if(0!==r.length&&(i=r.reduce(function(e,t){return x({},e,v()({},t,[]))},{})),c.split("&").forEach(function(e){if(e){var t=e.split("="),r=S()(t,2),n=r[0],o=r[1];Object.prototype.hasOwnProperty.call(i,n)&&(O(i[n])?i[n].push(o):i[n]=[i[n],o]),O(i[n])?i[n].forEach(function(e,t){i[n][t]=decodeURIComponent(e)}):i[n]=decodeURIComponent(o)}}),o){var u=function(t){try{var e=JSON.parse(t);return a(e)||f(e)||m(e)?e:t}catch(e){return t}};i=Object.entries(i).reduce(function(e,t){var r=S()(t,2),n=r[0],o=r[1];return x({},e,v()({},n,O(o)?o.map(function(e){return u(e)}):u(o)))},{})}return i};function k(){var e=document.createElement("div");e.style.visibility="hidden",e.style.width="100px",e.style.msOverflowStyle="scrollbar",document.body.appendChild(e);var t=e.offsetWidth;e.style.overflow="scroll";var r=document.createElement("div");r.style.width="100%",e.appendChild(r);var n=r.offsetWidth;return e.parentNode.removeChild(e),t-n}function C(e){if(p(e))throw new Error("[chober]: key is not passed.");if(!c(e))throw new Error("[chober]: key must to be a string.");var t="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===t.length?t.pop().split(";").shift():""}function N(e){if(p(e))throw new Error("[chober]: item is not passed.");var t=(c(e)?document.querySelector(e):e).getBoundingClientRect(),r=window.pageXOffset,n=window.pageYOffset;return{x:t.left+r,y:t.top+n,left:t.left+r,top:t.top+n,right:t.right+r,bottom:t.bottom+n}}function J(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function I(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?J(r,!0).forEach(function(e){v()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):J(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function R(e,n){var t=2<arguments.length&&void 0!==arguments[2]&&arguments[2];if(p(n))throw new Error("[chober]: param is not passed.");var r=e.reduce(function(e,r){var t=r[n];return I({},e,{},O(t)?t.reduce(function(e,t){return I({},e,v()({},t,[].concat(h()(e[t]||[]),[r])))},e):v()({},t,[].concat(h()(e[t]||[]),[r])))},{});return t?Object.values(r):r}var U=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];if(!O(e))throw new Error("[chober]: param must to be an array.");return d(e).map(function(e){return JSON.stringify(e)}).filter(function(e,t,r){return r.indexOf(e)===t}).map(function(e){return JSON.parse(e)})};var T=function r(e){return O(e)?e.reduce(function(e,t){return O(t)?e.concat(r(t)):e.concat(t)},[]):[]};function _(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function A(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?_(r,!0).forEach(function(e){v()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):_(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function M(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=t.isSaveOld,n=void 0===r||r,o=t.isSaveHash,c=void 0===o||o,i=t.isSaveEmptyFields,u=void 0!==i&&i,f=Object.prototype.hasOwnProperty,a=e?Object.entries(e).reduce(function(e,t){var r=t[0],n=O(t[1])?U(T(t[1]).map(function(e){return String(e)})):t[1];return A({},e,v()({},r,n))},{}):{},s=n&&D(),p=n&&Object.entries(a).concat(Object.entries(s)),l=c&&window.location.href.split("#")[1],y=n&&!b(s)?p.reduce(function(e,t){var r=t[0],n=t[1],o=f.call(e,r),c=f.call(s,r);if(!o||c)return o&&c?e:A({},e,v()({},r,n));var i=e[r]===n?n:[e[r],n],u=O(e[r])?U([].concat(h()(e[r]),h()(n))):i,a=O(n)?U([].concat(h()(n),h()(e[r]))):u;return A({},e,v()({},r,a))},{}):a,d=Object.keys(y).map(function(t){if("&"===t)return"";var e,r=y[t];return e=u?t?"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(r)):"":t&&r?"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(r)):"",O(r)?r.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,d?"?".concat(d).concat(l?"#".concat(l):""):window.location.href.split("?")[0].split("#")[0]+(l?"#".concat(l):""))}function q(e,t){var r=2<arguments.length&&void 0!==arguments[2]&&arguments[2];if(p(e)||p(t))throw new Error("[chober]: key or value is not passed.");var n=r&&(new Date).getTime()+r,o=r&&new Date(n).toUTCString(),c="".concat(e,"=").concat(t,"; path=/"),i="; expires=".concat(o);document.cookie=r?c:c+i}function $(e){if(p(e))throw new Error("[chober]: key is not passed.");document.cookie="".concat(e,"=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;")}function B(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))}function Q(e){var o=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(!u(e))throw new Error("[chober]: param is not an object.");return Object.entries(e).map(function(e){var t=S()(e,2),r=t[0],n=t[1];return O(n)?n.map(function(e){return"".concat(r).concat(o?"[]":"","=").concat(e)}).join("&"):"".concat(r,"=").concat(n)}).join("&")}function W(e){if(p(e))throw new Error("[chober]: item is not passed.");(c(e)?document.querySelector(e):e).scrollIntoView({block:"center",behavior:"smooth",inline:"end"})}var F=n.a;
/**

@@ -9,2 +9,2 @@ * Chober.js - is a collection of useful methods that are used by programmers every day.

* @license https://github.com/BrooonS/chober/blob/master/LICENSE
*/n.default={VERSION:H,isEmpty:y,isArray:b,isNumber:i,isString:c,isObject:a,isBoolean:u,isEqual:w,isUndefined:p,isNil:O,isFunction:S,getQuery:E,getNumbers:C,getScrollbarWidth:N,getCookie:k,getOffset:I,getType:o,setQuery:R,setCookie:U,removeCookie:P,decodeHtml:A,clone:v,invertObject:_,first:M,flattenDeep:T,formatNumber:D,debounce:q,scrollTo:$,uniq:J}}]).default});
*/t.default={VERSION:F,isEmpty:b,isArray:O,isNumber:a,isString:c,isObject:u,isBoolean:f,isEqual:w,isUndefined:p,isNil:m,isFunction:j,getQuery:D,getScrollbarWidth:k,getCookie:C,getOffset:N,getType:o,groupBy:R,setQuery:M,setCookie:q,removeCookie:$,clone:d,flattenDeep:T,formatNumber:B,formatQuery:Q,scrollTo:W,uniq:U}}],o.c=n,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=10)).default;function o(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}var r,n});

@@ -134,71 +134,2 @@ # Chober.js

* * *
### debounce
Useful for implementing behavior that should only happen after a repeated action has completed.
#### Since
- 0.1.0
#### Params
- `func`
- Type: `function`
- `delay`
- Type: `Number`
#### Returns
- `function`
#### Example
```JS
window.addEventListener('scroll', debounce(() => console.log(Math.random()), 100))
```
<a href="https://github.com/BrooonS/chober/blob/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&nbsp;my&nbsp;friend!</h1>') // => '<h1>Hi my friend!</h1>'
```
<a href="https://github.com/BrooonS/chober/blob/master/lib/decodeHtml.js" target="_blank">Source code</a>
* * *
### first
Returns the first item of array or &#x60;number&#x60; items.
#### Since
- 0.1.0
#### Params
- `array`
- Type: `Array`
- `number`
- Type: `Number`
- Description: *Number of items to returns.*
#### Returns
- `Array`
#### Example
```JS
first([1, null, '3']) // => [1] first([1, null, '3'], 2) // => [1, null]
```
<a href="https://github.com/BrooonS/chober/blob/master/lib/first.js" target="_blank">Source code</a>
* * *
### flattenDeep

@@ -245,30 +176,36 @@

```JS
formatNumer(1234) // => '1 234' formatNumer('1234', ',') // => '1,234'
formatNumber(1234) // => '1 234' formatNumber('1234', ',') // => '1,234'
```
<a href="https://github.com/BrooonS/chober/blob/master/lib/formatNumber.js" target="_blank">Source code</a>
* * *
### getCookie
### formatQuery
Get cookie.
Format query to set to url.
#### Since
- 0.1.0
- 2.0.0
#### Params
- `key`
- Type: `String`
- Description: *Cookie name.*
- `arrayFields`
- Type: `Array`
- Description: *Fields that must be arrays.*
#### Returns
- `String`
- `Object`
#### Example
```JS
getCookie('someCookie')
const query = { value: 'test', field: ['hi', 'hello'] };
formatQuery(query)
// => value=test&field=hi&field=hello
const query = { value: ['test'], field: 'hi' }
formatQuery(query, true)
// => value[]=test&field=hi
```
<a href="https://github.com/BrooonS/chober/blob/master/lib/getCookie.js" target="_blank">Source code</a>
<a href="https://github.com/BrooonS/chober/blob/master/lib/formatQuery.js" target="_blank">Source code</a>
* * *
### getNumbers
### getCookie
Get only numbers from string.
Get cookie.

@@ -279,5 +216,5 @@ #### Since

#### Params
- `string`
- Type: `String,Number`
- Description: *Some string or number, which from to pick only numbers.*
- `key`
- Type: `String`
- Description: *Cookie name.*

@@ -289,5 +226,5 @@ #### Returns

```JS
getNumbers('+7 (123) 456-78-90') // => '71234567890'
getCookie('someCookie')
```
<a href="https://github.com/BrooonS/chober/blob/master/lib/getNumbers.js" target="_blank">Source code</a>
<a href="https://github.com/BrooonS/chober/blob/master/lib/getCookie.js" target="_blank">Source code</a>
* * *

@@ -303,4 +240,4 @@ ### getOffset

- `item`
- Type: `String`
- Description: *Selector of HTML element to get coordinates of.*
- Type: `String,HTMLElement`
- Description: *Selector or HTML element to get coordinates of.*

@@ -312,3 +249,3 @@ #### Returns

```JS
getOffset('#element').left // => 8
getOffset('.j-block').left // => 8 getOffset(document.querySelector('.j-block')).left // => 8
```

@@ -334,3 +271,3 @@ <a href="https://github.com/BrooonS/chober/blob/master/lib/getOffset.js" target="_blank">Source code</a>

```JS
// /?value=test&field=hi&field=hello getQuery() // => { value: 'test', field: ['hi', 'hello'] } // /?value=test&field=hi getQuery(['value']) // => { value: ['test'], field: 'hi' }
// /?value=test&field=hi&field=hello getQuery() // => { value: 'test', field: ['hi', 'hello'] } // /?value=test&field=hi getQuery({ arrays: ['value'] }) // => { value: ['test'], field: 'hi' } // /?value=test&field=hi&value=123&test=true getQuery() // => { value: ['test', 123], field: 'hi', test: true }
```

@@ -373,13 +310,19 @@ <a href="https://github.com/BrooonS/chober/blob/master/lib/getQuery.js" target="_blank">Source code</a>

* * *
### invertObject
### groupBy
Invert object.
Group items of an array by their specific property.
#### Since
- 0.1.0
- 2.0.0
#### Params
- `object`
- Type: `Object`
- Description: *Some object to invert.*
- `arr`
- Type: `Array`
- Description: *An array/collection to group.*
- `param`
- Type: `String`
- Description: *A parameter of array&#x27;s item to group by.*
- `withoutKeys`
- Type: `Boolean`
- Description: *Remove keys from object and get an array.*

@@ -391,5 +334,34 @@ #### Returns

```JS
invertObject({ key: 'value' }) // => { value: 'key' }
const array = [
{ id: 1, prop1: 'a', prop2: ['d', 'y'] },
{ id: 2, prop1: 'a', prop2: 'c' },
{ id: 3, prop1: 'b', prop2: 'd' },
];
groupBy(array, 'prop2');
// => {
// d: [
// { id: 1, prop1: 'a', prop2: ['d', 'y'] },
// { id: 3, prop1: 'b', prop2: 'd' }
// ],
// y: [
// { id: 1, prop1: 'a', prop2: ['d', 'y'] }
// ],
// c: [
// { id: 2, prop1: 'a', prop2: 'c' }
// ]
// }
groupBy(array, 'prop1', true);
// => [
// [
// { id: 1, prop1: 'a', prop2: ['d', 'y'] },
// { id: 2, prop1: 'a', prop2: 'c' },
// ],
// [
// { id: 3, prop1: 'b', prop2: 'd' },
// ],
// ]
```
<a href="https://github.com/BrooonS/chober/blob/master/lib/invertObject.js" target="_blank">Source code</a>
<a href="https://github.com/BrooonS/chober/blob/master/lib/groupBy.js" target="_blank">Source code</a>
* * *

@@ -637,4 +609,4 @@ ### isArray

- `item`
- Type: `DOMElement`
- Description: *Element to which to scroll.*
- Type: `String,HTMLElement`
- Description: *Selector or HTML element to which to scroll.*

@@ -644,3 +616,3 @@

```JS
scrollTo(document.querySelector('.j-block'))
scrollTo(document.querySelector('.j-block')) scrollTo('.j-block')
```

@@ -647,0 +619,0 @@ <a href="https://github.com/BrooonS/chober/blob/master/lib/scrollTo.js" target="_blank">Source code</a>

@@ -26,3 +26,2 @@ /**

import getQuery from './lib/getQuery';
import getNumbers from './lib/getNumbers';
import getScrollbarWidth from './lib/getScrollbarWidth';

@@ -32,12 +31,10 @@ import getCookie from './lib/getCookie';

import getType from './lib/getType';
import groupBy from './lib/groupBy';
import setQuery from './lib/setQuery';
import setCookie from './lib/setCookie';
import removeCookie from './lib/removeCookie';
import decodeHtml from './lib/decondeHtml';
import clone from './lib/clone';
import invertObject from './lib/invertObject';
import first from './lib/first';
import flattenDeep from './lib/flattenDeep';
import formatNumber from './lib/formatNumber';
import debounce from './lib/debounce';
import formatQuery from './lib/formatQuery';
import scrollTo from './lib/scrollTo';

@@ -69,3 +66,2 @@ import uniq from './lib/uniq';

getQuery,
getNumbers,
getScrollbarWidth,

@@ -75,14 +71,12 @@ getCookie,

getType,
groupBy,
setQuery,
setCookie,
removeCookie,
decodeHtml,
clone,
invertObject,
first,
flattenDeep,
formatNumber,
debounce,
formatQuery,
scrollTo,
uniq,
};

@@ -10,6 +10,6 @@ /**

* @example
* formatNumer(1234)
* formatNumber(1234)
* // => '1 234'
*
* formatNumer('1234', ',')
* formatNumber('1234', ',')
* // => '1,234'

@@ -16,0 +16,0 @@ */

@@ -8,8 +8,11 @@ import isUndefined from './isUndefined';

* @since 0.1.0
* @param {String} item Selector or HTML element to get coordinates of.
* @param {String|HTMLElement} item Selector or HTML element to get coordinates of.
* @returns {Object}
*
* @example
* getOffset('#element').left
* getOffset('.j-block').left
* // => 8
*
* getOffset(document.querySelector('.j-block')).left
* // => 8
*/

@@ -16,0 +19,0 @@ function getOffset(item) {

import isArray from './isArray';
import isNumber from './isNumber';
import isBoolean from './isBoolean';
import isNil from './isNil';

@@ -16,6 +19,13 @@ /**

* // /?value=test&field=hi
* getQuery(['value'])
* getQuery({ arrays: ['value'] })
* // => { value: ['test'], field: 'hi' }
*
* // /?value=test&field=hi&value=123&test=true
* getQuery()
* // => { value: ['test', 123], field: 'hi', test: true }
*/
function getQuery(arrayFields = []) {
function getQuery({
arrays = [],
isParse = true,
} = {}) {
const query = window.location.search.substr(1);

@@ -27,4 +37,4 @@ let objectUrl = {};

// Set default array fields to objectUrl
if (arrayFields.length !== 0) {
objectUrl = arrayFields.reduce((object, field) => ({
if (arrays.length !== 0) {
objectUrl = arrays.reduce((object, field) => ({
...object,

@@ -59,2 +69,24 @@ [field]: [],

if (isParse) {
const tryToParse = (item) => {
try {
const parsedItem = JSON.parse(item);
return isNumber(parsedItem) || isBoolean(parsedItem) || isNil(parsedItem)
? parsedItem
: item;
} catch (err) {
return item;
}
};
objectUrl = Object.entries(objectUrl)
.reduce((acc, [key, value]) => ({
...acc,
[key]: isArray(value)
? value.map(item => tryToParse(item))
: tryToParse(value),
}), {});
}
return objectUrl;

@@ -61,0 +93,0 @@ }

@@ -8,5 +8,26 @@ /**

function getScrollbarWidth() {
return window.innerWidth - document.documentElement.clientWidth;
const outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.msOverflowStyle = 'scrollbar';
document.body.appendChild(outer);
const widthNoScroll = outer.offsetWidth;
outer.style.overflow = 'scroll';
const inner = document.createElement('div');
inner.style.width = '100%';
outer.appendChild(inner);
const widthWithScroll = inner.offsetWidth;
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;
}
export default getScrollbarWidth;

@@ -15,6 +15,6 @@ /**

*/
function getType(object) {
return Object.prototype.toString.call(object).replace(/^\[object (.+)\]$/, '$1').toLowerCase();
function getType(item) {
return Object.prototype.toString.call(item).replace(/^\[object (.+)\]$/, '$1').toLowerCase();
}
export default getType;

@@ -0,1 +1,2 @@

import isObject from './isObject';
import clone from './clone';

@@ -22,5 +23,15 @@

function isEqual(firstItem, secondItem) {
return JSON.stringify(clone(firstItem)) === JSON.stringify(clone(secondItem));
const prepareItem = (item) => {
const clonedItem = clone(item);
return isObject(clonedItem)
? Object.keys(clonedItem)
.sort()
.reduce((acc, name) => ({ ...acc, [name]: clonedItem[name] }), {})
: clonedItem;
};
return JSON.stringify(prepareItem(firstItem)) === JSON.stringify(prepareItem(secondItem));
}
export default isEqual;

@@ -8,6 +8,8 @@ import isUndefined from './isUndefined';

* @since 0.2.0
* @param {DOMElement} item Selector or HTML element to which to scroll.
* @param {String|HTMLElement} item Selector or HTML element to which to scroll.
*
* @example
* scrollTo(document.querySelector('.j-block'))
*
* scrollTo('.j-block')
*/

@@ -14,0 +16,0 @@ function scrollTo(item) {

@@ -33,3 +33,3 @@ import getQuery from './getQuery';

function setQuery(query, {
isSaveOld = false,
isSaveOld = true,
isSaveHash = true,

@@ -112,7 +112,7 @@ isSaveEmptyFields = false,

})
.filter(queryItem => queryItem) // Remove empty queries
.filter(queryItem => queryItem)
.join('&')
: fieldValue;
})
.filter(queryItem => queryItem) // Remove empty queries
.filter(queryItem => queryItem)
.join('&');

@@ -119,0 +119,0 @@

{
"name": "chober",
"version": "1.3.3",
"version": "2.0.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",
"types": "index.d.ts",
"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",
"start": "webpack --env development --watch",
"prod": "webpack --env production",
"dev": "webpack --env development",
"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"
"docs-server": "docsify serve ./docs -p 35730"
},

@@ -38,3 +39,2 @@ "repository": {

"getQuery",
"getNumbers",
"getScrollbarWidth",

@@ -44,12 +44,10 @@ "getCookie",

"getType",
"groupBy",
"setQuery",
"setCookie",
"removeCookie",
"decodeHtml",
"clone",
"invertObject",
"first",
"flatten",
"flattenDeep",
"formatNumber",
"debounce",
"formatQuery",
"scrollTo",

@@ -65,22 +63,22 @@ "uniq"

"devDependencies": {
"@babel/core": "^7.1.6",
"@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.6",
"@babel/runtime": "^7.1.5",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/runtime": "^7.5.5",
"babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6",
"docsify-cli": "^4.3.0",
"eslint": "^5.9.0",
"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.26.0",
"webpack-cli": "^3.1.2"
"eslint": "^6.1.0",
"eslint-config-airbnb": "^17.1.1",
"eslint-loader": "^2.2.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"jsdoc-to-markdown": "^5.0.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.38.0",
"webpack-cli": "^3.3.6"
}
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc