Skip to content

Commit

Permalink
Adding objectEmpty() fonction
Browse files Browse the repository at this point in the history
  • Loading branch information
bolenge committed Jun 9, 2020
1 parent 289b8ce commit 9c183d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
12 changes: 8 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const {
stripHtmlTags,
formatDateWithSlash,
rand
rand,
objectEmpty
} = require('./index');

console.log(stripHtmlTags("<h1>Hello world !</h1>"));
console.log(formatDateWithSlash(new Date()));
console.log(rand(1,90));
// console.log(stripHtmlTags("<h1>Hello world !</h1>"));
// console.log(formatDateWithSlash(new Date()));
// console.log(rand(1,90));


console.log(objectEmpty({nom: ''}));

0 comments on commit 9c183d6

Please sign in to comment.