Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/converts/hexToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* converts a hex color to rgb
*
* @param {string} hex
* @returns {number[]}
*/
export default function hexToRgb(hex: string): number[];
13 changes: 13 additions & 0 deletions lib/converts/hexToRgb.js
Original file line number Diff line number Diff line change
@@ -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));
}
9 changes: 9 additions & 0 deletions lib/converts/rgbToHex.d.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions lib/converts/rgbToHex.js
Original file line number Diff line number Diff line change
@@ -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);
}
8 changes: 8 additions & 0 deletions lib/converts/rgbToHsl.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
*
* @param r
* @param g
* @param b
* @returns
*/
export default function rgbToHsl(r: number, g: number, b: number): number[];
32 changes: 32 additions & 0 deletions lib/converts/rgbToHsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
*
* @param r
* @param g
* @param b
* @returns
*/
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];
}
7 changes: 7 additions & 0 deletions lib/dom/select.d.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/dom/select.js
Original file line number Diff line number Diff line change
@@ -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);
}
24 changes: 24 additions & 0 deletions lib/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ 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 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 select from "./dom/select";
declare const functionality: {
sumOfArray: typeof sumOfArray;
capitalize: typeof capitalize;
Expand All @@ -47,6 +59,18 @@ declare const functionality: {
randomHsl: typeof randomHsl;
isHappyNumber: typeof isHappyNumber;
randomPassword: typeof randomPassword;
rgbToHex: typeof rgbToHex;
hexToRgb: typeof hexToRgb;
rgbToHsl: typeof rgbToHsl;
removeInnerSpace: typeof removeInnerSpace;
getBrowser: typeof getBrowser;
getMonths: typeof getMonths;
getWeeks: typeof getWeeks;
getDays: typeof getDays;
getHours: typeof getHours;
getSeconds: typeof getSeconds;
getMinutes: typeof getMinutes;
select: typeof select;
};
declare global {
interface Window {
Expand Down
28 changes: 27 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ 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 select from "./dom/select";
const functionality = {
sumOfArray,
capitalize,
Expand All @@ -47,7 +62,18 @@ const functionality = {
randomHsl,
isHappyNumber,
randomPassword,
rgbToHex,
hexToRgb,
rgbToHsl,
removeInnerSpace,
getBrowser,
getMonths,
getWeeks,
getDays,
getHours,
getSeconds,
getMinutes,
select,
};
window.functionality = functionality;
// export * from "./sumOfArray";
export default functionality;
7 changes: 7 additions & 0 deletions lib/strings/hexToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* converts a hex color to rgb
*
* @param {string} hex
* @returns {number[]}
*/
export default function hexToRgb(hex: string): number[];
13 changes: 13 additions & 0 deletions lib/strings/hexToRgb.js
Original file line number Diff line number Diff line change
@@ -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));
}
8 changes: 8 additions & 0 deletions lib/strings/removeInnerSpace.d.ts
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 13 additions & 0 deletions lib/strings/removeInnerSpace.js
Original file line number Diff line number Diff line change
@@ -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, " ");
}
9 changes: 9 additions & 0 deletions lib/strings/rgbToHex.d.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions lib/strings/rgbToHex.js
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions lib/user/getBrowser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Returns the browser name of the active user.
*
* @returns {string}
*/
export default function getBrowser(): string;
8 changes: 8 additions & 0 deletions lib/user/getBrowser.js
Original file line number Diff line number Diff line change
@@ -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];
}
7 changes: 7 additions & 0 deletions lib/user/getDays.d.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/user/getDays.js
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions lib/user/getHours.d.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/user/getHours.js
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions lib/user/getMinutes.d.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/user/getMinutes.js
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions lib/user/getMonths.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* returns the months of the age
*
* @param {number} age
* @returns {number}
*/
export default function getMonths(age: number): number;
12 changes: 12 additions & 0 deletions lib/user/getMonths.js
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions lib/user/getSeconds.d.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/user/getSeconds.js
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions lib/user/getWeeks.d.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions lib/user/getWeeks.js
Original file line number Diff line number Diff line change
@@ -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;
}
Loading