woo-modules 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/main.js +47 -0
- package/package.json +16 -0
- package/test.js +8 -0
package/main.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
export default {
|
|
3
|
+
now(){
|
|
4
|
+
const d = new Date();
|
|
5
|
+
return d.getFullYear()
|
|
6
|
+
+ "-"
|
|
7
|
+
+ ("00" + (d.getMonth() + 1)).slice(-2)
|
|
8
|
+
+ "-"
|
|
9
|
+
+ ("00" + d.getDate()).slice(-2)
|
|
10
|
+
+ " "
|
|
11
|
+
+ ("00" + d.getHours()).slice(-2)
|
|
12
|
+
+ ":"
|
|
13
|
+
+ ("00" + d.getMinutes()).slice(-2)
|
|
14
|
+
+ ":"
|
|
15
|
+
+ ("00" + d.getSeconds()).slice(-2)
|
|
16
|
+
},
|
|
17
|
+
nowex(){
|
|
18
|
+
return this.now() + '.' + ("000" + (new Date()).getMilliseconds()).slice(-3);
|
|
19
|
+
},
|
|
20
|
+
uuid() {
|
|
21
|
+
let result = '';
|
|
22
|
+
for (let i = 0; i < 40; i++) {
|
|
23
|
+
result += crypto.randomInt(0, 10);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
},
|
|
27
|
+
uuidex() {
|
|
28
|
+
const d = new Date();
|
|
29
|
+
return d.getFullYear()
|
|
30
|
+
+ ("00" + (d.getMonth() + 1)).slice(-2)
|
|
31
|
+
+ ("00" + d.getDate()).slice(-2)
|
|
32
|
+
+ ("00" + d.getHours()).slice(-2)
|
|
33
|
+
+ ("00" + d.getMinutes()).slice(-2)
|
|
34
|
+
+ ("00" + d.getSeconds()).slice(-2)
|
|
35
|
+
+ this.uuid();
|
|
36
|
+
},
|
|
37
|
+
hashex(secret, data) {
|
|
38
|
+
const raw = `${secret}:${data}`;
|
|
39
|
+
return crypto.createHash('sha256').update(raw, 'utf8').digest('base64');
|
|
40
|
+
},
|
|
41
|
+
orderid(){
|
|
42
|
+
const d = new Date();
|
|
43
|
+
const date = d.getFullYear() + ("00" + (d.getMonth() + 1)).slice(-2) + ("00" + d.getDate()).slice(-2);
|
|
44
|
+
const num = "0000000000" + crypto.randomInt(0, 10_000_000_000);
|
|
45
|
+
return date + num.slice(-10);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "woo-modules",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Woo Modules",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Woo",
|
|
7
|
+
"Modules"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Woo",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "main.js",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/test.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Woo from "./main.js";
|
|
2
|
+
const SECRET = "000000000000";
|
|
3
|
+
console.log(`Woo.now() = ${Woo.now()}`);
|
|
4
|
+
console.log(`Woo.nowex() = ${Woo.nowex()}`);
|
|
5
|
+
console.log(`Woo.uuid() = ${Woo.uuid()}`);
|
|
6
|
+
console.log(`Woo.uuidex() = ${Woo.uuidex()}`);
|
|
7
|
+
console.log(`Woo.hashex(SECRET, "PASSWORD") = ${Woo.hashex(SECRET, "PASSWORD")}`);
|
|
8
|
+
console.log(`Woo.orderid() = ${Woo.orderid()}`);
|