Skip to content

Commit fb64633

Browse files
committed
Implement getorgbyname
1 parent 063bc1b commit fb64633

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build Library
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22.x'
20+
cache: 'yarn'
21+
22+
- name: Install deps
23+
run: yarn
24+
25+
- name: Build project
26+
run: yarn build

.github/workflows/publish-npm.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ jobs:
1616
node-version: "20.x"
1717
registry-url: "https://registry.npmjs.org"
1818

19-
- run: yarn build
20-
- run: npm publish --provenance --access public
19+
- name: Build library
20+
run: yarn build
21+
22+
- name: Publish to NPM
23+
run: npm publish --provenance --access public
2124
env:
2225
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@acm-uiuc/js-shared",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "ACM UIUC Shared JS code",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/orgs.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ export type OrganizationId = keyof typeof Organizations;
4242
export type Organization = (typeof Organizations)[OrganizationId];
4343
export type OrganizationName = Organization["name"];
4444

45+
// Create a reverse lookup map from name to ID
46+
export const OrganizationsByName = Object.entries(Organizations).reduce(
47+
(acc, [id, org]) => {
48+
if (acc[org.name]) {
49+
throw new Error(`Duplicate organization name: ${org.name}`);
50+
}
51+
acc[org.name] = id as OrganizationId;
52+
return acc;
53+
},
54+
{} as Record<OrganizationName, OrganizationId>
55+
);
56+
57+
export function getOrgByName(name: OrganizationName): (Organization & { id: OrganizationId }) | undefined {
58+
const id = OrganizationsByName[name];
59+
if (!id) return undefined;
60+
61+
return { ...Organizations[id], id };
62+
}
63+
4564
export function getOrgsByType(type: OrgType): Array<Organization & { id: OrganizationId }> {
4665
return (Object.entries(Organizations) as Array<[OrganizationId, Organization]>)
4766
.filter(([_, org]) => org.type === type)

0 commit comments

Comments
 (0)