Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
201flaviosilva committed Oct 20, 2022
1 parent 7c82fc5 commit d9d2943
Show file tree
Hide file tree
Showing 73 changed files with 627 additions and 286 deletions.
16 changes: 8 additions & 8 deletions CHANGELOG.md
Expand Up @@ -20,11 +20,11 @@ This file was based on [this template](https://gist.github.com/juampynr/4c18214a
- [Get Position With Angle Distance](https://github.com/201flaviosilva-labs/javascript-utils/commit/80b83a7f35508d9997fb95bf2b6af066b8b4e553);
- [Is Falsy](https://github.com/201flaviosilva-labs/javascript-utils/commit/25b13f2b7fc66c01e6709ac8adee2e57f79fc5fd) #84;
- [Is Truthy](https://github.com/201flaviosilva-labs/javascript-utils/commit/25b13f2b7fc66c01e6709ac8adee2e57f79fc5fd) #84;
- [getBrowser](https://github.com/201flaviosilva-labs/javascript-utils/pull/95/commits/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the browser name #44;
- [getBrowserVersion](https://github.com/201flaviosilva-labs/javascript-utils/pull/95/commits/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the browser version #44;
- [getOS](https://github.com/201flaviosilva-labs/javascript-utils/pull/95/commits/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the OS name #44;
- [getOSVersion](https://github.com/201flaviosilva-labs/javascript-utils/pull/95/commits/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the OS version #44;
- [isMobile](https://github.com/201flaviosilva-labs/javascript-utils/pull/95/commits/c81f718f9497adc9f69f057950f7594b12dfa52d) - Check if is in a mobile device #44;
- [getBrowser](https://github.com/201flaviosilva-labs/javascript-utils/commit/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the browser name #44;
- [getBrowserVersion](https://github.com/201flaviosilva-labs/javascript-utils/commit/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the browser version #44;
- [getOS](https://github.com/201flaviosilva-labs/javascript-utils/commit/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the OS name #44;
- [getOSVersion](https://github.com/201flaviosilva-labs/javascript-utils/commit/c81f718f9497adc9f69f057950f7594b12dfa52d) - Returns the OS version #44;
- [isMobile](https://github.com/201flaviosilva-labs/javascript-utils/commit/c81f718f9497adc9f69f057950f7594b12dfa52d) - Check if is in a mobile device #44;

### Changed
- [Add more examples to the functions](https://github.com/201flaviosilva-labs/javascript-utils/commit/06c75f5b84da32b9af4521eab48afc3d4982a8aa);
Expand All @@ -38,9 +38,9 @@ This file was based on [this template](https://gist.github.com/juampynr/4c18214a
- [Move `toggleFullScreen` to `DOM/toggleFullScreen`](https://github.com/201flaviosilva-labs/javascript-utils/commit/2c0e9f8d293c68f36e9297b70c18321678e40921);
- [Only export `getDate` function from `getDate` file](https://github.com/201flaviosilva-labs/javascript-utils/commit/2c0e9f8d293c68f36e9297b70c18321678e40921);
- [Removed `nand`, `nor`, `not` and `xnor`](https://github.com/201flaviosilva-labs/javascript-utils/commit/2473d089c7a699650abfce108425ee0d479ce7e7) #88;
- [Move array functions to a folder](https://github.com/201flaviosilva-labs/javascript-utils/pull/92/commits/237cbf42f22131dd83c5126107f21b32ce33e232) #89;
- [Move date function to device folder/namespace](https://github.com/201flaviosilva-labs/javascript-utils/pull/95/commits/c81f718f9497adc9f69f057950f7594b12dfa52d);
- [Removed Games](1974e18a0fc36d9648715786b8144e2b3b37e3be);
- [Move array functions to a folder](https://github.com/201flaviosilva-labs/javascript-utils/commit/237cbf42f22131dd83c5126107f21b32ce33e232) #89;
- [Move date function to device folder/namespace](https://github.com/201flaviosilva-labs/javascript-utils/commit/c81f718f9497adc9f69f057950f7594b12dfa52d);
- [Removed Games](https://github.com/201flaviosilva-labs/javascript-utils/commit/40367810b608d5271f2795df44ec4e7dea02fd29);


## [1.2.9] - 02-09-2022
Expand Down
2 changes: 1 addition & 1 deletion build/utils.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Maths/median.js
@@ -1,5 +1,5 @@
import { isEven } from "./isEvenOdd";
import { arraySortAscending } from "../Array/arraySortAscending";
import { sortAscending } from "../Array/sortAscending";

/**
* Returns the median of the givens numbers
Expand All @@ -20,7 +20,7 @@ export function median(...numbers) {
const { length } = numbers;
if (!length) return 0;

arraySortAscending(numbers, true);
sortAscending(numbers, true);

if (isEven(length)) return (numbers[length / 2 - 1] + numbers[length / 2]) / 2;
return numbers[(length - 1) / 2];
Expand Down
6 changes: 3 additions & 3 deletions src/SortingAlgorithms/bogoSort.js
@@ -1,4 +1,4 @@
import { arrayShuffle, arrayIsSorted } from "../Array/index.js";
import { shuffle, isSorted } from "../Array/index.js";

/**
* Sort given array using the Selection Sort algorithm
Expand All @@ -11,8 +11,8 @@ import { arrayShuffle, arrayIsSorted } from "../Array/index.js";
* @memberof SortingAlgorithms
*/
export function bogoSort(arr) {
while (!arrayIsSorted(arr)) {
arr = arrayShuffle(arr);
while (!isSorted(arr)) {
arr = shuffle(arr);
}

return arr;
Expand Down
2 changes: 1 addition & 1 deletion src/topDownCarMovimentation.js
@@ -1,4 +1,4 @@
import { clamp } from "../Maths/clamp.js";
import { clamp } from "./Maths/clamp.js";

/**
* Updates a position, rotation and speed of a car in the top down view
Expand Down
34 changes: 34 additions & 0 deletions types/Array/Move.d.ts
@@ -0,0 +1,34 @@
/**
* @description
* Move an array element to the right
*
* @example moveLeft([1,2,3,4,5]); // [5,1,2,3,4]
* @example moveLeft([1,2,3,4,5], 2); // [4,5,1,2,3]
* @example moveLeft(["a","b","c","d","e"], 7) // ["d","e","a","b","c"]
* @example moveLeft(["a","b"], 3) // ["b","a"]
*
* @param {any[]} array - The array to move
* @param {number} times - The number of times to move the array
* @returns {any[]}
*
* @function moveLeft
* @memberof Array
*/
export function moveLeft(array?: any[], times?: number): any[];
/**
* @description
* Move an array element to the left
*
* @example moveRight([1,2,3,4,5]); // [2,3,4,5,1]
* @example moveRight([1,2,3,4,5], 2); // [3,4,5,1,2]
* @example moveRight(["a","b","c","d","e"], 7) // ["c","d","e","a","b"]
* @example moveRight(["a","b"], 3) // ["b","a"]
*
* @param {any[]} array - The array to move
* @param {number} times - The number of times to move the array
* @returns {any[]}
*
* @function moveRight
* @memberof Array
*/
export function moveRight(array?: any[], times?: number): any[];
3 changes: 3 additions & 0 deletions types/allEqual.d.ts → types/Array/allEqual.d.ts
Expand Up @@ -14,5 +14,8 @@
*
* @param {any} arr - the array to check all elements
* @returns {boolean} true if all elements of the array ara equal
*
* @function allEqual
* @memberof Array
*/
export function allEqual(arr: any): boolean;
9 changes: 6 additions & 3 deletions types/arrayChoice.d.ts → types/Array/choice.d.ts
Expand Up @@ -3,10 +3,13 @@
*
* @see {@link https://www.w3schools.com/python/ref_random_choice.asp}
*
* @example arrayChoice(["A", "B", "C"]); // "B"
* @example arrayChoice([10, 5, 123]); // 10
* @example choice(["A", "B", "C"]); // "B"
* @example choice([10, 5, 123]); // 10
*
* @param {any[]} array - the array to select a random item
* @returns {any}
*
* @function choice
* @memberof Array
*/
export function arrayChoice(array: any[]): any;
export function choice(array: any[]): any;
18 changes: 12 additions & 6 deletions types/arrayFindBigObject.d.ts → types/Array/findBigObject.d.ts
Expand Up @@ -3,22 +3,28 @@
*
* @example
* const myArray = [{a:1, b:100}, {a: 0, b:50}, {a:0, b:200}]
* arrayFindBigObject(myArray, "b"); // {a:0, b:200}
* arrayFindBigObject(myArray, "a"); // {a:1, b:100}
* arrayGetMaxObjects(myArray, "b", true); // 200
* arrayGetMaxObjects(myArray, "a", true); // 1
* findBigObject(myArray, "b"); // {a:0, b:200}
* findBigObject(myArray, "a"); // {a:1, b:100}
* findBigObject(myArray, "b", true); // 200
* findBigObject(myArray, "a", true); // 1
*
* @param {any[]} array - The array to search
* @param {string} prop - The property to find the biggest element
* @param {boolean} [returnOnlyValue=false] - If true only returns the value of the given property with the biggest value
* @returns {any|number} - The biggest element in the array
*
* @function findBigObject
* @memberof Array
*/
export function arrayFindBigObject(array: any[], prop: string, returnOnlyValue?: boolean): any | number;
export function findBigObject(array: any[], prop: string, returnOnlyValue?: boolean): any | number;
/**
*
* @param {Object[]} array - The array to search
* @param {string} prop - The property to find the biggest element
* @returns {Object} - The biggest element in the array
*
* @function findBigObjectDeprecated
* @memberof Array
* @deprecated
*/
export function arrayFindBigObjectDeprecated(array: any[], prop: string): any;
export function findBigObjectDeprecated(array: any[], prop: string): any;
18 changes: 12 additions & 6 deletions types/arrayFindLowObject.d.ts → types/Array/findLowObject.d.ts
Expand Up @@ -3,22 +3,28 @@
*
* @example
* const myArray = [{a:1, b:100}, {a:10, b:50}, {a:0, b:200}]
* arrayFindLowObject(myArray, "b"); // {a:10, b:50}
* arrayFindLowObject(myArray, "a"); // {a:0, b:200}
* arrayGetMinObjects(myArray, "b", true); // 50
* arrayGetMinObjects(myArray, "a", true); // 0
* findLowObject(myArray, "b"); // {a:10, b:50}
* findLowObject(myArray, "a"); // {a:0, b:200}
* findLowObject(myArray, "b", true); // 50
* findLowObject(myArray, "a", true); // 0
*
* @param {Object[]} array - The array to search
* @param {string} prop - The property to find the lowest element
* @param {boolean} [returnOnlyValue=false] - If true only returns the value of the given property with the lowest value
* @returns {Object} - The lowest element in the array
*
* @function findLowObject
* @memberof Array
*/
export function arrayFindLowObject(array: any[], prop: string, returnOnlyValue?: boolean): any;
export function findLowObject(array: any[], prop: string, returnOnlyValue?: boolean): any;
/**
*
* @param {Object[]} array - The array to search
* @param {string} prop - The property to find the lowest element
* @returns {Object} - The lowest element in the array
*
* @function findLowObjectDeprecated
* @memberof Array
* @deprecated
*/
export function arrayFindLowObjectDeprecated(array: any[], prop: string): any;
export function findLowObjectDeprecated(array: any[], prop: string): any;
13 changes: 13 additions & 0 deletions types/Array/index.d.ts
@@ -0,0 +1,13 @@
import { allEqual } from "./allEqual.js";
import { choice } from "./choice.js";
import { findBigObject } from "./findBigObject.js";
import { findLowObject } from "./findLowObject.js";
import { isSorted } from "./isSorted.js";
import { moveLeft } from "./Move.js";
import { moveRight } from "./Move.js";
import { shuffle } from "./shuffle.js";
import { sortAscending } from "./sortAscending.js";
import { sortAscendingObject } from "./sortAscendingObject.js";
import { sortDescending } from "./sortDescending.js";
import { sortDescendingObject } from "./sortDescendingObject.js";
export { allEqual, choice, findBigObject, findLowObject, isSorted, moveLeft, moveRight, shuffle, sortAscending, sortAscendingObject, sortDescending, sortDescendingObject };
19 changes: 19 additions & 0 deletions types/Array/isSorted.d.ts
@@ -0,0 +1,19 @@
/**
* Check if the given array is sorted fom lowest to highest
*
* @example
* isSorted([]) // true
* isSorted([0,0,0,0]) // true
* isSorted([2,1,4]) // false
* isSorted([3,2,1]) // false
* isSorted([1,2,3]) // true
* isSorted(["B","A","D"]) // false
* isSorted(["A","B","C"]) // true
*
* @param {any} arr - the array to check
* @returns {boolean} true if the array is sorted
*
* @function isSorted
* @memberof Array
*/
export function isSorted(arr?: any): boolean;
17 changes: 17 additions & 0 deletions types/Array/shuffle.d.ts
@@ -0,0 +1,17 @@
/**
* This function will randomize the position of the array items. (change the original array!)
*
* To not mutate the original array pass in the `mutateOriginal` argument false, and this function will return a new array with the original items in random positions. (not changing the original array)
*
* @example shuffle(["A", "B", "C"]); // ["B","A","C"]
* @example shuffle([1,2,3,4,5,6,7,8,9]); // [8,5,1,4,3,6,9,2,7]
* @example shuffle([{a:1},{b:2},{c:3}]); // [{a:1},{c:3},{b:2}]
*
* @param {any[]} array - the array with the items to randomize
* @param {boolean} mutateOriginal - the array with the items to randomize
* @returns {any[]}
*
* @function shuffle
* @memberof Array
*/
export function shuffle(array: any[], mutateOriginal?: boolean): any[];
Expand Up @@ -3,10 +3,13 @@
*
* @example
* const myArr = [10,4,2,7,1,0,11,4,2,3,5,8,4,3,0,6];
* const myNewSortedArr = arraySortAscending(myArr); // [0,0,1,2,2,3,3,4,4,4,5,6,7,8,10,11]
* const myNewSortedArr = sortAscending(myArr); // [0,0,1,2,2,3,3,4,4,4,5,6,7,8,10,11]
*
* @param {number[]} arr - the array to sort
* @param {boolean} [changeArr=false] - if true will change the original array
* @returns {number[]} A new Array sorted
*
* @function sortAscending
* @memberof Array
*/
export function arraySortAscending(arr: number[], changeArr?: boolean): number[];
export function sortAscending(arr: number[], changeArr?: boolean): number[];
Expand Up @@ -4,5 +4,8 @@
* @param {any[]} arr - the array to sort
* @param {string} prop - the property base to sort
* @returns {any[]} - a new sorted array by the given property
*
* @function sortAscendingObject
* @memberof Array
*/
export function arraySortAscendingObject(arr: any[], prop: string): any[];
export function sortAscendingObject(arr: any[], prop: string): any[];
Expand Up @@ -7,5 +7,8 @@
*
* @param {number[]} arr - the array to sort
* @returns {number[]} A new Array sorted
*
* @function sortDescending
* @memberof Array
*/
export function arraySortDescending(arr: number[]): number[];
export function sortDescending(arr: number[]): number[];
Expand Up @@ -4,5 +4,8 @@
* @param {any[]} arr - the array to sort
* @param {string} prop - the property base to sort
* @returns {any[]} - a new sorted array by the given property
*
* @function sortDescendingObject
* @memberof Array
*/
export function arraySortDescendingObject(arr: any[], prop: string): any[];
export function sortDescendingObject(arr: any[], prop: string): any[];
7 changes: 7 additions & 0 deletions types/DOM/KeyboardManager.d.ts
Expand Up @@ -51,6 +51,13 @@ export namespace KEYS {
* const { left } = DOM.KeyboardManagerInstance.keys;
* if (DOM.KeyboardManagerInstance.isKeyPressed(left)) console.log("Left");
*
* @example
* import { DOM } from "201flaviosilva-labs";
* const { KEYS, KeyboardManager, KeyboardManagerInstance } = DOM;
* setInterval(() => console.log(KeyboardManagerInstance.isKeyPressed(KEYS.a)), 100);
* KeyboardManagerInstance.events.on("keyDown-left", () => console.log("down-left"));
* KeyboardManagerInstance.events.on("keyUp-up", () => console.log(`up-${KEYS.up}`));
*
* @memberof DOM
*/
export class KeyboardManager {
Expand Down
10 changes: 10 additions & 0 deletions types/DOM/MouseManager.d.ts
Expand Up @@ -11,6 +11,16 @@ export namespace MouseButton {
* const mouse = new DOM.MouseManager();
* const { x, y } = mouse;
* console.log(x, y);
*
* @example
* import { DOM } from "201flaviosilva-labs";
* const { MouseManager, MouseManagerInstance, MouseButton, } = DOM
* const beepDiv = document.getElementById("MyDiv");
* const mouse = new MouseManager(true);
* setInterval(() => console.log(mouse.getPosition(beepDiv)), 1000);
* MouseManagerInstance.events.on("buttonDown-left", () => console.log("down -> left"));
* MouseManagerInstance.events.on("buttonDown-right", () => console.log("up -> right"));
*
* @param {Boolean} [preventDefault=false] - Prevent the Default behavior on press right button
* @memberof DOM
Expand Down
3 changes: 2 additions & 1 deletion types/DOM/index.d.ts
Expand Up @@ -8,4 +8,5 @@ import { MouseManagerInstance } from "./MouseManager.js";
import { MouseButton } from "./MouseManager.js";
import { notification } from "./notification.js";
import { printObjectInDOM } from "./printObjectInDOM.js";
export { deleteAllChildDom, exportFile, KeyboardManager, KeyboardManagerInstance, KEYS, MouseManager, MouseManagerInstance, MouseButton, notification, printObjectInDOM };
import { toggleFullScreen } from "./toggleFullScreen.js";
export { deleteAllChildDom, exportFile, KeyboardManager, KeyboardManagerInstance, KEYS, MouseManager, MouseManagerInstance, MouseButton, notification, printObjectInDOM, toggleFullScreen };
16 changes: 16 additions & 0 deletions types/toggleFullScreen.d.ts → types/DOM/toggleFullScreen.d.ts
Expand Up @@ -4,8 +4,24 @@
*
* @example toggleFullScreen();
* @example toggleFullScreen(document.getElementById("myElement"));
* @example
* ```html
* <!--- html --->
* <button id="toggle">Toggle</button>
* ```
*
* ```js
* // js
* import { toggleFullScreen } from "201flaviosilva-utils";
* document.getElementById("toggle").addEventListener("click", () => {
* toggleFullScreen(document.getElementById("toggle"));
* });
* ```
*
* @param {HTMLElement} element - the DOM element to put in full screen
* @returns {void}
*
* @function toggleFullScreen
* @memberof DOM
*/
export function toggleFullScreen(element?: HTMLElement): void;
18 changes: 18 additions & 0 deletions types/Device/getBrowser.d.ts
@@ -0,0 +1,18 @@
/**
* Detects and returns the browser name
*
* Function based in ➜ {@link https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser}
*
* @example getBrowser(); // Opera
* @example getBrowser(); // Chrome
* @example getBrowser(); // Safari
* @example getBrowser(); // Firefox
* @example getBrowser(); // IE
* @example getBrowser(); // Unknown // Not detect
*
* @returns {String} browser name
*
* @function getBrowser
* @memberof Device
*/
export function getBrowser(): string;
14 changes: 14 additions & 0 deletions types/Device/getBrowserVersion.d.ts
@@ -0,0 +1,14 @@
/**
* Detects and returns the browser version
*
* Function based in ➜ {@link https://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser}
*
* @example getBrowserVersion(); // 106
* @example getBrowserVersion(); // 105
*
* @returns {Number|String} browser version
*
* @function getBrowserVersion
* @memberof Device
*/
export function getBrowserVersion(): number | string;

0 comments on commit d9d2943

Please sign in to comment.