jats-xml 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,7 +41,7 @@ jats summary /local/article.jats
41
41
 
42
42
  This will provide a summary, including a list of what the JATS file contains.
43
43
 
44
- ![Output of `jats summary`](images/jats-output.png)
44
+ ![Output of `jats summary`](/packages/jats-xml/images/jats-output.png)
45
45
 
46
46
  ## Working in Typescript
47
47
 
@@ -30,7 +30,7 @@ const utils_1 = require("../utils");
30
30
  function hasValidExtension(output) {
31
31
  return ['.xml', '.jats'].includes((0, path_1.extname)(output).toLowerCase());
32
32
  }
33
- function downloadJats(session, urlOrDoi, output) {
33
+ function downloadAndSaveJats(session, urlOrDoi, output) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  if (fs_1.default.existsSync(urlOrDoi)) {
36
36
  throw new Error(`File "${urlOrDoi}" is local and cannot be downloaded!`);
@@ -55,12 +55,9 @@ function parseJats(session, file) {
55
55
  session.log.debug(toc(`Parsed JATS file from disk in %s`));
56
56
  return new jats_1.Jats(data);
57
57
  }
58
- if (doi_utils_1.default.validate(file) || (0, myst_cli_utils_1.isUrl)(file)) {
59
- const data = yield (0, download_1.downloadJatsFromUrl)(session, file, resolvers_1.DEFAULT_RESOLVERS);
60
- session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
61
- return new jats_1.Jats(data);
62
- }
63
- throw new Error(`Could not find ${file} locally, and it doesn't look like a URL or DOI`);
58
+ const data = yield (0, download_1.downloadJatsFromUrl)(session, file, resolvers_1.DEFAULT_RESOLVERS);
59
+ session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
60
+ return new jats_1.Jats(data);
64
61
  });
65
62
  }
