weekly-fifty 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/LICENSE +9 -0
- package/README.md +31 -0
- package/dist/index.cjs +89 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +58 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Reuben Roessler. All rights reserved.
|
|
4
|
+
|
|
5
|
+
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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
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,31 @@
|
|
|
1
|
+
# The Weekly Fifty Library
|
|
2
|
+
|
|
3
|
+
Allows safely fetching [The Weekly Fifty](https://theweeklyfifty.com.au/) latests quizzes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install weekly-fifty
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
To use this library, the following is available:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { TW50 } from 'weekly-fifty';
|
|
17
|
+
|
|
18
|
+
// get the latest available quiz
|
|
19
|
+
const latest = await TW50.Fetch();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Options
|
|
23
|
+
|
|
24
|
+
The `Options` available for `TW50.Fetch` include:
|
|
25
|
+
|
|
26
|
+
- `url`: Optional override url for the quiz endpoint.
|
|
27
|
+
- `parse`: Handles parsing fetch responses to quiz data.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
[MIT](LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// source/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
TW50: () => exports_exports
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// source/_exports.ts
|
|
38
|
+
var exports_exports = {};
|
|
39
|
+
__export(exports_exports, {
|
|
40
|
+
Fetch: () => Fetch
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// source/fetch/index.ts
|
|
44
|
+
var import_myzod = __toESM(require("myzod"), 1);
|
|
45
|
+
async function Fetch(options = {}) {
|
|
46
|
+
const { url, parse } = Fetch.Options(options);
|
|
47
|
+
return fetch(url).then(parse);
|
|
48
|
+
}
|
|
49
|
+
((Fetch2) => {
|
|
50
|
+
const m_timestamp = import_myzod.default.object({ _seconds: import_myzod.default.required(import_myzod.default.number()), _nanoseconds: import_myzod.default.required(import_myzod.default.number()) }, { allowUnknown: true }).map(({ _seconds, _nanoseconds }) => new Date(_seconds * 1e3 + _nanoseconds * 1e6));
|
|
51
|
+
const m_question = import_myzod.default.object({ qTitle: import_myzod.default.required(import_myzod.default.string()), qAnswer: import_myzod.default.required(import_myzod.default.string()) }, { allowUnknown: true }).map(({ qTitle, qAnswer }) => ({ title: qTitle, answer: qAnswer }));
|
|
52
|
+
const m_quiz = import_myzod.default.object(
|
|
53
|
+
{
|
|
54
|
+
quizId: import_myzod.default.required(import_myzod.default.number()),
|
|
55
|
+
quizType: import_myzod.default.required(import_myzod.default.number()),
|
|
56
|
+
quizTitle: import_myzod.default.required(import_myzod.default.string()),
|
|
57
|
+
notesAbove: import_myzod.default.required(import_myzod.default.string()),
|
|
58
|
+
notesBelow: import_myzod.default.required(import_myzod.default.string()),
|
|
59
|
+
creationTime: import_myzod.default.required(m_timestamp),
|
|
60
|
+
deploymentDate: import_myzod.default.required(m_timestamp),
|
|
61
|
+
questions: import_myzod.default.required(import_myzod.default.array(m_question))
|
|
62
|
+
},
|
|
63
|
+
{ allowUnknown: true }
|
|
64
|
+
).map(
|
|
65
|
+
(api) => ({
|
|
66
|
+
id: api.quizId,
|
|
67
|
+
type: api.quizType,
|
|
68
|
+
title: api.quizTitle,
|
|
69
|
+
questions: api.questions,
|
|
70
|
+
creation: api.creationTime,
|
|
71
|
+
deployment: api.deploymentDate,
|
|
72
|
+
notes: { above: api.notesAbove, below: api.notesBelow }
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
Fetch2.Options = (options = {}) => ({
|
|
76
|
+
url: "https://weeklyfifty-7617b.web.app/api/getLatestQuiz",
|
|
77
|
+
parse: m_parse,
|
|
78
|
+
...options
|
|
79
|
+
});
|
|
80
|
+
const m_parse = async (response) => {
|
|
81
|
+
const ct = response.headers.get("content-type");
|
|
82
|
+
if (ct && ct.indexOf("application/json") === -1) throw new TypeError("Expected JSON response");
|
|
83
|
+
return response.json().then((data) => m_quiz.parse(data));
|
|
84
|
+
};
|
|
85
|
+
})(Fetch || (Fetch = {}));
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
TW50
|
|
89
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Question Output Typing. */
|
|
2
|
+
interface Question {
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly answer: string;
|
|
5
|
+
}
|
|
6
|
+
/** Notes Output Typing. */
|
|
7
|
+
interface Notes {
|
|
8
|
+
readonly above: string;
|
|
9
|
+
readonly below: string;
|
|
10
|
+
}
|
|
11
|
+
/** Quiz Output Typing. */
|
|
12
|
+
interface Quiz {
|
|
13
|
+
readonly id: number;
|
|
14
|
+
readonly type: number;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly notes: Notes;
|
|
17
|
+
readonly creation: Date;
|
|
18
|
+
readonly deployment: Date;
|
|
19
|
+
readonly questions: ReadonlyArray<Question>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Handles Fetching Quizzes. */
|
|
23
|
+
declare function Fetch(options?: Fetch.Options): Promise<Quiz>;
|
|
24
|
+
declare namespace Fetch {
|
|
25
|
+
/** Available Fetch Options. */
|
|
26
|
+
interface Options {
|
|
27
|
+
/** Overridable endpoint for quizzes. */
|
|
28
|
+
readonly url?: string;
|
|
29
|
+
/** Handles parsing incoming quizzes. */
|
|
30
|
+
readonly parse?: (response: Response) => Quiz | Promise<Quiz>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handles resolving options to be used.
|
|
34
|
+
* @param options
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
const Options: (options?: Options) => Required<Options>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare const _exports_Fetch: typeof Fetch;
|
|
41
|
+
type _exports_Notes = Notes;
|
|
42
|
+
type _exports_Question = Question;
|
|
43
|
+
type _exports_Quiz = Quiz;
|
|
44
|
+
declare namespace _exports {
|
|
45
|
+
export { _exports_Fetch as Fetch, type _exports_Notes as Notes, type _exports_Question as Question, type _exports_Quiz as Quiz };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { _exports as TW50 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Question Output Typing. */
|
|
2
|
+
interface Question {
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly answer: string;
|
|
5
|
+
}
|
|
6
|
+
/** Notes Output Typing. */
|
|
7
|
+
interface Notes {
|
|
8
|
+
readonly above: string;
|
|
9
|
+
readonly below: string;
|
|
10
|
+
}
|
|
11
|
+
/** Quiz Output Typing. */
|
|
12
|
+
interface Quiz {
|
|
13
|
+
readonly id: number;
|
|
14
|
+
readonly type: number;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly notes: Notes;
|
|
17
|
+
readonly creation: Date;
|
|
18
|
+
readonly deployment: Date;
|
|
19
|
+
readonly questions: ReadonlyArray<Question>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Handles Fetching Quizzes. */
|
|
23
|
+
declare function Fetch(options?: Fetch.Options): Promise<Quiz>;
|
|
24
|
+
declare namespace Fetch {
|
|
25
|
+
/** Available Fetch Options. */
|
|
26
|
+
interface Options {
|
|
27
|
+
/** Overridable endpoint for quizzes. */
|
|
28
|
+
readonly url?: string;
|
|
29
|
+
/** Handles parsing incoming quizzes. */
|
|
30
|
+
readonly parse?: (response: Response) => Quiz | Promise<Quiz>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handles resolving options to be used.
|
|
34
|
+
* @param options
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
const Options: (options?: Options) => Required<Options>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare const _exports_Fetch: typeof Fetch;
|
|
41
|
+
type _exports_Notes = Notes;
|
|
42
|
+
type _exports_Question = Question;
|
|
43
|
+
type _exports_Quiz = Quiz;
|
|
44
|
+
declare namespace _exports {
|
|
45
|
+
export { _exports_Fetch as Fetch, type _exports_Notes as Notes, type _exports_Question as Question, type _exports_Quiz as Quiz };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { _exports as TW50 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// source/_exports.ts
|
|
8
|
+
var exports_exports = {};
|
|
9
|
+
__export(exports_exports, {
|
|
10
|
+
Fetch: () => Fetch
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// source/fetch/index.ts
|
|
14
|
+
import z from "myzod";
|
|
15
|
+
async function Fetch(options = {}) {
|
|
16
|
+
const { url, parse } = Fetch.Options(options);
|
|
17
|
+
return fetch(url).then(parse);
|
|
18
|
+
}
|
|
19
|
+
((Fetch2) => {
|
|
20
|
+
const m_timestamp = z.object({ _seconds: z.required(z.number()), _nanoseconds: z.required(z.number()) }, { allowUnknown: true }).map(({ _seconds, _nanoseconds }) => new Date(_seconds * 1e3 + _nanoseconds * 1e6));
|
|
21
|
+
const m_question = z.object({ qTitle: z.required(z.string()), qAnswer: z.required(z.string()) }, { allowUnknown: true }).map(({ qTitle, qAnswer }) => ({ title: qTitle, answer: qAnswer }));
|
|
22
|
+
const m_quiz = z.object(
|
|
23
|
+
{
|
|
24
|
+
quizId: z.required(z.number()),
|
|
25
|
+
quizType: z.required(z.number()),
|
|
26
|
+
quizTitle: z.required(z.string()),
|
|
27
|
+
notesAbove: z.required(z.string()),
|
|
28
|
+
notesBelow: z.required(z.string()),
|
|
29
|
+
creationTime: z.required(m_timestamp),
|
|
30
|
+
deploymentDate: z.required(m_timestamp),
|
|
31
|
+
questions: z.required(z.array(m_question))
|
|
32
|
+
},
|
|
33
|
+
{ allowUnknown: true }
|
|
34
|
+
).map(
|
|
35
|
+
(api) => ({
|
|
36
|
+
id: api.quizId,
|
|
37
|
+
type: api.quizType,
|
|
38
|
+
title: api.quizTitle,
|
|
39
|
+
questions: api.questions,
|
|
40
|
+
creation: api.creationTime,
|
|
41
|
+
deployment: api.deploymentDate,
|
|
42
|
+
notes: { above: api.notesAbove, below: api.notesBelow }
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
Fetch2.Options = (options = {}) => ({
|
|
46
|
+
url: "https://weeklyfifty-7617b.web.app/api/getLatestQuiz",
|
|
47
|
+
parse: m_parse,
|
|
48
|
+
...options
|
|
49
|
+
});
|
|
50
|
+
const m_parse = async (response) => {
|
|
51
|
+
const ct = response.headers.get("content-type");
|
|
52
|
+
if (ct && ct.indexOf("application/json") === -1) throw new TypeError("Expected JSON response");
|
|
53
|
+
return response.json().then((data) => m_quiz.parse(data));
|
|
54
|
+
};
|
|
55
|
+
})(Fetch || (Fetch = {}));
|
|
56
|
+
export {
|
|
57
|
+
exports_exports as TW50
|
|
58
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"name": "weekly-fifty",
|
|
6
|
+
"author": "Reuben Roessler",
|
|
7
|
+
"repository": "rroessler/npm.weekly-fifty",
|
|
8
|
+
"description": "Library for fetching 'The Weekly Fifty' quizzes",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"// BUILD //": "",
|
|
22
|
+
"build": "tsup ./source/index.ts --dts --format esm,cjs",
|
|
23
|
+
"// PACKAGE //": "",
|
|
24
|
+
"publish": "run-s build publish:np",
|
|
25
|
+
"publish:np": "np"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"myzod": "^1.12.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@tsconfig/recommended": "^1.0.13",
|
|
32
|
+
"np": "^10.2.0",
|
|
33
|
+
"npm-run-all2": "^8.0.4",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"tsx": "^4.20.6",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
}
|
|
38
|
+
}
|