| ; | |
| Object.defineProperty(exports, "__esModule", { | |
| value: true | |
| }); | |
| exports.format = format; | |
| exports.parse = parse; | |
| exports.parseMixed = parseMixed; | |
| exports.parseNew = parseNew; | |
| exports.parseOld = parseOld; | |
| var _core = require("@citation-js/core"); | |
| var _config = _interopRequireDefault(require("./config.json")); | |
| var _index = require("./spec/index.js"); | |
| var _converters = _interopRequireDefault(require("./converters.js")); | |
| var _dataTypes = _interopRequireDefault(require("./dataTypes.json")); | |
| function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | |
| function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } | |
| function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | |
| function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } | |
| function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } | |
| function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | |
| const LINE_MATCH = /^[A-Z][A-Z0-9] {2}-( |$)/; | |
| const LINE_SPLIT = / {2}-(?: |$)/; | |
| const TRANSLATORS = new Map(); | |
| function prepareTranslator(spec) { | |
| if (!TRANSLATORS.has(spec)) { | |
| for (const mapping of spec) { | |
| if (mapping.target === 'issued' && !Array.isArray(mapping.source)) { | |
| mapping.convert = _converters.default.YEAR; | |
| continue; | |
| } | |
| if (mapping.target in _dataTypes.default) { | |
| mapping.convert = _converters.default[_dataTypes.default[mapping.target]]; | |
| } | |
| if (mapping.convert && mapping.convert.keepAll === true) { | |
| continue; | |
| } | |
| if (Array.isArray(mapping.source)) { | |
| if (mapping.convert) { | |
| const { | |
| toSource, | |
| toTarget | |
| } = mapping.convert; | |
| mapping.convert = { | |
| toTarget(...args) { | |
| return toTarget(_converters.default.ANY.toTarget(...args)); | |
| }, | |
| toSource(...args) { | |
| return _converters.default.ANY.toSource(toSource(...args)); | |
| } | |
| }; | |
| } else { | |
| mapping.convert = _converters.default.ANY; | |
| } | |
| } | |
| } | |
| TRANSLATORS.set(spec, new _core.util.Translator(spec)); | |
| } | |
| return TRANSLATORS.get(spec); | |
| } | |
| function parseType(type) { | |
| type = type.toUpperCase(); | |
| if (type === 'JOURN') { | |
| return 'JOUR'; | |
| } | |
| return type; | |
| } | |
| function parse(text) { | |
| const entries = []; | |
| let lastEntry; | |
| let lastTag; | |
| for (let line of text.split(/\r?\n/)) { | |
| line = line.trim(); | |
| if (!LINE_MATCH.test(line)) { | |
| if (lastEntry && lastTag) { | |
| lastEntry[lastTag] += ' ' + line; | |
| } | |
| continue; | |
| } | |
| let [tag, value] = line.split(LINE_SPLIT); | |
| if (value.trim() === '') { | |
| lastTag = undefined; | |
| continue; | |
| } | |
| switch (tag) { | |
| case 'ER': | |
| lastEntry = undefined; | |
| lastTag = undefined; | |
| break; | |
| case 'TY': | |
| lastEntry = {}; | |
| entries.push(lastEntry); | |
| value = parseType(value); | |
| default: | |
| if (Array.isArray(lastEntry[tag])) { | |
| lastEntry[tag].push(value); | |
| } else { | |
| lastEntry[tag] = lastEntry[tag] ? [lastEntry[tag], value] : value; | |
| } | |
| lastTag = tag; | |
| } | |
| } | |
| return entries; | |
| } | |
| function parseOld(data) { | |
| return prepareTranslator(_index.SPECS.old).convertToTarget(data); | |
| } | |
| function parseNew(data) { | |
| return prepareTranslator(_index.SPECS.new).convertToTarget(data); | |
| } | |
| function parseMixed(data) { | |
| return prepareTranslator(_index.SPECS.mixed).convertToTarget(data); | |
| } | |
| function format(data, { | |
| type, | |
| format = type || 'text', | |
| spec | |
| } = {}) { | |
| const outputSpec = spec || _config.default.outputSpec; | |
| const translate = prepareTranslator(_index.SPECS[outputSpec]).convertToSource; | |
| const entries = data.map(entry => translate(entry.type ? entry : _objectSpread(_objectSpread({}, entry), {}, { | |
| type: 'document' | |
| }))); | |
| if (format === 'object') { | |
| return entries; | |
| } | |
| return entries.map(entry => { | |
| const tags = []; | |
| for (const tag in entry) { | |
| if (tag === 'TY') { | |
| continue; | |
| } | |
| tags.push(...[].concat(entry[tag]).map(value => `${tag} - ${value.toString().replace(/(.{70})/g, '$1\n')}`)); | |
| } | |
| tags.unshift(`TY - ${entry.TY}`); | |
| tags.push('ER - '); | |
| return tags.join('\n'); | |
| }).join('\n'); | |
| } |
Xet Storage Details
- Size:
- 5.21 kB
- Xet hash:
- e8d5717aa4de84d817f25b6e10a2462a4b402733f0b956d76b79b91474fbf93f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.