Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7565424

Browse files
committedJul 14, 2024·
fix: remove es-toolkit dependency
1 parent c83fc8d commit 7565424

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed
 

‎deno.json

-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
"exports": "./mod.ts",
55
"tasks": {
66
"dev": "deno run --watch main.ts"
7-
},
8-
"imports": {
9-
"@es-toolkit/es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.7.0"
107
}
118
}

‎deno.lock

+1-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/_/keyby.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copied from https://github.com/cloudacy/keyby
2+
3+
export function keyBy<
4+
A extends object,
5+
K extends keyof {
6+
[P in keyof A as A[P] extends PropertyKey ? P : never]: unknown;
7+
},
8+
>(array: A[], key: K) {
9+
return array.reduce(
10+
(r, x) => ({ ...r, [x[key] as unknown as PropertyKey]: x }),
11+
{} as { [P in A[K] as A[K] extends PropertyKey ? A[K] : never]: A },
12+
);
13+
}
14+
15+
export function keyByFunction<A extends object, K extends PropertyKey>(
16+
array: A[],
17+
keyFn: (x: A) => K,
18+
) {
19+
return array.reduce(
20+
(r, x) => ({ ...r, [keyFn(x)]: x }),
21+
{} as { [P in K]: A },
22+
);
23+
}
24+
25+
export default keyBy;

‎src/config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import keyBy from "./_/keyby.ts";
12
import { getCapitals } from "./getCapitals.ts";
2-
import { isNotNil, keyBy } from "@es-toolkit/es-toolkit";
33

44
export type UserDetails = {
55
demat: string;
@@ -19,7 +19,7 @@ function getUsernamePassword(): { demat: string; password: string } {
1919
if (demat?.length !== 16) {
2020
throw new Error("DEMAT_ACCOUNT should be provided");
2121
}
22-
if (!isNotNil(password)) {
22+
if (!password || password === "") {
2323
throw new Error("DEMAT_PASSWORD is needed");
2424
}
2525
return { demat, password };
@@ -29,7 +29,7 @@ export async function loadConfig(): Promise<LoginDetails> {
2929
const { demat, password } = getUsernamePassword();
3030

3131
const capitals = await getCapitals();
32-
const capitalsMap = keyBy(capitals, (capital) => capital.code);
32+
const capitalsMap = keyBy(capitals, "code");
3333

3434
const clientCode = demat.substring(3, 8);
3535
const username = demat.substring(8, demat.length);

0 commit comments

Comments
 (0)
Please sign in to comment.