All files / ext.wikilambda.app/mixins wikidataUtils.js

100% Statements 27/27
100% Branches 4/4
100% Functions 2/2
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 287x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 13x 13x 13x 13x 13x 13x 7x 7x  
/**
 * WikiLambda Vue editor: Wikidata utils mixin
 * Mixin with util functions to handle wikidata entities
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
'use strict';
 
module.exports = exports = {
	methods: {
		/**
		 * Extract the array of wikidata Lexeme IDs referred
		 * in given ZObject
		 *
		 * @param {Object} zobject
		 * @return {Array}
		 */
		extractWikidataLexemeIds: function ( zobject ) {
			const str = JSON.stringify( zobject );
			const regexp = /(L[1-9]\d*)/g;
			const matches = [ ...str.matchAll( regexp ) ];
			const allMatches = matches.map( ( groups ) => groups[ 0 ] );
			return [ ...new Set( allMatches ) ];
		}
	}
};