@react-pakistan/util-functions 1.25.11 → 1.25.13

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.
Files changed (73) hide show
  1. package/constants/cache-time.d.ts +2 -0
  2. package/constants/cache-time.js +3 -1
  3. package/general/generate-article-schema.d.ts +49 -0
  4. package/general/generate-article-schema.js +100 -0
  5. package/general/generate-blog-schema.d.ts +7 -5
  6. package/general/generate-blog-schema.js +7 -5
  7. package/general/generate-book-schema.d.ts +57 -0
  8. package/general/generate-book-schema.js +109 -0
  9. package/general/generate-breadcrumb-schema.d.ts +22 -6
  10. package/general/generate-breadcrumb-schema.js +15 -4
  11. package/general/generate-carousel-schema.d.ts +51 -0
  12. package/general/generate-carousel-schema.js +172 -0
  13. package/general/generate-course-schema.d.ts +52 -0
  14. package/general/generate-course-schema.js +124 -0
  15. package/general/generate-dataset-schema.d.ts +64 -0
  16. package/general/generate-dataset-schema.js +156 -0
  17. package/general/generate-discussion-forum-schema.d.ts +38 -0
  18. package/general/generate-discussion-forum-schema.js +67 -0
  19. package/general/generate-education-schema.d.ts +67 -0
  20. package/general/generate-education-schema.js +137 -0
  21. package/general/generate-employer-aggregate-rating-schema.d.ts +28 -0
  22. package/general/generate-employer-aggregate-rating-schema.js +64 -0
  23. package/general/generate-event-schema.d.ts +62 -0
  24. package/general/generate-event-schema.js +214 -0
  25. package/general/generate-faq-schema.d.ts +15 -11
  26. package/general/generate-faq-schema.js +18 -6
  27. package/general/generate-image-metadata-schema.d.ts +35 -0
  28. package/general/generate-image-metadata-schema.js +73 -0
  29. package/general/generate-job-posting-schema.d.ts +48 -0
  30. package/general/generate-job-posting-schema.js +120 -0
  31. package/general/generate-local-business-schema.d.ts +41 -0
  32. package/general/generate-local-business-schema.js +75 -0
  33. package/general/generate-math-solver-schema.d.ts +44 -0
  34. package/general/generate-math-solver-schema.js +83 -0
  35. package/general/generate-movie-carousel-schema.d.ts +50 -0
  36. package/general/generate-movie-carousel-schema.js +160 -0
  37. package/general/generate-organization-schema.d.ts +9 -5
  38. package/general/generate-organization-schema.js +9 -5
  39. package/general/generate-profile-page-schema.d.ts +36 -0
  40. package/general/generate-profile-page-schema.js +82 -0
  41. package/general/generate-qa-page-schema.d.ts +33 -0
  42. package/general/generate-qa-page-schema.js +67 -0
  43. package/general/generate-recipe-schema.d.ts +48 -0
  44. package/general/generate-recipe-schema.js +104 -0
  45. package/general/generate-review-snippet-schema.d.ts +51 -0
  46. package/general/generate-review-snippet-schema.js +137 -0
  47. package/general/generate-shopping-loyalty-program-schema.d.ts +37 -0
  48. package/general/generate-shopping-loyalty-program-schema.js +59 -0
  49. package/general/generate-shopping-merchant-listing-schema.d.ts +52 -0
  50. package/general/generate-shopping-merchant-listing-schema.js +153 -0
  51. package/general/generate-shopping-merchant-return-policy-schema.d.ts +31 -0
  52. package/general/generate-shopping-merchant-return-policy-schema.js +68 -0
  53. package/general/generate-shopping-merchant-shipping-policy-schema.d.ts +35 -0
  54. package/general/generate-shopping-merchant-shipping-policy-schema.js +74 -0
  55. package/general/generate-shopping-overview-schema.d.ts +51 -0
  56. package/general/generate-shopping-overview-schema.js +157 -0
  57. package/general/generate-shopping-product-snippet-schema.d.ts +56 -0
  58. package/general/generate-shopping-product-snippet-schema.js +167 -0
  59. package/general/generate-shopping-variants-schema.d.ts +45 -0
  60. package/general/generate-shopping-variants-schema.js +143 -0
  61. package/general/generate-software-app-schema.d.ts +61 -0
  62. package/general/generate-software-app-schema.js +143 -0
  63. package/general/generate-speakable-schema.d.ts +63 -0
  64. package/general/generate-speakable-schema.js +139 -0
  65. package/general/generate-subscription-schema.d.ts +59 -0
  66. package/general/generate-subscription-schema.js +133 -0
  67. package/general/generate-vacation-rental-schema.d.ts +66 -0
  68. package/general/generate-vacation-rental-schema.js +135 -0
  69. package/general/generate-video-schema.d.ts +74 -0
  70. package/general/generate-video-schema.js +163 -0
  71. package/general/index.d.ts +30 -0
  72. package/general/index.js +30 -0
  73. package/package.json +1 -1
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Generate schema.org `ProfilePage` JSON-LD describing a person or profile.
3
+ *
4
+ * Accepts a `mainEntity` person object along with optional author or
5
+ * organization metadata. Images are normalized to `ImageObject` entries.
6
+ *
7
+ * See `ProfilePageOptions` and `PersonRef` for the input shape.
8
+ * @returns A JSON-LD compatible `ProfilePage` object
9
+ */
10
+ interface ImageRef {
11
+ url: string;
12
+ width?: number;
13
+ height?: number;
14
+ }
15
+ interface PersonRef {
16
+ name: string;
17
+ url?: string;
18
+ sameAs?: string[];
19
+ jobTitle?: string;
20
+ image?: string | ImageRef;
21
+ }
22
+ interface OrgRef {
23
+ name: string;
24
+ url?: string;
25
+ }
26
+ interface ProfilePageOptions {
27
+ name?: string;
28
+ headline?: string;
29
+ url?: string;
30
+ description?: string;
31
+ mainEntity?: PersonRef;
32
+ author?: PersonRef | OrgRef;
33
+ about?: string[];
34
+ }
35
+ export declare const generateProfilePageSchema: ({ name, headline, url, description, mainEntity, author, about, }: ProfilePageOptions) => any;
36
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org `ProfilePage` JSON-LD describing a person or profile.
4
+ *
5
+ * Accepts a `mainEntity` person object along with optional author or
6
+ * organization metadata. Images are normalized to `ImageObject` entries.
7
+ *
8
+ * See `ProfilePageOptions` and `PersonRef` for the input shape.
9
+ * @returns A JSON-LD compatible `ProfilePage` object
10
+ */
11
+ var __assign = (this && this.__assign) || function () {
12
+ __assign = Object.assign || function(t) {
13
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
14
+ s = arguments[i];
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
16
+ t[p] = s[p];
17
+ }
18
+ return t;
19
+ };
20
+ return __assign.apply(this, arguments);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.generateProfilePageSchema = void 0;
24
+ var formatImage = function (image) {
25
+ if (!image)
26
+ return undefined;
27
+ if (typeof image === 'string')
28
+ return image;
29
+ return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
30
+ };
31
+ var formatPerson = function (p) {
32
+ if (!p)
33
+ return undefined;
34
+ var out = { '@type': 'Person', name: p.name };
35
+ if (p.url)
36
+ out.url = p.url;
37
+ if (p.sameAs)
38
+ out.sameAs = p.sameAs;
39
+ if (p.jobTitle)
40
+ out.jobTitle = p.jobTitle;
41
+ var img = formatImage(p.image);
42
+ if (img)
43
+ out.image = img;
44
+ return out;
45
+ };
46
+ var formatAuthor = function (a) {
47
+ if (!a)
48
+ return undefined;
49
+ var isPerson = a.jobTitle !== undefined ||
50
+ a.sameAs !== undefined;
51
+ if (isPerson)
52
+ return formatPerson(a);
53
+ var out = { '@type': 'Organization', name: a.name };
54
+ if (a.url)
55
+ out.url = a.url;
56
+ return out;
57
+ };
58
+ var generateProfilePageSchema = function (_a) {
59
+ var name = _a.name, headline = _a.headline, url = _a.url, description = _a.description, mainEntity = _a.mainEntity, author = _a.author, about = _a.about;
60
+ var schema = {
61
+ '@context': 'https://schema.org',
62
+ '@type': 'ProfilePage',
63
+ };
64
+ if (name)
65
+ schema.name = name;
66
+ if (headline)
67
+ schema.headline = headline;
68
+ if (url)
69
+ schema.mainEntityOfPage = { '@type': 'WebPage', '@id': url };
70
+ if (description)
71
+ schema.description = description;
72
+ var me = formatPerson(mainEntity);
73
+ if (me)
74
+ schema.mainEntity = me;
75
+ var a = formatAuthor(author);
76
+ if (a)
77
+ schema.author = a;
78
+ if (about && about.length > 0)
79
+ schema.about = about;
80
+ return schema;
81
+ };
82
+ exports.generateProfilePageSchema = generateProfilePageSchema;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Generate schema.org `QAPage` JSON-LD (Question + Answers).
3
+ *
4
+ * The helper formats a single `Question` and its `Answer` entries,
5
+ * including author references and date fields. Use `acceptedAnswer` and
6
+ * `suggestedAnswer` to provide preferred or additional answers.
7
+ *
8
+ * See `QAPageOptions` and related types for the input contract.
9
+ * @returns A JSON-LD compatible `QAPage` object
10
+ */
11
+ interface PersonRef {
12
+ name: string;
13
+ url?: string;
14
+ }
15
+ interface AnswerItem {
16
+ text: string;
17
+ author?: string | PersonRef;
18
+ datePublished?: string;
19
+ }
20
+ interface QuestionItem {
21
+ name: string;
22
+ text?: string;
23
+ author?: string | PersonRef;
24
+ datePublished?: string;
25
+ answers?: AnswerItem[];
26
+ acceptedAnswer?: AnswerItem;
27
+ }
28
+ interface QAPageOptions {
29
+ headline?: string;
30
+ mainEntity: QuestionItem;
31
+ }
32
+ export declare const generateQAPageSchema: ({ headline, mainEntity, }: QAPageOptions) => any;
33
+ export {};
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org `QAPage` JSON-LD (Question + Answers).
4
+ *
5
+ * The helper formats a single `Question` and its `Answer` entries,
6
+ * including author references and date fields. Use `acceptedAnswer` and
7
+ * `suggestedAnswer` to provide preferred or additional answers.
8
+ *
9
+ * See `QAPageOptions` and related types for the input contract.
10
+ * @returns A JSON-LD compatible `QAPage` object
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.generateQAPageSchema = void 0;
14
+ var formatPerson = function (p) {
15
+ if (!p)
16
+ return undefined;
17
+ if (typeof p === 'string')
18
+ return { '@type': 'Person', name: p };
19
+ var out = { '@type': 'Person', name: p.name };
20
+ if (p.url)
21
+ out.url = p.url;
22
+ return out;
23
+ };
24
+ var formatAnswer = function (a) {
25
+ var out = { '@type': 'Answer' };
26
+ if (a.text)
27
+ out.text = a.text;
28
+ if (a.author)
29
+ out.author = formatPerson(a.author);
30
+ if (a.datePublished)
31
+ out.datePublished = a.datePublished;
32
+ return out;
33
+ };
34
+ var generateQAPageSchema = function (_a) {
35
+ var headline = _a.headline, mainEntity = _a.mainEntity;
36
+ var question = {
37
+ '@type': 'Question',
38
+ name: mainEntity.name,
39
+ };
40
+ if (mainEntity.text)
41
+ question.text = mainEntity.text;
42
+ if (mainEntity.author)
43
+ question.author = formatPerson(mainEntity.author);
44
+ if (mainEntity.datePublished)
45
+ question.datePublished = mainEntity.datePublished;
46
+ if (mainEntity.answers && mainEntity.answers.length > 0) {
47
+ question.answerCount = mainEntity.answers.length;
48
+ question.acceptedAnswer = mainEntity.acceptedAnswer
49
+ ? formatAnswer(mainEntity.acceptedAnswer)
50
+ : undefined;
51
+ question.suggestedAnswer = mainEntity.answers
52
+ .filter(function (a) {
53
+ return !mainEntity.acceptedAnswer ||
54
+ a.text !== mainEntity.acceptedAnswer.text;
55
+ })
56
+ .map(function (a) { return formatAnswer(a); });
57
+ }
58
+ var schema = {
59
+ '@context': 'https://schema.org',
60
+ '@type': 'QAPage',
61
+ mainEntity: question,
62
+ };
63
+ if (headline)
64
+ schema.headline = headline;
65
+ return schema;
66
+ };
67
+ exports.generateQAPageSchema = generateQAPageSchema;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Generate schema.org `Recipe` JSON-LD, with support for `HowToStep`
3
+ * instructions and `ItemList` ingredients.
4
+ *
5
+ * Accepts recipe metadata (times, yields, cuisine, ingredients, steps)
6
+ * and will format steps as `HowToStep` objects and images as `ImageObject`
7
+ * entries when provided.
8
+ *
9
+ * See `RecipeOptions` for the accepted input shape.
10
+ * @returns A JSON-LD compatible `Recipe` object
11
+ */
12
+ interface ImageRef {
13
+ url: string;
14
+ width?: number;
15
+ height?: number;
16
+ }
17
+ interface PersonRef {
18
+ name: string;
19
+ url?: string;
20
+ }
21
+ interface HowToStep {
22
+ name?: string;
23
+ text: string;
24
+ image?: string | ImageRef;
25
+ url?: string;
26
+ }
27
+ interface AggregateRating {
28
+ ratingValue: number | string;
29
+ reviewCount?: number;
30
+ }
31
+ interface RecipeOptions {
32
+ name: string;
33
+ description?: string;
34
+ image?: string | ImageRef;
35
+ author?: string | PersonRef;
36
+ recipeYield?: string;
37
+ prepTime?: string;
38
+ cookTime?: string;
39
+ totalTime?: string;
40
+ recipeCategory?: string | string[];
41
+ recipeCuisine?: string | string[];
42
+ keywords?: string | string[];
43
+ recipeIngredient?: string[];
44
+ recipeInstructions?: HowToStep[];
45
+ aggregateRating?: AggregateRating;
46
+ }
47
+ export declare const generateRecipeSchema: ({ name, description, image, author, recipeYield, prepTime, cookTime, totalTime, recipeCategory, recipeCuisine, keywords, recipeIngredient, recipeInstructions, aggregateRating, }: RecipeOptions) => any;
48
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org `Recipe` JSON-LD, with support for `HowToStep`
4
+ * instructions and `ItemList` ingredients.
5
+ *
6
+ * Accepts recipe metadata (times, yields, cuisine, ingredients, steps)
7
+ * and will format steps as `HowToStep` objects and images as `ImageObject`
8
+ * entries when provided.
9
+ *
10
+ * See `RecipeOptions` for the accepted input shape.
11
+ * @returns A JSON-LD compatible `Recipe` object
12
+ */
13
+ var __assign = (this && this.__assign) || function () {
14
+ __assign = Object.assign || function(t) {
15
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
16
+ s = arguments[i];
17
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
18
+ t[p] = s[p];
19
+ }
20
+ return t;
21
+ };
22
+ return __assign.apply(this, arguments);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.generateRecipeSchema = void 0;
26
+ var formatImage = function (image) {
27
+ if (!image)
28
+ return undefined;
29
+ if (typeof image === 'string')
30
+ return image;
31
+ return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
32
+ };
33
+ var formatPerson = function (p) {
34
+ if (!p)
35
+ return undefined;
36
+ if (typeof p === 'string')
37
+ return { '@type': 'Person', name: p };
38
+ var out = { '@type': 'Person', name: p.name };
39
+ if (p.url)
40
+ out.url = p.url;
41
+ return out;
42
+ };
43
+ var formatHowToStep = function (s) {
44
+ var out = { '@type': 'HowToStep' };
45
+ if (s.name)
46
+ out.name = s.name;
47
+ if (s.text)
48
+ out.text = s.text;
49
+ if (s.url)
50
+ out.url = s.url;
51
+ var img = formatImage(s.image);
52
+ if (img)
53
+ out.image = img;
54
+ return out;
55
+ };
56
+ var generateRecipeSchema = function (_a) {
57
+ var name = _a.name, description = _a.description, image = _a.image, author = _a.author, recipeYield = _a.recipeYield, prepTime = _a.prepTime, cookTime = _a.cookTime, totalTime = _a.totalTime, recipeCategory = _a.recipeCategory, recipeCuisine = _a.recipeCuisine, keywords = _a.keywords, recipeIngredient = _a.recipeIngredient, recipeInstructions = _a.recipeInstructions, aggregateRating = _a.aggregateRating;
58
+ var schema = {
59
+ '@context': 'https://schema.org',
60
+ '@type': 'Recipe',
61
+ name: name,
62
+ };
63
+ if (description)
64
+ schema.description = description;
65
+ var img = formatImage(image);
66
+ if (img)
67
+ schema.image = img;
68
+ var a = formatPerson(author);
69
+ if (a)
70
+ schema.author = a;
71
+ if (recipeYield)
72
+ schema.recipeYield = recipeYield;
73
+ if (prepTime)
74
+ schema.prepTime = prepTime;
75
+ if (cookTime)
76
+ schema.cookTime = cookTime;
77
+ if (totalTime)
78
+ schema.totalTime = totalTime;
79
+ if (recipeCategory)
80
+ schema.recipeCategory = Array.isArray(recipeCategory)
81
+ ? recipeCategory.join(', ')
82
+ : recipeCategory;
83
+ if (recipeCuisine)
84
+ schema.recipeCuisine = Array.isArray(recipeCuisine)
85
+ ? recipeCuisine.join(', ')
86
+ : recipeCuisine;
87
+ if (keywords)
88
+ schema.keywords = Array.isArray(keywords) ? keywords.join(', ') : keywords;
89
+ if (recipeIngredient && recipeIngredient.length > 0)
90
+ schema.recipeIngredient = recipeIngredient;
91
+ if (recipeInstructions && recipeInstructions.length > 0) {
92
+ schema.recipeInstructions = recipeInstructions.map(formatHowToStep);
93
+ }
94
+ if (aggregateRating) {
95
+ schema.aggregateRating = {
96
+ '@type': 'AggregateRating',
97
+ ratingValue: aggregateRating.ratingValue,
98
+ };
99
+ if (aggregateRating.reviewCount != null)
100
+ schema.aggregateRating.reviewCount = aggregateRating.reviewCount;
101
+ }
102
+ return schema;
103
+ };
104
+ exports.generateRecipeSchema = generateRecipeSchema;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Generate structured data for Review snippets and `AggregateRating`.
3
+ *
4
+ * Accepts a compact `ReviewSnippetOptions` object and returns a plain object
5
+ * compatible with schema.org JSON-LD for embedding in a page. The function
6
+ * supports formatting `Person` and `Organization` references and can produce
7
+ * an `AggregateRating` object either from supplied options or derived from
8
+ * reviews.
9
+ *
10
+ * See the TypeScript interfaces below for the exact input shape.
11
+ * @returns A JSON-LD compatible Review / ReviewSnippet object
12
+ */
13
+ interface PersonRef {
14
+ name: string;
15
+ url?: string;
16
+ }
17
+ interface OrgRef {
18
+ name: string;
19
+ url?: string;
20
+ }
21
+ interface RatingItem {
22
+ ratingValue: number | string;
23
+ bestRating?: number | string;
24
+ worstRating?: number | string;
25
+ }
26
+ interface ReviewItem {
27
+ author?: string | PersonRef;
28
+ datePublished?: string;
29
+ reviewBody?: string;
30
+ reviewRating?: RatingItem;
31
+ name?: string;
32
+ url?: string;
33
+ publisher?: string | OrgRef;
34
+ }
35
+ interface AggregateRatingOptions {
36
+ ratingValue: number | string;
37
+ reviewCount?: number;
38
+ ratingCount?: number;
39
+ bestRating?: number | string;
40
+ worstRating?: number | string;
41
+ }
42
+ interface ReviewSnippetOptions {
43
+ itemReviewed?: string | {
44
+ name: string;
45
+ '@type'?: string;
46
+ };
47
+ reviews?: ReviewItem[];
48
+ aggregateRating?: AggregateRatingOptions;
49
+ }
50
+ export declare const generateReviewSnippetSchema: ({ itemReviewed, reviews, aggregateRating, }: ReviewSnippetOptions) => any;
51
+ export default generateReviewSnippetSchema;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /**
3
+ * Generate structured data for Review snippets and `AggregateRating`.
4
+ *
5
+ * Accepts a compact `ReviewSnippetOptions` object and returns a plain object
6
+ * compatible with schema.org JSON-LD for embedding in a page. The function
7
+ * supports formatting `Person` and `Organization` references and can produce
8
+ * an `AggregateRating` object either from supplied options or derived from
9
+ * reviews.
10
+ *
11
+ * See the TypeScript interfaces below for the exact input shape.
12
+ * @returns A JSON-LD compatible Review / ReviewSnippet object
13
+ */
14
+ var __assign = (this && this.__assign) || function () {
15
+ __assign = Object.assign || function(t) {
16
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
17
+ s = arguments[i];
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19
+ t[p] = s[p];
20
+ }
21
+ return t;
22
+ };
23
+ return __assign.apply(this, arguments);
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateReviewSnippetSchema = void 0;
27
+ var formatPerson = function (p) {
28
+ if (!p)
29
+ return undefined;
30
+ if (typeof p === 'string')
31
+ return { '@type': 'Person', name: p };
32
+ var out = { '@type': 'Person', name: p.name };
33
+ if (p.url)
34
+ out.url = p.url;
35
+ return out;
36
+ };
37
+ var formatOrganization = function (o) {
38
+ if (!o)
39
+ return undefined;
40
+ if (typeof o === 'string')
41
+ return { '@type': 'Organization', name: o };
42
+ var out = { '@type': 'Organization', name: o.name };
43
+ if (o.url)
44
+ out.url = o.url;
45
+ return out;
46
+ };
47
+ var formatReview = function (r) {
48
+ var out = { '@type': 'Review' };
49
+ if (r.author)
50
+ out.author = formatPerson(r.author);
51
+ if (r.datePublished)
52
+ out.datePublished = r.datePublished;
53
+ if (r.reviewBody)
54
+ out.reviewBody = r.reviewBody;
55
+ if (r.name)
56
+ out.name = r.name;
57
+ if (r.url)
58
+ out.url = r.url;
59
+ if (r.publisher)
60
+ out.publisher = formatOrganization(r.publisher);
61
+ if (r.reviewRating) {
62
+ out.reviewRating = __assign(__assign({ '@type': 'Rating', ratingValue: r.reviewRating.ratingValue }, (r.reviewRating.bestRating != null && {
63
+ bestRating: r.reviewRating.bestRating,
64
+ })), (r.reviewRating.worstRating != null && {
65
+ worstRating: r.reviewRating.worstRating,
66
+ }));
67
+ }
68
+ return out;
69
+ };
70
+ var generateReviewSnippetSchema = function (_a) {
71
+ var itemReviewed = _a.itemReviewed, reviews = _a.reviews, aggregateRating = _a.aggregateRating;
72
+ // If an itemReviewed is provided we return that item with nested review(s)
73
+ var hasItem = !!itemReviewed;
74
+ // Map reviews if present
75
+ var mappedReviews = reviews && reviews.length > 0 ? reviews.map(formatReview) : undefined;
76
+ // Compute aggregate rating from provided aggregateRating or from reviews
77
+ var agg = undefined;
78
+ if (aggregateRating) {
79
+ agg = __assign(__assign(__assign(__assign({ '@type': 'AggregateRating', ratingValue: aggregateRating.ratingValue }, (aggregateRating.reviewCount != null && {
80
+ reviewCount: aggregateRating.reviewCount,
81
+ })), (aggregateRating.ratingCount != null && {
82
+ ratingCount: aggregateRating.ratingCount,
83
+ })), (aggregateRating.bestRating != null && {
84
+ bestRating: aggregateRating.bestRating,
85
+ })), (aggregateRating.worstRating != null && {
86
+ worstRating: aggregateRating.worstRating,
87
+ }));
88
+ }
89
+ else if (reviews && reviews.length > 0) {
90
+ var ratings = reviews
91
+ .map(function (r) { return (r.reviewRating ? Number(r.reviewRating.ratingValue) : NaN); })
92
+ .filter(function (n) { return !Number.isNaN(n); });
93
+ if (ratings.length > 0) {
94
+ var sum = ratings.reduce(function (a, b) { return a + b; }, 0);
95
+ agg = {
96
+ '@type': 'AggregateRating',
97
+ ratingValue: sum / ratings.length,
98
+ reviewCount: reviews.length,
99
+ ratingCount: ratings.length,
100
+ };
101
+ }
102
+ }
103
+ if (hasItem) {
104
+ var item = {
105
+ '@context': 'https://schema.org',
106
+ '@type': typeof itemReviewed === 'string'
107
+ ? 'Thing'
108
+ : (itemReviewed === null || itemReviewed === void 0 ? void 0 : itemReviewed['@type']) || 'Thing',
109
+ name: typeof itemReviewed === 'string'
110
+ ? itemReviewed
111
+ : itemReviewed.name,
112
+ };
113
+ if (mappedReviews)
114
+ item.review = mappedReviews;
115
+ if (agg)
116
+ item.aggregateRating = agg;
117
+ return item;
118
+ }
119
+ // No itemReviewed -> if single review return a Review object, else return an array wrapper
120
+ if (mappedReviews && mappedReviews.length === 1) {
121
+ var r = mappedReviews[0];
122
+ var schema_1 = __assign({ '@context': 'https://schema.org' }, r);
123
+ if (agg)
124
+ schema_1.aggregateRating = agg;
125
+ return schema_1;
126
+ }
127
+ var schema = {
128
+ '@context': 'https://schema.org',
129
+ };
130
+ if (mappedReviews)
131
+ schema.review = mappedReviews;
132
+ if (agg)
133
+ schema.aggregateRating = agg;
134
+ return schema;
135
+ };
136
+ exports.generateReviewSnippetSchema = generateReviewSnippetSchema;
137
+ exports.default = exports.generateReviewSnippetSchema;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Generate schema.org structured data for a loyalty or membership program
3
+ * (`ProgramMembership`).
4
+ *
5
+ * The helper formats membership details, member references, points and
6
+ * optional offers into a `ProgramMembership` object. Only supplied fields
7
+ * are emitted.
8
+ *
9
+ * See `LoyaltyOptions` for the accepted input properties.
10
+ * @returns A JSON-LD compatible `ProgramMembership` object
11
+ */
12
+ interface MemberRef {
13
+ name: string;
14
+ url?: string;
15
+ }
16
+ interface OrganizationRef {
17
+ name: string;
18
+ url?: string;
19
+ }
20
+ interface LoyaltyOffer {
21
+ description?: string;
22
+ url?: string;
23
+ }
24
+ interface LoyaltyOptions {
25
+ programName: string;
26
+ programUrl?: string;
27
+ programId?: string;
28
+ member?: MemberRef | OrganizationRef;
29
+ membershipNumber?: string;
30
+ enrollmentDate?: string;
31
+ pointsBalance?: number;
32
+ pointsEarned?: number;
33
+ benefits?: string[];
34
+ offers?: LoyaltyOffer[];
35
+ }
36
+ export declare const generateShoppingLoyaltyProgramSchema: ({ programName, programUrl, programId, member, membershipNumber, enrollmentDate, pointsBalance, pointsEarned, benefits, offers, }: LoyaltyOptions) => any;
37
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org structured data for a loyalty or membership program
4
+ * (`ProgramMembership`).
5
+ *
6
+ * The helper formats membership details, member references, points and
7
+ * optional offers into a `ProgramMembership` object. Only supplied fields
8
+ * are emitted.
9
+ *
10
+ * See `LoyaltyOptions` for the accepted input properties.
11
+ * @returns A JSON-LD compatible `ProgramMembership` object
12
+ */
13
+ var __assign = (this && this.__assign) || function () {
14
+ __assign = Object.assign || function(t) {
15
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
16
+ s = arguments[i];
17
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
18
+ t[p] = s[p];
19
+ }
20
+ return t;
21
+ };
22
+ return __assign.apply(this, arguments);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.generateShoppingLoyaltyProgramSchema = void 0;
26
+ var formatAgent = function (a) {
27
+ if (!a)
28
+ return undefined;
29
+ return __assign({ name: a.name }, (a.url && { url: a.url }));
30
+ };
31
+ var generateShoppingLoyaltyProgramSchema = function (_a) {
32
+ var programName = _a.programName, programUrl = _a.programUrl, programId = _a.programId, member = _a.member, membershipNumber = _a.membershipNumber, enrollmentDate = _a.enrollmentDate, pointsBalance = _a.pointsBalance, pointsEarned = _a.pointsEarned, benefits = _a.benefits, offers = _a.offers;
33
+ var schema = {
34
+ '@context': 'https://schema.org',
35
+ '@type': 'ProgramMembership',
36
+ programName: programName,
37
+ };
38
+ if (programUrl)
39
+ schema.url = programUrl;
40
+ if (programId)
41
+ schema['@id'] = programId;
42
+ if (member)
43
+ schema.member = formatAgent(member);
44
+ if (membershipNumber)
45
+ schema.membershipNumber = membershipNumber;
46
+ if (enrollmentDate)
47
+ schema.enrollmentDate = enrollmentDate;
48
+ if (typeof pointsBalance === 'number')
49
+ schema.pointsBalance = pointsBalance;
50
+ if (typeof pointsEarned === 'number')
51
+ schema.pointsEarned = pointsEarned;
52
+ if (benefits && benefits.length > 0)
53
+ schema.benefits = benefits;
54
+ if (offers && offers.length > 0) {
55
+ schema.offers = offers.map(function (o) { return (__assign(__assign({ '@type': 'Offer' }, (o.description && { description: o.description })), (o.url && { url: o.url }))); });
56
+ }
57
+ return schema;
58
+ };
59
+ exports.generateShoppingLoyaltyProgramSchema = generateShoppingLoyaltyProgramSchema;