Skip to content

Commit 5e8655f

Browse files
authored
Added store page URL option (#4)
1 parent 636746f commit 5e8655f

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,14 @@ What to do if a price is missing. Either "useZero", "useNull" or "useEmptyString
393393
| Type | Default value | Possible values | Required |
394394
| --- | --- | --- | --- |
395395
| `string` | `"useNull"` | `"useZero"`, `"useNull"` or `"useEmptyString"` | Yes |
396+
</details>
397+
398+
<details>
399+
<summary><code>storePage</code></summary>
400+
401+
Whether or not to include the game's store page URL. NOTE: THIS IS NOT GUARANTEED TO ALWAYS RESULT IN A WORKING URL, AS IT NEEDS TO BE INFERRED AND IS NOT AVAILABLE THROUGH THE API.
402+
403+
| Type | Default value | Possible values | Required |
404+
| --- | --- | --- | --- |
405+
| `boolean` | `true` | `true` or `false` | No |
396406
</details>

config.default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"WholesalePrice"
5454
],
5555
"missingPricePolicy": "useNull"
56-
}
56+
},
57+
"storePage": true
5758
}
5859
}

config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@
660660
"missingPricePolicy"
661661
],
662662
"additionalProperties": false
663+
},
664+
"storePage": {
665+
"description": "Whether or not to include the game's store page URL. NOTE: THIS IS NOT GUARANTEED TO ALWAYS RESULT IN A WORKING URL, AS IT NEEDS TO BE INFERRED AND IS NOT AVAILABLE THROUGH THE API.",
666+
"type": "boolean",
667+
"default": true
663668
}
664669
},
665670
"additionalProperties": false,

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ function getPropertyValue(game, property, propertyValue) {
202202
case "categories":
203203
result = getCategories(game, propertyValue);
204204
break;
205+
case "storePage":
206+
result = getStorePageUrl(game, propertyValue);
207+
break;
205208
default:
206209
// Due to our config validation, this should never happen, but just in case...
207210
console.log(`Invalid property: ${property}`);
@@ -369,4 +372,20 @@ function getCategories(game, categoriesProperty) {
369372
}
370373

371374
return categories;
375+
}
376+
377+
function getStorePageUrl(game, storePageUrlProperty) {
378+
if (!storePageUrlProperty) { return undefined; }
379+
380+
if(!game.LocalizedProperties[0].ProductTitle || !game.ProductId) {
381+
return undefined;
382+
}
383+
384+
// 1. Convert to lowercase
385+
// 2. Replace all non-alphanumeric characters with a dash
386+
// 3. Replace multiple dashes with a single dash
387+
// 4. Remove leading and trailing dashes
388+
const formattedGameName = game.LocalizedProperties[0].ProductTitle.toLowerCase().replace(/[^a-z0-9]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
389+
390+
return `https://www.xbox.com/${CONFIG.language}/games/store/${formattedGameName}/${game.ProductId}`;
372391
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "game-pass-api",
33
"type": "module",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"description": "Utility for fetching all games currently available for Xbox Game Pass and formatting the resulting data according to user requirements.",
66
"main": "index.js",
77
"dependencies": {

0 commit comments

Comments
 (0)