diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a4cfe69 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +# github: Ali-Eldeba # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: alieldeba # Replace with a single Patreon username +open_collective: alieldeba # Replace with a single Open Collective username +# ko_fi: # Replace with a single Ko-fi username +# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +# liberapay: # Replace with a single Liberapay username +# issuehunt: # Replace with a single IssueHunt username +# otechie: # Replace with a single Otechie username +# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +# custom: [https://www.buymeacoffee.com/alieldeba] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.gitignore b/.gitignore index 6a60a8e..1122c7d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ ehthumbs_vista.db *.msi *.msix *.msm -*.msp \ No newline at end of file +*.msp + +# Small Unimportant files +futureFunctions.txt \ No newline at end of file diff --git a/LICENSE b/LICENSE index 23727dd..4436283 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License Copyright (c) 2022 Functionalty.js -Copyright (c) 2022 Ali-Eldeba +Copyright (c) 2022 alieldeba Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c411747..af5204a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -#

Functionality.js (beta) 🔥

+

+ +#

Functionality.js

- + - + - +

## About ✍️ @@ -19,10 +21,16 @@ - So To Get Started Using Functionalty.js Library,
You Have To Install It By npm - ```cmd + ```sh npm install functionality.js ``` -- Or You Can Install it By CDN In Your HTML File +- Or You Can Install it By yarn In Your HTML File + + ```sh + yarn add functionality.js + ``` + +- Or Even You Can Get it By CDN ```html @@ -48,16 +56,8 @@ - By The Beginning You Have To Import Library After Installation,
You Can Import Unminified Version -- This is a Guid to how to import in HTML - ```html - - ``` - -- Or You Can Import Minified Version (recommended) - - ```html - + import functionality from "functionality.js"; ``` - Since You Have Downloaded And Imported The Library You Can Use It As Following ... @@ -68,41 +68,32 @@ - You Can Visit Functionalty.js Site From Here - Or This is A Quick Start From Here -#

Here Is What We Are Working On 🤞

- -1. Adding Logo -2. ✔️ Converting Library Into TypeScript -3. ✔️ Making File Supported By All Of Search Engines -4. ✔️ Making File Compressed -5. ✔️ Making File Light Weight -6. ✔️ Testing The Library -7. ✔️ Handling Function Errors -8. Making A Documentation Website -9. Adding Dark And White Theme In Website -10. ✔️ Adding New Functions -11. ✔️ Making npm Package For Installation -12. ✔️ Making a CDN Importing - #

Feel Free To Contribute To This Repositry 🤝