66
63
  function formatLongString(data, offset = 0, length = 88 - offset) {
@@ -145,7 +142,7 @@ function jatsReferencesCLI(session, file) {
145
142
  const jats = yield parseJats(session, file);
146
143
  const sorted = jats.references
147
144
  .map((ref) => {
148
- const doi = (0, utils_1.findDoi)(ref);
145
+ const doiString = (0, utils_1.findDoi)(ref);
149
146
  const title = (0, myst_common_1.toText)((0, unist_util_select_1.select)(types_1.Tags.articleTitle, ref));
150
147
  const year = (0, myst_common_1.toText)((0, unist_util_select_1.select)(types_1.Tags.year, ref));
151
148
  const surnames = (0, unist_util_select_1.selectAll)(types_1.Tags.surname, ref);
@@ -158,7 +155,7 @@ function jatsReferencesCLI(session, file) {
158
155
  return {
159
156
  Citation: `${short} (${year})`,
160
157
  Title: title,
161
- DOI: doi ? doi_utils_1.default.buildUrl(doi) : null,
158
+ DOI: doiString ? doi_utils_1.default.buildUrl(doiString) : null,
162
159
  Count: s.length,
163
160
  };
164
161
  })
@@ -188,7 +185,7 @@ function makeDownloadCLI(program) {
188
185
  .description('Parse a JATS file and provide a summary')
189
186
  .argument('<url>', 'The JATS url or a DOI')
190
187
  .argument('<output>', 'The JATS url or a DOI')
191
- .action((0, myst_cli_utils_1.clirun)(downloadJats, { program, getSession: session_1.getSession }));
188
+ .action((0, myst_cli_utils_1.clirun)(downloadAndSaveJats, { program, getSession: session_1.getSession }));
192
189
  return command;
193
190
  }
194
191
  function addDownloadCLI(program) {
@@ -33,22 +33,22 @@ exports.plos = {
33
33
  };
34
34
  exports.joss = {
35
35
  test(url) {
36
- return new URL(url).hostname === 'joss.theoj.org';
36
+ return new URL(url).hostname === 'joss.theoj.org' && doi_utils_1.default.validate(url);
37
37
  },
38
38
  jatsUrl(url) {
39
39
  // Probably a better way to do this, the joss papers on on github!
40
- const doi = new URL(url).pathname.replace('/papers/', '');
41
- const [org, jossId] = doi.split('/');
40
+ const doiString = doi_utils_1.default.normalize(url);
41
+ const [org, jossId] = doiString.split('/');
42
42
  const id = jossId.split('.')[1];
43
43
  return `https://raw.githubusercontent.com/openjournals/joss-papers/master/joss.${id}/${org}.${jossId}.jats`;
44
44
  },
45
45
  };
46
46
  exports.DEFAULT_RESOLVERS = [exports.elife, exports.plos, exports.joss];
47
- function resolveJatsUrlFromDoi(session, doi, resolvers = exports.DEFAULT_RESOLVERS) {
47
+ function resolveJatsUrlFromDoi(session, doiString, resolvers = exports.DEFAULT_RESOLVERS) {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
- if (!doi_utils_1.default.validate(doi))
50
- throw new Error(`The doi ${doi} is not valid`);
51
- const doiUrl = doi_utils_1.default.buildUrl(doi);
49
+ if (!doi_utils_1.default.validate(doiString))
50
+ throw new Error(`The doi ${doiString} is not valid`);
51
+ const doiUrl = doi_utils_1.default.buildUrl(doiString);
52
52
  session.log.debug(`Resolving DOI ${doiUrl}`);
53
53
  const resp = yield (0, node_fetch_1.default)(doiUrl);
54
54
  const articleUrl = resp.url;
@@ -5,7 +5,6 @@ const myst_cli_utils_1 = require("myst-cli-utils");
5
5
  class Session {
6
6
  constructor(opts) {
7
7
  var _a;
8
- this.API_URL = 'https://api.myst.tools';
9
8
  this.log = (_a = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _a !== void 0 ? _a : (0, myst_cli_utils_1.chalkLogger)(myst_cli_utils_1.LogLevel.debug);
10
9
  }
11
10
  }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const version = '0.0.3';
3
+ const version = '0.0.4';
4
4
  exports.default = version;
@@ -11,7 +11,7 @@ import { Command } from 'commander';
11
11
  import fs from 'fs';
12
12
  import { extname } from 'path';
13
13
  import { clirun, isUrl, tic, writeFileToFolder } from 'myst-cli-utils';
14
- import checkdoi from 'doi-utils';
14
+ import doi from 'doi-utils';
15
15
  import chalk from 'chalk';
16
16
  import { getSession } from '../session';
17
17
  import { Tags } from '../types';
@@ -24,12 +24,12 @@ import { findDoi, formatDate, toDate } from '../utils';
24
24
  function hasValidExtension(output) {
25
25
  return ['.xml', '.jats'].includes(extname(output).toLowerCase());
26
26
  }
27
- function downloadJats(session, urlOrDoi, output) {
27
+ function downloadAndSaveJats(session, urlOrDoi, output) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  if (fs.existsSync(urlOrDoi)) {
30
30
  throw new Error(`File "${urlOrDoi}" is local and cannot be downloaded!`);
31
31
  }
32
- if (!(checkdoi.validate(urlOrDoi) || isUrl(urlOrDoi))) {
32
+ if (!(doi.validate(urlOrDoi) || isUrl(urlOrDoi))) {
33
33
  throw new Error(`Path must be a URL or DOI, not "${urlOrDoi}"`);
34
34
  }
35
35
  if (!hasValidExtension(output)) {
@@ -49,12 +49,9 @@ function parseJats(session, file) {
49
49
  session.log.debug(toc(`Parsed JATS file from disk in %s`));
50
50
  return new Jats(data);
51
51
  }
52
- if (checkdoi.validate(file) || isUrl(file)) {
53
- const data = yield downloadJatsFromUrl(session, file, DEFAULT_RESOLVERS);
54
- session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
55
- return new Jats(data);
56
- }
57
- throw new Error(`Could not find ${file} locally, and it doesn't look like a URL or DOI`);
52
+ const data = yield downloadJatsFromUrl(session, file, DEFAULT_RESOLVERS);
53
+ session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
54
+ return new Jats(data);
58
55
  });
59
56
  }
60
57
  function formatLongString(data, offset = 0, length = 88 - offset) {
@@ -94,7 +91,7 @@ function jatsSummaryCLI(session, file) {
94
91
  return __awaiter(this, void 0, void 0, function* () {
95
92
  const jats = yield parseJats(session, file);
96
93
  const summary = {
97
- DOI: jats.doi ? checkdoi.buildUrl(jats.doi) : null,
94
+ DOI: jats.doi ? doi.buildUrl(jats.doi) : null,
98
95
  Title: (_a = toText(jats.articleTitle)) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, ' '),
99
96
  Date: formatDate(toDate(jats.publicationDate)),
100
97
  Authors: jats.articleAuthors
@@ -139,7 +136,7 @@ function jatsReferencesCLI(session, file) {
139
136
  const jats = yield parseJats(session, file);
140
137
  const sorted = jats.references
141
138
  .map((ref) => {
142
- const doi = findDoi(ref);
139
+ const doiString = findDoi(ref);
143
140
  const title = toText(select(Tags.articleTitle, ref));
144
141
  const year = toText(select(Tags.year, ref));
145
142
  const surnames = selectAll(Tags.surname, ref);
@@ -152,7 +149,7 @@ function jatsReferencesCLI(session, file) {
152
149
  return {
153
150
  Citation: `${short} (${year})`,
154
151
  Title: title,
155
- DOI: doi ? checkdoi.buildUrl(doi) : null,
152
+ DOI: doiString ? doi.buildUrl(doiString) : null,
156
153
  Count: s.length,
157
154
  };
158
155
  })
@@ -182,7 +179,7 @@ function makeDownloadCLI(program) {
182
179
  .description('Parse a JATS file and provide a summary')
183
180
  .argument('<url>', 'The JATS url or a DOI')
184
181
  .argument('<output>', 'The JATS url or a DOI')
185
- .action(clirun(downloadJats, { program, getSession }));
182
+ .action(clirun(downloadAndSaveJats, { program, getSession }));
186
183
  return command;
187
184
  }
188
185
  export function addDownloadCLI(program) {
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import checkdoi from 'doi-utils';
10
+ import doi from 'doi-utils';
11
11
  import fetch from 'node-fetch';
12
12
  import { isUrl } from 'myst-cli-utils';
13
13
  import { resolveJatsUrlFromDoi } from './resolvers';
@@ -27,7 +27,7 @@ function dowloadFromUrl(session, jatsUrl) {
27
27
  }
28
28
  export function downloadJatsFromUrl(session, urlOrDoi, resolvers) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- if (checkdoi.validate(urlOrDoi)) {
30
+ if (doi.validate(urlOrDoi)) {
31
31
  const jatsUrl = yield resolveJatsUrlFromDoi(session, urlOrDoi, resolvers);
32
32
  const data = yield dowloadFromUrl(session, jatsUrl);
33
33
  return data;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import checkdoi from 'doi-utils';
10
+ import doi from 'doi-utils';
11
11
  import fetch from 'node-fetch';
12
12
  export const elife = {
13
13
  test(url) {
@@ -27,22 +27,22 @@ export const plos = {
27
27
  };
28
28
  export const joss = {
29
29
  test(url) {
30
- return new URL(url).hostname === 'joss.theoj.org';
30
+ return new URL(url).hostname === 'joss.theoj.org' && doi.validate(url);
31
31
  },
32
32
  jatsUrl(url) {
33
33
  // Probably a better way to do this, the joss papers on on github!
34
- const doi = new URL(url).pathname.replace('/papers/', '');
35
- const [org, jossId] = doi.split('/');
34
+ const doiString = doi.normalize(url);
35
+ const [org, jossId] = doiString.split('/');
36
36
  const id = jossId.split('.')[1];
37
37
  return `https://raw.githubusercontent.com/openjournals/joss-papers/master/joss.${id}/${org}.${jossId}.jats`;
38
38
  },
39
39
  };
40
40
  export const DEFAULT_RESOLVERS = [elife, plos, joss];
41
- export function resolveJatsUrlFromDoi(session, doi, resolvers = DEFAULT_RESOLVERS) {
41
+ export function resolveJatsUrlFromDoi(session, doiString, resolvers = DEFAULT_RESOLVERS) {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
- if (!checkdoi.validate(doi))
44
- throw new Error(`The doi ${doi} is not valid`);
45
- const doiUrl = checkdoi.buildUrl(doi);
43
+ if (!doi.validate(doiString))
44
+ throw new Error(`The doi ${doiString} is not valid`);
45
+ const doiUrl = doi.buildUrl(doiString);
46
46
  session.log.debug(`Resolving DOI ${doiUrl}`);
47
47
  const resp = yield fetch(doiUrl);
48
48
  const articleUrl = resp.url;
@@ -2,7 +2,6 @@ import { chalkLogger, LogLevel } from 'myst-cli-utils';
2
2
  export class Session {
3
3
  constructor(opts) {
4
4
  var _a;
5
- this.API_URL = 'https://api.myst.tools';
6
5
  this.log = (_a = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _a !== void 0 ? _a : chalkLogger(LogLevel.debug);
7
6
  }
8
7
  }
package/dist/esm/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { toText } from 'myst-common';
2
- import checkdoi from 'doi-utils';
2
+ import doi from 'doi-utils';
3
3
  import { select, selectAll } from 'unist-util-select';
4
4
  import { Tags } from './types';
5
5
  export function convertToUnist(node) {
@@ -83,6 +83,6 @@ export function findDoi(node) {
83
83
  const id = select('[pub-id-type=doi]', node);
84
84
  if (id && toText(id))
85
85
  return toText(id);
86
- const doiTag = selectAll(`${Tags.articleId},${Tags.pubId}`, node).find((t) => checkdoi.validate(toText(t)));
86
+ const doiTag = selectAll(`${Tags.articleId},${Tags.pubId}`, node).find((t) => doi.validate(toText(t)));
87
87
  return toText(doiTag) || null;
88
88
  }
@@ -1,2 +1,2 @@
1
- const version = '0.0.3';
1
+ const version = '0.0.4';
2
2
  export default version;
package/dist/jats.js CHANGED
@@ -3279,7 +3279,7 @@ var require_resolvers = __commonJS({
3279
3279
  Object.defineProperty(exports, "__esModule", {
3280
3280
  value: true
3281
3281
  });
3282
- exports.DEFAULT_RESOLVERS = void 0;
3282
+ exports.DEFAULT_RESOLVERS = exports.STRICT_RESOLVERS = void 0;
3283
3283
  var _validatePart = require_validatePart();
3284
3284
  var doiOrg = {
3285
3285
  test(url) {
@@ -3329,6 +3329,10 @@ var require_resolvers = __commonJS({
3329
3329
  return clumpParts(url).find(_validatePart.validatePart);
3330
3330
  }
3331
3331
  };
3332
+ var STRICT_RESOLVERS = [
3333
+ doiOrg
3334
+ ];
3335
+ exports.STRICT_RESOLVERS = STRICT_RESOLVERS;
3332
3336
  var DEFAULT_RESOLVERS2 = [
3333
3337
  doiOrg,
3334
3338
  doiSubdomain,
@@ -3347,53 +3351,57 @@ var require_cjs = __commonJS({
3347
3351
  Object.defineProperty(exports, "__esModule", {
3348
3352
  value: true
3349
3353
  });
3350
- Object.defineProperty(exports, "validatePart", {
3354
+ Object.defineProperty(exports, "DEFAULT_RESOLVERS", {
3355
+ enumerable: true,
3356
+ get: function() {
3357
+ return _resolvers.DEFAULT_RESOLVERS;
3358
+ }
3359
+ });
3360
+ Object.defineProperty(exports, "STRICT_RESOLVERS", {
3351
3361
  enumerable: true,
3352
3362
  get: function() {
3353
- return _validatePart.validatePart;
3363
+ return _resolvers.STRICT_RESOLVERS;
3354
3364
  }
3355
3365
  });
3356
- exports.validate = validate;
3357
- exports.normalize = normalize;
3358
- exports.buildUrl = buildUrl;
3359
3366
  exports.default = void 0;
3360
3367
  var _resolvers = require_resolvers();
3361
3368
  var _validatePart = require_validatePart();
3362
- function validate(possibleDOI) {
3369
+ function validate(possibleDOI, opts) {
3363
3370
  if (!possibleDOI)
3364
3371
  return false;
3365
- return !!normalize(possibleDOI);
3372
+ return !!normalize(possibleDOI, opts);
3366
3373
  }
3367
- function normalize(possibleDOI) {
3368
- let doi = void 0;
3374
+ function normalize(possibleDOI, opts) {
3375
+ let doi5 = void 0;
3369
3376
  if (!possibleDOI)
3370
3377
  return void 0;
3371
3378
  if ((0, _validatePart).validatePart(possibleDOI))
3372
3379
  return possibleDOI;
3373
3380
  if (possibleDOI.startsWith("doi:")) {
3374
- doi = possibleDOI.slice(4);
3375
- if ((0, _validatePart).validatePart(doi))
3376
- return doi;
3381
+ doi5 = possibleDOI.slice(4);
3382
+ if ((0, _validatePart).validatePart(doi5))
3383
+ return doi5;
3377
3384
  }
3378
3385
  try {
3379
3386
  const url = new URL(possibleDOI.startsWith("http") ? possibleDOI : `http://${possibleDOI}`);
3380
- const resolver = _resolvers.DEFAULT_RESOLVERS.find(
3387
+ const resolvers = (opts === null || opts === void 0 ? void 0 : opts.strict) ? _resolvers.STRICT_RESOLVERS : _resolvers.DEFAULT_RESOLVERS;
3388
+ const resolver = resolvers.find(
3381
3389
  (r) => r.test(url)
3382
3390
  );
3383
3391
  if (!resolver)
3384
3392
  return void 0;
3385
- doi = resolver.parse(url);
3393
+ doi5 = resolver.parse(url);
3386
3394
  } catch (error) {
3387
3395
  }
3388
- if ((0, _validatePart).validatePart(doi))
3389
- return doi;
3396
+ if ((0, _validatePart).validatePart(doi5))
3397
+ return doi5;
3390
3398
  return void 0;
3391
3399
  }
3392
- function buildUrl(possibleDOI) {
3393
- const doi = normalize(possibleDOI);
3394
- if (!doi)
3400
+ function buildUrl(possibleDOI, opts) {
3401
+ const doi5 = normalize(possibleDOI, opts);
3402
+ if (!doi5)
3395
3403
  return void 0;
3396
- return `https://doi.org/${doi}`;
3404
+ return `https://doi.org/${doi5}`;
3397
3405
  }
3398
3406
  var _default = {
3399
3407
  validatePart: _validatePart.validatePart,
@@ -9094,7 +9102,7 @@ var require_lib4 = __commonJS({
9094
9102
  var import_commander2 = __toESM(require_commander());
9095
9103
 
9096
9104
  // src/version.ts
9097
- var version = "0.0.3";
9105
+ var version = "0.0.4";
9098
9106
  var version_default = version;
9099
9107
 
9100
9108
  // src/cli/parse.ts
@@ -9243,7 +9251,6 @@ var import_chalk2 = __toESM(require_source());
9243
9251
  // src/session.ts
9244
9252
  var Session2 = class {
9245
9253
  constructor(opts) {
9246
- this.API_URL = "https://api.myst.tools";
9247
9254
  var _a;
9248
9255
  this.log = (_a = opts == null ? void 0 : opts.logger) != null ? _a : chalkLogger(LogLevel.debug);
9249
9256
  }
@@ -10205,21 +10212,21 @@ var plos = {
10205
10212
  };
10206
10213
  var joss = {
10207
10214
  test(url) {
10208
- return new URL(url).hostname === "joss.theoj.org";
10215
+ return new URL(url).hostname === "joss.theoj.org" && import_doi_utils2.default.validate(url);
10209
10216
  },
10210
10217
  jatsUrl(url) {
10211
- const doi = new URL(url).pathname.replace("/papers/", "");
10212
- const [org, jossId] = doi.split("/");
10218
+ const doiString = import_doi_utils2.default.normalize(url);
10219
+ const [org, jossId] = doiString.split("/");
10213
10220
  const id = jossId.split(".")[1];
10214
10221
  return `https://raw.githubusercontent.com/openjournals/joss-papers/master/joss.${id}/${org}.${jossId}.jats`;
10215
10222
  }
10216
10223
  };
10217
10224
  var DEFAULT_RESOLVERS = [elife, plos, joss];
10218
10225
  function resolveJatsUrlFromDoi(_0, _1) {
10219
- return __async(this, arguments, function* (session, doi, resolvers = DEFAULT_RESOLVERS) {
10220
- if (!import_doi_utils2.default.validate(doi))
10221
- throw new Error(`The doi ${doi} is not valid`);
10222
- const doiUrl = import_doi_utils2.default.buildUrl(doi);
10226
+ return __async(this, arguments, function* (session, doiString, resolvers = DEFAULT_RESOLVERS) {
10227
+ if (!import_doi_utils2.default.validate(doiString))
10228
+ throw new Error(`The doi ${doiString} is not valid`);
10229
+ const doiUrl = import_doi_utils2.default.buildUrl(doiString);
10223
10230
  session.log.debug(`Resolving DOI ${doiUrl}`);
10224
10231
  const resp = yield (0, import_node_fetch.default)(doiUrl);
10225
10232
  const articleUrl = resp.url;
@@ -10268,7 +10275,7 @@ function downloadJatsFromUrl(session, urlOrDoi, resolvers) {
10268
10275
  function hasValidExtension(output) {
10269
10276
  return [".xml", ".jats"].includes((0, import_path2.extname)(output).toLowerCase());
10270
10277
  }
10271
- function downloadJats(session, urlOrDoi, output) {
10278
+ function downloadAndSaveJats(session, urlOrDoi, output) {
10272
10279
  return __async(this, null, function* () {
10273
10280
  if (import_fs2.default.existsSync(urlOrDoi)) {
10274
10281
  throw new Error(`File "${urlOrDoi}" is local and cannot be downloaded!`);
@@ -10293,16 +10300,13 @@ function parseJats(session, file) {
10293
10300
  const toc = tic();
10294
10301
  if (import_fs2.default.existsSync(file)) {
10295
10302
  session.log.debug(`Found ${file} locally, parsing`);
10296
- const data = import_fs2.default.readFileSync(file).toString();
10303
+ const data2 = import_fs2.default.readFileSync(file).toString();
10297
10304
  session.log.debug(toc(`Parsed JATS file from disk in %s`));
10298
- return new Jats(data);
10299
- }
10300
- if (import_doi_utils4.default.validate(file) || isUrl(file)) {
10301
- const data = yield downloadJatsFromUrl(session, file, DEFAULT_RESOLVERS);
10302
- session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
10303
- return new Jats(data);
10305
+ return new Jats(data2);
10304
10306
  }
10305
- throw new Error(`Could not find ${file} locally, and it doesn't look like a URL or DOI`);
10307
+ const data = yield downloadJatsFromUrl(session, file, DEFAULT_RESOLVERS);
10308
+ session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
10309
+ return new Jats(data);
10306
10310
  });
10307
10311
  }
10308
10312
  function formatLongString(data, offset = 0, length = 88 - offset) {
@@ -10380,7 +10384,7 @@ function jatsReferencesCLI(session, file) {
10380
10384
  return __async(this, null, function* () {
10381
10385
  const jats = yield parseJats(session, file);
10382
10386
  const sorted = jats.references.map((ref) => {
10383
- const doi = findDoi(ref);
10387
+ const doiString = findDoi(ref);
10384
10388
  const title = toText(select("article-title" /* articleTitle */, ref));
10385
10389
  const year = toText(select("year" /* year */, ref));
10386
10390
  const surnames = selectAll("surname" /* surname */, ref);
@@ -10389,7 +10393,7 @@ function jatsReferencesCLI(session, file) {
10389
10393
  return {
10390
10394
  Citation: `${short} (${year})`,
10391
10395
  Title: title,
10392
- DOI: doi ? import_doi_utils4.default.buildUrl(doi) : null,
10396
+ DOI: doiString ? import_doi_utils4.default.buildUrl(doiString) : null,
10393
10397
  Count: s.length
10394
10398
  };
10395
10399
  }).sort((a, b) => b.Count - a.Count);
@@ -10407,7 +10411,7 @@ function makeReferencesCLI(program2) {
10407
10411
  return command;
10408
10412
  }
10409
10413
  function makeDownloadCLI(program2) {
10410
- const command = new import_commander.Command("download").description("Parse a JATS file and provide a summary").argument("<url>", "The JATS url or a DOI").argument("<output>", "The JATS url or a DOI").action(clirun(downloadJats, { program: program2, getSession: getSession2 }));
10414
+ const command = new import_commander.Command("download").description("Parse a JATS file and provide a summary").argument("<url>", "The JATS url or a DOI").argument("<output>", "The JATS url or a DOI").action(clirun(downloadAndSaveJats, { program: program2, getSession: getSession2 }));
10411
10415
  return command;
10412
10416
  }
10413
10417
  function addDownloadCLI(program2) {
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/cli/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoMpC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAI9C"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/cli/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqMpC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAI9C"}
@@ -7,5 +7,5 @@ export declare const elife: Resolver;
7
7
  export declare const plos: Resolver;
8
8
  export declare const joss: Resolver;
9
9
  export declare const DEFAULT_RESOLVERS: Resolver[];
10
- export declare function resolveJatsUrlFromDoi(session: ISession, doi: string, resolvers?: Resolver[]): Promise<string>;
10
+ export declare function resolveJatsUrlFromDoi(session: ISession, doiString: string, resolvers?: Resolver[]): Promise<string>;
11
11
  //# sourceMappingURL=resolvers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../src/resolvers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CAClC;AAED,eAAO,MAAM,KAAK,EAAE,QAOnB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,QAOlB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,QAWlB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,EAAwB,CAAC;AAEjE,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,QAAQ,EACjB,GAAG,EAAE,MAAM,EACX,SAAS,aAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAWjB"}
1
+ {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../src/resolvers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CAClC;AAED,eAAO,MAAM,KAAK,EAAE,QAOnB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,QAOlB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,QAWlB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,EAAwB,CAAC;AAEjE,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,QAAQ,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,aAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAWjB"}
@@ -1,7 +1,6 @@
1
1
  import type { Logger } from 'myst-cli-utils';
2
2
  import type { ISession } from './types';
3
3
  export declare class Session implements ISession {
4
- API_URL: string;
5
4
  log: Logger;
6
5
  constructor(opts?: {
7
6
  logger?: Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,OAAQ,YAAW,QAAQ;IACtC,OAAO,SAA4B;IACnC,GAAG,EAAE,MAAM,CAAC;gBACA,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAGvC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,WAExC"}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,OAAQ,YAAW,QAAQ;IACtC,GAAG,EAAE,MAAM,CAAC;gBACA,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAGvC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,WAExC"}
@@ -1,3 +1,3 @@
1
- declare const version = "0.0.3";
1
+ declare const version = "0.0.4";
2
2
  export default version;
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jats-xml",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Types and utilities for working with JATS in Typescript",
5
5
  "author": "Rowan Cockett <rowan@curvenote.com>",
6
6
  "homepage": "https://github.com/executablebooks/mystjs/tree/main/packages/jats-xml",
@@ -34,25 +34,25 @@
34
34
  "scripts": {
35
35
  "copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts",
36
36
  "clean": "rm -rf dist",
37
- "prepublishOnly": "npm run build;",
37
+ "prepublishOnly": "npm run copy:version && npm run build;",
38
38
  "unlink": "npm uninstall -g jats-xml;",
39
39
  "link": "npm run unlink; npm link;",
40
- "dev": "npm run link && esbuild src/cli/index.ts --bundle --outfile=dist/jats.js --platform=node --watch",
40
+ "dev": "npm run copy:version && npm run link && esbuild src/cli/index.ts --bundle --outfile=dist/jats.js --platform=node --watch",
41
41
  "test": "npm run copy:version && jest",
42
42
  "test:watch": "jest --watchAll",
43
- "lint": "eslint \"src/**/*.ts\" -c .eslintrc.js --max-warnings 1",
43
+ "lint": "npm run copy:version && eslint \"src/**/*.ts\" -c .eslintrc.js --max-warnings 1",
44
44
  "lint:format": "prettier --check src/*.ts src/**/*.ts",
45
45
  "build:esm": "tsc --module es2015 --outDir dist/esm",
46
46
  "build:cjs": "tsc --module commonjs --outDir dist/cjs",
47
47
  "build:cli": "esbuild src/cli/index.ts --bundle --outfile=dist/jats.js --platform=node",
48
48
  "declarations": "tsc --declaration --emitDeclarationOnly --declarationMap --outDir dist/types",
49
- "build": "npm-run-all -l clean -p copy:version build:cjs build:esm declarations build:cli"
49
+ "build": "npm-run-all -l clean copy:version -p build:cjs build:esm declarations build:cli"
50
50
  },
51
51
  "bugs": {
52
52
  "url": "https://github.com/executablebooks/mystjs/issues"
53
53
  },
54
54
  "dependencies": {
55
- "myst-common": "^0.0.6"
55
+ "myst-common": "^0.0.7"
56
56
  },
57
57
  "devDependencies": {
58
58
  "npm-run-all": "^4.1.5",