Skip to content

Commit

Permalink
Try require() for loading JSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed May 9, 2024
1 parent f9283f0 commit cf4e058
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { inTone } from './tokenize';
import { Tone } from './types';
import dictionaryJson from '../dictionary/dictionary.json';
import unofficialJson from '../data/unofficial.json';

export const verbTypes = [
'name quote',
Expand Down Expand Up @@ -141,7 +139,10 @@ export class Dictionary {
}

private initialize() {
const entries: Entry[] = [...dictionaryJson, ...unofficialJson] as Entry[];
const entries: Entry[] = [
...require('../dictionary/dictionary.json'),
...require('../data/unofficial.json'),
] as Entry[];

for (const e of entries) {
delete (e as any).examples;
Expand Down
10 changes: 1 addition & 9 deletions src/toadua.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as fs from 'fs';
import path from 'path';

export interface ToaduaEntry {
head: string;
body: string;
Expand All @@ -13,10 +10,5 @@ export interface ToaduaEntry {
let _toadua: Record<string, ToaduaEntry>;

export function toadua(): Record<string, ToaduaEntry> {
return (_toadua ??= JSON.parse(
fs.readFileSync(
path.resolve(__dirname, '../data/toadua/toadua.json'),
'utf8',
),
));
return (_toadua ??= require('../data/toadua/toadua.json'));
}

0 comments on commit cf4e058

Please sign in to comment.