From 9c183d6c79b2f6e7be17faf4015860c40c6b4a91 Mon Sep 17 00:00:00 2001 From: Don de Dieu BOLENGE Date: Tue, 9 Jun 2020 17:08:53 +0100 Subject: [PATCH] Adding objectEmpty() fonction --- README.md | 14 ++++++++++++++ index.js | 10 ++++++++++ package.json | 2 +- test.js | 12 ++++++++---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0c2ab59..8fade0c 100644 --- a/README.md +++ b/README.md @@ -57,4 +57,18 @@ Exemple const { formatDateWithSlash } = require('self-helpers'); console.log(formatDateWithSlash(new Date())); // d-m-y +``` + +#### objectEmpty(object) + +Permet de vérifier si l'objet passé en paramètre est vide, ne contient aucun élément + +* `object` : L'objet à vérifier + +Exemple +```js +const helpers = require('self-helpers'); + +console.log(helpers.objectEmpty({})); // true +console.log(helpers.objectEmpty({name: 'Sekikande'})); // false ``` \ No newline at end of file diff --git a/index.js b/index.js index 8455419..6b79557 100644 --- a/index.js +++ b/index.js @@ -45,4 +45,14 @@ exports.rand = (min, max, integer = true) => { }else { return Math.floor(Math.random() * (max - min + 1) + min); } +} + +/** + * Vérifie si un object est vide + * @param {Object} object L'objet à tester + * @return {Boolean} + */ +exports.objectEmpty = (object) => { + + return Object.keys(object).length <= 0; } \ No newline at end of file diff --git a/package.json b/package.json index 8ad268e..61e7395 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "self-helpers", - "version": "0.0.1", + "version": "0.0.2", "description": "Package Javascript contenant un bon nombre des fonctions ou des logiques de code que nous utilisons régulièrement qui sont mis en fonctions", "main": "index.js", "scripts": { diff --git a/test.js b/test.js index 3dae164..c11b0b8 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,13 @@ const { stripHtmlTags, formatDateWithSlash, - rand + rand, + objectEmpty } = require('./index'); -console.log(stripHtmlTags("

Hello world !

")); -console.log(formatDateWithSlash(new Date())); -console.log(rand(1,90)); \ No newline at end of file +// console.log(stripHtmlTags("

Hello world !

")); +// console.log(formatDateWithSlash(new Date())); +// console.log(rand(1,90)); + + +console.log(objectEmpty({nom: ''})); \ No newline at end of file