billy-herrington-utils 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,7 +84,7 @@ function S(e, t) {
84
84
  return m(r, e), r.innerHTML = e.innerHTML, (n = e.parentNode) == null || n.replaceChild(r, e), r;
85
85
  }
86
86
  function z(e) {
87
- return Array.from(e).reduce((t, r) => (r.parentElement && t.includes(r.parentElement) && t.push(r.parentElement), t), []);
87
+ return Array.from(e).reduce((t, r) => (r.parentElement && !t.includes(r.parentElement) && t.push(r.parentElement), t), []);
88
88
  }
89
89
  function p(e) {
90
90
  return e.nextElementSibling ? e.nextElementSibling : e.parentElement ? p(e.parentElement) : null;
@@ -1 +1 @@
1
- (function(i,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(i=typeof globalThis<"u"?globalThis:i||self,l(i.bhutils={}))})(this,function(i){"use strict";var B=Object.defineProperty;var _=(i,l,c)=>l in i?B(i,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):i[l]=c;var o=(i,l,c)=>_(i,typeof l!="symbol"?l+"":l,c);function l(n){return n.split(",").map(e=>e.trim().toLowerCase()).filter(e=>e)}function c(n){return(n==null?void 0:n.replace(/\n|\t/," ").replace(/ {2,}/," ").trim().toLowerCase())||""}function w(n){return((n==null?void 0:n.match(/\d+/gm))||[0]).reverse().map((e,t)=>parseInt(e)*60**t).reduce((e,t)=>e+t)}function T(n,e){return Number.isInteger(parseInt(n))?parseInt(n):e}function E(n){const e=n.split(";").flatMap(t=>{const r=t.match(/([\+\w+]+):(\w+)?/),s=r==null?void 0:r[2];if(s)return r[1].split("+").map(a=>({[a]:s}))}).filter(t=>t);return Object.assign({},...e)}function k(n){return n.replace(/url\("|\"\).*/g,"")}class u{constructor(e){o(this,"observer");this.callback=e,this.observer=new IntersectionObserver(this.handleIntersection.bind(this))}observe(e){this.observer.observe(e)}throttle(e,t){this.observer.unobserve(e),setTimeout(()=>this.observer.observe(e),t)}handleIntersection(e){for(const t of e)t.isIntersecting&&this.callback(t.target)}static observeWhile(e,t,r){const s=new u(async a=>{await t()&&s.throttle(a,r)});return s.observe(e),s}}class h{constructor(e,t="data-lazy-load",r=!0){o(this,"lazyImgObserver");o(this,"delazify",e=>{this.lazyImgObserver.observer.unobserve(e),e.src=e.getAttribute(this.attributeName),this.removeTagAfter&&e.removeAttribute(this.attributeName)});this.attributeName=t,this.removeTagAfter=r,this.lazyImgObserver=new u(s=>{e(s,this.delazify)})}lazify(e,t,r){!t||!r||(t.setAttribute(this.attributeName,r),t.src="",this.lazyImgObserver.observe(t))}static create(e){return new h((r,s)=>{e(r)&&s(r)})}}function A(n,e=6,t=1){return(n+t)%e||e}function f(n){const e=new DOMParser().parseFromString(n,"text/html").body;return e.children.length>1?e:e.firstElementChild}function m(n,e){for(const t of e.attributes)t.nodeValue&&n.setAttribute(t.nodeName,t.nodeValue)}function I(n,e){var r;const t=document.createElement(e);return m(t,n),t.innerHTML=n.innerHTML,(r=n.parentNode)==null||r.replaceChild(t,n),t}function S(n){return Array.from(n).reduce((e,t)=>(t.parentElement&&e.includes(t.parentElement)&&e.push(t.parentElement),e),[])}function v(n){return n.nextElementSibling?n.nextElementSibling:n.parentElement?v(n.parentElement):null}function g(n,e,t){const r=new MutationObserver(s=>{const a=n.querySelector(e);a&&(r.disconnect(),t(a))});r.observe(document.body,{childList:!0,subtree:!0})}function O(n,e){let t=n.children.length;new MutationObserver((s,a)=>{for(const b of s)b.type==="childList"&&t!==n.children.length&&(t=n.children.length,e(a,t))}).observe(n,{childList:!0})}function L(n,e,t=1e3,r={childList:!0,subtree:!0,attributes:!0}){let s,a;new MutationObserver((G,K)=>{const y=Date.now();s&&y-s<t&&a&&clearTimeout(a),a=setTimeout(e,t),s=y}).observe(n,r)}function M(n={append:"",after:"",button:"",cbBefore:()=>{}}){var t,r;const e=f(n.button);n.append&&((t=document.querySelector(n.append))==null||t.append(e)),n.after&&((r=document.querySelector(n.after))==null||r.after(e)),e.addEventListener("click",s=>{s.preventDefault(),n.cbBefore&&n.cbBefore(),g(document.body,"video",a=>{window.location.href=a.getAttribute("src")})})}const p=["Mozilla/5.0 (Linux; Android 10; K)","AppleWebKit/537.36 (KHTML, like Gecko)","Chrome/114.0.0.0 Mobile Safari/537.36"].join(" ");function d(n,e={html:!1,mobile:!1}){const t={};return e.mobile&&Object.assign(t,{headers:new Headers({"User-Agent":p})}),fetch(n,t).then(r=>r.text()).then(r=>e.html?f(r):r)}const P=n=>d(n,{html:!0}),z=n=>d(n);function F(n){const e=new FormData;return Object.entries(n).forEach(([t,r])=>e.append(t,r)),e}function C(n,e,t){for(const r of e)n.addEventListener(r,t,!0)}class D{constructor(e,t=!0){o(this,"tick");o(this,"callbackFinal");this.delay=e,this.startImmediate=t,this.tick=null,this.delay=e,this.startImmediate=t}start(e,t=null){this.stop(),this.callbackFinal=t,this.startImmediate&&e(),this.tick=setInterval(e,this.delay)}stop(){this.tick!==null&&(clearInterval(this.tick),this.tick=null),this.callbackFinal&&(this.callbackFinal(),this.callbackFinal=null)}}function H(){return/iPhone|Android/i.test(navigator.userAgent)}async function N(n){const e=[];for await(const t of n)e.push(await t());return e}function j(n){return new Promise(e=>setTimeout(e,n))}class W{constructor(){o(this,"pull",[]);o(this,"lock",!1)}getHighPriorityFirst(e=0){if(e>3||this.pull.length===0)return;const t=this.pull.findIndex(r=>r.p===e);if(t>=0){const r=this.pull[t].v;return this.pull=this.pull.slice(0,t).concat(this.pull.slice(t+1)),r}return this.getHighPriorityFirst(e+1)}*pullGenerator(){for(;this.pull.length>0;)yield this.getHighPriorityFirst()}async processPull(){if(!this.lock){this.lock=!0;for await(const e of this.pullGenerator())await e();this.lock=!1}}push(e){this.pull.push(e),this.processPull()}}function U(n,e){const t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function q(n,e=1){return[...Array(n).keys()].map(t=>t+e)}i.LazyImgLoader=h,i.MOBILE_UA=p,i.Observer=u,i.SyncPull=W,i.Tick=D,i.chunks=U,i.circularShift=A,i.computeAsyncOneAtTime=N,i.copyAttributes=m,i.downloader=M,i.fetchHtml=P,i.fetchText=z,i.fetchWith=d,i.findNextSibling=v,i.getAllUniqueParents=S,i.isMob=H,i.listenEvents=C,i.objectToFormData=F,i.parseCSSUrl=k,i.parseDataParams=E,i.parseDom=f,i.parseIntegerOr=T,i.range=q,i.replaceElementTag=I,i.sanitizeStr=c,i.stringToWords=l,i.timeToSeconds=w,i.wait=j,i.waitForElementExists=g,i.watchDomChangesWithThrottle=L,i.watchElementChildrenCount=O,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(i=typeof globalThis<"u"?globalThis:i||self,l(i.bhutils={}))})(this,function(i){"use strict";var B=Object.defineProperty;var _=(i,l,c)=>l in i?B(i,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):i[l]=c;var o=(i,l,c)=>_(i,typeof l!="symbol"?l+"":l,c);function l(n){return n.split(",").map(e=>e.trim().toLowerCase()).filter(e=>e)}function c(n){return(n==null?void 0:n.replace(/\n|\t/," ").replace(/ {2,}/," ").trim().toLowerCase())||""}function w(n){return((n==null?void 0:n.match(/\d+/gm))||[0]).reverse().map((e,t)=>parseInt(e)*60**t).reduce((e,t)=>e+t)}function T(n,e){return Number.isInteger(parseInt(n))?parseInt(n):e}function E(n){const e=n.split(";").flatMap(t=>{const r=t.match(/([\+\w+]+):(\w+)?/),s=r==null?void 0:r[2];if(s)return r[1].split("+").map(a=>({[a]:s}))}).filter(t=>t);return Object.assign({},...e)}function k(n){return n.replace(/url\("|\"\).*/g,"")}class u{constructor(e){o(this,"observer");this.callback=e,this.observer=new IntersectionObserver(this.handleIntersection.bind(this))}observe(e){this.observer.observe(e)}throttle(e,t){this.observer.unobserve(e),setTimeout(()=>this.observer.observe(e),t)}handleIntersection(e){for(const t of e)t.isIntersecting&&this.callback(t.target)}static observeWhile(e,t,r){const s=new u(async a=>{await t()&&s.throttle(a,r)});return s.observe(e),s}}class h{constructor(e,t="data-lazy-load",r=!0){o(this,"lazyImgObserver");o(this,"delazify",e=>{this.lazyImgObserver.observer.unobserve(e),e.src=e.getAttribute(this.attributeName),this.removeTagAfter&&e.removeAttribute(this.attributeName)});this.attributeName=t,this.removeTagAfter=r,this.lazyImgObserver=new u(s=>{e(s,this.delazify)})}lazify(e,t,r){!t||!r||(t.setAttribute(this.attributeName,r),t.src="",this.lazyImgObserver.observe(t))}static create(e){return new h((r,s)=>{e(r)&&s(r)})}}function A(n,e=6,t=1){return(n+t)%e||e}function f(n){const e=new DOMParser().parseFromString(n,"text/html").body;return e.children.length>1?e:e.firstElementChild}function m(n,e){for(const t of e.attributes)t.nodeValue&&n.setAttribute(t.nodeName,t.nodeValue)}function I(n,e){var r;const t=document.createElement(e);return m(t,n),t.innerHTML=n.innerHTML,(r=n.parentNode)==null||r.replaceChild(t,n),t}function S(n){return Array.from(n).reduce((e,t)=>(t.parentElement&&!e.includes(t.parentElement)&&e.push(t.parentElement),e),[])}function v(n){return n.nextElementSibling?n.nextElementSibling:n.parentElement?v(n.parentElement):null}function g(n,e,t){const r=new MutationObserver(s=>{const a=n.querySelector(e);a&&(r.disconnect(),t(a))});r.observe(document.body,{childList:!0,subtree:!0})}function O(n,e){let t=n.children.length;new MutationObserver((s,a)=>{for(const b of s)b.type==="childList"&&t!==n.children.length&&(t=n.children.length,e(a,t))}).observe(n,{childList:!0})}function L(n,e,t=1e3,r={childList:!0,subtree:!0,attributes:!0}){let s,a;new MutationObserver((G,K)=>{const y=Date.now();s&&y-s<t&&a&&clearTimeout(a),a=setTimeout(e,t),s=y}).observe(n,r)}function M(n={append:"",after:"",button:"",cbBefore:()=>{}}){var t,r;const e=f(n.button);n.append&&((t=document.querySelector(n.append))==null||t.append(e)),n.after&&((r=document.querySelector(n.after))==null||r.after(e)),e.addEventListener("click",s=>{s.preventDefault(),n.cbBefore&&n.cbBefore(),g(document.body,"video",a=>{window.location.href=a.getAttribute("src")})})}const p=["Mozilla/5.0 (Linux; Android 10; K)","AppleWebKit/537.36 (KHTML, like Gecko)","Chrome/114.0.0.0 Mobile Safari/537.36"].join(" ");function d(n,e={html:!1,mobile:!1}){const t={};return e.mobile&&Object.assign(t,{headers:new Headers({"User-Agent":p})}),fetch(n,t).then(r=>r.text()).then(r=>e.html?f(r):r)}const P=n=>d(n,{html:!0}),z=n=>d(n);function F(n){const e=new FormData;return Object.entries(n).forEach(([t,r])=>e.append(t,r)),e}function C(n,e,t){for(const r of e)n.addEventListener(r,t,!0)}class D{constructor(e,t=!0){o(this,"tick");o(this,"callbackFinal");this.delay=e,this.startImmediate=t,this.tick=null,this.delay=e,this.startImmediate=t}start(e,t=null){this.stop(),this.callbackFinal=t,this.startImmediate&&e(),this.tick=setInterval(e,this.delay)}stop(){this.tick!==null&&(clearInterval(this.tick),this.tick=null),this.callbackFinal&&(this.callbackFinal(),this.callbackFinal=null)}}function H(){return/iPhone|Android/i.test(navigator.userAgent)}async function N(n){const e=[];for await(const t of n)e.push(await t());return e}function j(n){return new Promise(e=>setTimeout(e,n))}class W{constructor(){o(this,"pull",[]);o(this,"lock",!1)}getHighPriorityFirst(e=0){if(e>3||this.pull.length===0)return;const t=this.pull.findIndex(r=>r.p===e);if(t>=0){const r=this.pull[t].v;return this.pull=this.pull.slice(0,t).concat(this.pull.slice(t+1)),r}return this.getHighPriorityFirst(e+1)}*pullGenerator(){for(;this.pull.length>0;)yield this.getHighPriorityFirst()}async processPull(){if(!this.lock){this.lock=!0;for await(const e of this.pullGenerator())await e();this.lock=!1}}push(e){this.pull.push(e),this.processPull()}}function U(n,e){const t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function q(n,e=1){return[...Array(n).keys()].map(t=>t+e)}i.LazyImgLoader=h,i.MOBILE_UA=p,i.Observer=u,i.SyncPull=W,i.Tick=D,i.chunks=U,i.circularShift=A,i.computeAsyncOneAtTime=N,i.copyAttributes=m,i.downloader=M,i.fetchHtml=P,i.fetchText=z,i.fetchWith=d,i.findNextSibling=v,i.getAllUniqueParents=S,i.isMob=H,i.listenEvents=C,i.objectToFormData=F,i.parseCSSUrl=k,i.parseDataParams=E,i.parseDom=f,i.parseIntegerOr=T,i.range=q,i.replaceElementTag=I,i.sanitizeStr=c,i.stringToWords=l,i.timeToSeconds=w,i.wait=j,i.waitForElementExists=g,i.watchDomChangesWithThrottle=L,i.watchElementChildrenCount=O,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "billy-herrington-utils",
3
3
  "description": "daddy told us not to be ashamed of our utils",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "license": "MIT",
6
6
  "keywords": ["utils", "observer", "dom", "fetch", "arrays"],
7
7
  "author": "smartacephale atm.mormon@protonmail.com (https://github.com/smartacephale)",
@@ -19,7 +19,7 @@ export function replaceElementTag(e: HTMLElement | Element, tagName: string) {
19
19
 
20
20
  export function getAllUniqueParents(elements: HTMLCollection): Array<HTMLElement | Element> {
21
21
  return Array.from(elements).reduce((acc, v) => {
22
- if (v.parentElement && acc.includes(v.parentElement as HTMLElement)) { acc.push(v.parentElement); }
22
+ if (v.parentElement && !acc.includes(v.parentElement as HTMLElement)) { acc.push(v.parentElement); }
23
23
  return acc;
24
24
  }, [] as Array<HTMLElement | Element>);
25
25
  }