Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
putnik committed Mar 5, 2024
1 parent d88a5cc commit 4dcc1c6
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function loadDefaultReference(): Promise<void> {
return;
}

const sparql: string = `SELECT ?wiki WHERE { ?wiki wdt:P31/wdt:P279* wd:Q33120876 . ?wiki wdt:P856 ?site . FILTER REGEX(STR(?site), "https://${location.host}/") }`;
const sparql: string = `SELECT ?wiki WHERE { ?wiki wdt:P31/wdt:P279* wd:Q33120876 . ?wiki wdt:P856 ?site . FILTER REGEX(STR(?site), "https://${ location.host }/") }`;
const data: SparqlResponse = await sparqlRequest( sparql );
if ( !data?.results?.bindings?.length ) {
return;
Expand Down
30 changes: 15 additions & 15 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export async function setProperties( properties: Property[] ): Promise<void> {
} ) );

await bulkInsertIndexedDB( propertiesStore, data );
console.debug( `${properties.length} properties saved.` );
console.debug( `${ properties.length } properties saved.` );
}

export async function getType( typeId: ItemId ): Promise<Type | undefined> {
Expand All @@ -189,7 +189,7 @@ export async function setTypes( types: Type[] ): Promise<void> {
} ) );

await bulkInsertIndexedDB( typesStore, data );
console.debug( `${types.length} types saved.` );
console.debug( `${ types.length } types saved.` );
}

export async function getUnit( unitId: ItemId ): Promise<string[] | undefined> {
Expand All @@ -205,7 +205,7 @@ export async function setUnits( units: UnitsData ): Promise<void> {
expires
} ) );
await bulkInsertIndexedDB( unitsStore, data );
console.debug( `${data.length} units saved.` );
console.debug( `${ data.length } units saved.` );
}

