utills 0.1.2 → 0.1.3
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 +92 -12
- package/dist/core/generateSecret.d.ts +1 -0
- package/dist/core/generateSecret.d.ts.map +1 -0
- package/dist/core/generateSecret.js +1 -0
- package/dist/core/generateSecret.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/randomId.d.ts +1 -0
- package/dist/core/randomId.d.ts.map +1 -0
- package/dist/core/randomId.js +1 -0
- package/dist/core/randomId.js.map +1 -0
- package/dist/core/timeAgo.d.ts +1 -0
- package/dist/core/timeAgo.d.ts.map +1 -0
- package/dist/core/timeAgo.js +1 -0
- package/dist/core/timeAgo.js.map +1 -0
- package/dist/core/timePeriod.d.ts +9 -0
- package/dist/core/timePeriod.d.ts.map +1 -0
- package/dist/core/timePeriod.js +28 -0
- package/dist/core/timePeriod.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# utills
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
|
|
5
5
|
Lightweight, dependency-free utility functions for modern JavaScript and TypeScript projects.
|
|
6
6
|
|
|
7
|
-
This package is designed to be simple
|
|
7
|
+
This package is designed to be **simple**, **secure**, and **developer-friendly**.
|
|
8
8
|
It works in both **Node.js** and **browser environments** and follows modern **ESM standards**.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
👉 **Documentation:** https://utills.vercel.app/
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -18,30 +18,30 @@ It works in both **Node.js** and **browser environments** and follows modern **E
|
|
|
18
18
|
- Zero external dependencies
|
|
19
19
|
- Tree-shaking friendly
|
|
20
20
|
- Browser & Node.js support
|
|
21
|
-
-
|
|
21
|
+
- Crypto-based secure utilities
|
|
22
|
+
- Fully unit-tested with **Vitest**
|
|
22
23
|
|
|
23
24
|
---
|
|
24
25
|
|
|
25
26
|
## 📦 Installation
|
|
26
27
|
|
|
27
28
|
```bash
|
|
28
|
-
npm install
|
|
29
|
+
npm install utills
|
|
29
30
|
```
|
|
30
31
|
|
|
31
32
|
# Usage
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
|
-
|
|
35
35
|
import {
|
|
36
36
|
randomId,
|
|
37
37
|
timeAgo,
|
|
38
|
-
} from "
|
|
38
|
+
} from "utills";
|
|
39
39
|
|
|
40
40
|
randomId();
|
|
41
41
|
timeAgo(Date.now() - 60000);
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## Example Utilities
|
|
45
45
|
|
|
46
46
|
| Method | Parameters | Returns | Description |
|
|
47
47
|
| ------------------ | ----------------- | -------- | ------------------------------------------------------------ |
|
|
@@ -49,9 +49,33 @@ timeAgo(Date.now() - 60000);
|
|
|
49
49
|
| **generateSecret** | `length?` | `string` | Generates a cryptographically secure secret token. |
|
|
50
50
|
| **timeAgo** | `date`, `locale?` | `string` | Returns human-readable relative time (e.g. "2 minutes ago"). |
|
|
51
51
|
|
|
52
|
+
## Testing
|
|
53
|
+
|
|
54
|
+
This project uses Vitest for unit testing.
|
|
55
|
+
|
|
56
|
+
All utility functions must include tests, even if they generate random values.
|
|
57
|
+
|
|
58
|
+
Run test
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm run test
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Testing rules:
|
|
65
|
+
|
|
66
|
+
- Each utility must have a corresponding test file
|
|
67
|
+
- Random-based utilities should be tested using:
|
|
68
|
+
- output length
|
|
69
|
+
- output type
|
|
70
|
+
- allowed character sets
|
|
71
|
+
- error cases
|
|
72
|
+
- Edge cases must be covered
|
|
73
|
+
|
|
52
74
|
## Contributing
|
|
53
75
|
|
|
54
|
-
Contributions are welcome and appreciated
|
|
76
|
+
Contributions are welcome and appreciated!
|
|
77
|
+
|
|
78
|
+
Before contributing, please read the guidelines below carefully.
|
|
55
79
|
|
|
56
80
|
## How to contribute
|
|
57
81
|
|
|
@@ -76,6 +100,12 @@ git checkout -b feature/new-utility
|
|
|
76
100
|
src/core/
|
|
77
101
|
```
|
|
78
102
|
|
|
103
|
+
Rules
|
|
104
|
+
|
|
105
|
+
- One utility per file
|
|
106
|
+
- Must support both JS & TS
|
|
107
|
+
- Must handle invalid inputs properly
|
|
108
|
+
|
|
79
109
|
5: Export it from:
|
|
80
110
|
|
|
81
111
|
```bash
|
|
@@ -84,13 +114,58 @@ src/core/index.ts
|
|
|
84
114
|
|
|
85
115
|
6: Build and test
|
|
86
116
|
|
|
117
|
+
Add tests using Vitest for your utility.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm run test
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Pull requests **without tests will not be accepted**
|
|
124
|
+
|
|
125
|
+
7: Update Docs (Required)
|
|
126
|
+
|
|
127
|
+
This project has a docs website.
|
|
128
|
+
|
|
129
|
+
After adding a utility, you must update the docs data file:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
docs/src/api/methods.data.js
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Add your utility following the existing pattern, including:
|
|
136
|
+
|
|
137
|
+
- name
|
|
138
|
+
- description
|
|
139
|
+
- parameters
|
|
140
|
+
- return type
|
|
141
|
+
- example usage
|
|
142
|
+
|
|
143
|
+
Example structure:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
yourUtility: {
|
|
147
|
+
name: "yourUtility",
|
|
148
|
+
description: "What this utility does",
|
|
149
|
+
params: [],
|
|
150
|
+
returns: "string",
|
|
151
|
+
example: `import { yourUtility } from "utills"
|
|
152
|
+
|
|
153
|
+
yourUtility();`
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
This data is used to render the API documentation UI
|
|
158
|
+
|
|
159
|
+
8: Build and verify
|
|
160
|
+
|
|
87
161
|
```bash
|
|
88
162
|
npm run build
|
|
163
|
+
npm run test
|
|
89
164
|
```
|
|
90
165
|
|
|
91
|
-
|
|
166
|
+
9: Commit & Open PR
|
|
92
167
|
|
|
93
|
-
|
|
168
|
+
Use clear commit messages and open a Pull Request with a proper description.
|
|
94
169
|
|
|
95
170
|
## Contribution Guideline
|
|
96
171
|
|
|
@@ -99,6 +174,8 @@ npm run build
|
|
|
99
174
|
- Use native APIs where possible
|
|
100
175
|
- Handle edge cases properly
|
|
101
176
|
- Keep code clean and readable
|
|
177
|
+
- Tests are mandatory
|
|
178
|
+
- Utilities should be reusable & generic
|
|
102
179
|
|
|
103
180
|
## Roadmap
|
|
104
181
|
|
|
@@ -110,3 +187,6 @@ npm run build
|
|
|
110
187
|
## License
|
|
111
188
|
|
|
112
189
|
MIT License © Safayet Rahman
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSecret.d.ts","sourceRoot":"","sources":["../../src/core/generateSecret.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAwB1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSecret.js","sourceRoot":"","sources":["../../src/core/generateSecret.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB,EAAE;IAChD,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,gEAAgE,CAAA;IAChF,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAA;IAEpC,mCAAmC;IACnC,MAAM,SAAS,GACb,OAAO,MAAM,KAAK,WAAW;QAC3B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,aAAa;YACb,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAA;IAEjC,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IAC5C,SAAS,CAAC,eAAe,CAAC,YAAY,CAAC,CAAA;IAEvC,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/core/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/core/randomId.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomId.d.ts","sourceRoot":"","sources":["../../src/core/randomId.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAQD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM,CA4B9D"}
|
package/dist/core/randomId.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomId.js","sourceRoot":"","sources":["../../src/core/randomId.ts"],"names":[],"mappings":"AAuBA,MAAM,eAAe,GACnB,gEAAgE,CAAA;AAElE,MAAM,YAAY,GAChB,2DAA2D,CAAA;AAE7D;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,UAA2B,EAAE;IACpD,MAAM,EACJ,MAAM,GAAG,EAAE,EACX,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,eAAe,GACxD,GAAG,OAAO,CAAA;IAEX,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAA;IAClC,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,mCAAmC;IACnC,MAAM,SAAS,GACb,OAAO,MAAM,KAAK,WAAW;QAC3B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,aAAa;YACb,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAA;IAEjC,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IAC5C,SAAS,CAAC,eAAe,CAAC,YAAY,CAAC,CAAA;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAA;IAClD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/core/timeAgo.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeAgo.d.ts","sourceRoot":"","sources":["../../src/core/timeAgo.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC5B,MAAM,GAAE,MAAa,GACpB,MAAM,CA+BR"}
|
package/dist/core/timeAgo.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeAgo.js","sourceRoot":"","sources":["../../src/core/timeAgo.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CACrB,IAA4B,EAC5B,SAAiB,IAAI;IAErB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;IAChC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IAEtB,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,CAAA;IAEhD,IAAI,IAAI,GAAG,IAAI;QAAE,OAAO,UAAU,CAAA;IAElC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;IAEpE,MAAM,KAAK,GAA4C;QACrD,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;QACnC,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACnC,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QAC5B,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;QACxB,CAAC,QAAQ,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,CAAC,QAAQ,EAAE,IAAI,CAAC;KACjB,CAAA;IAED,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,CAAA;QACnC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACf,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current time period of the day
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* timePeriod() // "morning"
|
|
6
|
+
* timePeriod(new Date("2025-01-01T14:00:00")) // "afternoon"
|
|
7
|
+
*/
|
|
8
|
+
export declare function timePeriod(date?: Date): "morning" | "afternoon" | "evening" | "night";
|
|
9
|
+
//# sourceMappingURL=timePeriod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timePeriod.d.ts","sourceRoot":"","sources":["../../src/core/timePeriod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,IAAiB,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAwBjG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current time period of the day
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* timePeriod() // "morning"
|
|
6
|
+
* timePeriod(new Date("2025-01-01T14:00:00")) // "afternoon"
|
|
7
|
+
*/
|
|
8
|
+
export function timePeriod(date = new Date()) {
|
|
9
|
+
if (!(date instanceof Date) || isNaN(date.getTime())) {
|
|
10
|
+
throw new Error("timePeriod: invalid date");
|
|
11
|
+
}
|
|
12
|
+
const hour = date.getHours();
|
|
13
|
+
// morning — 5:00 AM to 11:59 AM
|
|
14
|
+
if (hour >= 5 && hour < 12) {
|
|
15
|
+
return "morning";
|
|
16
|
+
}
|
|
17
|
+
// afternoon — 12:00 PM to 4:59 PM
|
|
18
|
+
if (hour >= 12 && hour < 17) {
|
|
19
|
+
return "afternoon";
|
|
20
|
+
}
|
|
21
|
+
// evening — 5:00 PM to 8:59 PM
|
|
22
|
+
if (hour >= 17 && hour < 21) {
|
|
23
|
+
return "evening";
|
|
24
|
+
}
|
|
25
|
+
// night — 9:00 PM to 4:59 AM
|
|
26
|
+
return "night";
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=timePeriod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timePeriod.js","sourceRoot":"","sources":["../../src/core/timePeriod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,OAAa,IAAI,IAAI,EAAE;IAChD,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC7C,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;IAE5B,gCAAgC;IAChC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,kCAAkC;IAClC,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC;QAC5B,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,+BAA+B;IAC/B,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,6BAA6B;IAC7B,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utills",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "tsc"
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"test": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.9.3"
|
|
15
19
|
}
|
|
16
20
|
}
|