Skip to content

Commit

Permalink
Merge pull request #86 from 201flaviosilva-labs/84-isfalsy
Browse files Browse the repository at this point in the history
add: isFalsy and isTruthy functions #84
  • Loading branch information
201flaviosilva committed Oct 13, 2022
2 parents 80b83a7 + 1b84561 commit 9bd6bfc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/getPositionWithAngleDistance.js
@@ -1,3 +1,9 @@
/**
* @typedef {Object} Point
* @property {number} x - The X Coordinate
* @property {number} y - The Y Coordinate
*/

/**
* Calculates de position (x,y) of a object based in the angle and distance
*
Expand All @@ -9,7 +15,7 @@
* @param {Object} [origin] - origin position to analyze
* @param {number} [origin.x=0] - x axis value
* @param {number} [origin.y=0] - y axis value
* @returns {{x: number y: number}} the x and y position
* @returns {Point} position {x:number,y:number} the x and y position
*/
export function getPositionWithAngleDistance(angle, distance, origin = { x: 0, y: 0 }) {
return {
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Expand Up @@ -39,6 +39,7 @@ import { invertSentence, invertWords } from "./invertText.js";
import { isEven, isOdd } from "./isEvenOdd.js";
import { isMultipleOf } from "./isMultipleOf.js";
import { isNarcissisticNumber } from "./isNarcissisticNumber.js";
import { isFalsy, isTruthy } from "./isTruthyFalsy.js";
import { stringToKebabCase, kebabCaseToNormal } from "./kebabCase.js";
import { lerp } from "./lerp.js";
import { LIFO } from "./LIFO.js";
Expand Down Expand Up @@ -107,6 +108,7 @@ export {
isEven, isOdd,
isMultipleOf,
isNarcissisticNumber,
isFalsy, isTruthy,
stringToKebabCase, kebabCaseToNormal,
lerp,
LIFO,
Expand Down
57 changes: 57 additions & 0 deletions src/isTruthyFalsy.js
@@ -0,0 +1,57 @@
/**
* Check if the given value is a falsy value
*
* @see {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy}
*
* @example
* isFalsy(false) // true
* isFalsy("") // true
* isFalsy(0) // true
* isFalsy([]) // true
* isFalsy({}) // true
* isFalsy(null) // true
* isFalsy(undefined) // true
* isFalsy(NaN) // true
* isFalsy("beep") // false
* isFalsy(1) // false
* isFalsy({dog:"Lua"}) // false
* isFalsy(["Snoopy","Ninica","Lua"]) // false
* isFalsy(console) // false
*
* @param {*} value - the value to check
* @returns {boolean}
*/
export function isFalsy(value) {
try {
if (!value || (typeof value == "object" && (Object.keys(value).length == 0))) return true;
} catch (err) { return true; }

return false;
};

/**
* Check if the given value is a Truthy 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
* isFalsy("beep") // true
* isFalsy(1) // true
* isFalsy({dog:"Lua"}) // true
* isFalsy(["Snoopy","Ninica","Lua"]) // true
* isFalsy(console) // true
*
* @param {*} value - the value to check
* @returns {boolean}
*/
export function isTruthy(value) { return !isFalsy(value); }

0 comments on commit 9bd6bfc

Please sign in to comment.