function prepareUnit( unitId: ItemId, unitData: any ): string[] {
Expand All @@ -214,8 +214,8 @@ function prepareUnit( unitId: ItemId, unitData: any ): string[] {
return [];
}

if ( getI18nConfig( `units.${unitId}` ) ) {
unit = getI18nConfig( `units.${unitId}` );
if ( getI18nConfig( `units.${ unitId }` ) ) {
unit = getI18nConfig( `units.${ unitId }` );
}

if ( unitData.labels && unitData.labels[ contentLanguage ] ) {
Expand Down Expand Up @@ -266,13 +266,13 @@ async function loadUnits( units: ItemId[] ): Promise<void> {
async function loadUnitsSparql( typeIds: ItemId[], onlyUnitIds?: ItemId[] ): Promise<ItemId[]> {
const sparql: string = `SELECT DISTINCT (SUBSTR(STR(?unit), 32) as ?unitId) ?unitLabel ?unitAltLabel ?code WITH {
SELECT DISTINCT ?unit {
${onlyUnitIds?.length ? `VALUES ?unit {wd:${onlyUnitIds.join( ' wd:' )}}.` : ''}
VALUES ?type {wd:${typeIds.join( ' wd:' )}}.
${ onlyUnitIds?.length ? `VALUES ?unit {wd:${ onlyUnitIds.join( ' wd:' ) }}.` : '' }
VALUES ?type {wd:${ typeIds.join( ' wd:' ) }}.
?unit wdt:P31?/wdt:P279* ?type.
}} AS %Q {
INCLUDE %Q
OPTIONAL { ?unit wdt:P5061 ?code. FILTER(lang(?code) IN ("${contentLanguage}","mul")) }.
SERVICE wikibase:label { bd:serviceParam wikibase:language "${contentLanguage}" }
OPTIONAL { ?unit wdt:P5061 ?code. FILTER(lang(?code) IN ("${ contentLanguage }","mul")) }.
SERVICE wikibase:label { bd:serviceParam wikibase:language "${ contentLanguage }" }
}`;
const data: SparqlUnitsResponse = await sparqlRequest( sparql ) as SparqlUnitsResponse;
if ( !data?.results?.bindings?.length ) {
Expand All @@ -291,7 +291,7 @@ async function loadUnitsSparql( typeIds: ItemId[], onlyUnitIds?: ItemId[] ): Pro
}
continue;
}
unit = getI18nConfig( `units.${unitId}` ) || [];
unit = getI18nConfig( `units.${ unitId }` ) || [];

if ( bindings.unitLabel?.value !== unitId ) {
unit.push( prepareUnitSearchString( bindings.unitLabel?.value ) );
Expand All @@ -307,9 +307,9 @@ async function loadUnitsSparql( typeIds: ItemId[], onlyUnitIds?: ItemId[] ): Pro
unitsData[ unitId ] = unit;
if ( unit.length ) {
unitIds.push( unitId );
console.debug( `Unit ${unitId} loaded.` );
console.debug( `Unit ${ unitId } loaded.` );
} else {
console.debug( `Unit ${unitId} has no search strings.` );
console.debug( `Unit ${ unitId } has no search strings.` );
}
}
await setUnits( unitsData );
Expand Down Expand Up @@ -362,7 +362,7 @@ async function realLoadProperties( propertyIds: PropertyId[] ): Promise<void> {
const propertyId: PropertyId = key as PropertyId;
const entity: KeyValue = data.entities[ propertyId ];
if ( entity.labels === undefined ) {
console.debug( `Is property ${propertyId} deleted?` );
console.debug( `Is property ${ propertyId } deleted?` );
continue;
}
const label: string = getLabelValue( entity.labels, [ userLanguage, contentLanguage ], propertyId );
Expand Down Expand Up @@ -556,7 +556,7 @@ export async function getOrLoadProperty( propertyId: PropertyId ): Promise<Prope
await realLoadProperties( [ propertyId ] );
result = await getProperty( propertyId );
if ( typeof result === 'undefined' ) {
console.debug( `Data missed for property ${propertyId}` );
console.debug( `Data missed for property ${ propertyId }` );
return undefined;
}
}
Expand All @@ -571,7 +571,7 @@ export async function getOrLoadUnit( unitId: ItemId ): Promise<string[] | undefi
await loadUnits( [ unitId ] );
result = await getUnit( unitId );
if ( typeof result === 'undefined' ) {
console.debug( `Data missed for unit ${unitId}` );
console.debug( `Data missed for unit ${ unitId }` );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getRefSup( url: string, text: string ): JQuery {
.attr( 'href', url )
.attr( 'rel', 'noopener noreferrer' )
.attr( 'target', '_blank' )
.text( `[${text}]` );
.text( `[${ text }]` );
return $( '<sup>' )
.addClass( 'infobox-export-sup' )
.append( $link );
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function formatItemValue( value: ItemValue ): Promise<JQuery> {
const $mainLabel: JQuery = $( '<span>' )
.addClass( 'infobox-export-main-label' )
.text( itemLabel?.label || '' );
const $wdLink: JQuery = getRefSup( `https://wikidata.org/wiki/${value.id}`, 'd' );
const $wdLink: JQuery = getRefSup( `https://wikidata.org/wiki/${ value.id }`, 'd' );
const $label: JQuery = $( '<span>' ).append( $mainLabel, $wdLink );
if ( itemLabel?.description ) {
$label.append( $( '<span>' ).text( ' — ' + itemLabel.description ) );
Expand All @@ -106,7 +106,7 @@ function formatTimeValue( value: TimeValue ): JQuery {
let dateString: string;
if ( value.precision === 7 ) {
const century: number = Math.floor( ( parseInt( value.time.slice( 1, 5 ), 10 ) - 1 ) / 100 );
dateString = getConfig( `centuries.${century}` ) + getI18n( 'age-postfix' ) + bceMark;
dateString = getConfig( `centuries.${ century }` ) + getI18n( 'age-postfix' ) + bceMark;
} else {
const options: KeyValue = {
timeZone: 'UTC'
Expand Down
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ export async function prepareExternalId( context: Context ): Promise<Statement[]
return [];
}

const sparql = `SELECT ?item WHERE { ?item wdt:${context.propertyId} "${externalId}" } LIMIT 1`;
const sparql = `SELECT ?item WHERE { ?item wdt:${ context.propertyId } "${ externalId }" } LIMIT 1`;
const data: SparqlResponse = await sparqlRequest( sparql );
if ( data.results.bindings.length ) {
const url: string = data.results.bindings[ 0 ].item.value;
window.open( `${url}#${context.propertyId}`, '_blank' );
window.open( `${ url }#${ context.propertyId }`, '_blank' );

return [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export async function filterItemStatements( propertyId: PropertyId, statements:
const statementItemIds: ItemId[] = statements.map( ( statement: Statement ) => (
( statement.mainsnak.datavalue.value as ItemValue ).id
) );
const sparql: string = `SELECT DISTINCT ?item { VALUES ?item {wd:${statementItemIds.join( ' wd:' )}}.
VALUES ?class {wd:${property.constraints.valueType.join( ' wd:' )}}.
const sparql: string = `SELECT DISTINCT ?item { VALUES ?item {wd:${ statementItemIds.join( ' wd:' ) }}.
VALUES ?class {wd:${ property.constraints.valueType.join( ' wd:' ) }}.
?item wdt:P31?/wdt:P279* ?class }`;
const data: SparqlResponse = await sparqlRequest( sparql );
const validItemIds: ItemId[] = [];
Expand Down
12 changes: 6 additions & 6 deletions src/parser/quantity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,22 @@ async function recognizeUnits( text: string, units: KeyValue, label?: string ):
let expr = search[ j ];
if ( search[ j ].charAt( 0 ) !== '^' ) {
if ( search[ j ].length < 5 ) {
expr = `^${expr}|[\\d\\s\\.]${expr}\\.?$`;
expr = `^${ expr }|[\\d\\s\\.]${ expr }\\.?$`;
} else {
expr = `[\\d\\s\\.]${expr}`;
expr = `[\\d\\s\\.]${ expr }`;
}
}
if ( text.match( new RegExp( expr ) ) ) {
result.push( `http://www.wikidata.org/entity/${itemId}` );
result.push( `http://www.wikidata.org/entity/${ itemId }` );
break;
}

if ( search[ j ].charAt( 0 ) === '^' || label === undefined ) {
continue;
}
const labelRegExp = new RegExp( `\\s${search[ j ]}:?$` );
const labelRegExp = new RegExp( `\\s${ search[ j ] }:?$` );
if ( label.match( labelRegExp ) ) {
result.push( `http://www.wikidata.org/entity/${itemId}` );
result.push( `http://www.wikidata.org/entity/${ itemId }` );
break;
}
}
Expand Down Expand Up @@ -304,7 +304,7 @@ export async function prepareQuantity( context: Context ): Promise<Statement[]>
const supportedProperty: Property | undefined = await getOrLoadProperty( supportedProperties[ j ] );
const units: ItemId[] = supportedProperty?.units || [];
if ( units.length === 1 ) {
qualifierQuantity.unit = `http://www.wikidata.org/entity/${units[ 0 ]}`;
qualifierQuantity.unit = `http://www.wikidata.org/entity/${ units[ 0 ] }`;
if ( !statement.qualifiers ) {
statement.qualifiers = {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function addLanguageQualifier( statement: Statement, context: Context ): P
if ( !Object.keys( codes ).length ) {
return;
}
const sparql: string = `SELECT ?item WHERE { ?item wdt:P218 ?value . FILTER ( ?value IN ("${Object.keys( codes ).join( '","' )}") ) }`;
const sparql: string = `SELECT ?item WHERE { ?item wdt:P218 ?value . FILTER ( ?value IN ("${ Object.keys( codes ).join( '","' ) }") ) }`;
const data: SparqlResponse = await sparqlRequest( sparql );
for ( let i = 0; i < data.results.bindings.length; i++ ) {
const langValue: EntityIdValue = {
Expand Down
4 changes: 2 additions & 2 deletions src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function preloadAvailableProperties( typeIds: ItemId[] ): Promise<v
for ( const typeId of typeIdsToQuery ) {
const sparql: string = `SELECT DISTINCT (SUBSTR(STR(?property), 32) as ?pid) {
?property rdf:type wikibase:Property.
VALUES ?supportedTypes {wikibase:${supportedTypes.join( ' wikibase:' )}}.
VALUES ?supportedTypes {wikibase:${ supportedTypes.join( ' wikibase:' ) }}.
?property wikibase:propertyType ?supportedTypes.
?property p:P2302 ?scopeConstraint.
?scopeConstraint ps:P2302 wd:Q53869507;
Expand All @@ -57,7 +57,7 @@ export async function preloadAvailableProperties( typeIds: ItemId[] ): Promise<v
FILTER ( ?class != wd:Q29934200 )
}
FILTER( IF ( BOUND(?class),
EXISTS { wd:${typeId} wdt:P279* ?class. },
EXISTS { wd:${ typeId } wdt:P279* ?class. },
NOT EXISTS { ?property wikibase:propertyType wikibase:ExternalId }
) )
}`;
Expand Down
6 changes: 3 additions & 3 deletions src/types/wikidata/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type ItemId = `Q${number}`
export type PropertyId = `P${number}`
export type Entity = `http://www.wikidata.org/entity/${ItemId}`
export type ItemId = `Q${ number }`
export type PropertyId = `P${ number }`
export type Entity = `http://www.wikidata.org/entity/${ ItemId }`
export type Unit = Entity | '1';

export type Rank = 'normal' | 'preferred' | 'deprecated';
Expand Down
4 changes: 2 additions & 2 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function getPropertyFieldset( propertyId: PropertyId, statements: Statemen
const property: Property | undefined = await getOrLoadProperty( propertyId );
const label: string = property?.label || propertyId;
const $labelLink: JQuery = $( '<a>' )
.attr( 'href', `https://wikidata.org/wiki/Property:${propertyId}` )
.attr( 'href', `https://wikidata.org/wiki/Property:${ propertyId }` )
.attr( 'rel', 'noopener noreferrer' )
.attr( 'target', '_blank' )
.text( label );
Expand Down Expand Up @@ -291,7 +291,7 @@ async function createClaims( statements: Statement[] ): Promise<void> {
propertyIds = unique( propertyIds );
for ( const i in propertyIds ) {
const propertyId: PropertyId = propertyIds[ i ];
$( `.no-wikidata[data-wikidata-property-id=${propertyId}]` )
$( `.no-wikidata[data-wikidata-property-id=${ propertyId }]` )
.removeClass( 'no-wikidata' )
.off( 'dblclick' ); // FIXME: disable only clickEvent
}
Expand Down

0 comments on commit 4dcc1c6

Please sign in to comment.