@myusufazmi/ultimate-tools 1.0.0 → 1.1.1
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 +126 -31
- package/package.json +1 -1
- package/src/date.js +70 -0
- package/src/format.js +67 -0
- package/src/index.js +3 -0
- package/src/validation.js +56 -0
package/README.md
CHANGED
|
@@ -1,52 +1,147 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🚀 @myusufazmi/ultimate-tools
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A premium, lightweight, and modern JavaScript utility library designed for high-performance web development. Zero dependencies, pure ESM, and built for speed.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@myusufazmi/ultimate-tools)
|
|
6
|
+
[](https://github.com/myusufazmi/ultimate-tools/blob/main/LICENSE)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
---
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
- `$$(selector, context)`: Query selector all returning an array.
|
|
11
|
-
- `create(tag, options)`: Advanced element creation.
|
|
12
|
-
- `on(parent, event, selector, handler)`: Efficient event delegation.
|
|
10
|
+
## 📦 Installation
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
```bash
|
|
13
|
+
npm install @myusufazmi/ultimate-tools
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🛠 Modules & API Reference
|
|
19
|
+
|
|
20
|
+
### 🏗 DOM Utilities
|
|
21
|
+
|
|
22
|
+
Performance-oriented DOM manipulation with event delegation.
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
import { $, $$, create, on } from "@myusufazmi/ultimate-tools";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- **`$(selector, context = document)`**: Returns a single element.
|
|
29
|
+
- **`$$(selector, context = document)`**: Returns an **array** of elements.
|
|
30
|
+
- **`create(tag, options)`**: Create complex elements declaratively.
|
|
31
|
+
- **`on(parent, event, selector, handler)`**: High-performance event delegation.
|
|
15
32
|
|
|
16
|
-
|
|
17
|
-
- `http.post(url, body, options)`
|
|
18
|
-
- `http.put(url, body, options)`
|
|
19
|
-
- `http.delete(url, options)`
|
|
20
|
-
- Supports JSON by default and interceptors.
|
|
33
|
+
---
|
|
21
34
|
|
|
22
|
-
###
|
|
35
|
+
### 🌐 HTTP Wrapper
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
- `session.set(key, value)`, `session.get(key, fallback)`
|
|
26
|
-
- Auto-serialization/deserialization for all data types.
|
|
37
|
+
A clean, promise-based wrapper for the Fetch API with JSON support by default.
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
```javascript
|
|
40
|
+
import { http } from "@myusufazmi/ultimate-tools";
|
|
41
|
+
```
|
|
29
42
|
|
|
30
|
-
-
|
|
43
|
+
- **`http.get(url, options)`**
|
|
44
|
+
- **`http.post(url, body, options)`**
|
|
45
|
+
- **`http.put(url, body, options)`**
|
|
46
|
+
- **`http.delete(url, options)`**
|
|
31
47
|
|
|
32
|
-
|
|
48
|
+
---
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
- `throttle(fn, limit)`
|
|
36
|
-
- `deepClone(obj)`
|
|
37
|
-
- `uuid()`: Simple unique ID generator.
|
|
50
|
+
### 📅 Date Utilities (NEW v1.1.0)
|
|
38
51
|
|
|
39
|
-
|
|
52
|
+
Simple and efficient date formatting and manipulation.
|
|
40
53
|
|
|
41
54
|
```javascript
|
|
42
|
-
import {
|
|
55
|
+
import { formatDate, relativeTime, addDays } from "@myusufazmi/ultimate-tools";
|
|
56
|
+
|
|
57
|
+
formatDate(new Date(), "YYYY-MM-DD HH:mm:ss"); // "2026-02-09 11:58:39"
|
|
58
|
+
relativeTime(new Date(Date.now() - 3600000)); // "1 hours ago"
|
|
59
|
+
addDays(new Date(), 7); // Date object + 7 days
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 💎 Formatting Utilities (NEW v1.1.0)
|
|
65
|
+
|
|
66
|
+
Tools for number, currency, and string formatting.
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
import {
|
|
70
|
+
currency,
|
|
71
|
+
number,
|
|
72
|
+
slugify,
|
|
73
|
+
truncate,
|
|
74
|
+
} from "@myusufazmi/ultimate-tools";
|
|
75
|
+
|
|
76
|
+
currency(50000); // "Rp 50.000,00" (default id-ID)
|
|
77
|
+
number(1234.56, 1); // "1.234,6"
|
|
78
|
+
slugify("Halo Dunia!"); // "halo-dunia"
|
|
79
|
+
truncate("Teks yang sangat panjang sekali", 10); // "Teks yang..."
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
### 🛡 Validation Utilities (NEW v1.1.0)
|
|
85
|
+
|
|
86
|
+
Common regex-based validation helpers.
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
import { isEmail, isStrongPassword, isEmpty } from "@myusufazmi/ultimate-tools";
|
|
90
|
+
|
|
91
|
+
isEmail("test@example.com"); // true
|
|
92
|
+
isStrongPassword("Pass123"); // false (too short)
|
|
93
|
+
isEmpty(" "); // true
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### 💾 Storage Management
|
|
99
|
+
|
|
100
|
+
Type-safe and auto-serialized storage for persistent data.
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import { local, session } from "@myusufazmi/ultimate-tools";
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- **`local.set(key, value)`** / **`session.set(key, value)`**
|
|
107
|
+
- **`local.get(key, fallback)`** / **`session.get(key, fallback)`**
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### 🔄 State Management
|
|
112
|
+
|
|
113
|
+
A tiny ( < 1KB) reactive state manager.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { createStore } from "@myusufazmi/ultimate-tools";
|
|
43
117
|
|
|
44
118
|
const count = createStore(0);
|
|
45
|
-
count.subscribe((val) => console.log(
|
|
119
|
+
count.subscribe((val) => console.log(val));
|
|
120
|
+
count.update((n) => n + 1);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
46
124
|
|
|
47
|
-
|
|
125
|
+
### ⚡ General Utilities
|
|
126
|
+
|
|
127
|
+
Essential helpers for common logic patterns.
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
import {
|
|
131
|
+
debounce,
|
|
132
|
+
throttle,
|
|
133
|
+
deepClone,
|
|
134
|
+
uuid,
|
|
135
|
+
} from "@myusufazmi/ultimate-tools";
|
|
48
136
|
```
|
|
49
137
|
|
|
50
|
-
|
|
138
|
+
- **`debounce(fn, delay)`**
|
|
139
|
+
- **`throttle(fn, limit)`**
|
|
140
|
+
- **`deepClone(obj)`**
|
|
141
|
+
- **`uuid()`**
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 📜 License
|
|
51
146
|
|
|
52
|
-
|
|
147
|
+
ISC © 2026 [myusufazmi](https://github.com/myusufazmi)
|
package/package.json
CHANGED
package/src/date.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date Utilities
|
|
3
|
+
* Simple and efficient date formatting and manipulation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Basic Date Formatter
|
|
8
|
+
* @param {Date|string|number} date
|
|
9
|
+
* @param {string} pattern - Default: 'YYYY-MM-DD'
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export const formatDate = (date, pattern = "YYYY-MM-DD") => {
|
|
13
|
+
const d = new Date(date);
|
|
14
|
+
if (isNaN(d.getTime())) return "Invalid Date";
|
|
15
|
+
|
|
16
|
+
const map = {
|
|
17
|
+
YYYY: d.getFullYear(),
|
|
18
|
+
MM: String(d.getMonth() + 1).padStart(2, "0"),
|
|
19
|
+
DD: String(d.getDate()).padStart(2, "0"),
|
|
20
|
+
HH: String(d.getHours()).padStart(2, "0"),
|
|
21
|
+
mm: String(d.getMinutes()).padStart(2, "0"),
|
|
22
|
+
ss: String(d.getSeconds()).padStart(2, "0"),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return pattern.replace(/YYYY|MM|DD|HH|mm|ss/g, (matched) => map[matched]);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns a human-readable relative time (e.g., "5 minutes ago")
|
|
30
|
+
* @param {Date|string|number} date
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
export const relativeTime = (date) => {
|
|
34
|
+
const d = new Date(date);
|
|
35
|
+
const now = new Date();
|
|
36
|
+
const diff = Math.floor((now - d) / 1000);
|
|
37
|
+
|
|
38
|
+
if (diff < 60) return "just now";
|
|
39
|
+
if (diff < 3600) return `${Math.floor(diff / 60)} minutes ago`;
|
|
40
|
+
if (diff < 86400) return `${Math.floor(diff / 3600)} hours ago`;
|
|
41
|
+
if (diff < 2592000) return `${Math.floor(diff / 86400)} days ago`;
|
|
42
|
+
|
|
43
|
+
return formatDate(d);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Add days to a date
|
|
48
|
+
* @param {Date|string|number} date
|
|
49
|
+
* @param {number} days
|
|
50
|
+
* @returns {Date}
|
|
51
|
+
*/
|
|
52
|
+
export const addDays = (date, days) => {
|
|
53
|
+
const d = new Date(date);
|
|
54
|
+
d.setDate(d.getDate() + days);
|
|
55
|
+
return d;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check if two dates are the same day
|
|
60
|
+
* @param {Date} d1
|
|
61
|
+
* @param {Date} d2
|
|
62
|
+
* @returns {boolean}
|
|
63
|
+
*/
|
|
64
|
+
export const isSameDay = (d1, d2) => {
|
|
65
|
+
return (
|
|
66
|
+
d1.getFullYear() === d2.getFullYear() &&
|
|
67
|
+
d1.getMonth() === d2.getMonth() &&
|
|
68
|
+
d1.getDate() === d2.getDate()
|
|
69
|
+
);
|
|
70
|
+
};
|
package/src/format.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatting Utilities
|
|
3
|
+
* Tools for number, currency, and string formatting.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Currency Formatter
|
|
8
|
+
* @param {number} amount
|
|
9
|
+
* @param {string} locale - Default: 'id-ID'
|
|
10
|
+
* @param {string} currency - Default: 'IDR'
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export const currency = (amount, locale = "id-ID", currency = "IDR") => {
|
|
14
|
+
return new Intl.NumberFormat(locale, {
|
|
15
|
+
style: "currency",
|
|
16
|
+
currency: currency,
|
|
17
|
+
}).format(amount);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Number Formatter with decimals
|
|
22
|
+
* @param {number} n
|
|
23
|
+
* @param {number} decimals - Default: 0
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export const number = (n, decimals = 0) => {
|
|
27
|
+
return new Intl.NumberFormat("id-ID", {
|
|
28
|
+
minimumFractionDigits: decimals,
|
|
29
|
+
maximumFractionDigits: decimals,
|
|
30
|
+
}).format(n);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Truncate string with ellipsis
|
|
35
|
+
* @param {string} str
|
|
36
|
+
* @param {number} length - Default: 30
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
export const truncate = (str, length = 30) => {
|
|
40
|
+
if (!str) return "";
|
|
41
|
+
return str.length > length ? str.substring(0, length) + "..." : str;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert string to slug (URL friendly)
|
|
46
|
+
* @param {string} str
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
export const slugify = (str) => {
|
|
50
|
+
if (!str) return "";
|
|
51
|
+
return str
|
|
52
|
+
.toLowerCase()
|
|
53
|
+
.trim()
|
|
54
|
+
.replace(/[^\w\s-]/g, "")
|
|
55
|
+
.replace(/[\s_-]+/g, "-")
|
|
56
|
+
.replace(/^-+|-+$/g, "");
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Capitalize first letter of each word
|
|
61
|
+
* @param {string} str
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
64
|
+
export const capitalize = (str) => {
|
|
65
|
+
if (!str) return "";
|
|
66
|
+
return str.replace(/\b\w/g, (l) => l.toUpperCase());
|
|
67
|
+
};
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Utilities
|
|
3
|
+
* Common regex-based validation helpers.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if string is a valid email
|
|
8
|
+
* @param {string} str
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export const isEmail = (str) => {
|
|
12
|
+
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
13
|
+
return re.test(str);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Check if string is a valid URL
|
|
18
|
+
* @param {string} str
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
export const isURL = (str) => {
|
|
22
|
+
try {
|
|
23
|
+
new URL(str);
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Check if string contains only numbers
|
|
32
|
+
* @param {string} str
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
export const isNumeric = (str) => {
|
|
36
|
+
return /^\d+$/.test(str);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Check for strong password
|
|
41
|
+
* (Min 8 chars, 1 uppercase, 1 lowercase, 1 number)
|
|
42
|
+
* @param {string} str
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
export const isStrongPassword = (str) => {
|
|
46
|
+
return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/.test(str);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Check if string is empty or only whitespace
|
|
51
|
+
* @param {string} str
|
|
52
|
+
* @returns {boolean}
|
|
53
|
+
*/
|
|
54
|
+
export const isEmpty = (str) => {
|
|
55
|
+
return !str || str.trim().length === 0;
|
|
56
|
+
};
|