catto.js 0.0.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.
@@ -0,0 +1,33 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: actions/setup-node@v3
16
+ with:
17
+ node-version: 16
18
+ - run: npm ci
19
+ - run: npm test
20
+
21
+ publish-npm:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v3
26
+ - uses: actions/setup-node@v3
27
+ with:
28
+ node-version: 16
29
+ registry-url: https://registry.npmjs.org/
30
+ - run: npm ci
31
+ - run: npm publish
32
+ env:
33
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/AuthClient.js ADDED
@@ -0,0 +1,141 @@
1
+ var request = require("./request");
2
+ var User = require("./User");
3
+ module.exports = class {
4
+ constructor(options) {
5
+ this.options = Object.assign({
6
+ "server": null,
7
+ "scopes": [],
8
+ "id": "",
9
+ "secret": "",
10
+ "tokenType": "",
11
+ "accessToken": "",
12
+ "expires": new Date(0),
13
+ "refreshToken": "",
14
+ "apiv": 10,
15
+ "redirectPath": ""
16
+ }, options || {});
17
+ this.user = null;
18
+ }
19
+ get available() {
20
+ return (this.options.server
21
+ && this.options.scopes.length > 0
22
+ && this.options.id
23
+ && this.options.secret
24
+ && this.options.tokenType
25
+ && this.options.accessToken
26
+ && this.options.expires
27
+ && this.options.refreshToken
28
+ && this.options.apiv
29
+ && this.options.redirectPath
30
+ );
31
+ }
32
+ get redirectUri() {
33
+ return `http${((this.options.server.options.ssl || this.options.server.options.sslProxy) ? "s" : "")}://${this.options.server.options.domain}${this.options.redirectPath}`;
34
+ }
35
+ get link() {
36
+ return `https://discord.com/oauth2/authorize?client_id=${encodeURIComponent(this.options.id)}&scope=${encodeURIComponent(this.options.scopes.join(" "))}&redirect_uri=${encodeURIComponent(this.redirectUri)}&response_type=code&prompt=none`;
37
+ }
38
+ redirect(res) {
39
+ res.redirect(this.link);
40
+ }
41
+ async auth(req) {
42
+ try {
43
+ var result = await request.post({
44
+ "url": "https://discord.com/api/oauth2/token",
45
+ "form": {
46
+ "client_id": this.options.id,
47
+ "client_secret": this.options.secret,
48
+ "grant_type": "authorization_code",
49
+ "code": req.query.code,
50
+ "redirect_uri": this.redirectUri
51
+ }
52
+ });
53
+ } catch(e) {
54
+ return !1;
55
+ }
56
+ if (result.response.statusCode == 200) {
57
+ this.writeToken(result.body);
58
+ return !0;
59
+ } else {
60
+ return !1;
61
+ }
62
+ }
63
+ async renew(req) {
64
+ if (!this.available) {
65
+ throw new Error(`renew: Not available.`);
66
+ }
67
+ try {
68
+ var result = await request.post({
69
+ "url": "https://discord.com/api/oauth2/token",
70
+ "form": {
71
+ "client_id": this.options.id,
72
+ "client_secret": this.options.secret,
73
+ "grant_type": "refresh_token",
74
+ "refreshToken": this.options.refreshToken
75
+ }
76
+ });
77
+ } catch(e) {
78
+ return !1;
79
+ }
80
+ if (result.response.statusCode == 200) {
81
+ this.writeToken(result.body);
82
+ return !0;
83
+ } else {
84
+ return !1;
85
+ }
86
+ }
87
+ async revoke(req) {
88
+ if (!this.available) {
89
+ throw new Error(`revoke: Not available.`);
90
+ }
91
+ try {
92
+ var result = await request.post({
93
+ "url": "https://discord.com/api/oauth2/token/revoke",
94
+ "form": {
95
+ "client_id": this.options.id,
96
+ "client_secret": this.options.secret,
97
+ "token": this.options.accessToken
98
+ }
99
+ });
100
+ } catch(e) {
101
+ return !1;
102
+ }
103
+ if (result.response.statusCode == 200) {
104
+ this.options.accessToken = "";
105
+ this.options.refreshToken = "";
106
+ return !0;
107
+ } else {
108
+ return !1;
109
+ }
110
+ }
111
+ async sync() {
112
+ if (!this.available) {
113
+ throw new Error(`sync: Not available.`);
114
+ }
115
+ try {
116
+ var result = await request.get({
117
+ "url": `https://discord.com/api/v${this.options.apiv}/users/@me`,
118
+ "headers": {
119
+ "Authorization": `${this.options.tokenType} ${this.options.accessToken}`
120
+ }
121
+ });
122
+ } catch(e) {
123
+ return !1;
124
+ }
125
+ if (result.response.statusCode == 200) {
126
+ this.user = new User(result.body);
127
+ return !0;
128
+ } else {
129
+ return !1;
130
+ }
131
+ }
132
+ writeToken(body) {
133
+ this.options.tokenType = body.token_type;
134
+ this.options.accessToken = body.access_token;
135
+ this.options.expires = new Date(Date.now() +(body.expires_in *1e3));
136
+ this.options.refreshToken = body.refresh_token;
137
+ }
138
+ get expired() {
139
+ return (Date.now() >= this.options.expires.getTime());
140
+ }
141
+ };
package/Base64.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ "encode": text => {
3
+ return Buffer.from(text, "utf-8").toString("base64")
4
+ },
5
+ "decode": text => {
6
+ return Buffer.from(text, "base64").toString("utf-8")
7
+ }
8
+ };
package/GitHub.js ADDED
@@ -0,0 +1,43 @@
1
+ var request = require("./request");
2
+ var Base64 = require("./Base64");
3
+ module.exports = class {
4
+ constructor(options) {
5
+ this.options = Object.assign({
6
+ "token": "",
7
+ "username": "",
8
+ "repository": "",
9
+ "message": "cattojs"
10
+ }, options || {});
11
+ }
12
+ async read(file) {
13
+ var value = Base64.decode((await request.get({
14
+ "url": `https://api.github.com/repos/${this.options.username}/${this.options.repository}/contents/${file}`,
15
+ "headers": {
16
+ "User-Agent": this.options.username,
17
+ "Authorization": `token ${this.options.token}`
18
+ }
19
+ })).body.content);
20
+ try {
21
+ value = JSON.parse(value);
22
+ } catch(e) {}
23
+ return value;
24
+ }
25
+ async write(file, value) {
26
+ if (typeof value === "object") {
27
+ value = JSON.stringify(value);
28
+ }
29
+ await request.put({
30
+ "url": `https://api.github.com/repos/${this.options.username}/${this.options.repository}/contents/${file}`,
31
+ "headers": {
32
+ "User-Agent": this.options.username,
33
+ "Authorization": `token ${this.options.token}`
34
+ },
35
+ "json": !0,
36
+ "body": {
37
+ "content": Base64.encode(value),
38
+ "message": this.options.message
39
+ }
40
+ });
41
+ return !0;
42
+ }
43
+ };
package/HTML.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ "disable": text => {
3
+ return text.split("<").join("&lt;").split(">").join("&gt;");
4
+ }
5
+ };
package/LICENSE ADDED
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
package/README.md ADDED
File without changes
package/Server.js ADDED
@@ -0,0 +1,151 @@
1
+ /** @module Server */
2
+
3
+ var events = require("events");
4
+ var express = require("express");
5
+ var expressWs = require("express-ws");
6
+ var http = require("http");
7
+ var https = require("https");
8
+ var bodyParser = require("body-parser");
9
+ var urlencodedParser = bodyParser.urlencoded({"extended":!0});
10
+ var jsonParser = bodyParser.json();
11
+ var fs = require("fs");
12
+ var path = require("path");
13
+ var session = require("express-session");
14
+ var FileStore = require("session-file-store")(session);
15
+ if (typeof EventEmitter !== "undefined") {} else {
16
+ var { EventEmitter } = events;
17
+ }
18
+
19
+ /**
20
+ * Server.
21
+ * @class
22
+ * @param {object} options
23
+ */
24
+ class Server extends EventEmitter {
25
+ constructor(options) {
26
+ super();
27
+ this.options = Object.assign({
28
+ "domain": null,
29
+ "port": (process.env.PORT || 80),
30
+ "ssl": !1,
31
+ "sslProxy": !1,
32
+ "cert": null,
33
+ "key": null,
34
+ "serverOptions": {},
35
+ "expressWsiOptions": {},
36
+ "secret": null,
37
+ "storeOptions": {},
38
+ "ejs": !1
39
+ }, options || {});
40
+ this.app = express();
41
+ if (this.ssl) {
42
+ this.server = https.createServer(Object.assign(this.options.serverOptions, {
43
+ "cert": fs.readFileSync(path.join(__dirname, "..", "..", this.options.cert), "utf8"),
44
+ "key": fs.readFileSync(path.join(__dirname, "..", "..", this.options.key), "utf8")
45
+ }), this.app);
46
+ } else {
47
+ this.server = http.createServer(this.options.serverOptions, this.app);
48
+ }
49
+ this.expressWsi = expressWs(this.app, this.server, this.options.expressWsiOptions);
50
+ this.app.set("trust proxy", !0);
51
+ this.app.use(urlencodedParser);
52
+ this.app.use(jsonParser);
53
+ if (this.options.ejs) {
54
+ this.app.set("view engine", "ejs");
55
+ }
56
+ if (this.options.secret) {
57
+ this.app.use(session({
58
+ "store": new FileStore(this.options.storeOptions),
59
+ "secret": this.options.secret,
60
+ "cookie": {
61
+ "secure": (this.options.ssl || this.options.sslProxy)
62
+ }
63
+ }));
64
+ }
65
+ }
66
+ run() {
67
+ this.server.listen(this.options.port, () => {
68
+ this.emit("running");
69
+ });
70
+ return this;
71
+ }
72
+ all(...args) {
73
+ this.app.all(...args);
74
+ return this;
75
+ }
76
+ delete(...args) {
77
+ this.app.delete(...args);
78
+ return this;
79
+ }
80
+ disable(...args) {
81
+ this.app.disable(...args);
82
+ return this;
83
+ }
84
+ disabled(...args) {
85
+ this.app.disabled(...args);
86
+ return this;
87
+ }
88
+ enable(...args) {
89
+ this.app.enable(...args);
90
+ return this;
91
+ }
92
+ enabled(...args) {
93
+ this.app.enabled(...args);
94
+ return this;
95
+ }
96
+ engine(...args) {
97
+ this.app.engine(...args);
98
+ return this;
99
+ }
100
+ get(...args) {
101
+ this.app.get(...args);
102
+ return this;
103
+ }
104
+ param(...args) {
105
+ this.app.param(...args);
106
+ return this;
107
+ }
108
+ path(...args) {
109
+ this.app.path(...args);
110
+ return this;
111
+ }
112
+ post(...args) {
113
+ this.app.post(...args);
114
+ return this;
115
+ }
116
+ put(...args) {
117
+ this.app.put(...args);
118
+ return this;
119
+ }
120
+ render(...args) {
121
+ this.app.render(...args);
122
+ return this;
123
+ }
124
+ route(...args) {
125
+ this.app.route(...args);
126
+ return this;
127
+ }
128
+ set(...args) {
129
+ this.app.set(...args);
130
+ return this;
131
+ }
132
+ use(...args) {
133
+ this.app.use(...args);
134
+ return this;
135
+ }
136
+ ws(...args) {
137
+ this.app.ws(...args);
138
+ return this;
139
+ }
140
+ static(folder) {
141
+ this.app.use(express.static(path.join(__dirname,"..","..",folder)));
142
+ return this;
143
+ }
144
+ static fa(text) {
145
+ return (req,res) => {
146
+ res.end(text);
147
+ };
148
+ }
149
+ }
150
+
151
+ module.exports = Server;
package/User.js ADDED
@@ -0,0 +1,141 @@
1
+ module.exports = class {
2
+ constructor(options) {
3
+ this.options = Object.assign({
4
+ "id": "",
5
+ "username": "",
6
+ "avatar": "",
7
+ "discriminator": "",
8
+ "public_flags": 0,
9
+ "flags": 0,
10
+ "banner": "",
11
+ "banner_color": "",
12
+ "accent_color": 0,
13
+ "locale": "",
14
+ "mfa_enabled": !1,
15
+ "premium_type": 0,
16
+ "email": "",
17
+ "verified": !1,
18
+ "bot": !1,
19
+ "system": !1
20
+ }, options || {});
21
+ }
22
+ get id() {
23
+ return this.options.id;
24
+ }
25
+ get name() {
26
+ return this.options.username;
27
+ }
28
+ get avatarHash() {
29
+ return this.options.avatar;
30
+ }
31
+ get avatar() {
32
+ var avataru = this.avatarHash;
33
+ if (avataru.startsWith("a_")) {
34
+ avataru = `https://cdn.discordapp.com/avatars/${avataru}.gif?size=4096`;
35
+ } else if (avataru) {
36
+ avataru = `https://cdn.discordapp.com/avatars/${avataru}.webp?size=4096`;
37
+ } else {
38
+ avataru = `https://cdn.discordapp.com/embed/avatars/${(parseInt(this.discrim) % 5).toString()}.png`;
39
+ }
40
+ return avataru;
41
+ }
42
+ get discrim() {
43
+ return this.options.discriminator;
44
+ }
45
+ get tag() {
46
+ return `${this.name}#${this.discrim}`;
47
+ }
48
+ get badges() {
49
+ var i = 23;
50
+ var p = this.options.badges;
51
+ var f = [];
52
+ while (--i > -1) {
53
+ if (![21, 20, 15, 13, 12, 11, 5, 4].includes(i) && p >= (1 << i)) {
54
+ p -= (1 << i);
55
+ f.push(i);
56
+ }
57
+ }
58
+ var fl = [
59
+ "STAFF",
60
+ "PARTNER",
61
+ "HYPESQUAD",
62
+ "BUG_HUNTER_LEVEL_1",
63
+ null,
64
+ null,
65
+ "HYPESQUAD_ONLINE_HOUSE_1",
66
+ "HYPESQUAD_ONLINE_HOUSE_2",
67
+ "HYPESQUAD_ONLINE_HOUSE_3",
68
+ "PREMIUM_EARLY_SUPPORTER",
69
+ "TEAM_PSEUDO_USER",
70
+ null,
71
+ null,
72
+ null,
73
+ "BUG_HUNTER_LEVEL_2",
74
+ null,
75
+ "VERIFIED_BOT",
76
+ "VERIFIED_DEVELOPER",
77
+ "CERTIFIED_MODERATOR",
78
+ "BOT_HTTP_INTERACTIONS",
79
+ null,
80
+ null,
81
+ "ACTIVE_DEVELOPER"
82
+ ];
83
+ return f.map(n => fl[n]);
84
+ }
85
+ get bannerHash() {
86
+ return this.options.banner;
87
+ }
88
+ get bannerColor() {
89
+ return this.options.banner_color;
90
+ }
91
+ get banner() {
92
+ var banneru = this.bannerHash;
93
+ if (banneru.startsWith("a_")) {
94
+ banneru = `https://cdn.discordapp.com/avatars/${banneru}.gif?size=4096`;
95
+ } else if (banneru) {
96
+ banneru = `https://cdn.discordapp.com/avatars/${banneru}.webp?size=4096`;
97
+ } else {
98
+ banneru = this.bannerColor || this.accentColor;
99
+ }
100
+ return banneru;
101
+ }
102
+ get accentColor() {
103
+ return this.options.accent_color;
104
+ }
105
+ get lang() {
106
+ return this.options.locale;
107
+ }
108
+ get isRussian() {
109
+ return (this.lang == "ru");
110
+ }
111
+ get is2FAEnabled() {
112
+ return this.options.mfa_enabled;
113
+ }
114
+ get hasNitro() {
115
+ return (this.isBot || this.options.premium_type > 0);
116
+ }
117
+ get hasNitroClassic() {
118
+ return (this.options.premium_type == 1);
119
+ }
120
+ get hasNitroBoost() {
121
+ return (this.isBot || this.options.premium_type == 2);
122
+ }
123
+ get hasNitroBasic() {
124
+ return (this.options.premium_type == 3);
125
+ }
126
+ get email() {
127
+ return this.options.email;
128
+ }
129
+ get isEmailVerified() {
130
+ return this.options.verified;
131
+ }
132
+ get isBot() {
133
+ return this.options.bot;
134
+ }
135
+ get isBotVerified() {
136
+ return this.badges.has("VERIFIED_BOT");
137
+ }
138
+ get isSystem() {
139
+ return this.options.system;
140
+ }
141
+ };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ var mod = {};
2
+ ["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64"].forEach(part => {
3
+ mod[part] = require(`./${part}`);
4
+ });
5
+ module.exports = mod;
package/index.test.js ADDED
@@ -0,0 +1,27 @@
1
+ var cattojs = require("./index");
2
+ test("random float", () => {
3
+ expect(typeof cattojs.random.float(1, 3)).toBe("number");
4
+ });
5
+ test("random int", () => {
6
+ expect(typeof cattojs.random.int(1, 3)).toBe("number");
7
+ });
8
+ test("random range", () => {
9
+ expect(typeof cattojs.random.range(1, 3)).toBe("number");
10
+ });
11
+ test("random bool", () => {
12
+ expect(typeof cattojs.random.bool()).toBe("boolean");
13
+ });
14
+ test("html disable", () => {
15
+ expect(cattojs.HTML.disable("<>")).toBe("&lt;&gt;");
16
+ });
17
+ test("array remove", () => {
18
+ var arr = ["a", "b", "c"];
19
+ expect(arr.remove(1)).toBe("b");
20
+ expect(arr).toMatchObject(["a", "c"]);
21
+ });
22
+ test("base64 encode", () => {
23
+ expect(cattojs.Base64.encode("Test.")).toBe("VGVzdC4=");
24
+ });
25
+ test("base64 decode", () => {
26
+ expect(cattojs.Base64.decode("VGVzdC4=")).toBe("Test.");
27
+ });
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "catto.js",
3
+ "version": "0.0.1",
4
+ "description": "Universal module for everything.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/BoryaGames/catto.js.git"
12
+ },
13
+ "keywords": [
14
+ "catto",
15
+ "cat",
16
+ "js",
17
+ "discord",
18
+ "discord.js",
19
+ "express",
20
+ "passport",
21
+ "authorization",
22
+ "auth",
23
+ "discord-auth",
24
+ "kitten",
25
+ "cats",
26
+ "kittens",
27
+ "cattoes",
28
+ "easy",
29
+ "slash",
30
+ "random"
31
+ ],
32
+ "author": "cat1234",
33
+ "license": "ISC",
34
+ "bugs": {
35
+ "url": "https://github.com/BoryaGames/catto.js/issues"
36
+ },
37
+ "homepage": "https://github.com/BoryaGames/catto.js#readme",
38
+ "devDependencies": {
39
+ "jest": "^29.4.1"
40
+ },
41
+ "dependencies": {
42
+ "body-parser": "^1.20.1",
43
+ "ejs": "^3.1.8",
44
+ "express": "^4.18.2",
45
+ "express-session": "^1.17.3",
46
+ "express-ws": "^5.0.2",
47
+ "request": "^2.88.2",
48
+ "session-file-store": "^1.5.0"
49
+ }
50
+ }
package/random.js ADDED
@@ -0,0 +1,15 @@
1
+ function float(min, max) {
2
+ return (Math.random() *(max -min) +min);
3
+ }
4
+ function int(min, max) {
5
+ return Math.floor(Math.random() *(max -min) +min);
6
+ }
7
+ function range(min, max) {
8
+ return Math.floor(Math.random() *(max -min +1) +min);
9
+ }
10
+ function bool() {
11
+ return !Math.floor(Math.random() *2);
12
+ }
13
+ module.exports = {
14
+ float, int, range, bool
15
+ };
package/request.js ADDED
@@ -0,0 +1,50 @@
1
+ /** @module request */
2
+
3
+ var request = require("request");
4
+
5
+ function wrap(method, options) {
6
+ return new Promise((res, rej) => {
7
+ request[method](options, (error, response, body) => {
8
+ if (error) {
9
+ return rej(error);
10
+ }
11
+ try {
12
+ body = JSON.parse(body);
13
+ } catch(e) {}
14
+ res({
15
+ response, body
16
+ });
17
+ });
18
+ });
19
+ }
20
+
21
+ /**
22
+ * GET request.
23
+ * @param {object} options
24
+ * @return {promise}
25
+ */
26
+ function get(options) {
27
+ return wrap("get", options);
28
+ }
29
+
30
+ /**
31
+ * POST request.
32
+ * @param {object} options
33
+ * @return {promise}
34
+ */
35
+ function post(options) {
36
+ return wrap("post", options);
37
+ }
38
+
39
+ /**
40
+ * PUT request.
41
+ * @param {object} options
42
+ * @return {promise}
43
+ */
44
+ function put(options) {
45
+ return wrap("put", options);
46
+ }
47
+
48
+ module.exports = {
49
+ get, post, put
50
+ };
package/utils.js ADDED
@@ -0,0 +1,3 @@
1
+ Array.prototype.remove = function(index) {
2
+ return this.splice(index, 1)[0];
3
+ };