simple-utils123 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/index.js +38 -0
- package/package.json +20 -0
package/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Simple Utils
|
2
|
+
|
3
|
+
A simple utility package with basic functions for everyday use.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install simple-utils
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```javascript
|
14
|
+
const { capitalize, random, isEmpty } = require('simple-utils');
|
15
|
+
|
16
|
+
// Capitalize a string
|
17
|
+
console.log(capitalize('hello')); // Output: 'Hello'
|
18
|
+
|
19
|
+
// Generate a random number between 1 and 10
|
20
|
+
console.log(random(1, 10)); // Output: random number between 1 and 10
|
21
|
+
|
22
|
+
// Check if a value is empty
|
23
|
+
console.log(isEmpty('')); // Output: true
|
24
|
+
console.log(isEmpty([])); // Output: true
|
25
|
+
console.log(isEmpty({})); // Output: true
|
26
|
+
console.log(isEmpty('hello')); // Output: false
|
27
|
+
```
|
28
|
+
|
29
|
+
## Functions
|
30
|
+
|
31
|
+
- `capitalize(str)`: Capitalizes the first letter of a string
|
32
|
+
- `random(min, max)`: Generates a random number between min and max (inclusive)
|
33
|
+
- `isEmpty(value)`: Checks if a value is empty (null, undefined, empty string, empty array, or empty object)
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
MIT
|
package/index.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
/**
|
2
|
+
* Capitalizes the first letter of a string
|
3
|
+
* @param {string} str - The string to capitalize
|
4
|
+
* @returns {string} The capitalized string
|
5
|
+
*/
|
6
|
+
function capitalize(str) {
|
7
|
+
if (typeof str !== 'string') return '';
|
8
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
9
|
+
}
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Generates a random number between min and max (inclusive)
|
13
|
+
* @param {number} min - The minimum value
|
14
|
+
* @param {number} max - The maximum value
|
15
|
+
* @returns {number} A random number between min and max
|
16
|
+
*/
|
17
|
+
function random(min, max) {
|
18
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Checks if a value is empty (null, undefined, empty string, empty array, or empty object)
|
23
|
+
* @param {*} value - The value to check
|
24
|
+
* @returns {boolean} True if the value is empty, false otherwise
|
25
|
+
*/
|
26
|
+
function isEmpty(value) {
|
27
|
+
if (value === null || value === undefined) return true;
|
28
|
+
if (typeof value === 'string') return value.trim().length === 0;
|
29
|
+
if (Array.isArray(value)) return value.length === 0;
|
30
|
+
if (typeof value === 'object') return Object.keys(value).length === 0;
|
31
|
+
return false;
|
32
|
+
}
|
33
|
+
|
34
|
+
module.exports = {
|
35
|
+
capitalize,
|
36
|
+
random,
|
37
|
+
isEmpty
|
38
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"name": "simple-utils123",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "A simple utility package with basic functions",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
8
|
+
},
|
9
|
+
"keywords": [
|
10
|
+
"utils",
|
11
|
+
"utilities",
|
12
|
+
"simple"
|
13
|
+
],
|
14
|
+
"author": "",
|
15
|
+
"license": "MIT",
|
16
|
+
"repository": {
|
17
|
+
"type": "git",
|
18
|
+
"url": "git+https://github.com/yourusername/simple-utils.git"
|
19
|
+
}
|
20
|
+
}
|