rategame-shared 1.1.491 → 1.1.492

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,5 +12,12 @@ export declare function toStoredRatingTag(tag: string): string;
12
12
  export declare function getRatingTagPath(tag: string): string;
13
13
  export declare function getStadiumRatingTagPath(stadiumId: string, tag: string): string;
14
14
  export declare function getExperienceRatingTagPath(experienceId: string, tag: string): string;
15
+ export type RatingTagEntityType = "game" | "stadium" | "experience";
16
+ export type RatingTagCountValue = {
17
+ count: number;
18
+ display: string;
19
+ };
20
+ export declare function getEntityRatingTagPath(entityType: RatingTagEntityType, tag: string, entityId?: string): string;
21
+ export declare function getSortedRatingTags(ratingTagCounts: Record<string, RatingTagCountValue> | undefined): Array<[string, RatingTagCountValue]>;
15
22
  export declare function extractRatingTags(text: string): ExtractedRatingTag[];
16
23
  export declare function parseRatingTextWithTags(text: string): RatingTextPart[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRatingTextWithTags = exports.extractRatingTags = exports.getExperienceRatingTagPath = exports.getStadiumRatingTagPath = exports.getRatingTagPath = exports.toStoredRatingTag = exports.normalizeRatingTag = void 0;
3
+ exports.parseRatingTextWithTags = exports.extractRatingTags = exports.getSortedRatingTags = exports.getEntityRatingTagPath = exports.getExperienceRatingTagPath = exports.getStadiumRatingTagPath = exports.getRatingTagPath = exports.toStoredRatingTag = exports.normalizeRatingTag = void 0;
4
4
  const RATING_TAG_PATTERN = /(?:^|\s)(#[\p{L}\p{N}]+)/gu;
5
5
  function normalizeRatingTag(display) {
6
6
  return display.normalize("NFKC").toLowerCase();
@@ -23,6 +23,30 @@ function getExperienceRatingTagPath(experienceId, tag) {
23
23
  return `/experiences/${experienceId}/tag/${encodeURIComponent(toStoredRatingTag(tag).slice(1))}`;
24
24
  }
25
25
  exports.getExperienceRatingTagPath = getExperienceRatingTagPath;
26
+ function getEntityRatingTagPath(entityType, tag, entityId) {
27
+ if (entityType === "stadium") {
28
+ return getStadiumRatingTagPath(entityId !== null && entityId !== void 0 ? entityId : "", tag);
29
+ }
30
+ if (entityType === "experience") {
31
+ return getExperienceRatingTagPath(entityId !== null && entityId !== void 0 ? entityId : "", tag);
32
+ }
33
+ return getRatingTagPath(tag);
34
+ }
35
+ exports.getEntityRatingTagPath = getEntityRatingTagPath;
36
+ function getSortedRatingTags(ratingTagCounts) {
37
+ if (!ratingTagCounts) {
38
+ return [];
39
+ }
40
+ return Object.entries(ratingTagCounts)
41
+ .filter(([, tag]) => tag.count > 0)
42
+ .sort(([keyA, a], [keyB, b]) => {
43
+ if (b.count !== a.count) {
44
+ return b.count - a.count;
45
+ }
46
+ return a.display.localeCompare(b.display) || keyA.localeCompare(keyB);
47
+ });
48
+ }
49
+ exports.getSortedRatingTags = getSortedRatingTags;
26
50
  function getRatingTagMatches(text) {
27
51
  const matches = [];
28
52
  const regex = new RegExp(RATING_TAG_PATTERN.source, RATING_TAG_PATTERN.flags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rategame-shared",
3
- "version": "1.1.491",
3
+ "version": "1.1.492",
4
4
  "description": "This package contains shared resources for the Rate Game project.",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",