-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ new: custom list of cases; resolve #22
- Loading branch information
Showing
7 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Fuse from 'fuse.js' | ||
import type Law from "../../../types/Law" | ||
import CustomDB from './CustomDB' | ||
import type { RawCase } from './CustomDB' | ||
|
||
const { cases: CustomCases } = CustomDB | ||
|
||
const toLawCase = ({ citations, ...others }: RawCase): Law.Case => ({ | ||
...others, | ||
citation: citations[0], | ||
}) | ||
|
||
const getCaseByName = async (caseName: string): Promise<Law.Case[]> => { | ||
const fuse = new Fuse(CustomCases.map(({ name }) => name), {}) | ||
return fuse | ||
.search(caseName) | ||
.map(({ refIndex }) => CustomCases[refIndex]) | ||
.map(rawCase => toLawCase(rawCase)) | ||
} | ||
|
||
const getCaseByCitation = async (citation: string, court: string): Promise<Law.Case[]> => Promise.resolve( | ||
CustomCases | ||
.filter(({ citations }) => | ||
citations.some((cit) => (new RegExp(`${citation}`, `i`)).test(cit)), | ||
) | ||
.map(({ citations, ...others }) => ({ | ||
...others, | ||
citation: citations[0], | ||
})), | ||
) | ||
|
||
const Custom = { | ||
getCaseByCitation, | ||
getCaseByName, | ||
} | ||
|
||
export default Custom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type Law from "../../../types/Law" | ||
import Constants from "../../Constants" | ||
|
||
export interface RawCase extends Omit<Law.Case, `citation`> { | ||
citations: Law.Case[`citation`][], | ||
} | ||
|
||
const CustomDBCases: RawCase[] = [ | ||
{ | ||
citations: [ | ||
`[1957] 1 WLR 582`, | ||
`[1957] 2 All ER 118`, | ||
], | ||
database: Constants.DATABASES.custom, | ||
jurisdiction: Constants.JURISDICTIONS.UK.id, | ||
links: [ | ||
{ | ||
doctype: `Judgment`, | ||
filetype: `HTML`, | ||
url: `https://web.archive.org/web/20160122042428/http://oxcheps.new.ox.ac.uk:80/casebook/Resources/BOLAMV_1%20DOC.pdf`, | ||
}, | ||
{ | ||
doctype: `Judgment`, | ||
filetype: `PDF`, | ||
url: `https://web.archive.org/web/20160122042428if_/http://oxcheps.new.ox.ac.uk:80/casebook/Resources/BOLAMV_1%20DOC.pdf`, | ||
}, | ||
], | ||
name: `Bolam v Friern Hospital Management Committee`, | ||
}, | ||
] | ||
|
||
const CustomDB = { | ||
cases: CustomDBCases, | ||
} | ||
|
||
export default CustomDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Custom' |