## To Get Started Contributing ☕ - First Clone The Repository - ```cmd - git clone https://github.com/Ali-Eldeba/functionality.js.git + ```sh + git clone https://github.com/alieldeba/functionality.js.git ``` - Then Install Packages (node_modules) - ```cmd + ```sh npm install ``` - Run Website In Your Locahost Server With Live Reload - ```cmd - npm start + ```sh + npm run dev + ``` + +- Run the Build + + ```sh + npm run build-npm ``` - Feel Free To Add What You Want! diff --git a/dist/functionality.min.js b/dist/functionality.min.js index 65f1c9d..52a74c3 100644 --- a/dist/functionality.min.js +++ b/dist/functionality.min.js @@ -1 +1 @@ -const x=function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))i(o);new MutationObserver(o=>{for(const n of o)if(n.type==="childList")for(const a of n.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&i(a)}).observe(document,{childList:!0,subtree:!0});function t(o){const n={};return o.integrity&&(n.integrity=o.integrity),o.referrerpolicy&&(n.referrerPolicy=o.referrerpolicy),o.crossorigin==="use-credentials"?n.credentials="include":o.crossorigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function i(o){if(o.ep)return;o.ep=!0;const n=t(o);fetch(o.href,n)}};x();function u(e){if(!Array.isArray(e)||e.some(r=>typeof r!="number"))throw new TypeError("Expected an array of numbers but got "+(Array.isArray(e)?"array":typeof e));return e.reduce((r,t)=>r+t,0)}function f(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return e?e.charAt(0).toUpperCase()+e.slice(1):""}function s(e,r){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return e.filter(t=>t!=r)}function c(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return[...Array(e+1).keys()].filter(r=>e%r===0)}function y(e=0,r){return typeof e!="number"&&!r?0:!r&&typeof+e=="number"?e:isNaN(+e)||isNaN(+r)?0:Math.floor((+e+ +r)/2)}function d(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e%2==0}function h(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e%2!=0}function p(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);for(let r=2,t=Math.sqrt(e);r<=t;r++)if(e%r===0)return!1;return!0}function g(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return Math.max(...e)}function m(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return Math.min(...e)}function w(){return Math.random()>=.5}function M(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return e[Math.floor(Math.random()*e.length)]}function S(){return`#${Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}`}function E(e,r){if(typeof e!="number"||typeof r!="number")throw new TypeError("Expected numbers but got "+typeof e+" and "+typeof r);return Math.floor(Math.random()*(r-e+1)+e)}function G(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);e.filter(function(r,t){return[...new Set(e)]})}function k(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return!e||typeof e!="string"?"":e.split("").reverse().join("")}function A(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);if(e==0)return 0;if(e<10&&e>-10)return e;const r=+(e>10?e:e*-1).toString().split("").reverse().join("");return e>10?r:r*-1}function B(e){if(!Array.isArray(e))throw new TypeError("Expected an array");return e.sort((r,t)=>.5-Math.random())}function L(e=5){if(typeof e!="number")throw new TypeError("Expected numbers but got "+typeof e);for(var r="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",i=t.length,o=0;o0;)t+=Math.pow(e%10,2),e=Math.floor(e/10);e=t}return e===1}function P(){const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()_-+={[}]|\\:;\"'<,>.?/~`!";let r="";for(let t=0;t<12;t++)r+=e[Math.floor(Math.random()*e.length)];return r}const l={sumOfArray:u,capitalize:f,filterArray:s,getFactors:c,getMid:y,isEven:d,isOdd:h,isPrime:p,isPalindrome:b,maxArray:g,minArray:m,randomBoolean:w,randomElementFrom:M,randomHex:S,randomNumber:E,removeDuplicate:G,reverseString:k,reverseNumber:A,shuffle:B,randomString:L,randomColor:D,randomHsl:v,isHappyNumber:T,randomPassword:P};window.functionality=l;function b(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return e.toString()==l.reverseString(e.toString())}const O={sumOfArray:u,capitalize:f,filterArray:s,getFactors:c,getMid:y,isEven:d,isOdd:h,isPrime:p,isPalindrome:b,maxArray:g,minArray:m,randomBoolean:w,randomElementFrom:M,randomHex:S,randomNumber:E,removeDuplicate:G,reverseString:k,reverseNumber:A,shuffle:B,randomString:L,randomColor:D,randomHsl:v,isHappyNumber:T,randomPassword:P};window.functionality=O;console.log(l.reverseNumber(123)); +const U=function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const a of o.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&i(a)}).observe(document,{childList:!0,subtree:!0});function t(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerpolicy&&(o.referrerPolicy=n.referrerpolicy),n.crossorigin==="use-credentials"?o.credentials="include":n.crossorigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(n){if(n.ep)return;n.ep=!0;const o=t(n);fetch(n.href,o)}};U();function l(e){if(!Array.isArray(e)||e.some(r=>typeof r!="number"))throw new TypeError("Expected an array of numbers but got "+(Array.isArray(e)?"array":typeof e));return e.reduce((r,t)=>r+t,0)}function c(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return e?e.charAt(0).toUpperCase()+e.slice(1):""}function s(e,r){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return e.filter(t=>t!=r)}function p(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return[...Array(e+1).keys()].filter(r=>e%r===0)}function y(e=0,r){return typeof e!="number"&&!r?0:!r&&typeof+e=="number"?e:isNaN(+e)||isNaN(+r)?0:Math.floor((+e+ +r)/2)}function h(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e%2==0}function d(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e%2!=0}function g(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);for(let r=2,t=Math.sqrt(e);r<=t;r++)if(e%r===0)return!1;return!0}function m(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return Math.max(...e)}function w(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return Math.min(...e)}function M(){return Math.random()>=.5}function E(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);return e[Math.floor(Math.random()*e.length)]}function S(){return`#${Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}`}function b(e,r){if(typeof e!="number"||typeof r!="number")throw new TypeError("Expected numbers but got "+typeof e+" and "+typeof r);return Math.floor(Math.random()*(r-e+1)+e)}function k(e){if(!Array.isArray(e))throw new TypeError("Expected an array but got "+typeof e);e.filter(function(r,t){return[...new Set(e)]})}function B(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return!e||typeof e!="string"?"":e.split("").reverse().join("")}function G(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);if(e==0)return 0;if(e<10&&e>-10)return e;const r=+(e>10?e:e*-1).toString().split("").reverse().join("");return e>10?r:r*-1}function T(e){return e.toString().replace(new RegExp("\\B(?.5-Math.random())}function A(e=5){if(typeof e!="number")throw new TypeError("Expected numbers but got "+typeof e);for(var r="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",i=t.length,n=0;n0;)t+=Math.pow(e%10,2),e=Math.floor(e/10);e=t}return e===1}function P(){const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()_-+={[}]|\\:;\"'<,>.?/~`!";let r="";for(let t=0;t<12;t++)r+=e[Math.floor(Math.random()*e.length)];return r}function C(e,r,t){return"#"+((1<<24)+(e<<16)+(r<<8)+t).toString(16).slice(1)}function O(e){return e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(r,t,i,n)=>"#"+t+t+i+i+n+n).substring(1).match(/.{2}/g).map(r=>parseInt(r,16))}function R(e,r,t){e/=255,r/=255,t/=255;var i=Math.max(e,r,t),n=Math.min(e,r,t),o,a,f=(i+n)/2;if(i==n)o=a=0;else{var u=i-n;switch(a=f>.5?u/(2-i-n):u/(i+n),i){case e:o=(r-t)/u+(r(a+e/30)%12,n=r*Math.min(t,1-t),o=a=>t-n*Math.max(-1,Math.min(i(a)-3,Math.min(9-i(a),1)));return[Math.trunc(255*o(0)),Math.trunc(255*o(8)),Math.trunc(255*o(4))]}function W(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return e.replace(/\s+/g," ")}function q(){return navigator.userAgent.split(" ")[navigator.userAgent.split(" ").length-1]}function F(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e*12}function Y(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e*12*4}function H(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e*12*4*7}function $(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e*12*7*4*24}function I(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e*12*7*4*24*60}function V(e){if(typeof e!="number")throw new TypeError("Expected a number but got "+typeof e);return e*12*7*4*24*60*60}function _(e){var r=new Date,t=r.getFullYear();return t-e}function j(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return document.querySelector(e)}const K={sumOfArray:l,capitalize:c,filterArray:s,getFactors:p,getMid:y,isEven:h,isOdd:d,isPrime:g,isPalindrome:z,maxArray:m,minArray:w,randomBoolean:M,randomElementFrom:E,randomHex:S,randomNumber:b,addCommas:T,removeDuplicate:k,reverseString:B,reverseNumber:G,shuffle:v,randomString:A,randomColor:D,randomHsl:x,isHappyNumber:L,randomPassword:P,rgbToHex:C,hexToRgb:O,rgbToHsl:R,hslToRgb:N,removeInnerSpace:W,getBrowser:q,getMonths:F,getWeeks:Y,getDays:H,getHours:$,getSeconds:V,getMinutes:I,getBirthDay:_,select:j};window.functionality=K;function z(e){if(typeof e!="string")throw new TypeError("Expected a string but got "+typeof e);return e.toString()==K.reverseString(e.toString())}function J(e){var r=new Date,t=r.getFullYear();return t-e}const Q={sumOfArray:l,capitalize:c,filterArray:s,getFactors:p,getMid:y,isEven:h,isOdd:d,isPrime:g,isPalindrome:z,maxArray:m,minArray:w,randomBoolean:M,randomElementFrom:E,randomHex:S,randomNumber:b,addCommas:T,removeDuplicate:k,reverseString:B,reverseNumber:G,shuffle:v,randomString:A,randomColor:D,randomHsl:x,isHappyNumber:L,randomPassword:P,rgbToHex:C,hexToRgb:O,rgbToHsl:R,hslToRgb:N,removeInnerSpace:W,getBrowser:q,getMonths:F,getWeeks:Y,getDays:H,getHours:$,getMinutes:I,getSeconds:V,getBirthday:J,select:j};window.functionality=Q; diff --git a/dist/index.html b/dist/index.html index 411e5d0..19fbc02 100644 --- a/dist/index.html +++ b/dist/index.html @@ -1,13 +1,24 @@ - - - Title - - - - - - - - \ No newline at end of file + + + functionality.js + + + + +

Thanks for contributing to functionality.js Library ❤🙏

