@badstagram/urban-dictionary 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/LICENCE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Badstagram
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @badstagram/urban-dictionary
2
+
3
+ A simple [Urban Dictionary](https://urbandictionary.com) API wrapper
4
+
5
+ <details>
6
+ <summary>Define a word</summary>
7
+
8
+ ```ts
9
+ const client = new UrbanDictionaryClient();
10
+
11
+ console.log(client.define("term"));
12
+ /**
13
+ [{
14
+ author: "...",
15
+ current_vote: "",
16
+ defid: ...,
17
+ definition: "...",
18
+ example: "...",
19
+ permalink: "...",
20
+ thumbs_down: 0,
21
+ thumbs_up: 0,
22
+ word: "...",
23
+ written_on: "...",
24
+ }, ...]
25
+ **/
26
+ ```
27
+
28
+ </details>
29
+
30
+ <details>
31
+ <summary>Get Auto Completion</summary>
32
+
33
+ ```ts
34
+ const client = new UrbanDictionaryClient();
35
+
36
+ console.log(client.autoComplete("term"));
37
+ /**
38
+ [{
39
+ preview: '...',
40
+ term: '...'
41
+ }, ...]
42
+ **/
43
+ ```
44
+
45
+ </details>
46
+
47
+ </details>
48
+
49
+ <details>
50
+ <summary>Get a random definition</summary>
51
+
52
+ ```ts
53
+ const client = new UrbanDictionaryClient();
54
+
55
+ console.log(client.random()); // Also supports an optional 'count' parameter
56
+ /**
57
+ [{
58
+ author: "...",
59
+ current_vote: "",
60
+ defid: ...,
61
+ definition: "...",
62
+ example: "...",
63
+ permalink: "...",
64
+ thumbs_down: 0,
65
+ thumbs_up: 0,
66
+ word: "...",
67
+ written_on: "...",
68
+ }, ...]
69
+ **/
70
+ ```
71
+
72
+ </details>
package/dist/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+
2
+ //#region src/lib/util.ts
3
+ function pickRandom(arr) {
4
+ return arr[Math.floor(Math.random() * arr.length)];
5
+ }
6
+
7
+ //#endregion
8
+ //#region src/lib/UrbanDictionaryClient.ts
9
+ var UrbanDictionaryClient = class {
10
+ BASE_URL;
11
+ /**
12
+ * Creates a UrbanDictionaryClient
13
+ *
14
+ */
15
+ constructor() {
16
+ this.BASE_URL = new URL("http://api.urbandictionary.com/v0");
17
+ }
18
+ /**
19
+ * Defines a term
20
+ * @param term The term to define
21
+ * @returns The definitions of the term
22
+ */
23
+ async define(term) {
24
+ const url = new URL(`${this.BASE_URL}/define`);
25
+ url.searchParams.append("term", term);
26
+ return (await fetch(url).then((r) => r.json())).list;
27
+ }
28
+ async autoComplete(term) {
29
+ const url = new URL(`${this.BASE_URL}/autocomplete-extra`);
30
+ url.searchParams.append("term", term);
31
+ return (await fetch(url).then((r) => r.json())).results;
32
+ }
33
+ /**
34
+ *
35
+ * @returns A random definition
36
+ */
37
+ async random(count = 1) {
38
+ const url = new URL(`${this.BASE_URL}/random`);
39
+ const res = await fetch(url).then((r) => r.json());
40
+ const results = [];
41
+ for (let i = 0; i < count; i++) results.push(pickRandom(res.list));
42
+ return results;
43
+ }
44
+ };
45
+
46
+ //#endregion
47
+ exports.UrbanDictionaryClient = UrbanDictionaryClient;
@@ -0,0 +1,49 @@
1
+ //#region src/lib/interfaces/UrbanDictionaryResult.d.ts
2
+ interface UrbanDictionary {
3
+ list: Array<UrbanDictionaryList>;
4
+ }
5
+ interface UrbanDictionaryList {
6
+ author: string;
7
+ current_vote: string;
8
+ defid: number;
9
+ definition: string;
10
+ example: string;
11
+ permalink: string;
12
+ thumbs_down: number;
13
+ thumbs_up: number;
14
+ word: string;
15
+ written_on: Date;
16
+ }
17
+ //#endregion
18
+ //#region src/lib/UrbanDictionaryClient.d.ts
19
+ declare class UrbanDictionaryClient {
20
+ private readonly BASE_URL;
21
+ /**
22
+ * Creates a UrbanDictionaryClient
23
+ *
24
+ */
25
+ constructor();
26
+ /**
27
+ * Defines a term
28
+ * @param term The term to define
29
+ * @returns The definitions of the term
30
+ */
31
+ define(term: string): Promise<Array<UrbanDictionaryList>>;
32
+ autoComplete(term: string): Promise<UrbanDictionaryAutoCompleteResults[]>;
33
+ /**
34
+ *
35
+ * @returns A random definition
36
+ */
37
+ random(count?: number): Promise<UrbanDictionaryList[]>;
38
+ }
39
+ //#endregion
40
+ //#region src/lib/interfaces/UrbanDictionaryAutoComplete.d.ts
41
+ interface UrbanDictionaryAutoComplete {
42
+ results: Array<UrbanDictionaryAutoCompleteResults>;
43
+ }
44
+ interface UrbanDictionaryAutoCompleteResults {
45
+ preview: string;
46
+ term: string;
47
+ }
48
+ //#endregion
49
+ export { UrbanDictionary, UrbanDictionaryAutoComplete, UrbanDictionaryAutoCompleteResults, UrbanDictionaryClient, UrbanDictionaryList };
@@ -0,0 +1,49 @@
1
+ //#region src/lib/interfaces/UrbanDictionaryResult.d.ts
2
+ interface UrbanDictionary {
3
+ list: Array<UrbanDictionaryList>;
4
+ }
5
+ interface UrbanDictionaryList {
6
+ author: string;
7
+ current_vote: string;
8
+ defid: number;
9
+ definition: string;
10
+ example: string;
11
+ permalink: string;
12
+ thumbs_down: number;
13
+ thumbs_up: number;
14
+ word: string;
15
+ written_on: Date;
16
+ }
17
+ //#endregion
18
+ //#region src/lib/UrbanDictionaryClient.d.ts
19
+ declare class UrbanDictionaryClient {
20
+ private readonly BASE_URL;
21
+ /**
22
+ * Creates a UrbanDictionaryClient
23
+ *
24
+ */
25
+ constructor();
26
+ /**
27
+ * Defines a term
28
+ * @param term The term to define
29
+ * @returns The definitions of the term
30
+ */
31
+ define(term: string): Promise<Array<UrbanDictionaryList>>;
32
+ autoComplete(term: string): Promise<UrbanDictionaryAutoCompleteResults[]>;
33
+ /**
34
+ *
35
+ * @returns A random definition
36
+ */
37
+ random(count?: number): Promise<UrbanDictionaryList[]>;
38
+ }
39
+ //#endregion
40
+ //#region src/lib/interfaces/UrbanDictionaryAutoComplete.d.ts
41
+ interface UrbanDictionaryAutoComplete {
42
+ results: Array<UrbanDictionaryAutoCompleteResults>;
43
+ }
44
+ interface UrbanDictionaryAutoCompleteResults {
45
+ preview: string;
46
+ term: string;
47
+ }
48
+ //#endregion
49
+ export { UrbanDictionary, UrbanDictionaryAutoComplete, UrbanDictionaryAutoCompleteResults, UrbanDictionaryClient, UrbanDictionaryList };
package/dist/index.mjs ADDED
@@ -0,0 +1,46 @@
1
+ //#region src/lib/util.ts
2
+ function pickRandom(arr) {
3
+ return arr[Math.floor(Math.random() * arr.length)];
4
+ }
5
+
6
+ //#endregion
7
+ //#region src/lib/UrbanDictionaryClient.ts
8
+ var UrbanDictionaryClient = class {
9
+ BASE_URL;
10
+ /**
11
+ * Creates a UrbanDictionaryClient
12
+ *
13
+ */
14
+ constructor() {
15
+ this.BASE_URL = new URL("http://api.urbandictionary.com/v0");
16
+ }
17
+ /**
18
+ * Defines a term
19
+ * @param term The term to define
20
+ * @returns The definitions of the term
21
+ */
22
+ async define(term) {
23
+ const url = new URL(`${this.BASE_URL}/define`);
24
+ url.searchParams.append("term", term);
25
+ return (await fetch(url).then((r) => r.json())).list;
26
+ }
27
+ async autoComplete(term) {
28
+ const url = new URL(`${this.BASE_URL}/autocomplete-extra`);
29
+ url.searchParams.append("term", term);
30
+ return (await fetch(url).then((r) => r.json())).results;
31
+ }
32
+ /**
33
+ *
34
+ * @returns A random definition
35
+ */
36
+ async random(count = 1) {
37
+ const url = new URL(`${this.BASE_URL}/random`);
38
+ const res = await fetch(url).then((r) => r.json());
39
+ const results = [];
40
+ for (let i = 0; i < count; i++) results.push(pickRandom(res.list));
41
+ return results;
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ export { UrbanDictionaryClient };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@badstagram/urban-dictionary",
3
+ "description": "An urban dictionary API wrapper",
4
+ "version": "1.0.0",
5
+ "private": false,
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.mts",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "test": "vitest run",
17
+ "test:watch": "vitest",
18
+ "build": "tsdown",
19
+ "clean:build": "rm -rf dist/ && rm *.tgz; npm run build"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://git.badstagram.gay/badstagram/urban-dictionary"
24
+ },
25
+ "keywords": [
26
+ "discord",
27
+ "markdown"
28
+ ],
29
+ "author": "Badstagram",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://git.badstagram.gay/badstagram/urban-dictionary/issues"
33
+ },
34
+ "homepage": "https://git.badstagram.gay/badstagram/urban-dictionary",
35
+ "devDependencies": {
36
+ "@types/node": "^24.10.1",
37
+ "tsdown": "^0.18.1",
38
+ "typescript": "^5.9.3",
39
+ "vitest": "^4.0.13"
40
+ }
41
+ }