Skip to content

Commit

Permalink
test: clone, compare2Objects, decimal2Binary and isTruthyFalsy #96 an…
Browse files Browse the repository at this point in the history
…d organize functions
  • Loading branch information
201flaviosilva committed Oct 25, 2022
1 parent d4b1b1f commit 00440d4
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 56 deletions.
3 changes: 3 additions & 0 deletions src/getUrlParameter.js → src/DOM/getUrlParameter.js
Expand Up @@ -7,6 +7,9 @@
*
* @param {string} key - The key of the query parameter
* @returns {string} Returns the value of the key
*
* @function getUrlParameter
* @memberof DOM
*/
export function getUrlParameter(key) {
const urlSearchParams = new URLSearchParams(window.location.search);
Expand Down
2 changes: 2 additions & 0 deletions src/DOM/index.js
@@ -1,5 +1,6 @@
import { deleteAllChildDom } from "./deleteAllChildDom.js";
import { exportFile } from "./exportFile.js";
import { getUrlParameter } from "./getUrlParameter.js";
import { KeyboardManager, KeyboardManagerInstance, KEYS } from "./KeyboardManager.js";
import { MouseManager, MouseManagerInstance, MouseButton } from "./MouseManager.js";
import { notification } from "./notification.js";
Expand All @@ -13,6 +14,7 @@ import { toggleFullScreen } from "./toggleFullScreen.js";
export {
deleteAllChildDom,
exportFile,
getUrlParameter,
KeyboardManager, KeyboardManagerInstance, KEYS,
MouseManager, MouseManagerInstance, MouseButton,
notification,
Expand Down
3 changes: 3 additions & 0 deletions src/FIFO.js → src/Deprecated/FIFO.js
Expand Up @@ -11,6 +11,9 @@
*
* @param {any[]} initState - The initial state
* @constructor
*
* @memberof Deprecated
* @deprecated
*/
export class FIFO {
constructor(initState = []) {
Expand Down
3 changes: 3 additions & 0 deletions src/LIFO.js → src/Deprecated/LIFO.js
Expand Up @@ -11,6 +11,9 @@
*
* @param {any[]} initState - The initial state
* @constructor
*
* @memberof Deprecated
* @deprecated
*/
export class LIFO {
constructor(initState = []) {
Expand Down
8 changes: 8 additions & 0 deletions src/camelCase.js → src/Deprecated/camelCase.js
Expand Up @@ -9,6 +9,10 @@
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function stringToCamelCase
* @memberof Deprecated
* @deprecated
*/
export function stringToCamelCase(str) { return str.replace(/\s(.)/g, ($1) => $1.toUpperCase()); }

Expand All @@ -23,5 +27,9 @@ export function stringToCamelCase(str) { return str.replace(/\s(.)/g, ($1) => $1
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function camelCaseToNormal
* @memberof Deprecated
* @deprecated
*/
export function camelCaseToNormal(str) { return str.replace(/([A-Z])/g, ($1) => " " + $1.toLowerCase()); }
8 changes: 8 additions & 0 deletions src/capitalizeCase.js → src/Deprecated/capitalizeCase.js
Expand Up @@ -9,6 +9,10 @@
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function stringToCapitalize
* @memberof Deprecated
* @deprecated
*/
export function stringToCapitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); }

Expand All @@ -22,5 +26,9 @@ export function stringToCapitalize(str) { return str.charAt(0).toUpperCase() + s
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function capitalizeToNormal
* @memberof Deprecated
* @deprecated
*/
export function capitalizeToNormal(str) { return str.charAt(0).toLowerCase() + str.slice(1); }
23 changes: 23 additions & 0 deletions src/Deprecated/index.js
@@ -0,0 +1,23 @@
import { FIFO } from "./FIFO";
import { LIFO } from "./LIFO";

import { stringToCamelCase, camelCaseToNormal } from "./camelCase.js";
import { stringToCapitalize, capitalizeToNormal } from "./capitalizeCase.js";
import { stringToKebabCase, kebabCaseToNormal } from "./kebabCase.js";
import { stringToScreamingSnakeCase, screamingSnakeCaseToNormal, screamingSnakeCaseToNormalDeprecated } from "./screamingSnakeCase.js";
import { stringToSnakeCase, snakeCaseToNormal } from "./snakeCase.js";

/**
* Deprecated functions/class
* @namespace Deprecated
*/
export {
FIFO,
LIFO,

stringToCamelCase, camelCaseToNormal,
stringToCapitalize, capitalizeToNormal,
stringToKebabCase, kebabCaseToNormal,
stringToScreamingSnakeCase, screamingSnakeCaseToNormal, screamingSnakeCaseToNormalDeprecated,
stringToSnakeCase, snakeCaseToNormal,
};
8 changes: 8 additions & 0 deletions src/kebabCase.js → src/Deprecated/kebabCase.js
Expand Up @@ -8,6 +8,10 @@
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function stringToKebabCase
* @memberof Deprecated
* @deprecated
*/
export function stringToKebabCase(str) { return str.replaceAll(" ", "-"); }

Expand All @@ -21,5 +25,9 @@ export function stringToKebabCase(str) { return str.replaceAll(" ", "-"); }
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function kebabCaseToNormal
* @memberof Deprecated
* @deprecated
*/
export function kebabCaseToNormal(str) { return str.replaceAll("-", " "); }
10 changes: 10 additions & 0 deletions src/screamingSnakeCase.js → src/Deprecated/screamingSnakeCase.js
Expand Up @@ -8,6 +8,10 @@
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function stringToScreamingSnakeCase
* @memberof Deprecated
* @deprecated
*/
export function stringToScreamingSnakeCase(str) { return str.replaceAll(" ", "_").toUpperCase(); }

Expand All @@ -19,6 +23,10 @@ export function stringToScreamingSnakeCase(str) { return str.replaceAll(" ", "_"
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function screamingSnakeCaseToNormal
* @memberof Deprecated
* @deprecated
*/
export function screamingSnakeCaseToNormal(str) { return str.replaceAll("_", " ").toLowerCase(); }

Expand All @@ -31,6 +39,8 @@ export function screamingSnakeCaseToNormal(str) { return str.replaceAll("_", " "
* @see {@link screamingSnakeCaseToNormal}
*
*
* @function screamingSnakeCaseToNormalDeprecated
* @memberof Deprecated
* @deprecated
*/
export function screamingSnakeCaseToNormalDeprecated(str) { return str.split("_").map(s => s.toLocaleLowerCase()).join(" "); }
8 changes: 8 additions & 0 deletions src/snakeCase.js → src/Deprecated/snakeCase.js
Expand Up @@ -9,6 +9,10 @@
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function stringToSnakeCase
* @memberof Deprecated
* @deprecated
*/
export function stringToSnakeCase(str) { return str.replace(/\s/g, "_").replace(/([A-Z])/g, ($1) => "_" + $1.toLowerCase()); }

Expand All @@ -23,5 +27,9 @@ export function stringToSnakeCase(str) { return str.replace(/\s/g, "_").replace(
*
* @param {string} str - the text to transform
* @returns {string}
*
* @function snakeCaseToNormal
* @memberof Deprecated
* @deprecated
*/
export function snakeCaseToNormal(str) { return str.replace(/_/g, " ").replace(/([A-Z])/g, ($1) => " " + $1.toLowerCase()); }
22 changes: 4 additions & 18 deletions src/index.js
@@ -1,4 +1,5 @@
import * as Array from "./Array/index.js";
import * as Deprecated from "./Deprecated/index.js";
import * as Device from "./Device/index.js";
import * as DOM from "./DOM/index.js";
import * as Maths from "./Maths/index.js";
Expand All @@ -7,33 +8,26 @@ import * as SortingAlgorithms from "./SortingAlgorithms/index.js";
import { allCharactersSame } from "./allCharactersSame.js";
import { binary2Decimal } from "./binary2Decimal.js";
import { BinarySearchTree, BinarySearchTreeInstance } from "./BinarySearchTree.js";
import { stringToCamelCase, camelCaseToNormal } from "./camelCase.js";
import { stringToCapitalize, capitalizeToNormal } from "./capitalizeCase.js";
import { clone } from "./clone.js";
import { compare2Objects } from "./compare2Objects.js";
import { decimal2Binary } from "./decimal2Binary.js";
import { EventSystem, EventSystemInstance } from "./EventSystem.js";
import { Fibonacci, fibonacciSequence, fibonacciUntil, fibonacciCustomSequence, recursiveFibonacci } from "./Fibonacci.js";
import { FIFO } from "./FIFO.js";
import { getUrlParameter } from "./getUrlParameter.js";
import { getVersion } from "./getVersion.js";
import { invertSentence, invertWords } from "./invertText.js";
import { isObjectEmpty } from "./isObjectEmpty.js";
import { isFalsy, isTruthy } from "./isTruthyFalsy.js";
import { stringToKebabCase, kebabCaseToNormal } from "./kebabCase.js";
import { and, or, xor } from "./logicalOperators.js";
import { LIFO } from "./LIFO.js";
import { randomColor, randomColor0X, randomRGBColor, randomRGBAColor } from "./randomColor.js";
import { randomNumber, randomInt, randomFloat } from "./randomNumber.js";
import { randomString } from "./randomString.js";
import { randomWalk1D, randomWalk2D, randomWalk3D } from "./randomWalk.js";
import { stringToScreamingSnakeCase, screamingSnakeCaseToNormal } from "./screamingSnakeCase.js";
import { stringToSnakeCase, snakeCaseToNormal } from "./snakeCase.js";
import { topDownCarMovimentation } from "./topDownCarMovimentation.js";
import { reverseString } from "./reverseString.js";
import { Vector2 } from "./Vector2.js";

export {
Array,
Deprecated,
Device,
DOM,
Maths,
Expand All @@ -42,29 +36,21 @@ export {
BinarySearchTree, BinarySearchTreeInstance,
EventSystem, EventSystemInstance,
Fibonacci, fibonacciSequence, fibonacciUntil, fibonacciCustomSequence, recursiveFibonacci,
FIFO,
LIFO,
Vector2,

allCharactersSame,
binary2Decimal,
stringToCamelCase, camelCaseToNormal,
stringToCapitalize, capitalizeToNormal,
clone,
compare2Objects,
decimal2Binary,
getUrlParameter,
getVersion,
invertSentence, invertWords,
isObjectEmpty,
isFalsy, isTruthy,
stringToKebabCase, kebabCaseToNormal,
and, or, xor, // logicalOperators
randomColor, randomColor0X, randomRGBColor, randomRGBAColor,
randomNumber, randomInt, randomFloat,
randomString,
randomWalk1D, randomWalk2D, randomWalk3D,
stringToScreamingSnakeCase, screamingSnakeCaseToNormal,
stringToSnakeCase, snakeCaseToNormal,
reverseString,
topDownCarMovimentation,
};
25 changes: 0 additions & 25 deletions src/invertText.js

This file was deleted.

26 changes: 13 additions & 13 deletions src/isTruthyFalsy.js
Expand Up @@ -36,20 +36,20 @@ export function isFalsy(value) {
* @see {@link https://developer.mozilla.org/en-US/docs/Glossary/Truthy}
*
* @example
* isFalsy(false) // false
* isFalsy("") // false
* isFalsy(0) // false
* isFalsy([]) // false
* isFalsy({}) // false
* isFalsy(null) // false
* isFalsy(undefined) // false
* isFalsy(NaN) // false
* isTruthy(false) // false
* isTruthy("") // false
* isTruthy(0) // false
* isTruthy([]) // false
* isTruthy({}) // false
* isTruthy(null) // false
* isTruthy(undefined) // false
* isTruthy(NaN) // false
* isFalsy("beep") // true
* isFalsy(1) // true
* isFalsy({dog:"Lua"}) // true
* isFalsy(["Snoopy","Ninica","Lua"]) // true
* isFalsy(console) // true
* isTruthy("beep") // true
* isTruthy(1) // true
* isTruthy({dog:"Lua"}) // true
* isTruthy(["Snoopy","Ninica","Lua"]) // true
* isTruthy(console) // true
*
* @param {*} value - the value to check
* @returns {boolean}
Expand Down
12 changes: 12 additions & 0 deletions src/reverseString.js
@@ -0,0 +1,12 @@
/**
* Invert all letters from a given text
*
* @example reverseString("beep"); // peeb
* @example reverseString("Beep"); // peeB
* @example reverseString("Beep Boop"); // pooB peeB
* @example reverseString("beep boop 1 20"); // 02 1 poob peeb
*
* @param {string} str - the text to transform
* @returns {string}
*/
export function reverseString(str) { return str.split("").reverse().join(""); }
33 changes: 33 additions & 0 deletions tests/clone.test.js
@@ -0,0 +1,33 @@
import { clone } from "../src/index";

describe("clone.js", () => {
it("should return a new object with the same properties", () => {
expect(clone({})).toEqual({});

const mockObject1 = { one: 1 };
expect(clone(mockObject1)).not.toBe(mockObject1);
expect(clone(mockObject1)).toEqual(mockObject1);

const mockObject2 = { one: 1, arr: ["A", "B"] };
expect(clone(mockObject2)).toEqual(mockObject2);
});

it("should return a new array with the same values", () => {
expect(clone([])).toEqual([]);

const mockArr1 = [1, 2];
expect(clone(mockArr1)).not.toBe(mockArr1);
expect(clone(mockArr1)).toContain(1);
expect(clone(mockArr1)).toEqual(mockArr1);

const mockArr2 = ["A", { one: 1 }, { b: 2 }];
expect(clone(mockArr2)).toContain("A");
expect(clone(mockArr2)).toEqual(mockArr2);
});

it("should return the same given value for non object args", () => {
expect(clone(1)).toBe(1);
expect(clone("B")).toBe("B");
expect(clone(true)).toBe(true);
});
});

0 comments on commit 00440d4

Please sign in to comment.