@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,137 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org JSON-LD for a Quiz (Question and Answer items).
4
+ *
5
+ * Supports author and publisher metadata along with detailed `Question`
6
+ * and `Answer` structures (including accepted/suggested answers,
7
+ * feedback and scoring fields). Only provided values are emitted.
8
+ *
9
+ * See `QuizOptions`, `Question`, and `Answer` types for the available
10
+ * fields and formats.
11
+ * @returns A JSON-LD compatible `Quiz` object
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.generateEducationSchema = void 0;
15
+ var formatPerson = function (p) {
16
+ if (!p)
17
+ return undefined;
18
+ if (typeof p === 'string')
19
+ return { '@type': 'Person', name: p };
20
+ var out = { '@type': 'Person' };
21
+ if (p.name)
22
+ out.name = p.name;
23
+ if (p.url)
24
+ out.url = p.url;
25
+ return out;
26
+ };
27
+ var formatPublisher = function (p) {
28
+ if (!p)
29
+ return undefined;
30
+ if (typeof p === 'string')
31
+ return { '@type': 'Organization', name: p };
32
+ var out = { '@type': 'Organization', name: p.name };
33
+ if (p.url)
34
+ out.url = p.url;
35
+ return out;
36
+ };
37
+ var formatAnswer = function (a) {
38
+ var out = { '@type': 'Answer', text: a.text };
39
+ if (a.url)
40
+ out.url = a.url;
41
+ if (a.author)
42
+ out.author = formatPerson(a.author);
43
+ if (a.upvoteCount != null)
44
+ out.upvoteCount = a.upvoteCount;
45
+ if (a.feedback)
46
+ out.feedback = a.feedback;
47
+ return out;
48
+ };
49
+ var formatQuestion = function (q) {
50
+ var out = { '@type': 'Question' };
51
+ if (q.name)
52
+ out.name = q.name;
53
+ if (q.text)
54
+ out.text = q.text;
55
+ if (q.answerCount != null)
56
+ out.answerCount = q.answerCount;
57
+ if (q.upvoteCount != null)
58
+ out.upvoteCount = q.upvoteCount;
59
+ if (q.difficulty)
60
+ out.difficulty = q.difficulty;
61
+ if (q.points != null)
62
+ out.points = q.points;
63
+ if (q.score != null)
64
+ out.score = q.score;
65
+ if (q.timeLimit)
66
+ out.timeLimit = q.timeLimit;
67
+ if (q.attempts != null)
68
+ out.attempts = q.attempts;
69
+ if (q.tags && Array.isArray(q.tags))
70
+ out.tags = q.tags;
71
+ if (q.hints && Array.isArray(q.hints))
72
+ out.hints = q.hints;
73
+ if (q.learningObjective)
74
+ out.learningObjective = q.learningObjective;
75
+ if (q.timeRecommended)
76
+ out.timeRecommended = q.timeRecommended;
77
+ if (q.isRequired != null)
78
+ out.isRequired = q.isRequired;
79
+ if (q.acceptedAnswer) {
80
+ var a = Array.isArray(q.acceptedAnswer)
81
+ ? q.acceptedAnswer.map(formatAnswer)
82
+ : formatAnswer(q.acceptedAnswer);
83
+ out.acceptedAnswer = a;
84
+ }
85
+ if (q.suggestedAnswer) {
86
+ var s = Array.isArray(q.suggestedAnswer)
87
+ ? q.suggestedAnswer.map(formatAnswer)
88
+ : formatAnswer(q.suggestedAnswer);
89
+ out.suggestedAnswer = s;
90
+ }
91
+ return out;
92
+ };
93
+ var generateEducationSchema = function (_a) {
94
+ var _b = _a === void 0 ? {} : _a, name = _b.name, description = _b.description, url = _b.url, datePublished = _b.datePublished, author = _b.author, publisher = _b.publisher, difficulty = _b.difficulty, learningResourceType = _b.learningResourceType, educationalLevel = _b.educationalLevel, timeRequired = _b.timeRequired, typicalAgeRange = _b.typicalAgeRange, inLanguage = _b.inLanguage, keywords = _b.keywords, learningOutcome = _b.learningOutcome, isAccessibleForFree = _b.isAccessibleForFree, questions = _b.questions;
95
+ var schema = {
96
+ '@context': 'https://schema.org',
97
+ '@type': 'Quiz',
98
+ };
99
+ if (name)
100
+ schema.name = name;
101
+ if (description)
102
+ schema.description = description;
103
+ if (url)
104
+ schema.url = url;
105
+ if (datePublished)
106
+ schema.datePublished = datePublished;
107
+ var a = formatPerson(author);
108
+ if (a)
109
+ schema.author = a;
110
+ var p = formatPublisher(publisher);
111
+ if (p)
112
+ schema.publisher = p;
113
+ if (difficulty)
114
+ schema.difficulty = difficulty;
115
+ if (learningResourceType)
116
+ schema.learningResourceType = learningResourceType;
117
+ if (educationalLevel)
118
+ schema.educationalLevel = educationalLevel;
119
+ if (timeRequired)
120
+ schema.timeRequired = timeRequired;
121
+ if (typicalAgeRange != null)
122
+ schema.typicalAgeRange = typicalAgeRange;
123
+ if (inLanguage)
124
+ schema.inLanguage = inLanguage;
125
+ if (keywords && Array.isArray(keywords))
126
+ schema.keywords = keywords.join(', ');
127
+ if (learningOutcome)
128
+ schema.learningOutcome = learningOutcome;
129
+ if (isAccessibleForFree != null)
130
+ schema.isAccessibleForFree = isAccessibleForFree;
131
+ if (questions && Array.isArray(questions)) {
132
+ schema.question = questions.map(formatQuestion);
133
+ }
134
+ return schema;
135
+ };
136
+ exports.generateEducationSchema = generateEducationSchema;
137
+ exports.default = exports.generateEducationSchema;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Generate schema.org JSON-LD for `EmployerAggregateRating` and the
3
+ * hosting `Organization`.
4
+ *
5
+ * The helper builds an `EmployerAggregateRating` object and nests it
6
+ * inside an `Organization` representation of the employer. Use the
7
+ * `EmployerAggregateOptions` interface for inputs.
8
+ * @returns A JSON-LD compatible `Organization` object with
9
+ * `aggregateRating` included
10
+ */
11
+ interface OrgRef {
12
+ name: string;
13
+ url?: string;
14
+ sameAs?: string;
15
+ }
16
+ interface EmployerAggregateOptions {
17
+ employer: string | OrgRef;
18
+ ratingValue?: number;
19
+ ratingCount?: number;
20
+ reviewCount?: number;
21
+ bestRating?: number;
22
+ worstRating?: number;
23
+ url?: string;
24
+ description?: string;
25
+ datePublished?: string;
26
+ }
27
+ export declare const generateEmployerAggregateRatingSchema: ({ employer, ratingValue, ratingCount, reviewCount, bestRating, worstRating, url, description, datePublished, }: EmployerAggregateOptions) => any;
28
+ export default generateEmployerAggregateRatingSchema;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org JSON-LD for `EmployerAggregateRating` and the
4
+ * hosting `Organization`.
5
+ *
6
+ * The helper builds an `EmployerAggregateRating` object and nests it
7
+ * inside an `Organization` representation of the employer. Use the
8
+ * `EmployerAggregateOptions` interface for inputs.
9
+ * @returns A JSON-LD compatible `Organization` object with
10
+ * `aggregateRating` included
11
+ */
12
+ var __assign = (this && this.__assign) || function () {
13
+ __assign = Object.assign || function(t) {
14
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
15
+ s = arguments[i];
16
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
+ t[p] = s[p];
18
+ }
19
+ return t;
20
+ };
21
+ return __assign.apply(this, arguments);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.generateEmployerAggregateRatingSchema = void 0;
25
+ var formatOrganization = function (o) {
26
+ if (typeof o === 'string')
27
+ return { '@type': 'Organization', name: o };
28
+ var out = { '@type': 'Organization', name: o.name };
29
+ if (o.url)
30
+ out.url = o.url;
31
+ if (o.sameAs)
32
+ out.sameAs = o.sameAs;
33
+ return out;
34
+ };
35
+ var generateEmployerAggregateRatingSchema = function (_a) {
36
+ var employer = _a.employer, ratingValue = _a.ratingValue, ratingCount = _a.ratingCount, reviewCount = _a.reviewCount, bestRating = _a.bestRating, worstRating = _a.worstRating, url = _a.url, description = _a.description, datePublished = _a.datePublished;
37
+ // Build the EmployerAggregateRating object
38
+ var rating = {
39
+ '@type': 'EmployerAggregateRating',
40
+ };
41
+ if (ratingValue != null)
42
+ rating.ratingValue = ratingValue;
43
+ if (ratingCount != null)
44
+ rating.ratingCount = ratingCount;
45
+ if (reviewCount != null)
46
+ rating.reviewCount = reviewCount;
47
+ if (bestRating != null)
48
+ rating.bestRating = bestRating;
49
+ if (worstRating != null)
50
+ rating.worstRating = worstRating;
51
+ if (url)
52
+ rating.url = url;
53
+ if (description)
54
+ rating.description = description;
55
+ if (datePublished)
56
+ rating.datePublished = datePublished;
57
+ // Return the Organization with aggregateRating nested
58
+ var org = formatOrganization(employer);
59
+ var schema = __assign({ '@context': 'https://schema.org', '@type': 'Organization' }, org);
60
+ schema.aggregateRating = rating;
61
+ return schema;
62
+ };
63
+ exports.generateEmployerAggregateRatingSchema = generateEmployerAggregateRatingSchema;
64
+ exports.default = exports.generateEmployerAggregateRatingSchema;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Generate schema.org `Event` JSON-LD.
3
+ *
4
+ * Supports `Place` and `VirtualLocation` types for `location`, optional
5
+ * `offers`, performers, organizer, and availability/status normalization.
6
+ * Currency values are validated with `skipInvalidCurrency` when present.
7
+ *
8
+ * See `EventSchemaOptions` below for the complete input shape.
9
+ * @returns A JSON-LD compatible `Event` object
10
+ */
11
+ interface EventImage {
12
+ url: string;
13
+ width?: number;
14
+ height?: number;
15
+ }
16
+ interface EventLocationAddress {
17
+ streetAddress?: string;
18
+ addressLocality?: string;
19
+ postalCode?: string;
20
+ addressRegion?: string;
21
+ addressCountry?: string;
22
+ }
23
+ interface EventLocation {
24
+ type?: 'Place' | 'VirtualLocation';
25
+ name?: string;
26
+ url?: string;
27
+ address?: string | EventLocationAddress;
28
+ }
29
+ interface EventOrganizer {
30
+ name: string;
31
+ url?: string;
32
+ }
33
+ interface EventPerformer {
34
+ name: string;
35
+ url?: string;
36
+ type?: 'Person' | 'Organization';
37
+ }
38
+ interface EventOffer {
39
+ price?: string | number;
40
+ priceCurrency?: string;
41
+ availability?: string;
42
+ url?: string;
43
+ priceValidUntil?: string;
44
+ }
45
+ interface EventSchemaOptions {
46
+ name: string;
47
+ startDate: string;
48
+ endDate?: string;
49
+ description?: string;
50
+ location?: string | EventLocation;
51
+ url?: string;
52
+ image?: string | EventImage;
53
+ organizer?: string | EventOrganizer;
54
+ performers?: string | EventPerformer | Array<string | EventPerformer>;
55
+ offers?: EventOffer | EventOffer[];
56
+ isAccessibleForFree?: boolean;
57
+ eventStatus?: string;
58
+ eventAttendanceMode?: string;
59
+ skipInvalidCurrency?: boolean;
60
+ }
61
+ export declare const generateEventSchema: ({ name, startDate, endDate, description, location, url, image, organizer, performers, offers, isAccessibleForFree, eventStatus, eventAttendanceMode, skipInvalidCurrency, }: EventSchemaOptions) => any;
62
+ export {};
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org `Event` JSON-LD.
4
+ *
5
+ * Supports `Place` and `VirtualLocation` types for `location`, optional
6
+ * `offers`, performers, organizer, and availability/status normalization.
7
+ * Currency values are validated with `skipInvalidCurrency` when present.
8
+ *
9
+ * See `EventSchemaOptions` below for the complete input shape.
10
+ * @returns A JSON-LD compatible `Event` object
11
+ */
12
+ var __assign = (this && this.__assign) || function () {
13
+ __assign = Object.assign || function(t) {
14
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
15
+ s = arguments[i];
16
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
+ t[p] = s[p];
18
+ }
19
+ return t;
20
+ };
21
+ return __assign.apply(this, arguments);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.generateEventSchema = void 0;
25
+ var formatImage = function (image) {
26
+ if (!image)
27
+ return undefined;
28
+ if (typeof image === 'string')
29
+ return image;
30
+ return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
31
+ };
32
+ var isValidCurrency = function (code) {
33
+ if (!code)
34
+ return false;
35
+ return /^[A-Z]{3}$/.test(code);
36
+ };
37
+ var AVAILABILITIES = [
38
+ 'InStock',
39
+ 'OutOfStock',
40
+ 'PreOrder',
41
+ 'PreSale',
42
+ 'Discontinued',
43
+ 'OnlineOnly',
44
+ 'InStoreOnly',
45
+ 'LimitedAvailability',
46
+ 'BackOrder',
47
+ ];
48
+ var normalizeAvailability = function (val) {
49
+ if (!val)
50
+ return undefined;
51
+ try {
52
+ var asUrl = String(val);
53
+ if (asUrl.startsWith('http')) {
54
+ var token = asUrl.replace(/https?:\/\/schema\.org\//i, '');
55
+ if (AVAILABILITIES.includes(token))
56
+ return "https://schema.org/".concat(token);
57
+ return undefined;
58
+ }
59
+ if (AVAILABILITIES.includes(asUrl))
60
+ return "https://schema.org/".concat(asUrl);
61
+ return undefined;
62
+ }
63
+ catch (_a) {
64
+ return undefined;
65
+ }
66
+ };
67
+ var normalizeStatusOrMode = function (val) {
68
+ if (!val)
69
+ return undefined;
70
+ if (val.startsWith('http'))
71
+ return val;
72
+ return "https://schema.org/".concat(val);
73
+ };
74
+ var formatLocation = function (loc) {
75
+ if (!loc)
76
+ return undefined;
77
+ if (typeof loc === 'string')
78
+ return loc;
79
+ if (loc.type === 'VirtualLocation') {
80
+ var out = { '@type': 'VirtualLocation' };
81
+ if (loc.url)
82
+ out.url = loc.url;
83
+ if (loc.name)
84
+ out.name = loc.name;
85
+ return out;
86
+ }
87
+ var place = { '@type': 'Place' };
88
+ if (loc.name)
89
+ place.name = loc.name;
90
+ if (loc.url)
91
+ place.url = loc.url;
92
+ if (loc.address) {
93
+ if (typeof loc.address === 'string') {
94
+ place.address = loc.address;
95
+ }
96
+ else {
97
+ place.address = __assign(__assign(__assign(__assign(__assign({ '@type': 'PostalAddress' }, (loc.address.streetAddress && {
98
+ streetAddress: loc.address.streetAddress,
99
+ })), (loc.address.addressLocality && {
100
+ addressLocality: loc.address.addressLocality,
101
+ })), (loc.address.postalCode && { postalCode: loc.address.postalCode })), (loc.address.addressRegion && {
102
+ addressRegion: loc.address.addressRegion,
103
+ })), (loc.address.addressCountry && {
104
+ addressCountry: loc.address.addressCountry,
105
+ }));
106
+ }
107
+ }
108
+ return place;
109
+ };
110
+ var formatOrganizer = function (org) {
111
+ if (!org)
112
+ return undefined;
113
+ if (typeof org === 'string') {
114
+ return {
115
+ '@type': 'Organization',
116
+ name: org,
117
+ };
118
+ }
119
+ return __assign({ '@type': 'Organization', name: org.name }, (org.url && { url: org.url }));
120
+ };
121
+ var formatPerformer = function (p) {
122
+ if (typeof p === 'string') {
123
+ return {
124
+ '@type': 'Person',
125
+ name: p,
126
+ };
127
+ }
128
+ return __assign({ '@type': p.type || 'Person', name: p.name }, (p.url && { url: p.url }));
129
+ };
130
+ var generateEventSchema = function (_a) {
131
+ var name = _a.name, startDate = _a.startDate, endDate = _a.endDate, description = _a.description, location = _a.location, url = _a.url, image = _a.image, organizer = _a.organizer, performers = _a.performers, offers = _a.offers, isAccessibleForFree = _a.isAccessibleForFree, eventStatus = _a.eventStatus, eventAttendanceMode = _a.eventAttendanceMode, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
132
+ var schema = {
133
+ '@context': 'https://schema.org',
134
+ '@type': 'Event',
135
+ name: name,
136
+ startDate: startDate,
137
+ };
138
+ if (endDate)
139
+ schema.endDate = endDate;
140
+ if (description)
141
+ schema.description = description;
142
+ var img = formatImage(image);
143
+ if (img)
144
+ schema.image = img;
145
+ var loc = formatLocation(location);
146
+ if (loc)
147
+ schema.location = loc;
148
+ if (url) {
149
+ schema.mainEntityOfPage = {
150
+ '@type': 'WebPage',
151
+ '@id': url,
152
+ };
153
+ }
154
+ var org = formatOrganizer(organizer);
155
+ if (org)
156
+ schema.organizer = org;
157
+ if (performers) {
158
+ if (Array.isArray(performers)) {
159
+ schema.performer = performers.map(function (p) { return formatPerformer(p); });
160
+ }
161
+ else {
162
+ schema.performer = formatPerformer(performers);
163
+ }
164
+ }
165
+ if (typeof isAccessibleForFree === 'boolean')
166
+ schema.isAccessibleForFree = isAccessibleForFree;
167
+ if (eventStatus) {
168
+ var norm = normalizeStatusOrMode(eventStatus);
169
+ if (norm)
170
+ schema.eventStatus = norm;
171
+ }
172
+ if (eventAttendanceMode) {
173
+ var norm = normalizeStatusOrMode(eventAttendanceMode);
174
+ if (norm)
175
+ schema.eventAttendanceMode = norm;
176
+ }
177
+ // offers handling (single or array)
178
+ if (offers) {
179
+ var promises = Array.isArray(offers) ? offers : [offers];
180
+ var mapped = promises
181
+ .map(function (o) {
182
+ if (o.priceCurrency && !isValidCurrency(o.priceCurrency)) {
183
+ return { __invalidCurrency: o.priceCurrency };
184
+ }
185
+ var off = { '@type': 'Offer' };
186
+ if (o.price != null)
187
+ off.price = o.price;
188
+ if (o.priceCurrency)
189
+ off.priceCurrency = o.priceCurrency;
190
+ if (o.url)
191
+ off.url = o.url;
192
+ if (o.priceValidUntil)
193
+ off.priceValidUntil = o.priceValidUntil;
194
+ if (o.availability) {
195
+ var n = normalizeAvailability(o.availability);
196
+ if (n)
197
+ off.availability = n;
198
+ }
199
+ return off;
200
+ })
201
+ .filter(function (x) { return x && !('__invalidCurrency' in x); });
202
+ var hadInvalid = promises.some(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
203
+ if (hadInvalid && !skipInvalidCurrency) {
204
+ var bad = promises.find(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
205
+ throw new Error("Invalid currency code: ".concat(bad === null || bad === void 0 ? void 0 : bad.priceCurrency));
206
+ }
207
+ if (mapped.length === 1)
208
+ schema.offers = mapped[0];
209
+ else if (mapped.length > 1)
210
+ schema.offers = mapped;
211
+ }
212
+ return schema;
213
+ };
214
+ exports.generateEventSchema = generateEventSchema;
@@ -1,18 +1,22 @@
1
1
  /**
2
- * A util function to create Rich Schema for FAQ
2
+ * Generate a schema.org `FAQPage` JSON-LD object.
3
3
  *
4
- * @returns formatted date - Saturday, 11/01/2020
5
- * @author Taimoor Khan
6
- * @remarks AppCorp
4
+ * Each FAQ item becomes a `Question` with an `acceptedAnswer` of type
5
+ * `Answer`. Plain-text answers are wrapped in a single paragraph tag.
6
+ * If the provided answer already contains HTML tags it will be preserved
7
+ * as-is to avoid double-wrapping.
8
+ *
9
+ * @param props.data - Array of FAQ items with `question` and `answer`
10
+ * @returns A JSON-LD `FAQPage` object
7
11
  */
8
- /** End file docs */
9
- interface FAQ {
10
- data: Array<{
11
- answer: string;
12
- question: string;
13
- }>;
12
+ interface FAQItem {
13
+ question: string;
14
+ answer: string;
15
+ }
16
+ interface FAQProps {
17
+ data: FAQItem[];
14
18
  }
15
- export declare const generateFAQSchema: ({ data }: FAQ) => {
19
+ export declare const generateFAQSchema: ({ data }: FAQProps) => {
16
20
  '@context': string;
17
21
  '@type': string;
18
22
  mainEntity: {
@@ -1,14 +1,26 @@
1
1
  "use strict";
2
2
  /**
3
- * A util function to create Rich Schema for FAQ
3
+ * Generate a schema.org `FAQPage` JSON-LD object.
4
4
  *
5
- * @returns formatted date - Saturday, 11/01/2020
6
- * @author Taimoor Khan
7
- * @remarks AppCorp
5
+ * Each FAQ item becomes a `Question` with an `acceptedAnswer` of type
6
+ * `Answer`. Plain-text answers are wrapped in a single paragraph tag.
7
+ * If the provided answer already contains HTML tags it will be preserved
8
+ * as-is to avoid double-wrapping.
9
+ *
10
+ * @param props.data - Array of FAQ items with `question` and `answer`
11
+ * @returns A JSON-LD `FAQPage` object
8
12
  */
9
- /** End file docs */
10
13
  Object.defineProperty(exports, "__esModule", { value: true });
11
14
  exports.generateFAQSchema = void 0;
15
+ var wrapAnswer = function (text) {
16
+ if (!text)
17
+ return text;
18
+ var trimmed = text.trim();
19
+ // naive HTML detection: if it contains a tag, assume it's HTML
20
+ if (trimmed.startsWith('<') && trimmed.includes('>'))
21
+ return text;
22
+ return "<p>".concat(text, "</p>");
23
+ };
12
24
  var generateFAQSchema = function (_a) {
13
25
  var data = _a.data;
14
26
  var items = data.map(function (_a) {
@@ -18,7 +30,7 @@ var generateFAQSchema = function (_a) {
18
30
  name: question,
19
31
  acceptedAnswer: {
20
32
  '@type': 'Answer',
21
- text: "<p>".concat(answer, "</p>"),
33
+ text: wrapAnswer(answer),
22
34
  },
23
35
  };
24
36
  });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Generate schema.org `ImageObject` JSON-LD for image metadata.
3
+ *
4
+ * Accepts author/copyright holders, thumbnail, licenses and descriptive
5
+ * metadata and formats them into an `ImageObject` suitable for JSON-LD
6
+ * embedding. Only provided fields are emitted.
7
+ *
8
+ * See `ImageMetadataOptions` for the exact accepted fields.
9
+ * @returns A JSON-LD compatible `ImageObject`
10
+ */
11
+ interface SimplePerson {
12
+ name: string;
13
+ url?: string;
14
+ }
15
+ interface ImageThumbnail {
16
+ url: string;
17
+ width?: number;
18
+ height?: number;
19
+ }
20
+ interface ImageMetadataOptions {
21
+ name?: string;
22
+ contentUrl: string;
23
+ description?: string;
24
+ caption?: string;
25
+ uploadDate?: string;
26
+ author?: string | SimplePerson;
27
+ copyrightHolder?: string | SimplePerson;
28
+ license?: string;
29
+ encodingFormat?: string;
30
+ contentSize?: string;
31
+ thumbnail?: string | ImageThumbnail;
32
+ keywords?: string[];
33
+ }
34
+ export declare const generateImageMetadataSchema: ({ name, contentUrl, description, caption, uploadDate, author, copyrightHolder, license, encodingFormat, contentSize, thumbnail, keywords, }: ImageMetadataOptions) => any;
35
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Generate schema.org `ImageObject` JSON-LD for image metadata.
4
+ *
5
+ * Accepts author/copyright holders, thumbnail, licenses and descriptive
6
+ * metadata and formats them into an `ImageObject` suitable for JSON-LD
7
+ * embedding. Only provided fields are emitted.
8
+ *
9
+ * See `ImageMetadataOptions` for the exact accepted fields.
10
+ * @returns A JSON-LD compatible `ImageObject`
11
+ */
12
+ var __assign = (this && this.__assign) || function () {
13
+ __assign = Object.assign || function(t) {
14
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
15
+ s = arguments[i];
16
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
+ t[p] = s[p];
18
+ }
19
+ return t;
20
+ };
21
+ return __assign.apply(this, arguments);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.generateImageMetadataSchema = void 0;
25
+ var formatPerson = function (p) {
26
+ if (!p)
27
+ return undefined;
28
+ if (typeof p === 'string')
29
+ return { '@type': 'Person', name: p };
30
+ return __assign({ '@type': 'Person', name: p.name }, (p.url && { url: p.url }));
31
+ };
32
+ var formatThumbnail = function (t) {
33
+ if (!t)
34
+ return undefined;
35
+ if (typeof t === 'string')
36
+ return t;
37
+ return __assign(__assign({ '@type': 'ImageObject', url: t.url }, (t.width && { width: t.width })), (t.height && { height: t.height }));
38
+ };
39
+ var generateImageMetadataSchema = function (_a) {
40
+ var name = _a.name, contentUrl = _a.contentUrl, description = _a.description, caption = _a.caption, uploadDate = _a.uploadDate, author = _a.author, copyrightHolder = _a.copyrightHolder, license = _a.license, encodingFormat = _a.encodingFormat, contentSize = _a.contentSize, thumbnail = _a.thumbnail, keywords = _a.keywords;
41
+ var schema = {
42
+ '@context': 'https://schema.org',
43
+ '@type': 'ImageObject',
44
+ contentUrl: contentUrl,
45
+ };
46
+ if (name)
47
+ schema.name = name;
48
+ if (description)
49
+ schema.description = description;
50
+ if (caption)
51
+ schema.caption = caption;
52
+ if (uploadDate)
53
+ schema.uploadDate = uploadDate;
54
+ var a = formatPerson(author);
55
+ if (a)
56
+ schema.author = a;
57
+ var ch = formatPerson(copyrightHolder);
58
+ if (ch)
59
+ schema.copyrightHolder = ch;
60
+ if (license)
61
+ schema.license = license;
62
+ if (encodingFormat)
63
+ schema.encodingFormat = encodingFormat;
64
+ if (contentSize)
65
+ schema.contentSize = contentSize;
66
+ var thumb = formatThumbnail(thumbnail);
67
+ if (thumb)
68
+ schema.thumbnail = thumb;
69
+ if (keywords && keywords.length > 0)
70
+ schema.keywords = keywords.join(', ');
71
+ return schema;
72
+ };
73
+ exports.generateImageMetadataSchema = generateImageMetadataSchema;