Skip to content

Commit

Permalink
Support Jxiv URLs
Browse files Browse the repository at this point in the history
Refs #2209
  • Loading branch information
thewilkybarkid committed Jan 29, 2025
1 parent 77a2b53 commit 63eea2e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/types/preprint-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export function fromUrl(url: URL): Option.Option<IndeterminatePreprintId> {
.with(['biorxiv.org', P.select()], extractFromBiorxivMedrxivPath('biorxiv'))
.with(['edarxiv.org', P.select()], extractFromEdarxivPath)
.with(['engrxiv.org', P.select()], extractFromEngrxivPath)
.with(['jxiv.jst.go.jp', P.select()], extractFromJxivPath)
.with(['medrxiv.org', P.select()], extractFromBiorxivMedrxivPath('medrxiv'))
.with(['osf.io', P.select()], extractFromOsfPath)
.with(['philsci-archive.pitt.edu', P.select()], extractFromPhilsciPath)
Expand Down Expand Up @@ -363,6 +364,12 @@ const extractFromFigsharePath = (type: 'africarxiv') =>
Option.andThen(doi => ({ type, value: doi }) satisfies AfricarxivFigsharePreprintId),
)

const extractFromJxivPath = flow(
decodeURIComponent,
Option.liftNullable(s => /^index\.php\/jxiv\/preprint\/(?:view|download)\/([1-9][0-9]*)(?:\/|$)/.exec(s)?.[1]),
Option.andThen(flow(id => `10.51094/jxiv.${id}`, parsePreprintDoi)),
)

const extractFromOsfPath = flow(
decodeURIComponent,
Option.liftNullable(s =>
Expand Down
9 changes: 9 additions & 0 deletions test/fc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ export const supportedPreprintUrl = (): fc.Arbitrary<[URL, PreprintId]> =>
biorxivPreprintUrl(),
edarxivPreprintUrl(),
engrxivPreprintUrl(),
jxivPreprintUrl(),
medrxivPreprintUrl(),
metaarxivPreprintUrl(),
osfPreprintsPreprintUrl(),
Expand Down Expand Up @@ -653,6 +654,14 @@ export const jxivPreprintId = (): fc.Arbitrary<JxivPreprintId> =>
value: doi(constant('51094')),
})

export const jxivPreprintUrl = (): fc.Arbitrary<[URL, JxivPreprintId]> =>
fc
.integer({ min: 1 })
.map(id => [
new URL(`https://jxiv.jst.go.jp/index.php/jxiv/preprint/view/${id}`),
{ type: 'jxiv', value: `10.51094/jxiv.${id}` as Doi<'51094'> },
])

export const medrxivPreprintId = (): fc.Arbitrary<MedrxivPreprintId> =>
fc.record({
type: constant('medrxiv'),
Expand Down
25 changes: 25 additions & 0 deletions test/types/preprint-id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,31 @@ describe('fromUrl', () => {
expect(_.fromUrl(url)).toStrictEqual(Option.some({ type: 'engrxiv', value: doi }))
})

test.prop([fc.jxivPreprintUrl().map(([url, id]) => [url, id.value] as const)], {
examples: [
[
[
new URL('https://jxiv.jst.go.jp/index.php/jxiv/preprint/view/1041/version/1215'), // version
Doi('10.51094/jxiv.1041'),
],
],
[
[
new URL('https://jxiv.jst.go.jp/index.php/jxiv/preprint/view/1041/2898'), // html view of pdf
Doi('10.51094/jxiv.1041'),
],
],
[
[
new URL('https://jxiv.jst.go.jp/index.php/jxiv/preprint/download/1041/2898'), // pdf
Doi('10.51094/jxiv.1041'),
],
],
],
})('with a Jxiv URL', ([url, doi]) => {
expect(_.fromUrl(url)).toStrictEqual(Option.some({ type: 'jxiv', value: doi }))
})

test.prop([fc.medrxivPreprintUrl().map(([url, id]) => [url, id.value] as const)], {
examples: [
[
Expand Down

0 comments on commit 63eea2e

Please sign in to comment.