Cite/index.js

  1. import * as log from './log'
  2. import * as options from './options'
  3. import * as set from './set'
  4. import * as sort from './sort'
  5. import * as get from './get'
  6. /**
  7. * Citation.js input data, see {@tutorial input_types}
  8. *
  9. * @typedef InputData
  10. * @tutorial input_types
  11. */
  12. /**
  13. * Citation.js {@tutorial input_options}
  14. *
  15. * @typedef {Object} Cite~InputOptions
  16. * @tutorial input_options
  17. *
  18. * @property {Cite~OutputOptions} output
  19. * @property {Number} maxChainLength
  20. * @property {Boolean} generateGraph
  21. * @property {Cite.parse~format} forceType
  22. */
  23. /**
  24. * Citation.js {@tutorial output_options}
  25. *
  26. * @typedef {Object} Cite~OutputOptions
  27. * @tutorial output_options
  28. *
  29. * @property {String} format
  30. * @property {String} type
  31. * @property {String} style
  32. * @property {String} lang
  33. * @property {String|Cite~wrapper} prepend
  34. * @property {String|Cite~wrapper} append
  35. */
  36. /**
  37. * @callback Cite~wrapper
  38. * @param {CSL} data - Cite object
  39. * @return {String} wrapping string
  40. */
  41. /**
  42. * [CSL](https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html#csl-json-items) object
  43. *
  44. * @typedef {Object} CSL
  45. */
  46. /**
  47. * Create a `Cite` object with almost any kind of data, and manipulate it with its default methods.
  48. *
  49. * @access public
  50. * @constructor Cite
  51. *
  52. * @param {Cite~InputData} data - Input data
  53. * @param {Cite~InputOptions} [options={}] - Input options
  54. */
  55. function Cite (data, options = {}) {
  56. // Making it Scope-Safe
  57. if (!(this instanceof Cite)) {
  58. return new Cite(data, options)
  59. }
  60. /**
  61. * The default options for the output. See [input options](../#cite.in.options)
  62. *
  63. * @access protected
  64. * @memberof Cite#
  65. *
  66. * @property {Cite~InputOptions} options
  67. */
  68. this._options = options || {}
  69. /**
  70. * The saved-images-log
  71. *
  72. * @access protected
  73. * @memberof Cite#
  74. *
  75. * @property {Array<Array<String>>} log
  76. */
  77. this.log = []
  78. /**
  79. * The parsed data
  80. *
  81. * @access protected
  82. * @memberof Cite#
  83. *
  84. * @property {Array<CSL>} data
  85. */
  86. this.data = []
  87. this.set(data, options)
  88. this.options(options)
  89. this.save()
  90. return this
  91. }
  92. Object.assign(Cite.prototype, log, options, set, sort, get)
  93. Cite.prototype[Symbol.iterator] = function * () {
  94. yield * this.data
  95. }
  96. export default Cite