Skip to content

Commit c0f74f5

Browse files
committed
update to typescript
1 parent a16c31c commit c0f74f5

11 files changed

Lines changed: 61 additions & 18 deletions

File tree

.github/workflows/npm_publish.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ jobs:
1515
- name: 🟢 Setup Node
1616
uses: actions/setup-node@v3
1717
with:
18-
node-version: 12
18+
node-version: 22
1919
registry-url: https://registry.npmjs.org
2020

21+
- name: ☁️ Install Dependencies
22+
run: npm install
23+
24+
- name: 🔨 Build Typescript
25+
run: npm run build
26+
2127
- name: 🚀 Publish
2228
run: npm publish --access public
2329
env:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
api.env
2+
api.env
3+
dist

examples/example.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/example.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { getAuthentication, getBaseData } from "../src/index";
2+
3+
getAuthentication().then(async (auth) => {
4+
console.log(await getBaseData(auth))
5+
})

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "brazos-tranist-api",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "JS implementation of the Texas A&M Bus API",
55
"main": "src/index.js",
66
"files": [
7-
"src",
8-
"types"
7+
"dist/**/*"
98
],
109
"type": "module",
1110
"scripts": {
1211
"test": "echo \"Error: no test specified\" && exit 1",
13-
"example": "node examples/example.js"
12+
"example": "node examples/example.ts",
13+
"build": "tsc"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -25,5 +25,8 @@
2525
"dependencies": {
2626
"moment": "^2.29.4"
2727
},
28-
"types": "types/index.d.ts"
28+
"devDependencies": {
29+
"typescript": "^5.7.3"
30+
},
31+
"types": "dist/index.d.ts"
2932
}

src/api.js renamed to src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param {string} auth Authentication to use for the request
44
* @returns {string[]} list of route names ("01", "04", etc.)
55
*/
6-
export async function getBaseData(auth) {
6+
export async function getBaseData(auth: string) {
77
var res = await fetch(`https://ridebtd.org/Services/JSONPRelay.svc/GetRoutesForMapWithScheduleWithEncodedLine?apiKey=${auth}&isDispatch=false`)
88

99
return await res.json()
@@ -14,7 +14,7 @@ export async function getBaseData(auth) {
1414
* @param {string} auth authentication to use for the request
1515
* @returns list of all locations for buses that are active
1616
*/
17-
export async function getVehicleLocations(auth) {
17+
export async function getVehicleLocations(auth: string) {
1818
var res = await fetch(`https://ridebtd.org/Services/JSONPRelay.svc/GetMapVehiclePoints?apiKey=${auth}&isPublicMap=true`)
1919

2020
return await res.json()
@@ -26,7 +26,7 @@ export async function getVehicleLocations(auth) {
2626
* @param {string} auth authentication to use for the request
2727
* @returns list of stop times for the given routes
2828
*/
29-
export async function getNextStopTimes(routes, auth) {
29+
export async function getNextStopTimes(routes: string[], auth: string) {
3030
var res = await fetch(`https://ridebtd.org/Services/JSONPRelay.svc/GetStopArrivalTimes?apiKey=${auth}&routeIds=${routes.join(",")}&version=2`)
3131

3232
return await res.json()
File renamed without changes.
File renamed without changes.

src/utils.js renamed to src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import moment from "moment";
55
* @param {string} dateString - formatted as "/Date(1234)/"
66
* @returns {moment.Moment | null} converted time
77
*/
8-
export function convertDateString(dateString) {
8+
export function convertDateString(dateString: string): moment.Moment | undefined {
99
// Extract the timestamp from the string using a regular expression
1010
const match = dateString.match(/\/Date\((\d+)\)\//);
1111

@@ -17,6 +17,5 @@ export function convertDateString(dateString) {
1717
return moment(timestamp);
1818
}
1919

20-
// Return null or handle the error as needed
21-
return null;
20+
return undefined;
2221
}

0 commit comments

Comments
 (0)