Skip to content

Commit

Permalink
Refactor/remove dotenv (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishiko732 authored Nov 18, 2023
1 parent 8742375 commit 6e4352e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 75 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ developers apply FSRS to their flashcard applications, there by improving the us
npm install ts-fsrs
```

# Environment Variables
If you need to customize default parameters, you can modify the values using `.env`/`.env.local`/`.env.production`/`.env.development`.

Copy the [.env.local.example](./example/.env.local.example) file in this directory to .env.local (which will be ignored by Git):

```bash
cp .env.local.example .env.local
```

# Example

```typescript
Expand Down
18 changes: 5 additions & 13 deletions __tests__/models.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
envParams,
Rating,
RatingType,
State,
Expand Down Expand Up @@ -77,30 +76,23 @@ describe("Rating", () => {
});

describe("default FSRSParameters", () => {
const env = envParams;
// const env = envParams;
const params = generatorParameters();
const w_v4 = [
0.4, 0.6, 2.4, 5.8, 4.93, 0.94, 0.86, 0.01, 1.49, 0.14, 0.94, 2.18, 0.05,
0.34, 1.26, 0.29, 2.61,
];
it("default_request_retention", () => {
expect([0.9, env.FSRS_REQUEST_RETENTION]).toContainEqual(
params.request_retention,
);
expect(0.9).toEqual(params.request_retention);
});
it("default_maximum_interval", () => {
expect([36500, env.FSRS_MAXIMUM_INTERVAL]).toContainEqual(
params.maximum_interval,
);
expect(36500).toEqual(params.maximum_interval);
});
it("default_w ", () => {
expect([w_v4, env.FSRS_W]).toContainEqual(params.w);
if (env.FSRS_W) {
expect(env.FSRS_W.length).toEqual(w_v4.length);
}
expect(w_v4).toEqual(params.w);
});
it("default_enable_fuzz ", () => {
expect([false, env.FSRS_ENABLE_FUZZ]).toContainEqual(params.enable_fuzz);
expect(false).toEqual(params.enable_fuzz);
});
});

Expand Down
4 changes: 0 additions & 4 deletions example/.env.local.example

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-fsrs",
"version": "3.1.0-beta6",
"version": "3.1.0-beta7",
"description": "ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, thereby improving the user learning experience.",
"main": "dist/ts-fsrs.js",
"module": "dist/ts-fsrs.mjs",
Expand All @@ -13,7 +13,6 @@
"FSRS"
],
"dependencies": {
"dotenv": "^16.3.1",
"seedrandom": "^3.0.5"
},
"devDependencies": {
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 5 additions & 30 deletions src/fsrs/default.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
import { Card, DateInput, FSRSParameters, State } from "./models";
import { fixDate } from "./help";
import { EnvParams } from "./type";
import dotenv from "dotenv";

if (typeof window === "undefined") {
dotenv.config({ path: `./.env.local` });
dotenv.config({ path: `./.env.production` });
dotenv.config({ path: `./.env.` });
dotenv.config({ path: `./.env.development` });
}

export const envParams: EnvParams = {
FSRS_REQUEST_RETENTION: Number(process && process.env.FSRS_REQUEST_RETENTION),
FSRS_MAXIMUM_INTERVAL: Number(process && process.env.FSRS_MAXIMUM_INTERVAL),
FSRS_W:
process && process.env.FSRS_W
? JSON.parse(process.env.FSRS_W as string)
: undefined,
FSRS_ENABLE_FUZZ: Boolean(process && process.env.FSRS_ENABLE_FUZZ),
};

export const default_request_retention = !isNaN(
envParams.FSRS_REQUEST_RETENTION,
)
? envParams.FSRS_REQUEST_RETENTION
: 0.9;
export const default_maximum_interval = !isNaN(envParams.FSRS_MAXIMUM_INTERVAL)
? envParams.FSRS_MAXIMUM_INTERVAL
: 36500;
export const default_w = envParams.FSRS_W || [
export const default_request_retention = 0.9;
export const default_maximum_interval = 36500;
export const default_w = [
0.4, 0.6, 2.4, 5.8, 4.93, 0.94, 0.86, 0.01, 1.49, 0.14, 0.94, 2.18, 0.05,
0.34, 1.26, 0.29, 2.61,
];
export const default_enable_fuzz = envParams.FSRS_ENABLE_FUZZ || false;
export const default_enable_fuzz = false;

export const FSRSVersion: string = "3.1.0-beta6";
export const FSRSVersion: string = "3.1.0-beta7";

export const generatorParameters = (
props?: Partial<FSRSParameters>,
Expand Down
3 changes: 1 addition & 2 deletions src/fsrs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export {
default_enable_fuzz,
FSRSVersion,
generatorParameters,
createEmptyCard,
envParams
createEmptyCard
} from "./default";
export {
date_scheduler,
Expand Down
7 changes: 0 additions & 7 deletions src/fsrs/type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export type unit = "days" | "minutes";
export type int = number & { __int__: void };
export type double = number & { __double__: void };

export interface EnvParams{
FSRS_REQUEST_RETENTION:number,
FSRS_MAXIMUM_INTERVAL:number,
FSRS_W?:number[],
FSRS_ENABLE_FUZZ?:boolean
}

0 comments on commit 6e4352e

Please sign in to comment.