diff --git a/src/getPositionWithAngleDistance.js b/src/getPositionWithAngleDistance.js index 7b2dda5..55cd099 100644 --- a/src/getPositionWithAngleDistance.js +++ b/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 * @@ -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 { diff --git a/src/index.js b/src/index.js index f6663ce..b050420 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; @@ -107,6 +108,7 @@ export { isEven, isOdd, isMultipleOf, isNarcissisticNumber, + isFalsy, isTruthy, stringToKebabCase, kebabCaseToNormal, lerp, LIFO, diff --git a/src/isTruthyFalsy.js b/src/isTruthyFalsy.js new file mode 100644 index 0000000..39d63bf --- /dev/null +++ b/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); }