@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,139 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org structured data for an `Article` or `WebPage` with a
4
+ * `SpeakableSpecification`.
5
+ *
6
+ * The `speakable` input may be an array of XPaths/CSS selectors or an
7
+ * object with `xpath`/`cssSelector` arrays. The helper will produce a
8
+ * `SpeakableSpecification` and attach it to the chosen page type.
9
+ *
10
+ * See `SpeakableOptions` for full details.
11
+ * @returns A JSON-LD compatible Article/WebPage object with `speakable`
12
+ * specification when provided.
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.generateSpeakableSchema = 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 formatPublisher = function (p) {
38
+ if (!p)
39
+ return undefined;
40
+ var out = { '@type': 'Organization', name: p.name };
41
+ if (p.url)
42
+ out.url = p.url;
43
+ if (p.logo)
44
+ out.logo = __assign(__assign({ '@type': 'ImageObject', url: p.logo.url }, (p.logo.width && { width: p.logo.width })), (p.logo.height && { height: p.logo.height }));
45
+ return out;
46
+ };
47
+ var buildSpeakable = function (s) {
48
+ if (!s)
49
+ return undefined;
50
+ // Normalize into SpeakableSpecification object
51
+ var spec = { '@type': 'SpeakableSpecification' };
52
+ if (Array.isArray(s)) {
53
+ // treat as xpath default
54
+ spec.xpath = s;
55
+ return spec;
56
+ }
57
+ if (s.xpath && s.xpath.length > 0)
58
+ spec.xpath = s.xpath;
59
+ if (s.cssSelector && s.cssSelector.length > 0)
60
+ spec.cssSelector = s.cssSelector;
61
+ return spec;
62
+ };
63
+ var formatReview = function (r) {
64
+ var out = { '@type': 'Review' };
65
+ if (r.author)
66
+ out.author = formatPerson(r.author);
67
+ if (r.datePublished)
68
+ out.datePublished = r.datePublished;
69
+ if (r.reviewBody)
70
+ out.reviewBody = r.reviewBody;
71
+ if (r.reviewRating) {
72
+ out.reviewRating = __assign(__assign({ '@type': 'Rating', ratingValue: r.reviewRating.ratingValue }, (r.reviewRating.bestRating != null && {
73
+ bestRating: r.reviewRating.bestRating,
74
+ })), (r.reviewRating.worstRating != null && {
75
+ worstRating: r.reviewRating.worstRating,
76
+ }));
77
+ }
78
+ return out;
79
+ };
80
+ var generateSpeakableSchema = function (_a) {
81
+ var _b = _a.type, type = _b === void 0 ? 'Article' : _b, headline = _a.headline, name = _a.name, description = _a.description, url = _a.url, author = _a.author, publisher = _a.publisher, speakable = _a.speakable, reviews = _a.reviews, aggregateRating = _a.aggregateRating, keywords = _a.keywords;
82
+ var out = {
83
+ '@context': 'https://schema.org',
84
+ '@type': type,
85
+ };
86
+ if (type === 'Article' && headline)
87
+ out.headline = headline;
88
+ if (type === 'WebPage' && name)
89
+ out.name = name;
90
+ if (description)
91
+ out.description = description;
92
+ if (url)
93
+ out.mainEntityOfPage = { '@type': 'WebPage', '@id': url };
94
+ var a = formatPerson(author);
95
+ if (a)
96
+ out.author = a;
97
+ var p = formatPublisher(publisher);
98
+ if (p)
99
+ out.publisher = p;
100
+ var s = buildSpeakable(speakable);
101
+ if (s)
102
+ out.speakable = s;
103
+ // Reviews
104
+ if (reviews && reviews.length > 0) {
105
+ var mapped = reviews.map(formatReview);
106
+ out.review = mapped;
107
+ // compute aggregate if not given
108
+ if (!aggregateRating) {
109
+ var ratings = reviews
110
+ .map(function (r) { return (r.reviewRating ? Number(r.reviewRating.ratingValue) : NaN); })
111
+ .filter(function (n) { return !Number.isNaN(n); });
112
+ if (ratings.length > 0) {
113
+ var sum = ratings.reduce(function (a, b) { return a + b; }, 0);
114
+ out.aggregateRating = {
115
+ '@type': 'AggregateRating',
116
+ ratingValue: sum / ratings.length,
117
+ reviewCount: reviews.length,
118
+ ratingCount: ratings.length,
119
+ };
120
+ }
121
+ }
122
+ }
123
+ if (aggregateRating) {
124
+ out.aggregateRating = __assign(__assign(__assign(__assign({ '@type': 'AggregateRating', ratingValue: aggregateRating.ratingValue }, (aggregateRating.reviewCount != null && {
125
+ reviewCount: aggregateRating.reviewCount,
126
+ })), (aggregateRating.ratingCount != null && {
127
+ ratingCount: aggregateRating.ratingCount,
128
+ })), (aggregateRating.bestRating != null && {
129
+ bestRating: aggregateRating.bestRating,
130
+ })), (aggregateRating.worstRating != null && {
131
+ worstRating: aggregateRating.worstRating,
132
+ }));
133
+ }
134
+ if (keywords && keywords.length > 0)
135
+ out.keywords = keywords.join(', ');
136
+ return out;
137
+ };
138
+ exports.generateSpeakableSchema = generateSpeakableSchema;
139
+ exports.default = exports.generateSpeakableSchema;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Generate schema.org JSON-LD for a `CreativeWork` representing a
3
+ * Subscription.
4
+ *
5
+ * Supports author/publisher, reviews and aggregate ratings, accessibility
6
+ * flags and keywords. Only provided fields are emitted in the returned
7
+ * object.
8
+ *
9
+ * See `SubscriptionOptions` for accepted properties.
10
+ * @returns A JSON-LD compatible `CreativeWork` (Subscription) 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 OrgRef {
22
+ name: string;
23
+ url?: string;
24
+ }
25
+ interface RatingItem {
26
+ ratingValue: number | string;
27
+ bestRating?: number | string;
28
+ worstRating?: number | string;
29
+ }
30
+ interface ReviewItem {
31
+ author?: string | PersonRef;
32
+ datePublished?: string;
33
+ reviewBody?: string;
34
+ reviewRating?: RatingItem;
35
+ }
36
+ interface AggregateRatingOptions {
37
+ ratingValue: number | string;
38
+ reviewCount?: number;
39
+ ratingCount?: number;
40
+ bestRating?: number | string;
41
+ worstRating?: number | string;
42
+ }
43
+ interface SubscriptionOptions {
44
+ name: string;
45
+ description?: string;
46
+ image?: string | ImageRef;
47
+ url?: string;
48
+ author?: string | PersonRef;
49
+ publisher?: string | OrgRef;
50
+ datePublished?: string;
51
+ dateModified?: string;
52
+ isAccessibleForFree?: boolean;
53
+ genre?: string | string[];
54
+ keywords?: string | string[];
55
+ reviews?: ReviewItem[];
56
+ aggregateRating?: AggregateRatingOptions;
57
+ }
58
+ export declare const generateSubscriptionSchema: ({ name, description, image, url, author, publisher, datePublished, dateModified, isAccessibleForFree, genre, keywords, reviews, aggregateRating, }: SubscriptionOptions) => any;
59
+ export default generateSubscriptionSchema;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org JSON-LD for a `CreativeWork` representing a
4
+ * Subscription.
5
+ *
6
+ * Supports author/publisher, reviews and aggregate ratings, accessibility
7
+ * flags and keywords. Only provided fields are emitted in the returned
8
+ * object.
9
+ *
10
+ * See `SubscriptionOptions` for accepted properties.
11
+ * @returns A JSON-LD compatible `CreativeWork` (Subscription) 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.generateSubscriptionSchema = 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 formatOrganization = function (o) {
44
+ if (!o)
45
+ return undefined;
46
+ if (typeof o === 'string')
47
+ return { '@type': 'Organization', name: o };
48
+ var out = { '@type': 'Organization', name: o.name };
49
+ if (o.url)
50
+ out.url = o.url;
51
+ return out;
52
+ };
53
+ var formatReview = function (r) {
54
+ var out = { '@type': 'Review' };
55
+ if (r.author)
56
+ out.author = formatPerson(r.author);
57
+ if (r.datePublished)
58
+ out.datePublished = r.datePublished;
59
+ if (r.reviewBody)
60
+ out.reviewBody = r.reviewBody;
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 generateSubscriptionSchema = function (_a) {
71
+ var name = _a.name, description = _a.description, image = _a.image, url = _a.url, author = _a.author, publisher = _a.publisher, datePublished = _a.datePublished, dateModified = _a.dateModified, isAccessibleForFree = _a.isAccessibleForFree, genre = _a.genre, keywords = _a.keywords, reviews = _a.reviews, aggregateRating = _a.aggregateRating;
72
+ var schema = {
73
+ '@context': 'https://schema.org',
74
+ '@type': 'CreativeWork',
75
+ name: name,
76
+ };
77
+ if (description)
78
+ schema.description = description;
79
+ var img = formatImage(image);
80
+ if (img)
81
+ schema.image = img;
82
+ if (url)
83
+ schema.url = url;
84
+ var a = formatPerson(author);
85
+ if (a)
86
+ schema.author = a;
87
+ var p = formatOrganization(publisher);
88
+ if (p)
89
+ schema.publisher = p;
90
+ if (datePublished)
91
+ schema.datePublished = datePublished;
92
+ if (dateModified)
93
+ schema.dateModified = dateModified;
94
+ if (isAccessibleForFree != null)
95
+ schema.isAccessibleForFree = isAccessibleForFree;
96
+ if (genre)
97
+ schema.genre = Array.isArray(genre) ? genre.join(', ') : genre;
98
+ if (keywords)
99
+ schema.keywords = Array.isArray(keywords) ? keywords.join(', ') : keywords;
100
+ // Reviews -> map and compute aggregateRating if possible
101
+ if (reviews && reviews.length > 0) {
102
+ var mapped = reviews.map(formatReview);
103
+ schema.review = mapped;
104
+ if (!aggregateRating) {
105
+ var ratings = reviews
106
+ .map(function (r) { return (r.reviewRating ? Number(r.reviewRating.ratingValue) : NaN); })
107
+ .filter(function (n) { return !Number.isNaN(n); });
108
+ if (ratings.length > 0) {
109
+ var sum = ratings.reduce(function (a, b) { return a + b; }, 0);
110
+ schema.aggregateRating = {
111
+ '@type': 'AggregateRating',
112
+ ratingValue: sum / ratings.length,
113
+ reviewCount: reviews.length,
114
+ ratingCount: ratings.length,
115
+ };
116
+ }
117
+ }
118
+ }
119
+ if (aggregateRating) {
120
+ schema.aggregateRating = __assign(__assign(__assign(__assign({ '@type': 'AggregateRating', ratingValue: aggregateRating.ratingValue }, (aggregateRating.reviewCount != null && {
121
+ reviewCount: aggregateRating.reviewCount,
122
+ })), (aggregateRating.ratingCount != null && {
123
+ ratingCount: aggregateRating.ratingCount,
124
+ })), (aggregateRating.bestRating != null && {
125
+ bestRating: aggregateRating.bestRating,
126
+ })), (aggregateRating.worstRating != null && {
127
+ worstRating: aggregateRating.worstRating,
128
+ }));
129
+ }
130
+ return schema;
131
+ };
132
+ exports.generateSubscriptionSchema = generateSubscriptionSchema;
133
+ exports.default = exports.generateSubscriptionSchema;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Generate schema.org `VacationRental` JSON-LD including optional reviews
3
+ * and `AggregateRating`.
4
+ *
5
+ * The function accepts address or geo information, images, host references,
6
+ * and occupancy data. Reviews and aggregate ratings are formatted into
7
+ * `Review` and `AggregateRating` objects when provided.
8
+ *
9
+ * See `VacationRentalOptions` below for supported inputs.
10
+ * @returns A JSON-LD compatible `VacationRental` 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 AddressRef {
22
+ streetAddress?: string;
23
+ addressLocality?: string;
24
+ addressRegion?: string;
25
+ postalCode?: string;
26
+ addressCountry?: string;
27
+ }
28
+ interface GeoRef {
29
+ latitude?: number | string;
30
+ longitude?: number | string;
31
+ }
32
+ interface RatingItem {
33
+ ratingValue: number | string;
34
+ bestRating?: number | string;
35
+ worstRating?: number | string;
36
+ }
37
+ interface ReviewItem {
38
+ author?: string | PersonRef;
39
+ datePublished?: string;
40
+ reviewBody?: string;
41
+ reviewRating?: RatingItem;
42
+ }
43
+ interface AggregateRatingOptions {
44
+ ratingValue: number | string;
45
+ reviewCount?: number;
46
+ ratingCount?: number;
47
+ bestRating?: number | string;
48
+ worstRating?: number | string;
49
+ }
50
+ interface VacationRentalOptions {
51
+ name: string;
52
+ description?: string;
53
+ image?: string | ImageRef | (string | ImageRef)[];
54
+ url?: string;
55
+ address?: string | AddressRef;
56
+ geo?: GeoRef;
57
+ numberOfRooms?: number;
58
+ numberOfBeds?: number;
59
+ priceRange?: string;
60
+ host?: string | PersonRef;
61
+ reviews?: ReviewItem[];
62
+ aggregateRating?: AggregateRatingOptions;
63
+ keywords?: string | string[];
64
+ }
65
+ export declare const generateVacationRentalSchema: ({ name, description, image, url, address, geo, numberOfRooms, numberOfBeds, priceRange, host, reviews, aggregateRating, keywords, }: VacationRentalOptions) => any;
66
+ export default generateVacationRentalSchema;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org `VacationRental` JSON-LD including optional reviews
4
+ * and `AggregateRating`.
5
+ *
6
+ * The function accepts address or geo information, images, host references,
7
+ * and occupancy data. Reviews and aggregate ratings are formatted into
8
+ * `Review` and `AggregateRating` objects when provided.
9
+ *
10
+ * See `VacationRentalOptions` below for supported inputs.
11
+ * @returns A JSON-LD compatible `VacationRental` 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.generateVacationRentalSchema = void 0;
26
+ var formatImage = function (image) {
27
+ if (!image)
28
+ return undefined;
29
+ if (Array.isArray(image))
30
+ return image.map(function (i) {
31
+ return typeof i === 'string'
32
+ ? i
33
+ : __assign(__assign({ '@type': 'ImageObject', url: i.url }, (i.width && { width: i.width })), (i.height && { height: i.height }));
34
+ });
35
+ if (typeof image === 'string')
36
+ return image;
37
+ return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
38
+ };
39
+ var formatPerson = function (p) {
40
+ if (!p)
41
+ return undefined;
42
+ if (typeof p === 'string')
43
+ return { '@type': 'Person', name: p };
44
+ var out = { '@type': 'Person', name: p.name };
45
+ if (p.url)
46
+ out.url = p.url;
47
+ return out;
48
+ };
49
+ var formatAddress = function (a) {
50
+ if (!a)
51
+ return undefined;
52
+ if (typeof a === 'string')
53
+ return a;
54
+ return __assign(__assign(__assign(__assign(__assign({ '@type': 'PostalAddress' }, (a.streetAddress && { streetAddress: a.streetAddress })), (a.addressLocality && { addressLocality: a.addressLocality })), (a.addressRegion && { addressRegion: a.addressRegion })), (a.postalCode && { postalCode: a.postalCode })), (a.addressCountry && { addressCountry: a.addressCountry }));
55
+ };
56
+ var formatReview = function (r) {
57
+ var out = { '@type': 'Review' };
58
+ if (r.author)
59
+ out.author = formatPerson(r.author);
60
+ if (r.datePublished)
61
+ out.datePublished = r.datePublished;
62
+ if (r.reviewBody)
63
+ out.reviewBody = r.reviewBody;
64
+ if (r.reviewRating) {
65
+ out.reviewRating = __assign(__assign({ '@type': 'Rating', ratingValue: r.reviewRating.ratingValue }, (r.reviewRating.bestRating != null && {
66
+ bestRating: r.reviewRating.bestRating,
67
+ })), (r.reviewRating.worstRating != null && {
68
+ worstRating: r.reviewRating.worstRating,
69
+ }));
70
+ }
71
+ return out;
72
+ };
73
+ var generateVacationRentalSchema = function (_a) {
74
+ var name = _a.name, description = _a.description, image = _a.image, url = _a.url, address = _a.address, geo = _a.geo, numberOfRooms = _a.numberOfRooms, numberOfBeds = _a.numberOfBeds, priceRange = _a.priceRange, host = _a.host, reviews = _a.reviews, aggregateRating = _a.aggregateRating, keywords = _a.keywords;
75
+ var schema = {
76
+ '@context': 'https://schema.org',
77
+ '@type': 'VacationRental',
78
+ name: name,
79
+ };
80
+ if (description)
81
+ schema.description = description;
82
+ var img = formatImage(image);
83
+ if (img)
84
+ schema.image = img;
85
+ if (url)
86
+ schema.url = url;
87
+ var a = formatAddress(address);
88
+ if (a)
89
+ schema.address = a;
90
+ if (geo)
91
+ schema.geo = __assign(__assign({ '@type': 'GeoCoordinates' }, (geo.latitude != null && { latitude: geo.latitude })), (geo.longitude != null && { longitude: geo.longitude }));
92
+ if (numberOfRooms != null)
93
+ schema.numberOfRooms = numberOfRooms;
94
+ if (numberOfBeds != null)
95
+ schema.numberOfBeds = numberOfBeds;
96
+ if (priceRange)
97
+ schema.priceRange = priceRange;
98
+ var h = formatPerson(host);
99
+ if (h)
100
+ schema.host = h;
101
+ if (keywords)
102
+ schema.keywords = Array.isArray(keywords) ? keywords.join(', ') : keywords;
103
+ if (reviews && reviews.length > 0) {
104
+ var mapped = reviews.map(formatReview);
105
+ schema.review = mapped;
106
+ if (!aggregateRating) {
107
+ var ratings = reviews
108
+ .map(function (r) { return (r.reviewRating ? Number(r.reviewRating.ratingValue) : NaN); })
109
+ .filter(function (n) { return !Number.isNaN(n); });
110
+ if (ratings.length > 0) {
111
+ var sum = ratings.reduce(function (x, y) { return x + y; }, 0);
112
+ schema.aggregateRating = {
113
+ '@type': 'AggregateRating',
114
+ ratingValue: sum / ratings.length,
115
+ reviewCount: reviews.length,
116
+ ratingCount: ratings.length,
117
+ };
118
+ }
119
+ }
120
+ }
121
+ if (aggregateRating) {
122
+ schema.aggregateRating = __assign(__assign(__assign(__assign({ '@type': 'AggregateRating', ratingValue: aggregateRating.ratingValue }, (aggregateRating.reviewCount != null && {
123
+ reviewCount: aggregateRating.reviewCount,
124
+ })), (aggregateRating.ratingCount != null && {
125
+ ratingCount: aggregateRating.ratingCount,
126
+ })), (aggregateRating.bestRating != null && {
127
+ bestRating: aggregateRating.bestRating,
128
+ })), (aggregateRating.worstRating != null && {
129
+ worstRating: aggregateRating.worstRating,
130
+ }));
131
+ }
132
+ return schema;
133
+ };
134
+ exports.generateVacationRentalSchema = generateVacationRentalSchema;
135
+ exports.default = exports.generateVacationRentalSchema;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Generate schema.org structured data for `VideoObject`, `Clip`, or
3
+ * `BroadcastEvent`.
4
+ *
5
+ * The `VideoOptions` input controls which type is produced and supports
6
+ * optional fields like `aggregateRating`, `reviews`, thumbnails and
7
+ * associated `Clip` or `BroadcastEvent` metadata. The result is a plain
8
+ * object ready to be stringified as JSON-LD for inclusion in a page.
9
+ *
10
+ * See `VideoOptions` below for accepted fields and shapes.
11
+ * @returns A JSON-LD compatible Video/Clip/BroadcastEvent object
12
+ */
13
+ interface ImageRef {
14
+ url: string;
15
+ width?: number;
16
+ height?: number;
17
+ }
18
+ interface PersonRef {
19
+ name: string;
20
+ url?: string;
21
+ }
22
+ interface OrgRef {
23
+ name: string;
24
+ url?: string;
25
+ }
26
+ interface RatingItem {
27
+ ratingValue: number | string;
28
+ bestRating?: number | string;
29
+ worstRating?: number | string;
30
+ }
31
+ interface ReviewItem {
32
+ author?: string | PersonRef;
33
+ datePublished?: string;
34
+ reviewBody?: string;
35
+ reviewRating?: RatingItem;
36
+ }
37
+ interface ClipOptions {
38
+ name?: string;
39
+ startOffset?: number;
40
+ endOffset?: number;
41
+ url?: string;
42
+ }
43
+ interface BroadcastEventOptions {
44
+ name?: string;
45
+ startDate?: string;
46
+ endDate?: string;
47
+ isLiveBroadcast?: boolean;
48
+ url?: string;
49
+ }
50
+ interface AggregateRatingOptions {
51
+ ratingValue: number | string;
52
+ reviewCount?: number;
53
+ ratingCount?: number;
54
+ bestRating?: number | string;
55
+ worstRating?: number | string;
56
+ }
57
+ interface VideoOptions {
58
+ type?: 'VideoObject' | 'Clip' | 'BroadcastEvent';
59
+ name: string;
60
+ description?: string;
61
+ thumbnail?: string | ImageRef | (string | ImageRef)[];
62
+ uploadDate?: string;
63
+ duration?: string;
64
+ contentUrl?: string;
65
+ embedUrl?: string;
66
+ clip?: ClipOptions;
67
+ broadcastEvent?: BroadcastEventOptions;
68
+ publisher?: string | OrgRef;
69
+ author?: string | PersonRef;
70
+ reviews?: ReviewItem[];
71
+ aggregateRating?: AggregateRatingOptions;
72
+ }
73
+ export declare const generateVideoSchema: ({ type, name, description, thumbnail, uploadDate, duration, contentUrl, embedUrl, clip, broadcastEvent, publisher, author, reviews, aggregateRating, }: VideoOptions) => any;
74
+ export default generateVideoSchema;