Skip to content

Commit 79f4f5a

Browse files
committed
adding functions build
1 parent dcdaaa4 commit 79f4f5a

26 files changed

+295
-5
lines changed

lib/converts/hexToRgb.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* converts a hex color to rgb
3+
*
4+
* @param {string} hex
5+
* @returns {number[]}
6+
*/
7+
export default function hexToRgb(hex: string): number[];

lib/converts/hexToRgb.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* converts a hex color to rgb
3+
*
4+
* @param {string} hex
5+
* @returns {number[]}
6+
*/
7+
export default function hexToRgb(hex) {
8+
return hex
9+
.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => "#" + r + r + g + g + b + b)
10+
.substring(1)
11+
.match(/.{2}/g)
12+
.map((x) => parseInt(x, 16));
13+
}

lib/converts/rgbToHex.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Converts an RGB color value to a hexadecimal string.
3+
*
4+
* @param {number} r
5+
* @param {number} g
6+
* @param {number} b
7+
* @returns {string}
8+
*/
9+
export default function rgbToHex(r: number, g: number, b: number): string;

lib/converts/rgbToHex.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Converts an RGB color value to a hexadecimal string.
3+
*
4+
* @param {number} r
5+
* @param {number} g
6+
* @param {number} b
7+
* @returns {string}
8+
*/
9+
export default function rgbToHex(r, g, b) {
10+
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
11+
}

lib/converts/rgbToHsl.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
*
3+
* @param r
4+
* @param g
5+
* @param b
6+
* @returns
7+
*/
8+
export default function rgbToHsl(r: number, g: number, b: number): number[];

lib/converts/rgbToHsl.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
*
3+
* @param r
4+
* @param g
5+
* @param b
6+
* @returns
7+
*/
8+
export default function rgbToHsl(r, g, b) {
9+
(r /= 255), (g /= 255), (b /= 255);
10+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
11+
var h, s, l = (max + min) / 2;
12+
if (max == min) {
13+
h = s = 0;
14+
}
15+
else {
16+
var d = max - min;
17+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
18+
switch (max) {
19+
case r:
20+
h = (g - b) / d + (g < b ? 6 : 0);
21+
break;
22+
case g:
23+
h = (b - r) / d + 2;
24+
break;
25+
case b:
26+
h = (r - g) / d + 4;
27+
break;
28+
}
29+
h /= 6;
30+
}
31+
return [h, s, l];
32+
}

lib/dom/select.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* returns the number of Seconds in a given age
3+
*
4+
* @param {string} element
5+
* @returns {number}
6+
*/
7+
export default function select(element: string): any;

lib/dom/select.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* returns the number of Seconds in a given age
3+
*
4+
* @param {string} element
5+
* @returns {number}
6+
*/
7+
export default function select(element) {
8+
if (typeof element !== "string") {
9+
throw new TypeError("Expected a string but got " + typeof element);
10+
}
11+
return document.querySelector(element);
12+
}

lib/main.d.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ import randomColor from "./randoms/randomColor";
2222
import randomHsl from "./randoms/randomHsl";
2323
import isHappyNumber from "./numbers/isHappyNumber";
2424
import randomPassword from "./randoms/randomPassword";
25-
import rgbToHex from "./strings/rgbToHex";
26-
import hexToRgb from "./strings/hexToRgb";
25+
import rgbToHex from "./converts/rgbToHex";
26+
import hexToRgb from "./converts/hexToRgb";
27+
import rgbToHsl from "./converts/rgbToHsl";
28+
import removeInnerSpace from "./strings/removeInnerSpace";
29+
import getBrowser from "./user/getBrowser";
30+
import getMonths from "./user/getMonths";
31+
import getWeeks from "./user/getWeeks";
32+
import getDays from "./user/getDays";
33+
import getHours from "./user/getHours";
34+
import getMinutes from "./user/getMinutes";
35+
import getSeconds from "./user/getSeconds";
36+
import select from "./dom/select";
2737
declare const functionality: {
2838
sumOfArray: typeof sumOfArray;
2939
capitalize: typeof capitalize;
@@ -51,6 +61,16 @@ declare const functionality: {
5161
randomPassword: typeof randomPassword;
5262
rgbToHex: typeof rgbToHex;
5363
hexToRgb: typeof hexToRgb;
64+
rgbToHsl: typeof rgbToHsl;
65+
removeInnerSpace: typeof removeInnerSpace;
66+
getBrowser: typeof getBrowser;
67+
getMonths: typeof getMonths;
68+
getWeeks: typeof getWeeks;
69+
getDays: typeof getDays;
70+
getHours: typeof getHours;
71+
getSeconds: typeof getSeconds;
72+
getMinutes: typeof getMinutes;
73+
select: typeof select;
5474
};
5575
declare global {
5676
interface Window {

lib/main.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@ import randomColor from "./randoms/randomColor";
2222
import randomHsl from "./randoms/randomHsl";
2323
import isHappyNumber from "./numbers/isHappyNumber";
2424
import randomPassword from "./randoms/randomPassword";
25-
import rgbToHex from "./strings/rgbToHex";
26-
import hexToRgb from "./strings/hexToRgb";
25+
import rgbToHex from "./converts/rgbToHex";
26+
import hexToRgb from "./converts/hexToRgb";
27+
import rgbToHsl from "./converts/rgbToHsl";
28+
// import hexToHsl from "./converts/hexToHsl";
29+
// import hslToHex from "./converts/hslToHex";
30+
// import hslToRgb from "./converts/hslToRgb";
31+
import removeInnerSpace from "./strings/removeInnerSpace";
32+
import getBrowser from "./user/getBrowser";
33+
import getMonths from "./user/getMonths";
34+
import getWeeks from "./user/getWeeks";
35+
import getDays from "./user/getDays";
36+
import getHours from "./user/getHours";
37+
import getMinutes from "./user/getMinutes";
38+
import getSeconds from "./user/getSeconds";
39+
import select from "./dom/select";
2740
const functionality = {
2841
sumOfArray,
2942
capitalize,
@@ -51,7 +64,16 @@ const functionality = {
5164
randomPassword,
5265
rgbToHex,
5366
hexToRgb,
67+
rgbToHsl,
68+
removeInnerSpace,
69+
getBrowser,
70+
getMonths,
71+
getWeeks,
72+
getDays,
73+
getHours,
74+
getSeconds,
75+
getMinutes,
76+
select,
5477
};
5578
window.functionality = functionality;
56-
// export * from "./sumOfArray";
5779
export default functionality;

0 commit comments

Comments
 (0)