diff --git a/dist/display.es6.js b/dist/display.es6.js index 2903b42..57f7c5e 100644 --- a/dist/display.es6.js +++ b/dist/display.es6.js @@ -523,7 +523,7 @@ class DisplayJS { } } format = time_formats[time_formats.length - 1]; - return Math.floor(seconds / format[2]) + " " + format[1] + " " + token; + return `${Math.floor(seconds / format[2])} ${format[1]} ${token}`; } // import a script import(source, callback) { diff --git a/dist/display.es6.min.js b/dist/display.es6.min.js index 296e629..32e70b7 100644 --- a/dist/display.es6.min.js +++ b/dist/display.es6.min.js @@ -1 +1 @@ -class DisplayJS{constructor(a){this.obj=a}var(a){const b=()=>{this.if(),this.else();const a=document.querySelectorAll("[var]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}render(a){this.var(a)}renderVariables(a){this.var(a)}xss(a){const b=//g,d=/'/g,e=/"/g;return a.toString().replace(b,"<").replace(c,">").replace(d,"'").replace(e,""")}xssURI(a){return encodeURI(a)}target(b=()=>{this.var()}){const c=(()=>{return document.addEventListener?(a,b,c)=>{a.addEventListener(b,c,!1)}:(a,b,c)=>{a.attachEvent(`on${b}`,c)}})(),d=this.obj;[].forEach.call(document.querySelectorAll("[target]"),(e,f,g)=>{c(g[f],"change",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"keydown",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"input",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"paste",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()})})}if(a){const b=()=>{const a=document.querySelectorAll("[if]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}else(a){const b=()=>{const a=document.querySelectorAll("[else]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}repeat(a,b,c,d="",e=""){let f=d;if("object"==typeof c)for(let a=0;a{const c=document.querySelectorAll(`[${a}]`);for(let d=0;d{d()})):window.setInterval(()=>{d()},c):d()}live(a,b){const c={watch(a,b,c){const d=Object.getOwnPropertyDescriptor(a,b);if("undefined"==typeof d)throw new Error(`DisplayJS: Invalid descriptor for property: ${b}, object: ${a}`);if("function"!=typeof c)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${c}`);let e=a[b];Object.defineProperty(a,b,{enumerable:!0,configurable:!0,get(){return e},set(d){if(d!==e)return c(a,b,d,e),e=d}})},watchAll(a,b){if("function"!=typeof b)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${b}`);for(const c in a)this.watch(a,c,b)}};c.watchAll(a,(a,c,d,e)=>{b(a,c,d,e)})}load(a,b,c=()=>{}){this.ajax(b,"GET","",(b)=>{try{document.querySelector(a).innerHTML=b.responseXML.querySelector(a),c()}catch(a){c(a)}})}onEvent(){const a=document.querySelectorAll("[on]");for(let b=0;b{eval(d)})}}all(a,b){a.forEach((a)=>{const c=[];c.push(a),b(c)})}text(a,b){a[0].innerHTML=this.xss(b)}html(a,b){a[0].innerHTML=b}append(a,b){a[0].innerHTML+=b}after(a,b){a[0].insertAdjacentHTML("afterend",b)}before(a,b){a[0].insertAdjacentHTML("beforebegin",b)}clone(a){a[0].cloneNode(!0)}is(a,b){return!(a[0]!==b[0])}select(a){return this.isElement(a)?Array(a):document.querySelectorAll(a)}single(a){return this.isElement(a)?a:document.querySelector(a)}s(a){return this.select(a)}empty(a){a[0].innerHTML=null}valEmpty(a){a[0].value=null}remove(a){a[0].parentNode.removeChild(a[0])}on(a,b,c){a[0].addEventListener(b,c)}ready(a){(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?a():document.addEventListener("DOMContentLoaded",a)}scroll(a){window.addEventListener("scroll",a)}scrollTo(a,b){window.scroll(a,b)}scrollTop(a=[document.body]){return a[0].scrollTop}show(a){return a[0].style.display="block",!0}hide(a){return a[0].style.display="none",!0}ajax(a,b,c,d,e="application/x-www-form-urlencoded; charset=UTF-8"){const f=new XMLHttpRequest;f.open(b,a,!0),f.setRequestHeader("Content-Type",e),f.onload=()=>{if(200<=f.status&&400>f.status){const a=f.responseText;d(a)}else console.error("DisplayJS error: The ajax request returned an error.")},f.onerror=()=>{console.error("DisplayJS error: The ajax request returned an error.")},f.send(c)}hasClass(a,b){return a[0].classList?a[0].classList.contains(b):!!a[0].className.match(new RegExp(`(\\s|^)${b}(\\s|$)`))}addClass(a,b){a[0].classList?a[0].classList.add(b):!this.hasClass(a,b)&&(a[0].className+=` ${b}`)}removeClass(a,b){if(a[0].classList)a[0].classList.remove(b);else if(this.hasClass(a,b)){const c=new RegExp(`(\\s|^)${b}(\\s|$)`);a[0].className=a[0].className.replace(c," ")}}toggleClass(a,b){this.hasClass(a,b)?this.removeClass(a,b):this.addClass(a,b)}css(a,b,c){a[0].style[b]=c}getStyle(a,b){return a[0].style[b]}fadeOut(a,b=0.1){const c=a[0];c.style.opacity=1,function a(){0>(c.style.opacity-=b)?c.style.display="none":requestAnimationFrame(a)}()}fadeIn(a,b=0.1,c){const d=a[0];d.style.opacity=0,d.style.display=c||"block",function a(){let c=parseFloat(d.style.opacity);1<(c+=b)||(d.style.opacity=c,requestAnimationFrame(a))}()}get fn(){return DisplayJS.prototype}dynamic(a,b=250){window.setInterval(a,b)}parent(a,b=0){let c=a[0];for(const d in this.range(b))c=c.parentNode;return Array(c)}isNode(a){return"object"==typeof Node?a instanceof Node:a&&"object"==typeof a&&"number"==typeof a.nodeType&&"string"==typeof a.nodeName}isElement(a){return"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName}component(a,b){class component extends HTMLElement{constructor(){super(),b(this)}}customElements.define(a,component)}time_ago(a){var b=Math.floor;switch(typeof a){case"number":break;case"string":a=+new Date(a);break;case"object":a.constructor===Date&&(a=a.getTime());break;default:a=+new Date;}const c=[[60,"seconds",1],[120,"1 minute ago","1 minute from now"],[3600,"minutes",60],[7200,"1 hour ago","1 hour from now"],[86400,"hours",3600],[172800,"Yesterday","Tomorrow"],[604800,"days",86400],[1209600,"Last week","Next week"],[2419200,"weeks",604800],[4838400,"Last month","Next month"],[29030400,"months",2419200],[58060800,"Last year","Next year"],[2903040000,"years",29030400],[5806080000,"Last century","Next century"],[58060800000,"centuries",2903040000]];let d=(+new Date-a)/1e3,e="ago",f=1;if(0==d)return"Just now";0>d&&(d=Math.abs(d),e="from now",f=2);let g,h=0;for(;g=c[h++];)if(d{(d||!c.readyState||/loaded|complete/.test(c.readyState))&&(c.onload=c.onreadystatechange=null,c=void 0,!d&&b&&b())},c.src=a,d.parentNode.insertBefore(c,d)}extend(a,b){const c={};for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);for(d in b)Object.prototype.hasOwnProperty.call(b,d)&&(c[d]=b[d]);return c}arange(a,b,c,d){const e=(Math.abs(b-a)+2*(d||0))/(c||1)+1,f=aa-f*(d||0)+f*(c||1)*e)}range(a){return this.arange(0,a,1)}linespace(a,b,c){return this.arange(a,b,(b-a)/c)}reshape(a,b){const c=[];for(let d=0;dthis.math.add(c,a),0)}multiply(a){return a.reduce((c,a)=>this.math.mul(c,a),0)}flatten(a){return a.reduce((c,a)=>c.concat(a),[])}drop(a,b){return 0this.math.sub(c,a));const b=Math.floor(this.math.div(a.length,2));return a.length%2?a[b]:this.math.div(this.math.add(a[b-1],a[b]),2)}predict(c,a,b=!1){function d(d,f){const g=c[0][0],h=c[1][0],i=c[0][1],j=c[1][1],k=e.math.div(e.math.sub(i,j),e.math.sub(g,h)),a=e.math.sub(j,e.math.mul(h,k));return!0==f?`f(x) = ${k}x+${a}; f(${d}) = ${d*k+a}`:d*k+a}const e=this;return function(a){return!(2=9007199254740991)throw"DisplayJS: The result is not a safe integer."},shiftComma(a,b){return this.toExponent(this.countDecimals([a]),-b)[0]},countResult(a,b){let c=a[0];for(let d=1;da.length)throw"DisplayJS: Set at least two numerical values.";for(const b in a){if(a[b]=parseFloat(a[b]),"number"!=typeof a[b]||isNaN(a[b]))throw"DisplayJS: Every Math argument must be of type number.";if(a[b]===Number.POSITIVE_INFINITY||a[b]===Number.NEGATIVE_INFINITY)throw"DisplayJS: Every Math argument must be a numerical value between positive and negative Infinity."}return a},countDecimals(a){const b=[];for(const c in a){let d=0;const e=a[c].toString().split("e"),f=e[0].indexOf(".");d-=-1===f?0:e[0].length-1-f,d+=isNaN(+e[1])?0:+e[1],e[0]=+e[0].replace(".",""),b.push({integer:e[0],comma:d})}return b}};return a}}"function"==typeof define&&define.amd?define(()=>new DisplayJS):"undefined"==typeof exports?global.DisplayJS=new DisplayJS:("undefined"!=typeof module&&module.exports&&(exports=module.exports=new DisplayJS),exports.DisplayJS=new DisplayJS); \ No newline at end of file +class DisplayJS{constructor(a){this.obj=a}var(a){const b=()=>{this.if(),this.else();const a=document.querySelectorAll("[var]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}render(a){this.var(a)}renderVariables(a){this.var(a)}xss(a){const b=//g,d=/'/g,e=/"/g;return a.toString().replace(b,"<").replace(c,">").replace(d,"'").replace(e,""")}xssURI(a){return encodeURI(a)}target(b=()=>{this.var()}){const c=(()=>{return document.addEventListener?(a,b,c)=>{a.addEventListener(b,c,!1)}:(a,b,c)=>{a.attachEvent(`on${b}`,c)}})(),d=this.obj;[].forEach.call(document.querySelectorAll("[target]"),(e,f,g)=>{c(g[f],"change",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"keydown",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"input",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()}),c(g[f],"paste",function(){const a=g[f].getAttribute("target");d[a]="checkbox"==this.type?this.checked:"select"==this.type?this.options[this.selectedIndex].value:this.value,b()})})}if(a){const b=()=>{const a=document.querySelectorAll("[if]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}else(a){const b=()=>{const a=document.querySelectorAll("[else]");for(let b=0;b{b()})):window.setInterval(()=>{b()},a):b()}repeat(a,b,c,d="",e=""){let f=d;if("object"==typeof c)for(let a=0;a{const c=document.querySelectorAll(`[${a}]`);for(let d=0;d{d()})):window.setInterval(()=>{d()},c):d()}live(a,b){const c={watch(a,b,c){const d=Object.getOwnPropertyDescriptor(a,b);if("undefined"==typeof d)throw new Error(`DisplayJS: Invalid descriptor for property: ${b}, object: ${a}`);if("function"!=typeof c)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${c}`);let e=a[b];Object.defineProperty(a,b,{enumerable:!0,configurable:!0,get(){return e},set(d){if(d!==e)return c(a,b,d,e),e=d}})},watchAll(a,b){if("function"!=typeof b)throw new Error(`DisplayJS: Invalid onPropertyChange handler: ${b}`);for(const c in a)this.watch(a,c,b)}};c.watchAll(a,(a,c,d,e)=>{b(a,c,d,e)})}load(a,b,c=()=>{}){this.ajax(b,"GET","",(b)=>{try{document.querySelector(a).innerHTML=b.responseXML.querySelector(a),c()}catch(a){c(a)}})}onEvent(){const a=document.querySelectorAll("[on]");for(let b=0;b{eval(d)})}}all(a,b){a.forEach((a)=>{const c=[];c.push(a),b(c)})}text(a,b){a[0].innerHTML=this.xss(b)}html(a,b){a[0].innerHTML=b}append(a,b){a[0].innerHTML+=b}after(a,b){a[0].insertAdjacentHTML("afterend",b)}before(a,b){a[0].insertAdjacentHTML("beforebegin",b)}clone(a){a[0].cloneNode(!0)}is(a,b){return!(a[0]!==b[0])}select(a){return this.isElement(a)?Array(a):document.querySelectorAll(a)}single(a){return this.isElement(a)?a:document.querySelector(a)}s(a){return this.select(a)}empty(a){a[0].innerHTML=null}valEmpty(a){a[0].value=null}remove(a){a[0].parentNode.removeChild(a[0])}on(a,b,c){a[0].addEventListener(b,c)}ready(a){(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?a():document.addEventListener("DOMContentLoaded",a)}scroll(a){window.addEventListener("scroll",a)}scrollTo(a,b){window.scroll(a,b)}scrollTop(a=[document.body]){return a[0].scrollTop}show(a){return a[0].style.display="block",!0}hide(a){return a[0].style.display="none",!0}ajax(a,b,c,d,e="application/x-www-form-urlencoded; charset=UTF-8"){const f=new XMLHttpRequest;f.open(b,a,!0),f.setRequestHeader("Content-Type",e),f.onload=()=>{if(200<=f.status&&400>f.status){const a=f.responseText;d(a)}else console.error("DisplayJS error: The ajax request returned an error.")},f.onerror=()=>{console.error("DisplayJS error: The ajax request returned an error.")},f.send(c)}hasClass(a,b){return a[0].classList?a[0].classList.contains(b):!!a[0].className.match(new RegExp(`(\\s|^)${b}(\\s|$)`))}addClass(a,b){a[0].classList?a[0].classList.add(b):!this.hasClass(a,b)&&(a[0].className+=` ${b}`)}removeClass(a,b){if(a[0].classList)a[0].classList.remove(b);else if(this.hasClass(a,b)){const c=new RegExp(`(\\s|^)${b}(\\s|$)`);a[0].className=a[0].className.replace(c," ")}}toggleClass(a,b){this.hasClass(a,b)?this.removeClass(a,b):this.addClass(a,b)}css(a,b,c){a[0].style[b]=c}getStyle(a,b){return a[0].style[b]}fadeOut(a,b=0.1){const c=a[0];c.style.opacity=1,function a(){0>(c.style.opacity-=b)?c.style.display="none":requestAnimationFrame(a)}()}fadeIn(a,b=0.1,c){const d=a[0];d.style.opacity=0,d.style.display=c||"block",function a(){let c=parseFloat(d.style.opacity);1<(c+=b)||(d.style.opacity=c,requestAnimationFrame(a))}()}get fn(){return DisplayJS.prototype}dynamic(a,b=250){window.setInterval(a,b)}parent(a,b=0){let c=a[0];for(const d in this.range(b))c=c.parentNode;return Array(c)}isNode(a){return"object"==typeof Node?a instanceof Node:a&&"object"==typeof a&&"number"==typeof a.nodeType&&"string"==typeof a.nodeName}isElement(a){return"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName}component(a,b){class component extends HTMLElement{constructor(){super(),b(this)}}customElements.define(a,component)}time_ago(a){var b=Math.floor;switch(typeof a){case"number":break;case"string":a=+new Date(a);break;case"object":a.constructor===Date&&(a=a.getTime());break;default:a=+new Date;}const c=[[60,"seconds",1],[120,"1 minute ago","1 minute from now"],[3600,"minutes",60],[7200,"1 hour ago","1 hour from now"],[86400,"hours",3600],[172800,"Yesterday","Tomorrow"],[604800,"days",86400],[1209600,"Last week","Next week"],[2419200,"weeks",604800],[4838400,"Last month","Next month"],[29030400,"months",2419200],[58060800,"Last year","Next year"],[2903040000,"years",29030400],[5806080000,"Last century","Next century"],[58060800000,"centuries",2903040000]];let d=(+new Date-a)/1e3,e="ago",f=1;if(0==d)return"Just now";0>d&&(d=Math.abs(d),e="from now",f=2);let g,h=0;for(;g=c[h++];)if(d{(d||!c.readyState||/loaded|complete/.test(c.readyState))&&(c.onload=c.onreadystatechange=null,c=void 0,!d&&b&&b())},c.src=a,d.parentNode.insertBefore(c,d)}extend(a,b){const c={};for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);for(d in b)Object.prototype.hasOwnProperty.call(b,d)&&(c[d]=b[d]);return c}arange(a,b,c,d){const e=(Math.abs(b-a)+2*(d||0))/(c||1)+1,f=aa-f*(d||0)+f*(c||1)*e)}range(a){return this.arange(0,a,1)}linespace(a,b,c){return this.arange(a,b,(b-a)/c)}reshape(a,b){const c=[];for(let d=0;dthis.math.add(c,a),0)}multiply(a){return a.reduce((c,a)=>this.math.mul(c,a),0)}flatten(a){return a.reduce((c,a)=>c.concat(a),[])}drop(a,b){return 0this.math.sub(c,a));const b=Math.floor(this.math.div(a.length,2));return a.length%2?a[b]:this.math.div(this.math.add(a[b-1],a[b]),2)}predict(c,a,b=!1){function d(d,f){const g=c[0][0],h=c[1][0],i=c[0][1],j=c[1][1],k=e.math.div(e.math.sub(i,j),e.math.sub(g,h)),a=e.math.sub(j,e.math.mul(h,k));return!0==f?`f(x) = ${k}x+${a}; f(${d}) = ${d*k+a}`:d*k+a}const e=this;return function(a){return!(2=9007199254740991)throw"DisplayJS: The result is not a safe integer."},shiftComma(a,b){return this.toExponent(this.countDecimals([a]),-b)[0]},countResult(a,b){let c=a[0];for(let d=1;da.length)throw"DisplayJS: Set at least two numerical values.";for(const b in a){if(a[b]=parseFloat(a[b]),"number"!=typeof a[b]||isNaN(a[b]))throw"DisplayJS: Every Math argument must be of type number.";if(a[b]===Number.POSITIVE_INFINITY||a[b]===Number.NEGATIVE_INFINITY)throw"DisplayJS: Every Math argument must be a numerical value between positive and negative Infinity."}return a},countDecimals(a){const b=[];for(const c in a){let d=0;const e=a[c].toString().split("e"),f=e[0].indexOf(".");d-=-1===f?0:e[0].length-1-f,d+=isNaN(+e[1])?0:+e[1],e[0]=+e[0].replace(".",""),b.push({integer:e[0],comma:d})}return b}};return a}}"function"==typeof define&&define.amd?define(()=>new DisplayJS):"undefined"==typeof exports?global.DisplayJS=new DisplayJS:("undefined"!=typeof module&&module.exports&&(exports=module.exports=new DisplayJS),exports.DisplayJS=new DisplayJS); \ No newline at end of file diff --git a/src/display.js b/src/display.js index 2903b42..57f7c5e 100644 --- a/src/display.js +++ b/src/display.js @@ -523,7 +523,7 @@ class DisplayJS { } } format = time_formats[time_formats.length - 1]; - return Math.floor(seconds / format[2]) + " " + format[1] + " " + token; + return `${Math.floor(seconds / format[2])} ${format[1]} ${token}`; } // import a script import(source, callback) {