@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.
- package/constants/cache-time.d.ts +2 -0
- package/constants/cache-time.js +3 -1
- package/general/generate-article-schema.d.ts +49 -0
- package/general/generate-article-schema.js +100 -0
- package/general/generate-blog-schema.d.ts +7 -5
- package/general/generate-blog-schema.js +7 -5
- package/general/generate-book-schema.d.ts +57 -0
- package/general/generate-book-schema.js +109 -0
- package/general/generate-breadcrumb-schema.d.ts +22 -6
- package/general/generate-breadcrumb-schema.js +15 -4
- package/general/generate-carousel-schema.d.ts +51 -0
- package/general/generate-carousel-schema.js +172 -0
- package/general/generate-course-schema.d.ts +52 -0
- package/general/generate-course-schema.js +124 -0
- package/general/generate-dataset-schema.d.ts +64 -0
- package/general/generate-dataset-schema.js +156 -0
- package/general/generate-discussion-forum-schema.d.ts +38 -0
- package/general/generate-discussion-forum-schema.js +67 -0
- package/general/generate-education-schema.d.ts +67 -0
- package/general/generate-education-schema.js +137 -0
- package/general/generate-employer-aggregate-rating-schema.d.ts +28 -0
- package/general/generate-employer-aggregate-rating-schema.js +64 -0
- package/general/generate-event-schema.d.ts +62 -0
- package/general/generate-event-schema.js +214 -0
- package/general/generate-faq-schema.d.ts +15 -11
- package/general/generate-faq-schema.js +18 -6
- package/general/generate-image-metadata-schema.d.ts +35 -0
- package/general/generate-image-metadata-schema.js +73 -0
- package/general/generate-job-posting-schema.d.ts +48 -0
- package/general/generate-job-posting-schema.js +120 -0
- package/general/generate-local-business-schema.d.ts +41 -0
- package/general/generate-local-business-schema.js +75 -0
- package/general/generate-math-solver-schema.d.ts +44 -0
- package/general/generate-math-solver-schema.js +83 -0
- package/general/generate-movie-carousel-schema.d.ts +50 -0
- package/general/generate-movie-carousel-schema.js +160 -0
- package/general/generate-organization-schema.d.ts +9 -5
- package/general/generate-organization-schema.js +9 -5
- package/general/generate-profile-page-schema.d.ts +36 -0
- package/general/generate-profile-page-schema.js +82 -0
- package/general/generate-qa-page-schema.d.ts +33 -0
- package/general/generate-qa-page-schema.js +67 -0
- package/general/generate-recipe-schema.d.ts +48 -0
- package/general/generate-recipe-schema.js +104 -0
- package/general/generate-review-snippet-schema.d.ts +51 -0
- package/general/generate-review-snippet-schema.js +137 -0
- package/general/generate-shopping-loyalty-program-schema.d.ts +37 -0
- package/general/generate-shopping-loyalty-program-schema.js +59 -0
- package/general/generate-shopping-merchant-listing-schema.d.ts +52 -0
- package/general/generate-shopping-merchant-listing-schema.js +153 -0
- package/general/generate-shopping-merchant-return-policy-schema.d.ts +31 -0
- package/general/generate-shopping-merchant-return-policy-schema.js +68 -0
- package/general/generate-shopping-merchant-shipping-policy-schema.d.ts +35 -0
- package/general/generate-shopping-merchant-shipping-policy-schema.js +74 -0
- package/general/generate-shopping-overview-schema.d.ts +51 -0
- package/general/generate-shopping-overview-schema.js +157 -0
- package/general/generate-shopping-product-snippet-schema.d.ts +56 -0
- package/general/generate-shopping-product-snippet-schema.js +167 -0
- package/general/generate-shopping-variants-schema.d.ts +45 -0
- package/general/generate-shopping-variants-schema.js +143 -0
- package/general/generate-software-app-schema.d.ts +61 -0
- package/general/generate-software-app-schema.js +143 -0
- package/general/generate-speakable-schema.d.ts +63 -0
- package/general/generate-speakable-schema.js +139 -0
- package/general/generate-subscription-schema.d.ts +59 -0
- package/general/generate-subscription-schema.js +133 -0
- package/general/generate-vacation-rental-schema.d.ts +66 -0
- package/general/generate-vacation-rental-schema.js +135 -0
- package/general/generate-video-schema.d.ts +74 -0
- package/general/generate-video-schema.js +163 -0
- package/general/index.d.ts +30 -0
- package/general/index.js +30 -0
- package/package.json +1 -1
package/constants/cache-time.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ONE_MONTH_IN_MS = exports.ONE_WEEK_IN_MS = exports.ONE_DAY_IN_MS = void 0;
|
|
3
|
+
exports.ONE_YEAR_IN_MS = exports.SIX_MONTHS_IN_MS = exports.ONE_MONTH_IN_MS = exports.ONE_WEEK_IN_MS = exports.ONE_DAY_IN_MS = void 0;
|
|
4
4
|
exports.ONE_DAY_IN_MS = 1 * 24 * 60 * 60 * 1000; // 1 day in milliseconds
|
|
5
5
|
exports.ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000; // 1 week in milliseconds
|
|
6
6
|
exports.ONE_MONTH_IN_MS = 30 * 24 * 60 * 60 * 1000; // 1 month in milliseconds
|
|
7
|
+
exports.SIX_MONTHS_IN_MS = 6 * 30 * 24 * 60 * 60 * 1000; // 6 months in milliseconds
|
|
8
|
+
exports.ONE_YEAR_IN_MS = 12 * 30 * 24 * 60 * 60 * 1000; // 1 year in milliseconds
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate schema.org JSON-LD for `Article`, `NewsArticle`, or `BlogPosting`.
|
|
3
|
+
*
|
|
4
|
+
* This helper accepts `ArticleSchema` inputs and formats authors,
|
|
5
|
+
* publisher/logo, images, and optional fields such as `keywords`,
|
|
6
|
+
* `articleSection`, and `wordCount`. Only supplied fields are emitted in
|
|
7
|
+
* the resulting object, making the output safe to merge into page
|
|
8
|
+
* metadata bundles.
|
|
9
|
+
*
|
|
10
|
+
* Examples are provided in the interface comments below — consult the
|
|
11
|
+
* `ArticleSchema` type for full details of supported inputs.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Article metadata and optional fields
|
|
14
|
+
* @returns A JSON-LD compatible Article/NewsArticle/BlogPosting object
|
|
15
|
+
*/
|
|
16
|
+
type ArticleType = 'Article' | 'NewsArticle' | 'BlogPosting';
|
|
17
|
+
interface ArticleAuthor {
|
|
18
|
+
name: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ArticleImage {
|
|
22
|
+
url: string;
|
|
23
|
+
width?: number;
|
|
24
|
+
height?: number;
|
|
25
|
+
}
|
|
26
|
+
interface ArticlePublisher {
|
|
27
|
+
name: string;
|
|
28
|
+
logo?: {
|
|
29
|
+
url: string;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface ArticleSchema {
|
|
35
|
+
type?: ArticleType;
|
|
36
|
+
headline: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
image: string | string[] | ArticleImage | ArticleImage[];
|
|
39
|
+
author: string | ArticleAuthor | ArticleAuthor[];
|
|
40
|
+
publisher: ArticlePublisher;
|
|
41
|
+
datePublished: string;
|
|
42
|
+
dateModified?: string;
|
|
43
|
+
url?: string;
|
|
44
|
+
keywords?: string[];
|
|
45
|
+
articleSection?: string;
|
|
46
|
+
wordCount?: number;
|
|
47
|
+
}
|
|
48
|
+
export declare const generateArticleSchema: ({ type, headline, description, image, author, publisher, datePublished, dateModified, url, keywords, articleSection, wordCount, }: ArticleSchema) => any;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generate schema.org JSON-LD for `Article`, `NewsArticle`, or `BlogPosting`.
|
|
4
|
+
*
|
|
5
|
+
* This helper accepts `ArticleSchema` inputs and formats authors,
|
|
6
|
+
* publisher/logo, images, and optional fields such as `keywords`,
|
|
7
|
+
* `articleSection`, and `wordCount`. Only supplied fields are emitted in
|
|
8
|
+
* the resulting object, making the output safe to merge into page
|
|
9
|
+
* metadata bundles.
|
|
10
|
+
*
|
|
11
|
+
* Examples are provided in the interface comments below — consult the
|
|
12
|
+
* `ArticleSchema` type for full details of supported inputs.
|
|
13
|
+
*
|
|
14
|
+
* @param options - Article metadata and optional fields
|
|
15
|
+
* @returns A JSON-LD compatible Article/NewsArticle/BlogPosting object
|
|
16
|
+
*/
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.generateArticleSchema = void 0;
|
|
30
|
+
var formatAuthor = function (author) {
|
|
31
|
+
if (typeof author === 'string') {
|
|
32
|
+
return {
|
|
33
|
+
'@type': 'Person',
|
|
34
|
+
name: author,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(author)) {
|
|
38
|
+
return author.map(function (a) { return (__assign({ '@type': 'Person', name: a.name }, (a.url && { url: a.url }))); });
|
|
39
|
+
}
|
|
40
|
+
return __assign({ '@type': 'Person', name: author.name }, (author.url && { url: author.url }));
|
|
41
|
+
};
|
|
42
|
+
var formatImage = function (image) {
|
|
43
|
+
if (typeof image === 'string') {
|
|
44
|
+
return image;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(image)) {
|
|
47
|
+
return image.map(function (img) {
|
|
48
|
+
if (typeof img === 'string') {
|
|
49
|
+
return img;
|
|
50
|
+
}
|
|
51
|
+
return __assign(__assign({ '@type': 'ImageObject', url: img.url }, (img.width && { width: img.width })), (img.height && { height: img.height }));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
|
|
55
|
+
};
|
|
56
|
+
var formatPublisher = function (publisher) {
|
|
57
|
+
var publisherData = {
|
|
58
|
+
'@type': 'Organization',
|
|
59
|
+
name: publisher.name,
|
|
60
|
+
};
|
|
61
|
+
if (publisher.logo) {
|
|
62
|
+
publisherData.logo = __assign(__assign({ '@type': 'ImageObject', url: publisher.logo.url }, (publisher.logo.width && { width: publisher.logo.width })), (publisher.logo.height && { height: publisher.logo.height }));
|
|
63
|
+
}
|
|
64
|
+
return publisherData;
|
|
65
|
+
};
|
|
66
|
+
var generateArticleSchema = function (_a) {
|
|
67
|
+
var _b = _a.type, type = _b === void 0 ? 'Article' : _b, headline = _a.headline, description = _a.description, image = _a.image, author = _a.author, publisher = _a.publisher, datePublished = _a.datePublished, dateModified = _a.dateModified, url = _a.url, keywords = _a.keywords, articleSection = _a.articleSection, wordCount = _a.wordCount;
|
|
68
|
+
var schema = {
|
|
69
|
+
'@context': 'https://schema.org',
|
|
70
|
+
'@type': type,
|
|
71
|
+
headline: headline,
|
|
72
|
+
image: formatImage(image),
|
|
73
|
+
author: formatAuthor(author),
|
|
74
|
+
publisher: formatPublisher(publisher),
|
|
75
|
+
datePublished: datePublished,
|
|
76
|
+
};
|
|
77
|
+
if (description) {
|
|
78
|
+
schema.description = description;
|
|
79
|
+
}
|
|
80
|
+
if (dateModified) {
|
|
81
|
+
schema.dateModified = dateModified;
|
|
82
|
+
}
|
|
83
|
+
if (url) {
|
|
84
|
+
schema.mainEntityOfPage = {
|
|
85
|
+
'@type': 'WebPage',
|
|
86
|
+
'@id': url,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (keywords && keywords.length > 0) {
|
|
90
|
+
schema.keywords = keywords.join(', ');
|
|
91
|
+
}
|
|
92
|
+
if (articleSection) {
|
|
93
|
+
schema.articleSection = articleSection;
|
|
94
|
+
}
|
|
95
|
+
if (wordCount) {
|
|
96
|
+
schema.wordCount = wordCount;
|
|
97
|
+
}
|
|
98
|
+
return schema;
|
|
99
|
+
};
|
|
100
|
+
exports.generateArticleSchema = generateArticleSchema;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Generate schema.org `BlogPosting` JSON-LD for a blog entry.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Produces a compact `BlogPosting` object using headline, dates, image and
|
|
5
|
+
* author information. Only provided fields are emitted, and the returned
|
|
6
|
+
* object is ready to be stringified as JSON-LD.
|
|
7
|
+
*
|
|
8
|
+
* See the `Blog` interface below for the accepted properties.
|
|
9
|
+
* @returns A JSON-LD compatible `BlogPosting` object
|
|
7
10
|
*/
|
|
8
|
-
/** End file docs */
|
|
9
11
|
interface Blog {
|
|
10
12
|
authorImage: string;
|
|
11
13
|
authorName: string;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Generate schema.org `BlogPosting` JSON-LD for a blog entry.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Produces a compact `BlogPosting` object using headline, dates, image and
|
|
6
|
+
* author information. Only provided fields are emitted, and the returned
|
|
7
|
+
* object is ready to be stringified as JSON-LD.
|
|
8
|
+
*
|
|
9
|
+
* See the `Blog` interface below for the accepted properties.
|
|
10
|
+
* @returns A JSON-LD compatible `BlogPosting` object
|
|
8
11
|
*/
|
|
9
|
-
/** End file docs */
|
|
10
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
13
|
exports.generateBlogSchema = void 0;
|
|
12
14
|
var generateBlogSchema = function (_a) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate schema.org `Book` JSON-LD for use in page <script type="application/ld+json">.
|
|
3
|
+
*
|
|
4
|
+
* This helper accepts a compact `BookSchemaOptions` input and returns a
|
|
5
|
+
* plain object ready to be stringified and inlined on a page. Common
|
|
6
|
+
* fields supported:
|
|
7
|
+
*
|
|
8
|
+
* - `title` → maps to `name`
|
|
9
|
+
* - `author` → accepts a `string`, an `{ name, url? }` object, or an array of
|
|
10
|
+
* those; these are formatted as `Person` objects
|
|
11
|
+
* - `publisher` → `{ name, logo? }` formatted as an `Organization` with
|
|
12
|
+
* an optional `ImageObject` logo
|
|
13
|
+
* - `image` → accepts a `string`, `BookImage` or arrays; non-string images are
|
|
14
|
+
* converted to `ImageObject` entries
|
|
15
|
+
* - `url` → attached to `mainEntityOfPage.@id` when provided
|
|
16
|
+
* - `keywords` → joined into a comma-separated string
|
|
17
|
+
*
|
|
18
|
+
* The implementation intentionally produces minimal output (only provided
|
|
19
|
+
* fields are added) so the result can be safely merged into other page
|
|
20
|
+
* metadata.
|
|
21
|
+
*
|
|
22
|
+
* @param options.book title, author, publisher and optional metadata
|
|
23
|
+
* @returns A JSON-LD compatible `Book` object
|
|
24
|
+
*/
|
|
25
|
+
interface BookAuthor {
|
|
26
|
+
name: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
}
|
|
29
|
+
interface BookImage {
|
|
30
|
+
url: string;
|
|
31
|
+
width?: number;
|
|
32
|
+
height?: number;
|
|
33
|
+
}
|
|
34
|
+
interface BookPublisher {
|
|
35
|
+
name: string;
|
|
36
|
+
logo?: {
|
|
37
|
+
url: string;
|
|
38
|
+
width?: number;
|
|
39
|
+
height?: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface BookSchemaOptions {
|
|
43
|
+
title: string;
|
|
44
|
+
author: string | BookAuthor | BookAuthor[];
|
|
45
|
+
isbn?: string;
|
|
46
|
+
numberOfPages?: number;
|
|
47
|
+
inLanguage?: string;
|
|
48
|
+
publisher: BookPublisher;
|
|
49
|
+
datePublished?: string;
|
|
50
|
+
image?: string | string[] | BookImage | BookImage[];
|
|
51
|
+
description?: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
keywords?: string[];
|
|
54
|
+
bookFormat?: string;
|
|
55
|
+
}
|
|
56
|
+
export declare const generateBookSchema: ({ title, author, isbn, numberOfPages, inLanguage, publisher, datePublished, image, description, url, keywords, bookFormat, }: BookSchemaOptions) => any;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generate schema.org `Book` JSON-LD for use in page <script type="application/ld+json">.
|
|
4
|
+
*
|
|
5
|
+
* This helper accepts a compact `BookSchemaOptions` input and returns a
|
|
6
|
+
* plain object ready to be stringified and inlined on a page. Common
|
|
7
|
+
* fields supported:
|
|
8
|
+
*
|
|
9
|
+
* - `title` → maps to `name`
|
|
10
|
+
* - `author` → accepts a `string`, an `{ name, url? }` object, or an array of
|
|
11
|
+
* those; these are formatted as `Person` objects
|
|
12
|
+
* - `publisher` → `{ name, logo? }` formatted as an `Organization` with
|
|
13
|
+
* an optional `ImageObject` logo
|
|
14
|
+
* - `image` → accepts a `string`, `BookImage` or arrays; non-string images are
|
|
15
|
+
* converted to `ImageObject` entries
|
|
16
|
+
* - `url` → attached to `mainEntityOfPage.@id` when provided
|
|
17
|
+
* - `keywords` → joined into a comma-separated string
|
|
18
|
+
*
|
|
19
|
+
* The implementation intentionally produces minimal output (only provided
|
|
20
|
+
* fields are added) so the result can be safely merged into other page
|
|
21
|
+
* metadata.
|
|
22
|
+
*
|
|
23
|
+
* @param options.book title, author, publisher and optional metadata
|
|
24
|
+
* @returns A JSON-LD compatible `Book` object
|
|
25
|
+
*/
|
|
26
|
+
var __assign = (this && this.__assign) || function () {
|
|
27
|
+
__assign = Object.assign || function(t) {
|
|
28
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29
|
+
s = arguments[i];
|
|
30
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
31
|
+
t[p] = s[p];
|
|
32
|
+
}
|
|
33
|
+
return t;
|
|
34
|
+
};
|
|
35
|
+
return __assign.apply(this, arguments);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.generateBookSchema = void 0;
|
|
39
|
+
var formatAuthor = function (author) {
|
|
40
|
+
if (typeof author === 'string') {
|
|
41
|
+
return {
|
|
42
|
+
'@type': 'Person',
|
|
43
|
+
name: author,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(author)) {
|
|
47
|
+
return author.map(function (a) { return (__assign({ '@type': 'Person', name: a.name }, (a.url && { url: a.url }))); });
|
|
48
|
+
}
|
|
49
|
+
return __assign({ '@type': 'Person', name: author.name }, (author.url && { url: author.url }));
|
|
50
|
+
};
|
|
51
|
+
var formatImage = function (image) {
|
|
52
|
+
if (!image)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (typeof image === 'string')
|
|
55
|
+
return image;
|
|
56
|
+
if (Array.isArray(image)) {
|
|
57
|
+
return image.map(function (img) {
|
|
58
|
+
if (typeof img === 'string')
|
|
59
|
+
return img;
|
|
60
|
+
return __assign(__assign({ '@type': 'ImageObject', url: img.url }, (img.width && { width: img.width })), (img.height && { height: img.height }));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
|
|
64
|
+
};
|
|
65
|
+
var formatPublisher = function (publisher) {
|
|
66
|
+
var out = {
|
|
67
|
+
'@type': 'Organization',
|
|
68
|
+
name: publisher.name,
|
|
69
|
+
};
|
|
70
|
+
if (publisher.logo) {
|
|
71
|
+
out.logo = __assign(__assign({ '@type': 'ImageObject', url: publisher.logo.url }, (publisher.logo.width && { width: publisher.logo.width })), (publisher.logo.height && { height: publisher.logo.height }));
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
};
|
|
75
|
+
var generateBookSchema = function (_a) {
|
|
76
|
+
var title = _a.title, author = _a.author, isbn = _a.isbn, numberOfPages = _a.numberOfPages, inLanguage = _a.inLanguage, publisher = _a.publisher, datePublished = _a.datePublished, image = _a.image, description = _a.description, url = _a.url, keywords = _a.keywords, bookFormat = _a.bookFormat;
|
|
77
|
+
var schema = {
|
|
78
|
+
'@context': 'https://schema.org',
|
|
79
|
+
'@type': 'Book',
|
|
80
|
+
name: title,
|
|
81
|
+
author: formatAuthor(author),
|
|
82
|
+
publisher: formatPublisher(publisher),
|
|
83
|
+
};
|
|
84
|
+
if (isbn)
|
|
85
|
+
schema.isbn = isbn;
|
|
86
|
+
if (numberOfPages)
|
|
87
|
+
schema.numberOfPages = numberOfPages;
|
|
88
|
+
if (inLanguage)
|
|
89
|
+
schema.inLanguage = inLanguage;
|
|
90
|
+
if (datePublished)
|
|
91
|
+
schema.datePublished = datePublished;
|
|
92
|
+
if (description)
|
|
93
|
+
schema.description = description;
|
|
94
|
+
if (bookFormat)
|
|
95
|
+
schema.bookFormat = bookFormat;
|
|
96
|
+
var img = formatImage(image);
|
|
97
|
+
if (img)
|
|
98
|
+
schema.image = img;
|
|
99
|
+
if (url) {
|
|
100
|
+
schema.mainEntityOfPage = {
|
|
101
|
+
'@type': 'WebPage',
|
|
102
|
+
'@id': url,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (keywords && keywords.length > 0)
|
|
106
|
+
schema.keywords = keywords.join(', ');
|
|
107
|
+
return schema;
|
|
108
|
+
};
|
|
109
|
+
exports.generateBookSchema = generateBookSchema;
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Generate a schema.org `BreadcrumbList` JSON-LD object.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* The `data` array may contain either strings or `Crumb` objects. If an
|
|
5
|
+
* entry is a string it will be treated as a path segment and slugified when
|
|
6
|
+
* appended to `baseUrl`. A `Crumb` object may provide an explicit `path` to
|
|
7
|
+
* use when building the segment, or an absolute `url` to use directly.
|
|
8
|
+
*
|
|
9
|
+
* Output: each list item will include an `item` object with `@id` (the URL)
|
|
10
|
+
* and `name` (the breadcrumb label).
|
|
11
|
+
*
|
|
12
|
+
* @param props.data - Array of path segments or Crumb objects
|
|
13
|
+
* @param props.baseUrl - The base URL to build breadcrumb URLs from
|
|
14
|
+
* @returns A JSON-LD `BreadcrumbList` object
|
|
5
15
|
* @author Taimoor Khan
|
|
6
|
-
* @remarks AppCorp
|
|
7
16
|
*/
|
|
8
|
-
|
|
17
|
+
interface Crumb {
|
|
18
|
+
name: string;
|
|
19
|
+
path?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
}
|
|
9
22
|
interface Props {
|
|
10
|
-
data: Array<string>;
|
|
23
|
+
data: Array<string | Crumb>;
|
|
11
24
|
baseUrl: string;
|
|
12
25
|
}
|
|
13
26
|
export declare const generateBreadcrumbSchema: ({ data, baseUrl }: Props) => {
|
|
@@ -17,7 +30,10 @@ export declare const generateBreadcrumbSchema: ({ data, baseUrl }: Props) => {
|
|
|
17
30
|
'@type': string;
|
|
18
31
|
position: number;
|
|
19
32
|
name: string;
|
|
20
|
-
item:
|
|
33
|
+
item: {
|
|
34
|
+
'@id': string;
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
21
37
|
}[];
|
|
22
38
|
};
|
|
23
39
|
export {};
|
|
@@ -5,13 +5,24 @@ var slugify_1 = require("./slugify");
|
|
|
5
5
|
var generateBreadcrumbSchema = function (_a) {
|
|
6
6
|
var data = _a.data, baseUrl = _a.baseUrl;
|
|
7
7
|
var urlItem = baseUrl;
|
|
8
|
-
var items = data.map(function (
|
|
9
|
-
|
|
8
|
+
var items = data.map(function (entry, index) {
|
|
9
|
+
var name = typeof entry === 'string' ? entry : entry.name;
|
|
10
|
+
if (typeof entry !== 'string' && entry.url) {
|
|
11
|
+
// use provided absolute url
|
|
12
|
+
urlItem = entry.url;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
var segment = typeof entry === 'string' ? entry : entry.path || entry.name;
|
|
16
|
+
urlItem += "/".concat((0, slugify_1.slugify)(segment));
|
|
17
|
+
}
|
|
10
18
|
return {
|
|
11
19
|
'@type': 'ListItem',
|
|
12
20
|
position: index + 1,
|
|
13
|
-
name:
|
|
14
|
-
item:
|
|
21
|
+
name: name,
|
|
22
|
+
item: {
|
|
23
|
+
'@id': urlItem,
|
|
24
|
+
name: name,
|
|
25
|
+
},
|
|
15
26
|
};
|
|
16
27
|
});
|
|
17
28
|
return {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate schema.org `ItemList` JSON-LD for a carousel of items.
|
|
3
|
+
*
|
|
4
|
+
* Each carousel item is emitted as a `ListItem` containing a `Thing`
|
|
5
|
+
* (Product, Article, Movie, etc.) depending on the provided item fields.
|
|
6
|
+
* Currency and availability values are normalized where applicable; use
|
|
7
|
+
* `skipInvalidCurrency` to bypass currency validation.
|
|
8
|
+
*
|
|
9
|
+
* See `CarouselSchemaOptions` and `CarouselItem` for input details.
|
|
10
|
+
* @returns A JSON-LD compatible `ItemList` object
|
|
11
|
+
*/
|
|
12
|
+
interface CarouselImage {
|
|
13
|
+
url: string;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
}
|
|
17
|
+
interface CarouselItem {
|
|
18
|
+
id?: string;
|
|
19
|
+
name: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
image?: string | CarouselImage;
|
|
22
|
+
description?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
price?: string | number;
|
|
25
|
+
priceCurrency?: string;
|
|
26
|
+
aggregateRating?: {
|
|
27
|
+
ratingValue: number | string;
|
|
28
|
+
reviewCount?: number;
|
|
29
|
+
bestRating?: number;
|
|
30
|
+
worstRating?: number;
|
|
31
|
+
};
|
|
32
|
+
offers?: Array<{
|
|
33
|
+
price: string | number;
|
|
34
|
+
priceCurrency?: string;
|
|
35
|
+
availability?: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
priceValidUntil?: string;
|
|
38
|
+
priceRange?: {
|
|
39
|
+
low?: string | number;
|
|
40
|
+
high?: string | number;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
interface CarouselSchemaOptions {
|
|
45
|
+
name?: string;
|
|
46
|
+
url?: string;
|
|
47
|
+
items: CarouselItem[];
|
|
48
|
+
skipInvalidCurrency?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare const generateCarouselSchema: ({ name, url, items, skipInvalidCurrency, }: CarouselSchemaOptions) => any;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generate schema.org `ItemList` JSON-LD for a carousel of items.
|
|
4
|
+
*
|
|
5
|
+
* Each carousel item is emitted as a `ListItem` containing a `Thing`
|
|
6
|
+
* (Product, Article, Movie, etc.) depending on the provided item fields.
|
|
7
|
+
* Currency and availability values are normalized where applicable; use
|
|
8
|
+
* `skipInvalidCurrency` to bypass currency validation.
|
|
9
|
+
*
|
|
10
|
+
* See `CarouselSchemaOptions` and `CarouselItem` for input details.
|
|
11
|
+
* @returns A JSON-LD compatible `ItemList` 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.generateCarouselSchema = 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 isValidCurrency = function (code) {
|
|
34
|
+
if (!code)
|
|
35
|
+
return false;
|
|
36
|
+
return /^[A-Z]{3}$/.test(code);
|
|
37
|
+
};
|
|
38
|
+
var AVAILABILITIES = [
|
|
39
|
+
'InStock',
|
|
40
|
+
'OutOfStock',
|
|
41
|
+
'PreOrder',
|
|
42
|
+
'PreSale',
|
|
43
|
+
'Discontinued',
|
|
44
|
+
'OnlineOnly',
|
|
45
|
+
'InStoreOnly',
|
|
46
|
+
'LimitedAvailability',
|
|
47
|
+
'BackOrder',
|
|
48
|
+
];
|
|
49
|
+
var normalizeAvailability = function (val) {
|
|
50
|
+
if (!val)
|
|
51
|
+
return undefined;
|
|
52
|
+
// accept full https://schema.org/InStock or short 'InStock'
|
|
53
|
+
try {
|
|
54
|
+
var asUrl = String(val);
|
|
55
|
+
if (asUrl.startsWith('http')) {
|
|
56
|
+
var token = asUrl.replace(/https?:\/\/schema\.org\//i, '');
|
|
57
|
+
if (AVAILABILITIES.includes(token))
|
|
58
|
+
return "https://schema.org/".concat(token);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (AVAILABILITIES.includes(asUrl))
|
|
62
|
+
return "https://schema.org/".concat(asUrl);
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var generateCarouselSchema = function (_a) {
|
|
70
|
+
var name = _a.name, url = _a.url, items = _a.items, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
71
|
+
var itemList = items.map(function (it, index) {
|
|
72
|
+
var itemObj = {
|
|
73
|
+
'@type': it.type || 'Thing',
|
|
74
|
+
name: it.name,
|
|
75
|
+
};
|
|
76
|
+
if (it.url)
|
|
77
|
+
itemObj.url = it.url;
|
|
78
|
+
if (it.id)
|
|
79
|
+
itemObj['@id'] = it.id;
|
|
80
|
+
var img = formatImage(it.image);
|
|
81
|
+
if (img)
|
|
82
|
+
itemObj.image = img;
|
|
83
|
+
if (it.description)
|
|
84
|
+
itemObj.description = it.description;
|
|
85
|
+
// offers: support multiple offers or single price fallback
|
|
86
|
+
if (it.offers && Array.isArray(it.offers) && it.offers.length > 0) {
|
|
87
|
+
var mapped = it.offers
|
|
88
|
+
.map(function (o) {
|
|
89
|
+
if (o.priceCurrency && !isValidCurrency(o.priceCurrency)) {
|
|
90
|
+
// either skip or throw depending on top-level option
|
|
91
|
+
return { __invalidCurrency: o.priceCurrency };
|
|
92
|
+
}
|
|
93
|
+
var offer = {
|
|
94
|
+
'@type': 'Offer',
|
|
95
|
+
};
|
|
96
|
+
if (o.price !== undefined)
|
|
97
|
+
offer.price = o.price;
|
|
98
|
+
if (o.priceCurrency)
|
|
99
|
+
offer.priceCurrency = o.priceCurrency;
|
|
100
|
+
if (o.availability) {
|
|
101
|
+
var norm = normalizeAvailability(o.availability);
|
|
102
|
+
if (norm)
|
|
103
|
+
offer.availability = norm;
|
|
104
|
+
// if invalid availability, skip the field silently
|
|
105
|
+
}
|
|
106
|
+
if (o.url)
|
|
107
|
+
offer.url = o.url;
|
|
108
|
+
if (o.priceValidUntil)
|
|
109
|
+
offer.priceValidUntil = o.priceValidUntil;
|
|
110
|
+
if (o.priceRange) {
|
|
111
|
+
var pr = o.priceRange;
|
|
112
|
+
offer.priceSpecification = __assign(__assign(__assign({ '@type': 'PriceSpecification' }, (pr.low != null && { minPrice: pr.low })), (pr.high != null && { maxPrice: pr.high })), (o.priceCurrency && { priceCurrency: o.priceCurrency }));
|
|
113
|
+
}
|
|
114
|
+
return offer;
|
|
115
|
+
})
|
|
116
|
+
.filter(function (x) { return x && !('__invalidCurrency' in x); });
|
|
117
|
+
// if any invalid currency markers were present and skipInvalidCurrency is false, throw
|
|
118
|
+
var hadInvalid = it.offers.some(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
119
|
+
if (hadInvalid && !skipInvalidCurrency) {
|
|
120
|
+
var bad = it.offers.find(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
121
|
+
throw new Error("Invalid currency code: ".concat(bad === null || bad === void 0 ? void 0 : bad.priceCurrency));
|
|
122
|
+
}
|
|
123
|
+
if (mapped.length > 0)
|
|
124
|
+
itemObj.offers = mapped;
|
|
125
|
+
}
|
|
126
|
+
else if (it.price !== undefined) {
|
|
127
|
+
if (it.priceCurrency && !isValidCurrency(it.priceCurrency)) {
|
|
128
|
+
if (!skipInvalidCurrency) {
|
|
129
|
+
throw new Error("Invalid currency code: ".concat(it.priceCurrency));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
var offer = {
|
|
134
|
+
'@type': 'Offer',
|
|
135
|
+
price: it.price,
|
|
136
|
+
};
|
|
137
|
+
if (it.priceCurrency)
|
|
138
|
+
offer.priceCurrency = it.priceCurrency;
|
|
139
|
+
itemObj.offers = offer;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (it.aggregateRating) {
|
|
143
|
+
itemObj.aggregateRating = __assign(__assign(__assign({ '@type': 'AggregateRating', ratingValue: it.aggregateRating.ratingValue }, (it.aggregateRating.reviewCount != null && {
|
|
144
|
+
reviewCount: it.aggregateRating.reviewCount,
|
|
145
|
+
})), (it.aggregateRating.bestRating != null && {
|
|
146
|
+
bestRating: it.aggregateRating.bestRating,
|
|
147
|
+
})), (it.aggregateRating.worstRating != null && {
|
|
148
|
+
worstRating: it.aggregateRating.worstRating,
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
'@type': 'ListItem',
|
|
153
|
+
position: index + 1,
|
|
154
|
+
item: itemObj,
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
var schema = {
|
|
158
|
+
'@context': 'https://schema.org',
|
|
159
|
+
'@type': 'ItemList',
|
|
160
|
+
itemListElement: itemList,
|
|
161
|
+
};
|
|
162
|
+
if (name)
|
|
163
|
+
schema.name = name;
|
|
164
|
+
if (url) {
|
|
165
|
+
schema.mainEntityOfPage = {
|
|
166
|
+
'@type': 'WebPage',
|
|
167
|
+
'@id': url,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return schema;
|
|
171
|
+
};
|
|
172
|
+
exports.generateCarouselSchema = generateCarouselSchema;
|