+ + + + diff --git a/functionalty.zip b/functionalty.zip deleted file mode 100644 index 09ed820..0000000 Binary files a/functionalty.zip and /dev/null differ diff --git a/futureFunctions.txt b/futureFunctions.txt index 83ec111..f1be9f8 100644 --- a/futureFunctions.txt +++ b/futureFunctions.txt @@ -1,6 +1 @@ -- Arrays - - zip -- Strings -- Numbers -- Numbers -- randoms \ No newline at end of file +- zip \ No newline at end of file diff --git a/index.js b/index.js index f4a3b38..8ea1234 100644 --- a/index.js +++ b/index.js @@ -1 +1,2 @@ -export {default as functionality} from './lib/main.js'; +import functionality from './lib/main.js'; +export default functionality diff --git a/lib/converts/hexToHsl.d.ts b/lib/converts/hexToHsl.d.ts new file mode 100644 index 0000000..3ddab6e --- /dev/null +++ b/lib/converts/hexToHsl.d.ts @@ -0,0 +1 @@ +export default function hexToHsl(hex: string): number[]; diff --git a/lib/converts/hexToHsl.js b/lib/converts/hexToHsl.js new file mode 100644 index 0000000..96caf05 --- /dev/null +++ b/lib/converts/hexToHsl.js @@ -0,0 +1,30 @@ +export default function hexToHsl(hex) { + let rgb = hex + .replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => "#" + r + r + g + g + b + b) + .substring(1) + .match(/.{2}/g) + .map((x) => parseInt(x, 16)); + (rgb[0] /= 255), (rgb[1] /= 255), (rgb[2] /= 255); + var max = Math.max(rgb[0], rgb[1], rgb[2]), min = Math.min(rgb[0], rgb[1], rgb[2]); + var h, s, l = (max + min) / 2; + if (max == min) { + h = s = 0; + } + else { + var d = max - min; + s = l > 0.5 ? d / (2 - max - min) : d / (max + min); + switch (max) { + case rgb[0]: + h = (rgb[1] - rgb[2]) / d + (rgb[1] < rgb[2] ? 6 : 0); + break; + case rgb[1]: + h = (rgb[2] - rgb[1]) / d + 2; + break; + case rgb[2]: + h = (rgb[0] - rgb[1]) / d + 4; + break; + } + h /= 6; + } + return [h, s, l]; +} diff --git a/lib/converts/hexToRgb.d.ts b/lib/converts/hexToRgb.d.ts new file mode 100644 index 0000000..f4bd8e3 --- /dev/null +++ b/lib/converts/hexToRgb.d.ts @@ -0,0 +1,7 @@ +/** + * converts a hex color to rgb + * + * @param {string} hex + * @returns {number[]} + */ +export default function hexToRgb(hex: string): number[]; diff --git a/lib/converts/hexToRgb.js b/lib/converts/hexToRgb.js new file mode 100644 index 0000000..b9be5a1 --- /dev/null +++ b/lib/converts/hexToRgb.js @@ -0,0 +1,13 @@ +/** + * converts a hex color to rgb + * + * @param {string} hex + * @returns {number[]} + */ +export default function hexToRgb(hex) { + return hex + .replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => "#" + r + r + g + g + b + b) + .substring(1) + .match(/.{2}/g) + .map((x) => parseInt(x, 16)); +} diff --git a/lib/converts/hslToRgb.d.ts b/lib/converts/hslToRgb.d.ts new file mode 100644 index 0000000..bc92384 --- /dev/null +++ b/lib/converts/hslToRgb.d.ts @@ -0,0 +1,9 @@ +/** + * Converts HSL color to RGB color + * + * @param {number} h + * @param {number} s + * @param {number} l + * @returns {number[]} + */ +export default function hslToRgb(h: number, s: number, l: number): number[]; diff --git a/lib/converts/hslToRgb.js b/lib/converts/hslToRgb.js new file mode 100644 index 0000000..b00408a --- /dev/null +++ b/lib/converts/hslToRgb.js @@ -0,0 +1,20 @@ +/** + * Converts HSL color to RGB color + * + * @param {number} h + * @param {number} s + * @param {number} l + * @returns {number[]} + */ +export default function hslToRgb(h, s, l) { + s /= 100; + l /= 100; + const k = (n) => (n + h / 30) % 12; + const a = s * Math.min(l, 1 - l); + const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1))); + return [ + Math.trunc(255 * f(0)), + Math.trunc(255 * f(8)), + Math.trunc(255 * f(4)), + ]; +} diff --git a/lib/converts/rgbToHex.d.ts b/lib/converts/rgbToHex.d.ts new file mode 100644 index 0000000..ae1b12c --- /dev/null +++ b/lib/converts/rgbToHex.d.ts @@ -0,0 +1,9 @@ +/** + * Converts an RGB color value to a hexadecimal string. + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {string} + */ +export default function rgbToHex(r: number, g: number, b: number): string; diff --git a/lib/converts/rgbToHex.js b/lib/converts/rgbToHex.js new file mode 100644 index 0000000..efe2c2a --- /dev/null +++ b/lib/converts/rgbToHex.js @@ -0,0 +1,11 @@ +/** + * Converts an RGB color value to a hexadecimal string. + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {string} + */ +export default function rgbToHex(r, g, b) { + return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); +} diff --git a/lib/converts/rgbToHsl.d.ts b/lib/converts/rgbToHsl.d.ts new file mode 100644 index 0000000..38e5ed3 --- /dev/null +++ b/lib/converts/rgbToHsl.d.ts @@ -0,0 +1,9 @@ +/** + * Converts RGB Color To HSL + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {number[]} + */ +export default function rgbToHsl(r: number, g: number, b: number): number[]; diff --git a/lib/converts/rgbToHsl.js b/lib/converts/rgbToHsl.js new file mode 100644 index 0000000..973c43e --- /dev/null +++ b/lib/converts/rgbToHsl.js @@ -0,0 +1,33 @@ +/** + * Converts RGB Color To HSL + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {number[]} + */ +export default function rgbToHsl(r, g, b) { + (r /= 255), (g /= 255), (b /= 255); + var max = Math.max(r, g, b), min = Math.min(r, g, b); + var h, s, l = (max + min) / 2; + if (max == min) { + h = s = 0; + } + else { + var d = max - min; + s = l > 0.5 ? d / (2 - max - min) : d / (max + min); + switch (max) { + case r: + h = (g - b) / d + (g < b ? 6 : 0); + break; + case g: + h = (b - r) / d + 2; + break; + case b: + h = (r - g) / d + 4; + break; + } + h /= 6; + } + return [h, s, l]; +} diff --git a/lib/dom/select.d.ts b/lib/dom/select.d.ts new file mode 100644 index 0000000..e3cf31a --- /dev/null +++ b/lib/dom/select.d.ts @@ -0,0 +1,7 @@ +/** + * returns the number of Seconds in a given age + * + * @param {string} element + * @returns {number} + */ +export default function select(element: string): any; diff --git a/lib/dom/select.js b/lib/dom/select.js new file mode 100644 index 0000000..7d2d82f --- /dev/null +++ b/lib/dom/select.js @@ -0,0 +1,12 @@ +/** + * returns the number of Seconds in a given age + * + * @param {string} element + * @returns {number} + */ +export default function select(element) { + if (typeof element !== "string") { + throw new TypeError("Expected a string but got " + typeof element); + } + return document.querySelector(element); +} diff --git a/lib/main.d.ts b/lib/main.d.ts index 80cdd75..2ce4447 100644 --- a/lib/main.d.ts +++ b/lib/main.d.ts @@ -16,12 +16,28 @@ import randomNumber from "./randoms/randomNumber"; import removeDuplicate from "./arrays/removeDuplicate"; import reverseString from "./strings/reverseString"; import reverseNumber from "./numbers/reverseNumber"; +import addCommas from "./numbers/addCommas"; import shuffle from "./arrays/shuffle"; import randomString from "./randoms/randomString"; import randomColor from "./randoms/randomColor"; import randomHsl from "./randoms/randomHsl"; import isHappyNumber from "./numbers/isHappyNumber"; import randomPassword from "./randoms/randomPassword"; +import rgbToHex from "./converts/rgbToHex"; +import hexToRgb from "./converts/hexToRgb"; +import rgbToHsl from "./converts/rgbToHsl"; +import hslToRgb from "./converts/hslToRgb"; +import removeInnerSpace from "./strings/removeInnerSpace"; +import getBrowser from "./user/getBrowser"; +import getMonths from "./user/getMonths"; +import getWeeks from "./user/getWeeks"; +import getDays from "./user/getDays"; +import getHours from "./user/getHours"; +import getMinutes from "./user/getMinutes"; +import getSeconds from "./user/getSeconds"; +import getBirthday from "./user/getBirthday"; +import copy from "./user/copy"; +import select from "./dom/select"; declare const functionality: { sumOfArray: typeof sumOfArray; capitalize: typeof capitalize; @@ -38,6 +54,7 @@ declare const functionality: { randomElementFrom: typeof randomElementFrom; randomHex: typeof randomHex; randomNumber: typeof randomNumber; + addCommas: typeof addCommas; removeDuplicate: typeof removeDuplicate; reverseString: typeof reverseString; reverseNumber: typeof reverseNumber; @@ -47,6 +64,21 @@ declare const functionality: { randomHsl: typeof randomHsl; isHappyNumber: typeof isHappyNumber; randomPassword: typeof randomPassword; + rgbToHex: typeof rgbToHex; + hexToRgb: typeof hexToRgb; + rgbToHsl: typeof rgbToHsl; + hslToRgb: typeof hslToRgb; + removeInnerSpace: typeof removeInnerSpace; + getBrowser: typeof getBrowser; + getMonths: typeof getMonths; + getWeeks: typeof getWeeks; + getDays: typeof getDays; + getHours: typeof getHours; + getMinutes: typeof getMinutes; + getSeconds: typeof getSeconds; + getBirthday: typeof getBirthday; + copy: typeof copy; + select: typeof select; }; declare global { interface Window { diff --git a/lib/main.js b/lib/main.js index 76a682a..73d4f5a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -16,12 +16,30 @@ import randomNumber from "./randoms/randomNumber"; import removeDuplicate from "./arrays/removeDuplicate"; import reverseString from "./strings/reverseString"; import reverseNumber from "./numbers/reverseNumber"; +import addCommas from "./numbers/addCommas"; import shuffle from "./arrays/shuffle"; import randomString from "./randoms/randomString"; import randomColor from "./randoms/randomColor"; import randomHsl from "./randoms/randomHsl"; import isHappyNumber from "./numbers/isHappyNumber"; import randomPassword from "./randoms/randomPassword"; +import rgbToHex from "./converts/rgbToHex"; +import hexToRgb from "./converts/hexToRgb"; +import rgbToHsl from "./converts/rgbToHsl"; +// import hexToHsl from "./converts/hexToHsl"; +// import hslToHex from "./converts/hslToHex"; +import hslToRgb from "./converts/hslToRgb"; +import removeInnerSpace from "./strings/removeInnerSpace"; +import getBrowser from "./user/getBrowser"; +import getMonths from "./user/getMonths"; +import getWeeks from "./user/getWeeks"; +import getDays from "./user/getDays"; +import getHours from "./user/getHours"; +import getMinutes from "./user/getMinutes"; +import getSeconds from "./user/getSeconds"; +import getBirthday from "./user/getBirthday"; +import copy from "./user/copy"; +import select from "./dom/select"; const functionality = { sumOfArray, capitalize, @@ -38,6 +56,7 @@ const functionality = { randomElementFrom, randomHex, randomNumber, + addCommas, removeDuplicate, reverseString, reverseNumber, @@ -47,7 +66,21 @@ const functionality = { randomHsl, isHappyNumber, randomPassword, + rgbToHex, + hexToRgb, + rgbToHsl, + hslToRgb, + removeInnerSpace, + getBrowser, + getMonths, + getWeeks, + getDays, + getHours, + getMinutes, + getSeconds, + getBirthday, + copy, + select, }; window.functionality = functionality; -// export * from "./sumOfArray"; export default functionality; diff --git a/lib/numbers/addCommas.d.ts b/lib/numbers/addCommas.d.ts new file mode 100644 index 0000000..b73cc6c --- /dev/null +++ b/lib/numbers/addCommas.d.ts @@ -0,0 +1,7 @@ +/** + * Returns Number With Commas To Facilitate Reading | e.g 1000000 => 1,000,000 + * + * @param {number} number + * @returns {string} + */ +export default function addCommas(number: number): string; diff --git a/lib/numbers/addCommas.js b/lib/numbers/addCommas.js new file mode 100644 index 0000000..6a2c0e7 --- /dev/null +++ b/lib/numbers/addCommas.js @@ -0,0 +1,9 @@ +/** + * Returns Number With Commas To Facilitate Reading | e.g 1000000 => 1,000,000 + * + * @param {number} number + * @returns {string} + */ +export default function addCommas(number) { + return number.toString().replace(/\B(? "#" + r + r + g + g + b + b) + .substring(1) + .match(/.{2}/g) + .map((x) => parseInt(x, 16)); +} diff --git a/lib/strings/removeInnerSpace.d.ts b/lib/strings/removeInnerSpace.d.ts new file mode 100644 index 0000000..f5dc2ee --- /dev/null +++ b/lib/strings/removeInnerSpace.d.ts @@ -0,0 +1,8 @@ +/** + * Removes the inner whitespace from a string + * e.g. " Hello World " -> "Hello World" + * + * @param {string} word + * @returns {string} + */ +export default function removeInnerSpace(word: string): string; diff --git a/lib/strings/removeInnerSpace.js b/lib/strings/removeInnerSpace.js new file mode 100644 index 0000000..f76e6a8 --- /dev/null +++ b/lib/strings/removeInnerSpace.js @@ -0,0 +1,13 @@ +/** + * Removes the inner whitespace from a string + * e.g. " Hello World " -> "Hello World" + * + * @param {string} word + * @returns {string} + */ +export default function removeInnerSpace(word) { + if (typeof word !== "string") { + throw new TypeError("Expected a string but got " + typeof word); + } + return word.replace(/\s+/g, " "); +} diff --git a/lib/strings/rgbToHex.d.ts b/lib/strings/rgbToHex.d.ts new file mode 100644 index 0000000..ae1b12c --- /dev/null +++ b/lib/strings/rgbToHex.d.ts @@ -0,0 +1,9 @@ +/** + * Converts an RGB color value to a hexadecimal string. + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {string} + */ +export default function rgbToHex(r: number, g: number, b: number): string; diff --git a/lib/strings/rgbToHex.js b/lib/strings/rgbToHex.js new file mode 100644 index 0000000..efe2c2a --- /dev/null +++ b/lib/strings/rgbToHex.js @@ -0,0 +1,11 @@ +/** + * Converts an RGB color value to a hexadecimal string. + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {string} + */ +export default function rgbToHex(r, g, b) { + return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); +} diff --git a/lib/user/copy.d.ts b/lib/user/copy.d.ts new file mode 100644 index 0000000..48ebdf9 --- /dev/null +++ b/lib/user/copy.d.ts @@ -0,0 +1,6 @@ +/** + * It takes text to copy it to the user + * + * @param {string} text - The text to copy to the clipboard. + */ +export default function copy(text: string): void; diff --git a/lib/user/copy.js b/lib/user/copy.js new file mode 100644 index 0000000..40c16f9 --- /dev/null +++ b/lib/user/copy.js @@ -0,0 +1,12 @@ +/** + * It takes text to copy it to the user + * + * @param {string} text - The text to copy to the clipboard. + */ +export default function copy(text) { + navigator.clipboard.writeText(text).then(function () { + console.log("Async: Copying to clipboard was successful!"); + }, function (err) { + console.error("Async: Could not copy text: ", err); + }); +} diff --git a/lib/user/getBirthDay.d.ts b/lib/user/getBirthDay.d.ts new file mode 100644 index 0000000..879339a --- /dev/null +++ b/lib/user/getBirthDay.d.ts @@ -0,0 +1,7 @@ +/** + * Returns the Age From a Given Year | e.g 2007 -> 15 + * + * @param {number} year + * @returns {number} + */ +export default function getBirthday(year: number): number; diff --git a/lib/user/getBirthDay.js b/lib/user/getBirthDay.js new file mode 100644 index 0000000..7939aa5 --- /dev/null +++ b/lib/user/getBirthDay.js @@ -0,0 +1,11 @@ +/** + * Returns the Age From a Given Year | e.g 2007 -> 15 + * + * @param {number} year + * @returns {number} + */ +export default function getBirthday(year) { + var currentDate = new Date(); + var currentYear = currentDate.getFullYear(); + return currentYear - year; +} diff --git a/lib/user/getBrowser.d.ts b/lib/user/getBrowser.d.ts new file mode 100644 index 0000000..2041a84 --- /dev/null +++ b/lib/user/getBrowser.d.ts @@ -0,0 +1,6 @@ +/** + * Returns the browser name of the active user. + * + * @returns {string} + */ +export default function getBrowser(): string; diff --git a/lib/user/getBrowser.js b/lib/user/getBrowser.js new file mode 100644 index 0000000..d1397c3 --- /dev/null +++ b/lib/user/getBrowser.js @@ -0,0 +1,8 @@ +/** + * Returns the browser name of the active user. + * + * @returns {string} + */ +export default function getBrowser() { + return navigator.userAgent.split(" ")[navigator.userAgent.split(" ").length - 1]; +} diff --git a/lib/user/getDays.d.ts b/lib/user/getDays.d.ts new file mode 100644 index 0000000..97dc114 --- /dev/null +++ b/lib/user/getDays.d.ts @@ -0,0 +1,7 @@ +/** + * returns the number of days in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getDays(age: number): number; diff --git a/lib/user/getDays.js b/lib/user/getDays.js new file mode 100644 index 0000000..e26bf56 --- /dev/null +++ b/lib/user/getDays.js @@ -0,0 +1,12 @@ +/** + * returns the number of days in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getDays(age) { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 4 * 7; +} diff --git a/lib/user/getHours.d.ts b/lib/user/getHours.d.ts new file mode 100644 index 0000000..fc2971e --- /dev/null +++ b/lib/user/getHours.d.ts @@ -0,0 +1,7 @@ +/** + * returns the number of hours in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getHours(age: number): number; diff --git a/lib/user/getHours.js b/lib/user/getHours.js new file mode 100644 index 0000000..a15dd09 --- /dev/null +++ b/lib/user/getHours.js @@ -0,0 +1,12 @@ +/** + * returns the number of hours in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getHours(age) { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 7 * 4 * 24; +} diff --git a/lib/user/getMinutes.d.ts b/lib/user/getMinutes.d.ts new file mode 100644 index 0000000..72a13f5 --- /dev/null +++ b/lib/user/getMinutes.d.ts @@ -0,0 +1,7 @@ +/** + * returns the number of minutes in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getWeeks(age: number): number; diff --git a/lib/user/getMinutes.js b/lib/user/getMinutes.js new file mode 100644 index 0000000..a6791b9 --- /dev/null +++ b/lib/user/getMinutes.js @@ -0,0 +1,12 @@ +/** + * returns the number of minutes in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getWeeks(age) { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 7 * 4 * 24 * 60; +} diff --git a/lib/user/getMonths.d.ts b/lib/user/getMonths.d.ts new file mode 100644 index 0000000..bccd283 --- /dev/null +++ b/lib/user/getMonths.d.ts @@ -0,0 +1,7 @@ +/** + * returns the months of the age + * + * @param {number} age + * @returns {number} + */ +export default function getMonths(age: number): number; diff --git a/lib/user/getMonths.js b/lib/user/getMonths.js new file mode 100644 index 0000000..b32e02d --- /dev/null +++ b/lib/user/getMonths.js @@ -0,0 +1,12 @@ +/** + * returns the months of the age + * + * @param {number} age + * @returns {number} + */ +export default function getMonths(age) { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12; +} diff --git a/lib/user/getSeconds.d.ts b/lib/user/getSeconds.d.ts new file mode 100644 index 0000000..13b6b19 --- /dev/null +++ b/lib/user/getSeconds.d.ts @@ -0,0 +1,7 @@ +/** + * returns the number of Seconds in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getSeconds(age: number): number; diff --git a/lib/user/getSeconds.js b/lib/user/getSeconds.js new file mode 100644 index 0000000..920fb17 --- /dev/null +++ b/lib/user/getSeconds.js @@ -0,0 +1,12 @@ +/** + * returns the number of Seconds in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getSeconds(age) { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 7 * 4 * 24 * 60 * 60; +} diff --git a/lib/user/getWeeks.d.ts b/lib/user/getWeeks.d.ts new file mode 100644 index 0000000..7a79fdb --- /dev/null +++ b/lib/user/getWeeks.d.ts @@ -0,0 +1,7 @@ +/** + * returns the number of weeks in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getWeeks(age: number): number; diff --git a/lib/user/getWeeks.js b/lib/user/getWeeks.js new file mode 100644 index 0000000..fe4ae3b --- /dev/null +++ b/lib/user/getWeeks.js @@ -0,0 +1,12 @@ +/** + * returns the number of weeks in a given age + * + * @param {number} age + * @returns {number} + */ +export default function getWeeks(age) { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 4; +} diff --git a/package-lock.json b/package-lock.json index 2eef772..2cf416b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "functionality", - "version": "1.0.0", + "name": "functionality.js", + "version": "3.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "functionality", - "version": "1.0.0", + "name": "functionality.js", + "version": "3.2.3", "license": "ISC", "dependencies": { "@types/node": "^17.0.42", diff --git a/package.json b/package.json index 33b948a..9836d0b 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,16 @@ { "name": "functionality.js", "entry": "index.js", - "version": "3.2.1", + "version": "3.2.4", "description": "- This Is A JavaScript Library To Make Your Work Easier/Faster,
\r You Can See Functionalty.js Website From Here\r - Born In May 5 / 16 / 2022", + "homepage": "https://github.com/alieldeba/functionalty.js#readme", + "author": "alieldeba", "main": "index.js", + "keywords": [ + "functionality", + "javascript", + "modules" + ], "scripts": { "test": "jest --watchAll", "dev": "node server.js", @@ -12,14 +19,12 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/Ali-Eldeba/functionalty.js.git" + "url": "git+https://github.com/alieldeba/functionalty.js.git" }, - "author": "Ali-Eldeba", "license": "ISC", "bugs": { - "url": "https://github.com/Ali-Eldeba/functionalty.js/issues" + "url": "https://github.com/alieldeba/functionalty.js/issues" }, - "homepage": "https://github.com/Ali-Eldeba/functionalty.js#readme", "devDependencies": { "jest": "^26.6.3", "sass": "^1.52.0", diff --git a/project/ts/functionality/arrays/ascending.ts b/project/arrays/ascending.ts similarity index 100% rename from project/ts/functionality/arrays/ascending.ts rename to project/arrays/ascending.ts diff --git a/project/ts/functionality/arrays/descending.ts b/project/arrays/descending.ts similarity index 100% rename from project/ts/functionality/arrays/descending.ts rename to project/arrays/descending.ts diff --git a/project/ts/functionality/arrays/filterArray.ts b/project/arrays/filterArray.ts similarity index 100% rename from project/ts/functionality/arrays/filterArray.ts rename to project/arrays/filterArray.ts diff --git a/project/ts/functionality/arrays/getFactors.ts b/project/arrays/getFactors.ts similarity index 100% rename from project/ts/functionality/arrays/getFactors.ts rename to project/arrays/getFactors.ts diff --git a/project/ts/functionality/arrays/maxArray.ts b/project/arrays/maxArray.ts similarity index 100% rename from project/ts/functionality/arrays/maxArray.ts rename to project/arrays/maxArray.ts diff --git a/project/ts/functionality/arrays/minArray.ts b/project/arrays/minArray.ts similarity index 100% rename from project/ts/functionality/arrays/minArray.ts rename to project/arrays/minArray.ts diff --git a/project/ts/functionality/arrays/randomElementFrom.ts b/project/arrays/randomElementFrom.ts similarity index 100% rename from project/ts/functionality/arrays/randomElementFrom.ts rename to project/arrays/randomElementFrom.ts diff --git a/project/ts/functionality/arrays/removeDuplicate.ts b/project/arrays/removeDuplicate.ts similarity index 100% rename from project/ts/functionality/arrays/removeDuplicate.ts rename to project/arrays/removeDuplicate.ts diff --git a/project/ts/functionality/arrays/shuffle.ts b/project/arrays/shuffle.ts similarity index 100% rename from project/ts/functionality/arrays/shuffle.ts rename to project/arrays/shuffle.ts diff --git a/project/ts/functionality/arrays/sumOfArray.ts b/project/arrays/sumOfArray.ts similarity index 100% rename from project/ts/functionality/arrays/sumOfArray.ts rename to project/arrays/sumOfArray.ts diff --git a/project/converts/hexToRgb.ts b/project/converts/hexToRgb.ts new file mode 100644 index 0000000..2c85f42 --- /dev/null +++ b/project/converts/hexToRgb.ts @@ -0,0 +1,16 @@ +/** + * converts a hex color to rgb + * + * @param {string} hex + * @returns {number[]} + */ +export default function hexToRgb(hex: string) { + return hex + .replace( + /^#?([a-f\d])([a-f\d])([a-f\d])$/i, + (m, r, g, b) => "#" + r + r + g + g + b + b + ) + .substring(1) + .match(/.{2}/g) + .map((x) => parseInt(x, 16)); +} diff --git a/project/converts/hslToHex.ts b/project/converts/hslToHex.ts new file mode 100644 index 0000000..e69de29 diff --git a/project/converts/hslToRgb.ts b/project/converts/hslToRgb.ts new file mode 100644 index 0000000..9ea5f1f --- /dev/null +++ b/project/converts/hslToRgb.ts @@ -0,0 +1,21 @@ +/** + * Converts HSL color to RGB color + * + * @param {number} h + * @param {number} s + * @param {number} l + * @returns {number[]} + */ +export default function hslToRgb(h: number, s: number, l: number): number[] { + s /= 100; + l /= 100; + const k = (n: number) => (n + h / 30) % 12; + const a = s * Math.min(l, 1 - l); + const f = (n: number) => + l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1))); + return [ + Math.trunc(255 * f(0)), + Math.trunc(255 * f(8)), + Math.trunc(255 * f(4)), + ]; +} diff --git a/project/converts/rgbToHex.ts b/project/converts/rgbToHex.ts new file mode 100644 index 0000000..ed8f897 --- /dev/null +++ b/project/converts/rgbToHex.ts @@ -0,0 +1,11 @@ +/** + * Converts an RGB color value to a hexadecimal string. + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {string} + */ +export default function rgbToHex(r: number, g: number, b: number): string { + return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); +} diff --git a/project/converts/rgbToHsl.ts b/project/converts/rgbToHsl.ts new file mode 100644 index 0000000..740dd9c --- /dev/null +++ b/project/converts/rgbToHsl.ts @@ -0,0 +1,37 @@ +/** + * Converts RGB Color To HSL + * + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {number[]} + */ +export default function rgbToHsl(r: number, g: number, b: number): number[] { + (r /= 255), (g /= 255), (b /= 255); + var max = Math.max(r, g, b), + min = Math.min(r, g, b); + var h, + s, + l = (max + min) / 2; + + if (max == min) { + h = s = 0; + } else { + var d = max - min; + s = l > 0.5 ? d / (2 - max - min) : d / (max + min); + switch (max) { + case r: + h = (g - b) / d + (g < b ? 6 : 0); + break; + case g: + h = (b - r) / d + 2; + break; + case b: + h = (r - g) / d + 4; + break; + } + h /= 6; + } + + return [h, s, l]; +} diff --git a/project/dom/select.ts b/project/dom/select.ts new file mode 100644 index 0000000..7dacd4f --- /dev/null +++ b/project/dom/select.ts @@ -0,0 +1,12 @@ +/** + * gets HTML dom element + * + * @param {string} element + * @returns {number} + */ +export default function select(element: string): any { + if (typeof element !== "string") { + throw new TypeError("Expected a string but got " + typeof element); + } + return document.querySelector(element); +} diff --git a/project/index.html b/project/index.html new file mode 100644 index 0000000..0bdc08b --- /dev/null +++ b/project/index.html @@ -0,0 +1,25 @@ + + + + + functionality.js + + + +

Thanks for contributing to functionality.js Library ❤🙏

+ + + + diff --git a/project/ts/functionality/main.js b/project/main.js similarity index 62% rename from project/ts/functionality/main.js rename to project/main.js index 76a682a..79fa3fd 100644 --- a/project/ts/functionality/main.js +++ b/project/main.js @@ -16,12 +16,29 @@ import randomNumber from "./randoms/randomNumber"; import removeDuplicate from "./arrays/removeDuplicate"; import reverseString from "./strings/reverseString"; import reverseNumber from "./numbers/reverseNumber"; +import addCommas from "./numbers/addCommas"; import shuffle from "./arrays/shuffle"; import randomString from "./randoms/randomString"; import randomColor from "./randoms/randomColor"; import randomHsl from "./randoms/randomHsl"; import isHappyNumber from "./numbers/isHappyNumber"; import randomPassword from "./randoms/randomPassword"; +import rgbToHex from "./converts/rgbToHex"; +import hexToRgb from "./converts/hexToRgb"; +import rgbToHsl from "./converts/rgbToHsl"; +// import hexToHsl from "./converts/hexToHsl"; +// import hslToHex from "./converts/hslToHex"; +import hslToRgb from "./converts/hslToRgb"; +import removeInnerSpace from "./strings/removeInnerSpace"; +import getBrowser from "./user/getBrowser"; +import getMonths from "./user/getMonths"; +import getWeeks from "./user/getWeeks"; +import getDays from "./user/getDays"; +import getHours from "./user/getHours"; +import getMinutes from "./user/getMinutes"; +import getSeconds from "./user/getSeconds"; +import getBirthDay from "./user/getBirthDay"; +import select from "./dom/select"; const functionality = { sumOfArray, capitalize, @@ -38,6 +55,7 @@ const functionality = { randomElementFrom, randomHex, randomNumber, + addCommas, removeDuplicate, reverseString, reverseNumber, @@ -47,7 +65,20 @@ const functionality = { randomHsl, isHappyNumber, randomPassword, + rgbToHex, + hexToRgb, + rgbToHsl, + hslToRgb, + removeInnerSpace, + getBrowser, + getMonths, + getWeeks, + getDays, + getHours, + getSeconds, + getMinutes, + getBirthDay, + select, }; window.functionality = functionality; -// export * from "./sumOfArray"; export default functionality; diff --git a/project/ts/functionality/main.ts b/project/main.ts similarity index 62% rename from project/ts/functionality/main.ts rename to project/main.ts index 7afee2c..1e8fb35 100644 --- a/project/ts/functionality/main.ts +++ b/project/main.ts @@ -16,12 +16,30 @@ import randomNumber from "./randoms/randomNumber"; import removeDuplicate from "./arrays/removeDuplicate"; import reverseString from "./strings/reverseString"; import reverseNumber from "./numbers/reverseNumber"; +import addCommas from "./numbers/addCommas"; import shuffle from "./arrays/shuffle"; import randomString from "./randoms/randomString"; import randomColor from "./randoms/randomColor"; import randomHsl from "./randoms/randomHsl"; import isHappyNumber from "./numbers/isHappyNumber"; import randomPassword from "./randoms/randomPassword"; +import rgbToHex from "./converts/rgbToHex"; +import hexToRgb from "./converts/hexToRgb"; +import rgbToHsl from "./converts/rgbToHsl"; +// import hexToHsl from "./converts/hexToHsl"; +// import hslToHex from "./converts/hslToHex"; +import hslToRgb from "./converts/hslToRgb"; +import removeInnerSpace from "./strings/removeInnerSpace"; +import getBrowser from "./user/getBrowser"; +import getMonths from "./user/getMonths"; +import getWeeks from "./user/getWeeks"; +import getDays from "./user/getDays"; +import getHours from "./user/getHours"; +import getMinutes from "./user/getMinutes"; +import getSeconds from "./user/getSeconds"; +import getBirthday from "./user/getBirthday"; +// import copy from "./user/copy"; +import select from "./dom/select"; const functionality = { sumOfArray, @@ -39,6 +57,7 @@ const functionality = { randomElementFrom, randomHex, randomNumber, + addCommas, removeDuplicate, reverseString, reverseNumber, @@ -48,6 +67,21 @@ const functionality = { randomHsl, isHappyNumber, randomPassword, + rgbToHex, + hexToRgb, + rgbToHsl, + hslToRgb, + removeInnerSpace, + getBrowser, + getMonths, + getWeeks, + getDays, + getHours, + getMinutes, + getSeconds, + getBirthday, + // copy, + select, }; declare global { @@ -56,5 +90,4 @@ declare global { } } window.functionality = functionality; -// export * from "./sumOfArray"; export default functionality; diff --git a/project/numbers/addCommas.ts b/project/numbers/addCommas.ts new file mode 100644 index 0000000..5f3eb8c --- /dev/null +++ b/project/numbers/addCommas.ts @@ -0,0 +1,9 @@ +/** + * Returns Number With Commas To Facilitate Reading | e.g 1000000 => 1,000,000 + * + * @param {number} number + * @returns {string} + */ +export default function addCommas(number: number): string { + return number.toString().replace(/\B(? "Hello World" + * + * @param {string} word + * @returns {string} + */ +export default function removeInnerSpace(word: string): string { + if (typeof word !== "string") { + throw new TypeError("Expected a string but got " + typeof word); + } + return word.replace(/\s+/g, " "); +} diff --git a/project/ts/functionality/strings/reverseString.ts b/project/strings/reverseString.ts similarity index 100% rename from project/ts/functionality/strings/reverseString.ts rename to project/strings/reverseString.ts diff --git a/project/ts/functionality/index.html b/project/ts/functionality/index.html deleted file mode 100644 index ab10b16..0000000 --- a/project/ts/functionality/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - Title - - - - - - - \ No newline at end of file diff --git a/project/user/copy.ts b/project/user/copy.ts new file mode 100644 index 0000000..5eb60f1 --- /dev/null +++ b/project/user/copy.ts @@ -0,0 +1,14 @@ +/** + * It takes text to copy it to the user + * + * @param {string} text + */ +export default async function copy(text: string) { + try { + const toCopy = text || location.href; + await navigator.clipboard.writeText(toCopy); + console.log("Text or Page URL copied"); + } catch (err) { + console.error("Failed to copy: ", err); + } +} diff --git a/project/user/getBirthday.ts b/project/user/getBirthday.ts new file mode 100644 index 0000000..cf1cae2 --- /dev/null +++ b/project/user/getBirthday.ts @@ -0,0 +1,11 @@ +/** + * Returns the Age From a Given Year | e.g 2007 -> 15 + * + * @param {number} year + * @returns {number} + */ + export default function getBirthday(year: number): number { + var currentDate = new Date(); + var currentYear = currentDate.getFullYear(); + return currentYear - year; +} \ No newline at end of file diff --git a/project/user/getBrowser.ts b/project/user/getBrowser.ts new file mode 100644 index 0000000..bc335e7 --- /dev/null +++ b/project/user/getBrowser.ts @@ -0,0 +1,10 @@ +/** + * Returns the browser name of the active user. + * + * @returns {string} + */ +export default function getBrowser(): string { + return navigator.userAgent.split(" ")[ + navigator.userAgent.split(" ").length - 1 + ]; +} diff --git a/project/user/getDays.ts b/project/user/getDays.ts new file mode 100644 index 0000000..d3174dd --- /dev/null +++ b/project/user/getDays.ts @@ -0,0 +1,12 @@ +/** + * returns the number of days in a given age + * + * @param {number} age + * @returns {number} + */ + export default function getDays(age: number): number { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 4 * 7; +} \ No newline at end of file diff --git a/project/user/getHours.ts b/project/user/getHours.ts new file mode 100644 index 0000000..ddf3cce --- /dev/null +++ b/project/user/getHours.ts @@ -0,0 +1,12 @@ +/** + * returns the number of hours in a given age + * + * @param {number} age + * @returns {number} + */ + export default function getHours(age: number): number { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 7 * 4 * 24; +} \ No newline at end of file diff --git a/project/user/getMinutes.ts b/project/user/getMinutes.ts new file mode 100644 index 0000000..fd87544 --- /dev/null +++ b/project/user/getMinutes.ts @@ -0,0 +1,12 @@ +/** + * returns the number of minutes in a given age + * + * @param {number} age + * @returns {number} + */ + export default function getWeeks(age: number): number { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 7 * 4 * 24 * 60; + } \ No newline at end of file diff --git a/project/user/getMonths.ts b/project/user/getMonths.ts new file mode 100644 index 0000000..eb10390 --- /dev/null +++ b/project/user/getMonths.ts @@ -0,0 +1,12 @@ +/** + * returns the months of the age + * + * @param {number} age + * @returns {number} + */ + export default function getMonths(age: number): number { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12; + } \ No newline at end of file diff --git a/project/user/getSeconds.ts b/project/user/getSeconds.ts new file mode 100644 index 0000000..2c979ea --- /dev/null +++ b/project/user/getSeconds.ts @@ -0,0 +1,12 @@ +/** + * returns the number of Seconds in a given age + * + * @param {number} age + * @returns {number} + */ + export default function getSeconds(age: number): number { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 7 * 4 * 24 * 60 * 60; + } \ No newline at end of file diff --git a/project/user/getWeeks.ts b/project/user/getWeeks.ts new file mode 100644 index 0000000..dd702bf --- /dev/null +++ b/project/user/getWeeks.ts @@ -0,0 +1,12 @@ +/** + * returns the number of weeks in a given age + * + * @param {number} age + * @returns {number} + */ + export default function getWeeks(age: number): number { + if (typeof age !== "number") { + throw new TypeError("Expected a number but got " + typeof age); + } + return age * 12 * 4; +} \ No newline at end of file diff --git a/robots.txt b/robots.txt deleted file mode 100644 index 9e60f97..0000000 --- a/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: diff --git a/tests/capitalize.test.js b/tests/capitalize.test.js new file mode 100644 index 0000000..15aa330 --- /dev/null +++ b/tests/capitalize.test.js @@ -0,0 +1,13 @@ +const capitalize = require("../project/js/functionality/capitalize.js"); + +it("always make the first letter capital", function () { + expect(capitalize("hello")).toBe("Hello"); +}); + +it("returns any value type", function () { + expect(capitalize("hello")).toEqual(expect.anything()); +}); + +it("returns empty if no parameter", function () { + expect(capitalize()).toBe(""); +}); diff --git a/tests/getMid.test.js b/tests/getMid.test.js new file mode 100644 index 0000000..dbb3535 --- /dev/null +++ b/tests/getMid.test.js @@ -0,0 +1,41 @@ +const getMid = require("../project/js/functionality/getMid"); + +it("always returns a number", function () { + expect(typeof getMid(1, 2)).toBe("number"); +}); + +it("always returns a number also if the parameters are string", function () { + expect(typeof getMid("ali", "ahmed")).toBe("number"); +}); + +it("always returns a zero if the first parameter is not a number", function () { + expect(getMid("ali", 5)).toBe(0); +}); + +it("always returns a zero if the second parameter is not a number", function () { + expect(getMid(5, "ali")).toBe(0); +}); + +it("returns the two parameters value if they are the same also if they are a string type", function () { + expect(getMid("5", "5")).toBe(5); +}); + +it("returns the middle of two parameters", function () { + expect(getMid(10, 20)).toBe(15); +}); + +it("returns the two parameters value if they are the same", function () { + expect(getMid(5, 5)).toBe(5); +}); + +it("returns the first number if not Entering The Second Number", function () { + expect(getMid(5)).toBe(5); +}); + +it("returns zero if the first parameter is not a number and the second parameter is not passing", function () { + expect(getMid([1, 2, 3, 4])).toBe(0); +}); + +it("returns zero if there is no parameters", function () { + expect(getMid()).toBe(0); +}); diff --git a/tests/isPalindrome.test.js b/tests/isPalindrome.test.js new file mode 100644 index 0000000..95dd180 --- /dev/null +++ b/tests/isPalindrome.test.js @@ -0,0 +1,25 @@ +const isPalindrome = require("../project/js/functionality/isPalindrome.js"); + +it("always returns a boolean value", function () { + expect(typeof isPalindrome("123")).toBe("boolean"); +}); + +it("returns true if word is palindrome", function () { + expect(isPalindrome("mum")).toBe(true); +}); + +it("returns false if word is not palindrome", function () { + expect(isPalindrome("muom")).toBe(false); +}); + +it("returns true if word is palindrome also if the parameter is number", function () { + expect(isPalindrome(121)).toBe(true); +}); + +it("returns false if word is not palindrome also if the parameter is number", function () { + expect(isPalindrome(123)).toBe(false); +}); + +it("returns empty string if there is no parameter", function () { + expect(isPalindrome()).toBe(""); +}); diff --git a/tests/randomBoolean.test.js b/tests/randomBoolean.test.js new file mode 100644 index 0000000..d102852 --- /dev/null +++ b/tests/randomBoolean.test.js @@ -0,0 +1,13 @@ +const randomBoolean = require("../project/js/functionality/randomBoolean.js"); + +it("always return a boolean value", function () { + expect(typeof randomBoolean()).toBe("boolean"); +}); + +it("always return true or false only", function () { + expect(randomBoolean()).toEqual(expect.any(Boolean)); +}); + +it("does not matter about parameters", function () { + expect(randomBoolean(5, 7)).toEqual(expect.any(Boolean)); +}); diff --git a/tests/randomHex.test.js b/tests/randomHex.test.js new file mode 100644 index 0000000..e193e42 --- /dev/null +++ b/tests/randomHex.test.js @@ -0,0 +1,22 @@ +const randomHex = require("../project/js/functionality/randomHex"); + +it("always returns a string", () => { + expect(typeof randomHex()).toBe("string"); +}); + +it("always returns a colour", () => { + const colours = Array(100) + .fill(null) + .map(() => randomHex()); + + colours.every((colour) => expect(colour).toMatch(/^#[\da-f]{6}$/)); +}); + +it("doesn't always return the same colour", () => { + const colours = Array(100) + .fill(null) + .map(() => randomHex()); + + expect(new Set(colours).size).toBeGreaterThan(1); + // or a higher number, but e.g. `.toEqual(colours.length)` can fail due to collisions +}); diff --git a/tests/reverseNum.test.js b/tests/reverseNum.test.js new file mode 100644 index 0000000..042f51b --- /dev/null +++ b/tests/reverseNum.test.js @@ -0,0 +1,21 @@ +const reverseNum = require("../project/js/functionality/reverseNum.js"); + +it("always returns a number", function () { + expect(typeof reverseNum(123)).toBe("number"); +}); + +it("returns the number reversed", function () { + expect(reverseNum(123)).toBe(321); +}); + +it("returns empty string if there is no parameter", function () { + expect(reverseNum()).toBe(""); +}); + +it("returns the number if it its length equal to 1", function () { + expect(reverseNum(0)).toBe(0); +}); + +it("does not reverse the negative sign when reversing number", function () { + expect(reverseNum(-123)).toBe(-321); +}); diff --git a/tests/reverseString.test.js b/tests/reverseString.test.js new file mode 100644 index 0000000..7393c2d --- /dev/null +++ b/tests/reverseString.test.js @@ -0,0 +1,21 @@ +const reverseString = require("../project/js/functionality/reverseString.js"); + +it("always return a string", function () { + expect(typeof reverseString("hello")).toBe("string"); +}); + +it("always reverse the parameter", function () { + expect(reverseString("hello")).toBe("olleh"); +}); + +it("returns empty string if no parameter", function () { + expect(reverseString()).toBe(""); +}); + +it("returns empty string if the parameter is not a string", function () { + expect(reverseString(5)).toBe(""); +}); + +it("does not matter about multiple parameters", function () { + expect(reverseString("hello", "world")).toBe("olleh"); +}); diff --git a/tsconfig.json b/tsconfig.json index b939474..7ead1ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "files": ["project/ts/functionality/main.ts"], + "files": ["project/main.ts"], "compilerOptions": { "noImplicitAny": true, "target": "es2015", diff --git a/tsconfig.npm.json b/tsconfig.npm.json index fb11725..ee97ccb 100644 --- a/tsconfig.npm.json +++ b/tsconfig.npm.json @@ -1,7 +1,7 @@ { - "files": ["project/ts/functionality/main.ts"], + "files": ["project/main.ts"], "compilerOptions": { - "rootDir": "project/ts/functionality", + "rootDir": "project/", "noImplicitAny": true, "target": "ES2020", "module": "ES2020", @@ -10,6 +10,5 @@ "declaration": true, "declarationDir": "./lib/", "outDir": "./lib/" - } -} \ No newline at end of file +} diff --git a/vite.config.ts b/vite.config.ts index 474a428..d1dc6af 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,19 +2,19 @@ import { defineConfig } from "vite"; export default defineConfig({ plugins: [], - root: "./project/ts/functionality", + root: "./project/", build: { - outDir: "./../../../dist", + outDir: "../dist", rollupOptions: { output: { - entryFileNames: "functionality.min.js", - } + entryFileNames: "functionality.min.js", + }, }, emptyOutDir: true, - assetsDir: "./../../../dist", + assetsDir: "../dist", watch: { buildDelay: 0, clearScreen: true, }, }, -}); \ No newline at end of file +}); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy