citation-js 0.7.11 → 0.7.12

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/build/citation.js CHANGED
@@ -4269,6 +4269,7 @@ var _default = exports["default"] = {
4269
4269
  },
4270
4270
  format: {
4271
4271
  useIdAsLabel: false,
4272
+ checkLabel: true,
4272
4273
  asciiOnly: true
4273
4274
  },
4274
4275
  biber: {
@@ -7268,6 +7269,20 @@ function _interopRequireDefault(obj) {
7268
7269
  var stopWords = new Set(['the', 'a', 'an']);
7269
7270
  var unsafeChars = /(?:<\/?.*?>|[\u0020-\u002F\u003A-\u0040\u005B-\u005E\u0060\u007B-\u007F])+/g;
7270
7271
  var unicode = /[^\u0020-\u007F]+/g;
7272
+ function isLabelSafe(text) {
7273
+ return !_config["default"].format.checkLabel || !text.match(unsafeChars);
7274
+ }
7275
+ function formatLabelFromId(id) {
7276
+ if (id === null) {
7277
+ return 'null';
7278
+ } else if (id === undefined) {
7279
+ return 'undefined';
7280
+ } else if (_config["default"].format.checkLabel) {
7281
+ return id.toString().replace(unsafeChars, '');
7282
+ } else {
7283
+ return id.toString();
7284
+ }
7285
+ }
7271
7286
  function firstWord(text) {
7272
7287
  if (!text) {
7273
7288
  return '';
@@ -7498,21 +7513,12 @@ var Converters = exports.Converters = {
7498
7513
  return [label, label];
7499
7514
  },
7500
7515
  toSource: function toSource(id, label, author, issued, suffix, title) {
7501
- var safeId;
7502
- if (id === null) {
7503
- safeId = 'null';
7504
- } else if (id === undefined) {
7505
- safeId = 'undefined';
7506
- } else {
7507
- safeId = id.toString().replace(unsafeChars, '');
7508
- }
7509
- if (_config["default"].format.useIdAsLabel) {
7510
- return safeId;
7511
- }
7512
- if (label && !unsafeChars.test(label)) {
7516
+ if (label && isLabelSafe(label)) {
7513
7517
  return label;
7518
+ } else if (_config["default"].format.useIdAsLabel) {
7519
+ return formatLabelFromId(id);
7514
7520
  } else {
7515
- return formatLabel(author, issued, suffix, title) || safeId;
7521
+ return formatLabel(author, issued, suffix, title) || formatLabelFromId(id);
7516
7522
  }
7517
7523
  }
7518
7524
  },