New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@citation-js/plugin-wikidata

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@citation-js/plugin-wikidata - npm Package Compare versions

Comparing version 0.4.7 to 0.4.8

4

lib-mjs/api.js
import { util } from '@citation-js/core';
var fetchFile = util.fetchFile,
fetchFileAsync = util.fetchFileAsync;
const fetchFile = util.fetchFile,
fetchFileAsync = util.fetchFileAsync;
export function parse(urls) {

@@ -5,0 +5,0 @@ return [].concat(urls).map(fetchFile);

@@ -5,18 +5,2 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { logger } from '@citation-js/core';

@@ -28,9 +12,5 @@ import * as response from './response';

function resolveProp(prop_, entity, unkown) {
function resolve(_ref, _ref2) {
var _ref3 = _toArray(_ref),
prop = _ref3[0],
parts = _ref3.slice(1);
var claims = _ref2.claims;
function resolve([prop, ...parts], {
claims
}) {
if (!parts.length) {

@@ -43,4 +23,4 @@ return claims[prop];

var parts = prop_.split('.');
unkown["delete"](parts[0]);
const parts = prop_.split('.');
unkown.delete(parts[0]);
return resolve(parts, entity);

@@ -50,12 +30,8 @@ }

function prepareValue(statement, entity, unkown) {
var _ref4;
if (_typeof(statement) !== 'object') {
var value = resolveProp(statement, entity, unkown);
if (typeof statement !== 'object') {
const value = resolveProp(statement, entity, unkown);
return value && value[0].value;
}
var values = (_ref4 = []).concat.apply(_ref4, _toConsumableArray(statement.props.map(function (prop) {
return resolveProp(prop, entity, unkown);
}).filter(Boolean)));
const values = [].concat(...statement.props.map(prop => resolveProp(prop, entity, unkown)).filter(Boolean));

@@ -70,3 +46,3 @@ if (statement.values === 'all') {

export function parseEntity(entity) {
var data = {
const data = {
id: entity.id,

@@ -76,9 +52,9 @@ _wikiId: entity.id,

};
var unkown = new Set(Object.keys(entity.claims));
const unkown = new Set(Object.keys(entity.claims));
for (var prop in props) {
var input = prepareValue(props[prop], entity, unkown);
for (let prop in props) {
const input = prepareValue(props[prop], entity, unkown);
if (input) {
var output = parseProp(prop, input, entity);
const output = parseProp(prop, input, entity);

@@ -97,9 +73,9 @@ if (output) {

for (var _iterator = unkown[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _prop = _step.value;
let prop = _step.value;
if (_prop in ignoredProps) {
if (prop in ignoredProps) {
continue;
}
logger.unmapped('[plugin-wikidata]', 'property', _prop);
logger.unmapped('[plugin-wikidata]', 'property', prop);
}

@@ -111,4 +87,4 @@ } catch (err) {

try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}

@@ -149,30 +125,15 @@ } finally {

function _parseEntitiesAsync() {
_parseEntitiesAsync = _asyncToGenerator(regeneratorRuntime.mark(function _callee(_ref5) {
var entities;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
entities = _ref5.entities;
_context.next = 3;
return response.parseAsync(entities);
case 3:
_context.t0 = parseEntity;
return _context.abrupt("return", _context.sent.map(_context.t0));
case 5:
case "end":
return _context.stop();
}
}
}, _callee);
}));
_parseEntitiesAsync = _asyncToGenerator(function* ({
entities
}) {
return (yield response.parseAsync(entities)).map(parseEntity);
});
return _parseEntitiesAsync.apply(this, arguments);
}
export function parseEntities(_ref6) {
var entities = _ref6.entities;
export function parseEntities({
entities
}) {
return response.parse(entities).map(parseEntity);
}
export { parseEntities as parse, parseEntitiesAsync as parseAsync, parseEntities as default };
import wdk from 'wikidata-sdk';
import config from './config';
var parseWikidata = function parseWikidata(data, langs) {
var list = [].concat(data);
const parseWikidata = function parseWikidata(data, langs) {
const list = [].concat(data);
return [].concat(wdk.getManyEntities(list, langs || config.langs));

@@ -7,0 +7,0 @@ };

@@ -8,11 +8,11 @@ import { plugins } from '@citation-js/core';

import config from './config';
var ref = '@wikidata';
var parsers = {
id: id,
entity: entity,
prop: prop,
url: url,
api: api
const ref = '@wikidata';
const parsers = {
id,
entity,
prop,
url,
api
};
var formats = {
const formats = {
'@wikidata/id': {

@@ -26,5 +26,6 @@ parse: id.parse,

'@wikidata/list+text': {
parse: function parse(data) {
parse(data) {
return data.trim().split(/(?:[\s,]\s*)/g);
},
parseType: {

@@ -41,3 +42,3 @@ dataType: 'String',

predicate: /^(https?:\/\/(?:www\.)?wikidata.org\/w\/api\.php(?:\?.*)?)$/,
"extends": '@else/url'
extends: '@else/url'
}

@@ -58,3 +59,3 @@ },

predicate: /\/(Q\d+)(?:[#?/]|\s*$)/,
"extends": '@else/url'
extends: '@else/url'
}

@@ -80,6 +81,7 @@ },

'@wikidata/array+object': {
parse: function parse(responses) {
return responses.reduce(function (combined, _ref) {
var success = _ref.success,
entities = _ref.entities;
parse(responses) {
return responses.reduce((combined, {
success,
entities
}) => {
combined.success &= success;

@@ -90,2 +92,3 @@ Object.assign(combined.entities, entities);

},
parseType: {

@@ -106,4 +109,4 @@ dataType: 'Array',

input: formats,
config: config
config
});
export { ref, parsers, formats };

@@ -9,10 +9,2 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
import { logger } from '@citation-js/core';

@@ -24,18 +16,13 @@ import { parse as parseNameString } from '@citation-js/name';

var getSeriesOrdinal = function getSeriesOrdinal(_ref) {
var P1545 = _ref.P1545;
return P1545 ? parseInt(P1545[0]) : -1;
};
const getSeriesOrdinal = ({
P1545
}) => P1545 ? parseInt(P1545[0]) : -1;
var getStatedAs = function getStatedAs(qualifiers) {
var _ref2;
const getStatedAs = qualifiers => [].concat(...[qualifiers.P1932, qualifiers.P1810].filter(Boolean));
return (_ref2 = []).concat.apply(_ref2, _toConsumableArray([qualifiers.P1932, qualifiers.P1810].filter(Boolean)));
};
var parseName = function parseName(_ref3) {
var value = _ref3.value,
qualifiers = _ref3.qualifiers;
var _getStatedAs = getStatedAs(qualifiers),
const parseName = ({
value,
qualifiers
}) => {
let _getStatedAs = getStatedAs(qualifiers),
_getStatedAs2 = _slicedToArray(_getStatedAs, 1),

@@ -55,39 +42,29 @@ name = _getStatedAs2[0];

var parseNames = function parseNames(values) {
return values.map(parseName).sort(function (a, b) {
return a._ordinal - b._ordinal;
});
const parseNames = values => {
return values.map(parseName).sort((a, b) => a._ordinal - b._ordinal);
};
var getPlace = function getPlace(value) {
var country = value.claims.P17[0].value;
var shortNames = country.claims.P1813.filter(function (_ref4) {
var P31 = _ref4.qualifiers.P31;
return !P31 || P31[0] !== 'Q28840786';
});
const getPlace = value => {
const country = value.claims.P17[0].value;
const shortNames = country.claims.P1813.filter(({
qualifiers: {
P31
}
}) => !P31 || P31[0] !== 'Q28840786');
return getLabel(value) + ', ' + (shortNames[0] || country.claims.P1448[0]).value;
};
var getTitle = function getTitle(value) {
const getTitle = value => {
return value.claims.P1476 ? value.claims.P1476[0].value : getLabel(value);
};
var parseKeywords = function parseKeywords(values) {
return values.map(function (_ref5) {
var value = _ref5.value;
return getLabel(value);
}).join(',');
const parseKeywords = values => {
return values.map(({
value
}) => getLabel(value)).join(',');
};
var parseDateRange = function parseDateRange(dates) {
return {
'date-parts': dates.map(function (date) {
return parseDate(date.value);
}).filter(function (date) {
return date && date['date-parts'];
}).map(function (date) {
return date['date-parts'][0];
})
};
};
const parseDateRange = dates => ({
'date-parts': dates.map(date => parseDate(date.value)).filter(date => date && date['date-parts']).map(date => date['date-parts'][0])
});

@@ -158,7 +135,5 @@ export function parseProp(prop, value, entity) {

var lang = config.langs.find(function (lang) {
return entity.labels[lang];
});
const lang = config.langs.find(lang => entity.labels[lang]);
return entity.labels[lang];
}
export { parseProp as parse, parseProp as default };

@@ -5,25 +5,17 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
import { simplify } from 'wikidata-sdk';
import { parse as fetch, parseAsync as fetchAsync } from './api';
import { parse as getUrls } from './id';
var SIMPLIFY_OPTS = {
const SIMPLIFY_OPTS = {
keepQualifiers: true,
timeConverter: 'simple-day'
};
var FETCH_PLACE = {
const FETCH_PLACE = {
P17: null
};
var FETCH_PUBLISHER = {
const FETCH_PUBLISHER = {
P740: FETCH_PLACE,
P159: FETCH_PLACE
};
var FETCH_ADDITIONAL = {
const FETCH_ADDITIONAL = {
P50: null,

@@ -62,3 +54,3 @@ P57: null,

function flat(array, part) {
array.push.apply(array, _toConsumableArray(part));
array.push(...part);
return array;

@@ -73,10 +65,5 @@ }

entity._needed = Object.assign(entity._needed || {}, needed);
return Object.keys(entity.claims).filter(function (prop) {
return prop in needed;
}).map(function (prop) {
return entity.claims[prop].map(function (_ref) {
var value = _ref.value;
return value;
});
}).reduce(flat, []);
return Object.keys(entity.claims).filter(prop => prop in needed).map(prop => entity.claims[prop].map(({
value
}) => value.id || value)).reduce(flat, []);
}

@@ -86,7 +73,6 @@

if (!old) {
var allIds = [];
let allIds = [];
for (var _id in entities) {
var _ids = collectAdditionalIds(entities[_id], FETCH_ADDITIONAL);
for (let id in entities) {
const ids = collectAdditionalIds(entities[id], FETCH_ADDITIONAL);
var _iteratorNormalCompletion = true;

@@ -97,7 +83,7 @@ var _didIteratorError = false;

try {
for (var _iterator = _ids[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _id2 = _step.value;
for (var _iterator = ids[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
let id = _step.value;
if (!allIds.includes(_id2)) {
allIds.push(_id2);
if (!allIds.includes(id)) {
allIds.push(id);
}

@@ -110,4 +96,4 @@ }

try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}

@@ -125,3 +111,3 @@ } finally {

var ids = [];
const ids = [];
var _iteratorNormalCompletion2 = true;

@@ -148,3 +134,3 @@ var _didIteratorError2 = false;

for (var _iterator3 = entity.claims[prop][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var claim = _step3.value;
let claim = _step3.value;

@@ -156,3 +142,3 @@ if (claim.value && claim.value.id) {

claim.value = entities[claim.value];
ids.push.apply(ids, _toConsumableArray(collectAdditionalIds(claim.value, entity._needed[prop])));
ids.push(...collectAdditionalIds(claim.value, entity._needed[prop]));
}

@@ -164,4 +150,4 @@ } catch (err) {

try {
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
_iterator3["return"]();
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
_iterator3.return();
}

@@ -184,4 +170,4 @@ } finally {

try {
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
_iterator2["return"]();
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}

@@ -210,5 +196,3 @@ } finally {

function filterIdsAndGetUrls(needed, cache) {
var shouldFetch = needed.filter(function (id, i) {
return !(id in cache) && needed.indexOf(id) === i;
});
const shouldFetch = needed.filter((id, i) => !(id in cache) && needed.indexOf(id) === i);
return getUrls(shouldFetch);

@@ -218,4 +202,4 @@ }

function addItemsToCache(response, cache) {
var _JSON$parse = JSON.parse(response),
entities = _JSON$parse.entities;
const _JSON$parse = JSON.parse(response),
entities = _JSON$parse.entities;

@@ -233,16 +217,12 @@ Object.assign(cache, simplifyEntities(entities));

function finalizeItems(entities, cache) {
return Object.keys(entities).map(function (id) {
return cache[id];
});
return Object.keys(entities).map(id => cache[id]);
}
export function fillCache(entities) {
var cache = simplifyEntities(entities);
var state = initLoopState(entities, cache);
const cache = simplifyEntities(entities);
let state = initLoopState(entities, cache);
while (state.needed.length) {
var urls = filterIdsAndGetUrls(state.needed, cache);
urls.map(function (url) {
return addItemsToCache(fetch(url), cache);
});
const urls = filterIdsAndGetUrls(state.needed, cache);
urls.map(url => addItemsToCache(fetch(url), cache));
state = updateLoopState(state, cache);

@@ -254,3 +234,3 @@ }

export function parse(entities) {
var cache = fillCache(entities);
const cache = fillCache(entities);
return finalizeItems(entities, cache);

@@ -263,62 +243,22 @@ }

function _fillCacheAsync() {
_fillCacheAsync = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(entities) {
var cache, state, urls;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
cache = simplifyEntities(entities);
state = initLoopState(entities, cache);
_fillCacheAsync = _asyncToGenerator(function* (entities) {
const cache = simplifyEntities(entities);
let state = initLoopState(entities, cache);
case 2:
if (!state.needed.length) {
_context2.next = 9;
break;
}
while (state.needed.length) {
const urls = filterIdsAndGetUrls(state.needed, cache);
yield Promise.all(urls.map(function () {
var _ref = _asyncToGenerator(function* (url) {
return addItemsToCache((yield fetchAsync(url)), cache);
});
urls = filterIdsAndGetUrls(state.needed, cache);
_context2.next = 6;
return Promise.all(urls.map(function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee(url) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.t0 = addItemsToCache;
_context.next = 3;
return fetchAsync(url);
return function (_x3) {
return _ref.apply(this, arguments);
};
}()));
state = updateLoopState(state, cache);
}
case 3:
_context.t1 = _context.sent;
_context.t2 = cache;
return _context.abrupt("return", (0, _context.t0)(_context.t1, _context.t2));
case 6:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x3) {
return _ref2.apply(this, arguments);
};
}()));
case 6:
state = updateLoopState(state, cache);
_context2.next = 2;
break;
case 9:
return _context2.abrupt("return", cache);
case 10:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return cache;
});
return _fillCacheAsync.apply(this, arguments);

@@ -332,23 +272,7 @@ }

function _parseAsync() {
_parseAsync = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(entities) {
var cache;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return fillCacheAsync(entities);
case 2:
cache = _context3.sent;
return _context3.abrupt("return", finalizeItems(entities, cache));
case 4:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
_parseAsync = _asyncToGenerator(function* (entities) {
const cache = yield fillCacheAsync(entities);
return finalizeItems(entities, cache);
});
return _parseAsync.apply(this, arguments);
}

@@ -1,3 +0,1 @@

export var parse = function parse(input) {
return input.match(/\/(Q\d+)(?:[#?/]|\s*$)/)[1];
};
export const parse = input => input.match(/\/(Q\d+)(?:[#?/]|\s*$)/)[1];

@@ -78,3 +78,3 @@ "use strict";

value
}) => value)).reduce(flat, []);
}) => value.id || value)).reduce(flat, []);
}

@@ -81,0 +81,0 @@

{
"name": "@citation-js/plugin-wikidata",
"version": "0.4.7",
"version": "0.4.8",
"description": "Plugin for Wikidata for Citation.js",

@@ -39,3 +39,3 @@ "keywords": [

"devDependencies": {
"@citation-js/core": "^0.4.7"
"@citation-js/core": "^0.4.8"
},

@@ -45,3 +45,3 @@ "peerDependencies": {

},
"gitHead": "96d42cc13bf1ce0a53f54f186007ff40b15d1460"
"gitHead": "0be8501cbe0541828e73912230b9d56762038f8d"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc