@react-pakistan/util-functions 1.25.90 → 2.0.0
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/README.md +74 -315
- package/constants/api-methods.d.ts +3 -1
- package/constants/api-methods.js +1 -15
- package/constants/cache-time.d.ts +7 -5
- package/constants/cache-time.js +1 -8
- package/constants/countries-timezones.d.ts +4 -2
- package/constants/countries-timezones.js +1 -1411
- package/constants/currencies.d.ts +4 -2
- package/constants/currencies.js +1 -1076
- package/constants/dial-codes.d.ts +5 -3
- package/constants/dial-codes.js +1 -1216
- package/constants/layout-direction.d.ts +3 -1
- package/constants/layout-direction.js +1 -8
- package/constants/react-pakistan-meta.d.ts +4 -2
- package/constants/react-pakistan-meta.js +1 -35
- package/constants/react-pakistan.d.ts +5 -3
- package/constants/react-pakistan.js +12 -104
- package/constants/select-value-delimiter.d.ts +3 -1
- package/constants/select-value-delimiter.js +1 -13
- package/constants/social-media-colors.d.ts +3 -1
- package/constants/social-media-colors.js +1 -42
- package/constants/social-media-sizes.d.ts +6 -4
- package/constants/social-media-sizes.js +1 -327
- package/constants/user-roles.d.ts +3 -1
- package/constants/user-roles.js +1 -9
- package/edu-pilot-pro/types/academics.d.ts +2 -266
- package/edu-pilot-pro/types/academics.js +1 -9
- package/edu-pilot-pro/types/admission.d.ts +803 -10
- package/edu-pilot-pro/types/admission.js +1 -7
- package/edu-pilot-pro/types/communication.d.ts +2 -165
- package/edu-pilot-pro/types/communication.js +1 -8
- package/edu-pilot-pro/types/enums.d.ts +30 -28
- package/edu-pilot-pro/types/enums.js +1 -445
- package/edu-pilot-pro/types/finance.d.ts +2 -128
- package/edu-pilot-pro/types/finance.js +1 -8
- package/edu-pilot-pro/types/index.d.ts +2 -12
- package/edu-pilot-pro/types/index.js +1 -28
- package/edu-pilot-pro/types/user-management.d.ts +2 -236
- package/edu-pilot-pro/types/user-management.js +1 -8
- package/factory/generic-component-factory.d.ts +12 -9
- package/factory/generic-component-factory.js +1 -131
- package/factory/generic-module-factory.d.ts +14 -10
- package/factory/generic-module-factory.js +1 -190
- package/general/basic-get.d.ts +8 -1
- package/general/basic-get.js +1 -83
- package/general/basic-post.d.ts +8 -1
- package/general/basic-post.js +1 -70
- package/general/calculate-pages.d.ts +9 -1
- package/general/calculate-pages.js +1 -7
- package/general/camel-to-sentence-case.d.ts +3 -1
- package/general/camel-to-sentence-case.js +1 -20
- package/general/check-even-odd-length.d.ts +3 -1
- package/general/check-even-odd-length.js +1 -17
- package/general/clear-cache.d.ts +7 -2
- package/general/clear-cache.js +1 -12
- package/general/cnic-formatter.d.ts +16 -3
- package/general/cnic-formatter.js +1 -53
- package/general/convert-url-to-base64.d.ts +8 -6
- package/general/convert-url-to-base64.js +1 -231
- package/general/countries.d.ts +5 -3
- package/general/countries.js +1 -514
- package/general/create-date.d.ts +3 -1
- package/general/create-date.js +1 -22
- package/general/crypto.d.ts +4 -2
- package/general/crypto.js +1 -45
- package/general/currencies.d.ts +2 -0
- package/general/currencies.js +0 -1077
- package/general/delete-image-from-private-supabase.d.ts +10 -2
- package/general/delete-image-from-private-supabase.js +1 -66
- package/general/delete-image-from-public-supabase.d.ts +10 -2
- package/general/delete-image-from-public-supabase.js +1 -66
- package/general/download-from-url.d.ts +8 -1
- package/general/download-from-url.js +1 -82
- package/general/dynamic-page-limit.d.ts +9 -3
- package/general/dynamic-page-limit.js +1 -7
- package/general/enum-to-text.d.ts +8 -1
- package/general/enum-to-text.js +1 -11
- package/general/fetch-data.d.ts +16 -4
- package/general/fetch-data.js +1 -95
- package/general/fetch-supabase-image.d.ts +11 -2
- package/general/fetch-supabase-image.js +1 -67
- package/general/fetch-supabase-private-assets.d.ts +11 -2
- package/general/fetch-supabase-private-assets.js +1 -69
- package/general/format-date.d.ts +10 -2
- package/general/format-date.js +1 -49
- package/general/format-number.d.ts +12 -2
- package/general/format-number.js +1 -35
- package/general/format-phone-display.d.ts +9 -1
- package/general/format-phone-display.js +1 -32
- package/general/format-phone.d.ts +10 -2
- package/general/format-phone.js +1 -20
- package/general/format-pricing.d.ts +8 -1
- package/general/format-pricing.js +1 -23
- package/general/format-secs.d.ts +8 -1
- package/general/format-secs.js +1 -21
- package/general/format-time.d.ts +8 -2
- package/general/format-time.js +1 -38
- package/general/format-value.d.ts +8 -1
- package/general/format-value.js +1 -7
- package/general/full-month-range.d.ts +3 -2
- package/general/full-month-range.js +1 -24
- package/general/full-year-range.d.ts +3 -2
- package/general/full-year-range.js +1 -20
- package/general/generate-article-schema.d.ts +3 -2
- package/general/generate-article-schema.js +1 -100
- package/general/generate-blog-schema.d.ts +3 -2
- package/general/generate-blog-schema.js +1 -32
- package/general/generate-book-schema.d.ts +3 -2
- package/general/generate-book-schema.js +1 -109
- package/general/generate-breadcrumb-schema.d.ts +3 -2
- package/general/generate-breadcrumb-schema.js +1 -34
- package/general/generate-carousel-schema.d.ts +3 -2
- package/general/generate-carousel-schema.js +1 -172
- package/general/generate-course-schema.d.ts +3 -2
- package/general/generate-course-schema.js +1 -124
- package/general/generate-dataset-schema.d.ts +3 -2
- package/general/generate-dataset-schema.js +1 -156
- package/general/generate-discussion-forum-schema.d.ts +3 -2
- package/general/generate-discussion-forum-schema.js +1 -67
- package/general/generate-education-schema.d.ts +3 -2
- package/general/generate-education-schema.js +1 -137
- package/general/generate-employer-aggregate-rating-schema.d.ts +3 -2
- package/general/generate-employer-aggregate-rating-schema.js +1 -64
- package/general/generate-event-schema.d.ts +3 -2
- package/general/generate-event-schema.js +1 -214
- package/general/generate-faq-schema.d.ts +3 -2
- package/general/generate-faq-schema.js +1 -43
- package/general/generate-grid.d.ts +3 -2
- package/general/generate-grid.js +1 -55
- package/general/generate-image-metadata-schema.d.ts +3 -2
- package/general/generate-image-metadata-schema.js +1 -73
- package/general/generate-job-posting-schema.d.ts +3 -2
- package/general/generate-job-posting-schema.js +1 -120
- package/general/generate-local-business-schema.d.ts +3 -2
- package/general/generate-local-business-schema.js +1 -75
- package/general/generate-math-solver-schema.d.ts +3 -2
- package/general/generate-math-solver-schema.js +1 -83
- package/general/generate-movie-carousel-schema.d.ts +3 -2
- package/general/generate-movie-carousel-schema.js +1 -160
- package/general/generate-organization-schema.d.ts +3 -2
- package/general/generate-organization-schema.js +1 -39
- package/general/generate-profile-page-schema.d.ts +3 -2
- package/general/generate-profile-page-schema.js +1 -82
- package/general/generate-qa-page-schema.d.ts +3 -2
- package/general/generate-qa-page-schema.js +1 -67
- package/general/generate-recipe-schema.d.ts +3 -2
- package/general/generate-recipe-schema.js +1 -104
- package/general/generate-ref.d.ts +8 -2
- package/general/generate-ref.js +1 -12
- package/general/generate-review-snippet-schema.d.ts +3 -2
- package/general/generate-review-snippet-schema.js +1 -137
- package/general/generate-shopping-loyalty-program-schema.d.ts +3 -2
- package/general/generate-shopping-loyalty-program-schema.js +1 -59
- package/general/generate-shopping-merchant-listing-schema.d.ts +3 -2
- package/general/generate-shopping-merchant-listing-schema.js +1 -153
- package/general/generate-shopping-merchant-return-policy-schema.d.ts +3 -2
- package/general/generate-shopping-merchant-return-policy-schema.js +1 -68
- package/general/generate-shopping-merchant-shipping-policy-schema.d.ts +3 -2
- package/general/generate-shopping-merchant-shipping-policy-schema.js +1 -74
- package/general/generate-shopping-overview-schema.d.ts +3 -2
- package/general/generate-shopping-overview-schema.js +1 -157
- package/general/generate-shopping-product-snippet-schema.d.ts +3 -2
- package/general/generate-shopping-product-snippet-schema.js +1 -167
- package/general/generate-shopping-variants-schema.d.ts +3 -2
- package/general/generate-shopping-variants-schema.js +1 -143
- package/general/generate-software-app-schema.d.ts +3 -2
- package/general/generate-software-app-schema.js +1 -143
- package/general/generate-speakable-schema.d.ts +3 -2
- package/general/generate-speakable-schema.js +1 -139
- package/general/generate-subscription-schema.d.ts +3 -2
- package/general/generate-subscription-schema.js +1 -133
- package/general/generate-vacation-rental-schema.d.ts +3 -2
- package/general/generate-vacation-rental-schema.js +1 -135
- package/general/generate-video-schema.d.ts +3 -2
- package/general/generate-video-schema.js +1 -163
- package/general/generic-cache.d.ts +17 -15
- package/general/generic-cache.js +1 -659
- package/general/get-available-page-limit.d.ts +8 -2
- package/general/get-available-page-limit.js +1 -31
- package/general/get-calendar-current-month.d.ts +11 -3
- package/general/get-calendar-current-month.js +1 -31
- package/general/get-calendar-dates.d.ts +11 -3
- package/general/get-calendar-dates.js +1 -42
- package/general/get-calendar-next-month.d.ts +12 -3
- package/general/get-calendar-next-month.js +1 -32
- package/general/get-calendar-previous-month.d.ts +12 -3
- package/general/get-calendar-previous-month.js +1 -36
- package/general/get-current-year.d.ts +7 -1
- package/general/get-current-year.js +1 -5
- package/general/get-day-name.d.ts +5 -3
- package/general/get-day-name.js +1 -14
- package/general/get-dial-code.d.ts +8 -1
- package/general/get-dial-code.js +1 -8
- package/general/get-full-name.d.ts +9 -2
- package/general/get-full-name.js +1 -8
- package/general/get-href.d.ts +3 -1
- package/general/get-href.js +1 -13
- package/general/get-month-name.d.ts +5 -3
- package/general/get-month-name.js +1 -19
- package/general/get-month-number.d.ts +5 -3
- package/general/get-month-number.js +1 -29
- package/general/get-number-of-days-in-month.d.ts +9 -2
- package/general/get-number-of-days-in-month.js +1 -12
- package/general/get-pathname.d.ts +3 -1
- package/general/get-pathname.js +1 -16
- package/general/get-week-day.d.ts +8 -1
- package/general/get-week-day.js +1 -9
- package/general/image-url-to-base64.d.ts +3 -1
- package/general/image-url-to-base64.js +1 -80
- package/general/is-created-or-updated.d.ts +3 -1
- package/general/is-created-or-updated.js +1 -26
- package/general/is-next-button-disabled.d.ts +9 -1
- package/general/is-next-button-disabled.js +1 -5
- package/general/is-odd.d.ts +3 -1
- package/general/is-odd.js +1 -13
- package/general/is-previous-button-disabled.d.ts +8 -1
- package/general/is-previous-button-disabled.js +1 -7
- package/general/linear-gradients.d.ts +4 -2
- package/general/linear-gradients.js +1 -52
- package/general/multi-part-search.d.ts +10 -2
- package/general/multi-part-search.js +1 -16
- package/general/normalize-phone.d.ts +15 -2
- package/general/normalize-phone.js +1 -40
- package/general/parse-frontmatter.d.ts +11 -4
- package/general/parse-frontmatter.js +2 -35
- package/general/remove-data-image-prefix.d.ts +8 -1
- package/general/remove-data-image-prefix.js +1 -7
- package/general/repeat-times.d.ts +3 -1
- package/general/repeat-times.js +1 -21
- package/general/resolve-anchor-link.d.ts +3 -1
- package/general/resolve-anchor-link.js +1 -26
- package/general/resolve-current-date.d.ts +3 -1
- package/general/resolve-current-date.js +1 -22
- package/general/resolve-grid.d.ts +3 -1
- package/general/resolve-grid.js +1 -18
- package/general/resolve-initials.d.ts +3 -1
- package/general/resolve-initials.js +1 -17
- package/general/set-timezone.d.ts +11 -1
- package/general/set-timezone.js +1 -12
- package/general/slugify.d.ts +3 -1
- package/general/slugify.js +1 -24
- package/general/text-to-enum.d.ts +8 -1
- package/general/text-to-enum.js +1 -10
- package/general/text-to-sentence-case.d.ts +3 -1
- package/general/text-to-sentence-case.js +1 -16
- package/general/time-out.d.ts +3 -1
- package/general/time-out.js +1 -16
- package/general/time-zones.d.ts +3 -1
- package/general/time-zones.js +1 -437
- package/general/truncate-text.d.ts +3 -1
- package/general/truncate-text.js +1 -18
- package/general/type.d.ts +3 -1
- package/general/type.js +1 -2
- package/general/upload-blob-to-private-supabase.d.ts +14 -2
- package/general/upload-blob-to-private-supabase.js +1 -62
- package/general/upload-blob-to-public-supabase.d.ts +14 -2
- package/general/upload-blob-to-public-supabase.js +1 -62
- package/general/upload-image-to-private-supabase.d.ts +15 -3
- package/general/upload-image-to-private-supabase.js +1 -66
- package/general/upload-image-to-public-supabase.d.ts +15 -3
- package/general/upload-image-to-public-supabase.js +1 -66
- package/general/url-to-sentence-case.d.ts +3 -1
- package/general/url-to-sentence-case.js +1 -19
- package/general/validate-comment.d.ts +3 -1
- package/general/validate-comment.js +1 -21
- package/general/validate-email.d.ts +3 -1
- package/general/validate-email.js +1 -24
- package/general/validate-form.d.ts +12 -3
- package/general/validate-form.js +1 -29
- package/general/validate-name.d.ts +3 -1
- package/general/validate-name.js +1 -21
- package/hooks/use-change.d.ts +11 -2
- package/hooks/use-change.js +1 -23
- package/hooks/use-debounce.d.ts +10 -1
- package/hooks/use-debounce.js +1 -14
- package/hooks/use-fetch.d.ts +7 -5
- package/hooks/use-fetch.js +1 -239
- package/hooks/use-force-render.d.ts +6 -2
- package/hooks/use-force-render.js +1 -17
- package/hooks/use-ip-geo-location.d.ts +8 -1
- package/hooks/use-ip-geo-location.js +1 -79
- package/hooks/use-is-mobile.d.ts +8 -1
- package/hooks/use-is-mobile.js +1 -22
- package/hooks/use-module-entity-v2.d.ts +7 -4
- package/hooks/use-module-entity-v2.js +1 -188
- package/hooks/use-module-entity.d.ts +7 -4
- package/hooks/use-module-entity.js +1 -177
- package/hooks/use-phone-formatter.d.ts +10 -2
- package/hooks/use-phone-formatter.js +1 -23
- package/hooks/use-position.d.ts +6 -3
- package/hooks/use-position.js +1 -43
- package/hooks/use-rtl.d.ts +4 -2
- package/hooks/use-rtl.js +1 -84
- package/hooks/use-sticky.d.ts +3 -1
- package/hooks/use-sticky.js +1 -39
- package/hooks/use-toggle-state.d.ts +3 -2
- package/hooks/use-toggle-state.js +1 -26
- package/hooks/use-window-event-listener.d.ts +9 -1
- package/hooks/use-window-event-listener.js +1 -11
- package/hooks/with-seo.d.ts +11 -2
- package/hooks/with-seo.js +1 -37
- package/local-storage/get-storage-value.d.ts +5 -2
- package/local-storage/get-storage-value.js +1 -20
- package/local-storage/remove-storage-value.d.ts +3 -1
- package/local-storage/remove-storage-value.js +1 -14
- package/local-storage/set-storage-value.d.ts +3 -1
- package/local-storage/set-storage-value.js +1 -14
- package/local-storage/type.d.ts +3 -1
- package/local-storage/type.js +1 -2
- package/npm.d.d.ts +2 -0
- package/npm.d.js +0 -0
- package/package.json +20 -18
- package/storybook/generate-sitemap.d.ts +3 -1
- package/storybook/generate-sitemap.js +17 -26
- package/storybook/preview.d.ts +4 -2
- package/storybook/preview.js +1 -62
- package/storybook/react-design-story-script.d.ts +3 -1
- package/storybook/react-design-story-script.js +5 -27
- package/storybook/react-emoji-collection.d.ts +3 -1
- package/storybook/react-emoji-collection.js +10 -55
- package/storybook/react-emoji-story-script.d.ts +3 -1
- package/storybook/react-emoji-story-script.js +5 -31
- package/storybook/react-emoji-story-template.d.ts +3 -1
- package/storybook/react-emoji-story-template.js +45 -15
- package/storybook/react-icon-collection.d.ts +3 -1
- package/storybook/react-icon-collection.js +10 -42
- package/storybook/react-icon-story-script.d.ts +3 -1
- package/storybook/react-icon-story-script.js +5 -27
- package/storybook/react-icon-story-template.d.ts +3 -1
- package/storybook/react-icon-story-template.js +45 -14
- package/storybook/react-logo-collection.d.ts +3 -1
- package/storybook/react-logo-collection.js +10 -42
- package/storybook/react-logo-story-script.d.ts +3 -1
- package/storybook/react-logo-story-script.js +5 -27
- package/storybook/react-logo-story-template.d.ts +3 -1
- package/storybook/react-logo-story-template.js +45 -14
- package/storybook/react-pakistan-theme.d.ts +3 -1
- package/storybook/react-pakistan-theme.js +1 -31
- package/storybook/responsive-args.d.ts +11 -10
- package/storybook/responsive-args.js +1 -19
- package/storybook/responsive-component.d.ts +4 -2
- package/storybook/responsive-component.js +37 -23
- package/storybook/responsive-screens.d.ts +3 -1
- package/storybook/responsive-screens.js +1 -109
- package/storybook/theme.d.ts +17 -15
- package/storybook/theme.js +1 -1022
- package/api/stellar-solutions/app-user/index.d.ts +0 -51
- package/api/stellar-solutions/app-user/index.js +0 -210
- package/api/stellar-solutions/bank/index.d.ts +0 -59
- package/api/stellar-solutions/bank/index.js +0 -210
- package/api/stellar-solutions/branch/index.d.ts +0 -58
- package/api/stellar-solutions/branch/index.js +0 -220
- package/api/stellar-solutions/company/index.d.ts +0 -57
- package/api/stellar-solutions/company/index.js +0 -218
- package/api/stellar-solutions/company-report/index.d.ts +0 -15
- package/api/stellar-solutions/company-report/index.js +0 -74
- package/api/stellar-solutions/constants.d.ts +0 -19
- package/api/stellar-solutions/constants.js +0 -22
- package/api/stellar-solutions/contact/index.d.ts +0 -56
- package/api/stellar-solutions/contact/index.js +0 -217
- package/api/stellar-solutions/currency/index.d.ts +0 -55
- package/api/stellar-solutions/currency/index.js +0 -212
- package/api/stellar-solutions/customer/index.d.ts +0 -68
- package/api/stellar-solutions/customer/index.js +0 -249
- package/api/stellar-solutions/expense/index.d.ts +0 -58
- package/api/stellar-solutions/expense/index.js +0 -229
- package/api/stellar-solutions/expense-category/index.d.ts +0 -53
- package/api/stellar-solutions/expense-category/index.js +0 -214
- package/api/stellar-solutions/lead/index.d.ts +0 -51
- package/api/stellar-solutions/lead/index.js +0 -206
- package/api/stellar-solutions/menu-order/index.d.ts +0 -53
- package/api/stellar-solutions/menu-order/index.js +0 -202
- package/api/stellar-solutions/payment/index.d.ts +0 -65
- package/api/stellar-solutions/payment/index.js +0 -230
- package/api/stellar-solutions/payment-mode/index.d.ts +0 -53
- package/api/stellar-solutions/payment-mode/index.js +0 -191
- package/api/stellar-solutions/preference/index.d.ts +0 -25
- package/api/stellar-solutions/preference/index.js +0 -114
- package/api/stellar-solutions/product/index.d.ts +0 -64
- package/api/stellar-solutions/product/index.js +0 -235
- package/api/stellar-solutions/product-category/index.d.ts +0 -51
- package/api/stellar-solutions/product-category/index.js +0 -212
- package/api/stellar-solutions/profile/index.d.ts +0 -78
- package/api/stellar-solutions/profile/index.js +0 -234
- package/api/stellar-solutions/quote-invoice/index.d.ts +0 -97
- package/api/stellar-solutions/quote-invoice/index.js +0 -369
- package/api/stellar-solutions/quote-invoice-report/index.d.ts +0 -15
- package/api/stellar-solutions/quote-invoice-report/index.js +0 -74
- package/api/stellar-solutions/tax/index.d.ts +0 -55
- package/api/stellar-solutions/tax/index.js +0 -224
- package/api/stellar-solutions/types/common.d.ts +0 -24
- package/api/stellar-solutions/types/common.js +0 -22
- package/api/stellar-solutions/types/erp.d.ts +0 -302
- package/api/stellar-solutions/types/erp.js +0 -73
- package/api/stellar-solutions/types/index.d.ts +0 -3
- package/api/stellar-solutions/types/index.js +0 -19
- package/api/stellar-solutions/types/pos.d.ts +0 -176
- package/api/stellar-solutions/types/pos.js +0 -61
- package/constants/index.d.ts +0 -12
- package/constants/index.js +0 -28
- package/factory/index.d.ts +0 -2
- package/factory/index.js +0 -18
- package/general/index.d.ts +0 -95
- package/general/index.js +0 -111
- package/index.d.ts +0 -28
- package/index.js +0 -44
- package/local-storage/index.d.ts +0 -4
- package/local-storage/index.js +0 -20
- package/setupTests.d.ts +0 -1
- package/setupTests.js +0 -52
- package/storybook/index.d.ts +0 -17
- package/storybook/index.js +0 -33
|
@@ -1,167 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Create schema.org structured data for a single `Product` with optional
|
|
4
|
-
* `Review` and `Offer` entries.
|
|
5
|
-
*
|
|
6
|
-
* Supports brand and seller references, image normalization, review
|
|
7
|
-
* formatting and simple availability/price handling. Use
|
|
8
|
-
* `skipInvalidCurrency` to avoid throwing on bad currency codes.
|
|
9
|
-
*
|
|
10
|
-
* See `ProductSnippetOptions` for accepted fields.
|
|
11
|
-
* @returns A JSON-LD compatible `Product` 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.generateShoppingProductSnippetSchema = 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 formatBrand = function (b) {
|
|
34
|
-
if (!b)
|
|
35
|
-
return undefined;
|
|
36
|
-
if (typeof b === 'string')
|
|
37
|
-
return { '@type': 'Brand', name: b };
|
|
38
|
-
return __assign({ '@type': 'Brand', name: b.name }, (b.url && { url: b.url }));
|
|
39
|
-
};
|
|
40
|
-
var isValidCurrency = function (code) {
|
|
41
|
-
if (!code)
|
|
42
|
-
return false;
|
|
43
|
-
return /^[A-Z]{3}$/.test(code);
|
|
44
|
-
};
|
|
45
|
-
var AVAILABILITIES = [
|
|
46
|
-
'InStock',
|
|
47
|
-
'OutOfStock',
|
|
48
|
-
'PreOrder',
|
|
49
|
-
'PreSale',
|
|
50
|
-
'Discontinued',
|
|
51
|
-
'OnlineOnly',
|
|
52
|
-
'InStoreOnly',
|
|
53
|
-
'LimitedAvailability',
|
|
54
|
-
'BackOrder',
|
|
55
|
-
];
|
|
56
|
-
var normalizeAvailability = function (val) {
|
|
57
|
-
if (!val)
|
|
58
|
-
return undefined;
|
|
59
|
-
try {
|
|
60
|
-
var asUrl = String(val);
|
|
61
|
-
if (asUrl.startsWith('http')) {
|
|
62
|
-
var token = asUrl.replace(/https?:\/\/schema\.org\//i, '');
|
|
63
|
-
if (AVAILABILITIES.includes(token))
|
|
64
|
-
return "https://schema.org/".concat(token);
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
if (AVAILABILITIES.includes(asUrl))
|
|
68
|
-
return "https://schema.org/".concat(asUrl);
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
catch (_a) {
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var generateShoppingProductSnippetSchema = function (_a) {
|
|
76
|
-
var name = _a.name, description = _a.description, image = _a.image, sku = _a.sku, brand = _a.brand, reviews = _a.reviews, offers = _a.offers, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
77
|
-
var product = {
|
|
78
|
-
'@context': 'https://schema.org',
|
|
79
|
-
'@type': 'Product',
|
|
80
|
-
name: name,
|
|
81
|
-
};
|
|
82
|
-
if (description)
|
|
83
|
-
product.description = description;
|
|
84
|
-
var img = formatImage(image);
|
|
85
|
-
if (img)
|
|
86
|
-
product.image = img;
|
|
87
|
-
if (sku)
|
|
88
|
-
product.sku = sku;
|
|
89
|
-
var b = formatBrand(brand);
|
|
90
|
-
if (b)
|
|
91
|
-
product.brand = b;
|
|
92
|
-
// Reviews -> Review entries + aggregateRating if possible
|
|
93
|
-
if (reviews && reviews.length > 0) {
|
|
94
|
-
var mapped = reviews.map(function (r) {
|
|
95
|
-
var out = { '@type': 'Review' };
|
|
96
|
-
if (r.author) {
|
|
97
|
-
out.author =
|
|
98
|
-
typeof r.author === 'string'
|
|
99
|
-
? { '@type': 'Person', name: r.author }
|
|
100
|
-
: { '@type': 'Person', name: r.author.name };
|
|
101
|
-
}
|
|
102
|
-
if (r.datePublished)
|
|
103
|
-
out.datePublished = r.datePublished;
|
|
104
|
-
if (r.reviewBody)
|
|
105
|
-
out.reviewBody = r.reviewBody;
|
|
106
|
-
if (r.reviewRating) {
|
|
107
|
-
out.reviewRating = __assign({ '@type': 'Rating', ratingValue: r.reviewRating.ratingValue }, (r.reviewRating.bestRating != null && {
|
|
108
|
-
bestRating: r.reviewRating.bestRating,
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
return out;
|
|
112
|
-
});
|
|
113
|
-
product.review = mapped;
|
|
114
|
-
// compute aggregate rating if ratings present
|
|
115
|
-
var ratings = reviews
|
|
116
|
-
.map(function (r) { return (r.reviewRating ? Number(r.reviewRating.ratingValue) : NaN); })
|
|
117
|
-
.filter(function (n) { return !Number.isNaN(n); });
|
|
118
|
-
if (ratings.length > 0) {
|
|
119
|
-
var sum = ratings.reduce(function (a, b) { return a + b; }, 0);
|
|
120
|
-
product.aggregateRating = {
|
|
121
|
-
'@type': 'AggregateRating',
|
|
122
|
-
ratingValue: sum / ratings.length,
|
|
123
|
-
reviewCount: reviews.length,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Offers
|
|
128
|
-
if (offers) {
|
|
129
|
-
var offs = Array.isArray(offers) ? offers : [offers];
|
|
130
|
-
var mapped = offs
|
|
131
|
-
.map(function (o) {
|
|
132
|
-
if (o.priceCurrency && !isValidCurrency(o.priceCurrency))
|
|
133
|
-
return { __invalidCurrency: o.priceCurrency };
|
|
134
|
-
var of = { '@type': 'Offer' };
|
|
135
|
-
if (o.price != null)
|
|
136
|
-
of.price = o.price;
|
|
137
|
-
if (o.priceCurrency)
|
|
138
|
-
of.priceCurrency = o.priceCurrency;
|
|
139
|
-
if (o.availability) {
|
|
140
|
-
var n = normalizeAvailability(o.availability);
|
|
141
|
-
if (n)
|
|
142
|
-
of.availability = n;
|
|
143
|
-
}
|
|
144
|
-
if (o.url)
|
|
145
|
-
of.url = o.url;
|
|
146
|
-
if (o.seller)
|
|
147
|
-
of.seller = __assign(__assign({ '@type': 'Organization' }, (o.seller.name && { name: o.seller.name })), (o.seller.url && { url: o.seller.url }));
|
|
148
|
-
if (o.priceValidUntil)
|
|
149
|
-
of.priceValidUntil = o.priceValidUntil;
|
|
150
|
-
if (o.itemCondition)
|
|
151
|
-
of.itemCondition = o.itemCondition;
|
|
152
|
-
return of;
|
|
153
|
-
})
|
|
154
|
-
.filter(function (x) { return x && !('__invalidCurrency' in x); });
|
|
155
|
-
var hadInvalid = offs.some(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
156
|
-
if (hadInvalid && !skipInvalidCurrency) {
|
|
157
|
-
var bad = offs.find(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
158
|
-
throw new Error("Invalid currency code: ".concat(bad === null || bad === void 0 ? void 0 : bad.priceCurrency));
|
|
159
|
-
}
|
|
160
|
-
if (mapped.length === 1)
|
|
161
|
-
product.offers = mapped[0];
|
|
162
|
-
else if (mapped.length > 1)
|
|
163
|
-
product.offers = mapped;
|
|
164
|
-
}
|
|
165
|
-
return product;
|
|
166
|
-
};
|
|
167
|
-
exports.generateShoppingProductSnippetSchema = generateShoppingProductSnippetSchema;
|
|
1
|
+
var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var I=(r,n)=>{for(var a in n)p(r,a,{get:n[a],enumerable:!0})},O=(r,n,a,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of w(n))!C.call(r,l)&&l!==a&&p(r,l,{get:()=>n[l],enumerable:!(c=b(n,l))||c.enumerable});return r};var S=r=>O(p({},"__esModule",{value:!0}),r);var k={};I(k,{generateShoppingProductSnippetSchema:()=>A});module.exports=S(k);const B=r=>{if(r)return typeof r=="string"?r:{"@type":"ImageObject",url:r.url,...r.width&&{width:r.width},...r.height&&{height:r.height}}},P=r=>{if(r)return typeof r=="string"?{"@type":"Brand",name:r}:{"@type":"Brand",name:r.name,...r.url&&{url:r.url}}},o=r=>r?/^[A-Z]{3}$/.test(r):!1,v=["InStock","OutOfStock","PreOrder","PreSale","Discontinued","OnlineOnly","InStoreOnly","LimitedAvailability","BackOrder"],V=r=>{if(r)try{const n=String(r);if(n.startsWith("http")){const a=n.replace(/https?:\/\/schema\.org\//i,"");return v.includes(a)?`https://schema.org/${a}`:void 0}return v.includes(n)?`https://schema.org/${n}`:void 0}catch{return}},A=({name:r,description:n,image:a,sku:c,brand:l,reviews:g,offers:f,skipInvalidCurrency:R=!1})=>{const u={"@context":"https://schema.org","@type":"Product",name:r};n&&(u.description=n);const y=B(a);y&&(u.image=y),c&&(u.sku=c);const h=P(l);if(h&&(u.brand=h),g&&g.length>0){const d=g.map(i=>{const e={"@type":"Review"};return i.author&&(e.author=typeof i.author=="string"?{"@type":"Person",name:i.author}:{"@type":"Person",name:i.author.name}),i.datePublished&&(e.datePublished=i.datePublished),i.reviewBody&&(e.reviewBody=i.reviewBody),i.reviewRating&&(e.reviewRating={"@type":"Rating",ratingValue:i.reviewRating.ratingValue,...i.reviewRating.bestRating!=null&&{bestRating:i.reviewRating.bestRating}}),e});u.review=d;const s=g.map(i=>i.reviewRating?Number(i.reviewRating.ratingValue):NaN).filter(i=>!Number.isNaN(i));if(s.length>0){const i=s.reduce((e,t)=>e+t,0);u.aggregateRating={"@type":"AggregateRating",ratingValue:i/s.length,reviewCount:g.length}}}if(f){const d=Array.isArray(f)?f:[f],s=d.map(e=>{if(e.priceCurrency&&!o(e.priceCurrency))return{__invalidCurrency:e.priceCurrency};const t={"@type":"Offer"};if(e.price!=null&&(t.price=e.price),e.priceCurrency&&(t.priceCurrency=e.priceCurrency),e.availability){const m=V(e.availability);m&&(t.availability=m)}return e.url&&(t.url=e.url),e.seller&&(t.seller={"@type":"Organization",...e.seller.name&&{name:e.seller.name},...e.seller.url&&{url:e.seller.url}}),e.priceValidUntil&&(t.priceValidUntil=e.priceValidUntil),e.itemCondition&&(t.itemCondition=e.itemCondition),t}).filter(e=>e&&!("__invalidCurrency"in e));if(d.some(e=>e.priceCurrency&&!o(e.priceCurrency))&&!R){const e=d.find(t=>t.priceCurrency&&!o(t.priceCurrency));throw new Error(`Invalid currency code: ${e?.priceCurrency}`)}s.length===1?u.offers=s[0]:s.length>1&&(u.offers=s)}return u};0&&(module.exports={generateShoppingProductSnippetSchema});
|
|
@@ -41,5 +41,6 @@ interface VariantsOptions {
|
|
|
41
41
|
variants: VariantProduct[];
|
|
42
42
|
skipInvalidCurrency?: boolean;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
declare const generateShoppingVariantsSchema: ({ name, productGroupId, variants, skipInvalidCurrency, }: VariantsOptions) => any;
|
|
45
|
+
|
|
46
|
+
export { generateShoppingVariantsSchema };
|
|
@@ -1,143 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Generate schema.org `ProductGroup` (variants) and its `Product` variants
|
|
4
|
-
* JSON-LD.
|
|
5
|
-
*
|
|
6
|
-
* Accepts a parent group name and a list of variant `Product` entries with
|
|
7
|
-
* optional offers. Images and brand references are normalized into the
|
|
8
|
-
* appropriate schema.org objects.
|
|
9
|
-
*
|
|
10
|
-
* See `VariantsOptions` and `VariantProduct` for accepted fields.
|
|
11
|
-
* @returns A JSON-LD compatible `ProductGroup` 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.generateShoppingVariantsSchema = 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 formatBrand = function (b) {
|
|
34
|
-
if (!b)
|
|
35
|
-
return undefined;
|
|
36
|
-
if (typeof b === 'string')
|
|
37
|
-
return { '@type': 'Brand', name: b };
|
|
38
|
-
return __assign({ '@type': 'Brand', name: b.name }, (b.url && { url: b.url }));
|
|
39
|
-
};
|
|
40
|
-
var isValidCurrency = function (code) {
|
|
41
|
-
if (!code)
|
|
42
|
-
return false;
|
|
43
|
-
return /^[A-Z]{3}$/.test(code);
|
|
44
|
-
};
|
|
45
|
-
var AVAILABILITIES = [
|
|
46
|
-
'InStock',
|
|
47
|
-
'OutOfStock',
|
|
48
|
-
'PreOrder',
|
|
49
|
-
'PreSale',
|
|
50
|
-
'Discontinued',
|
|
51
|
-
'OnlineOnly',
|
|
52
|
-
'InStoreOnly',
|
|
53
|
-
'LimitedAvailability',
|
|
54
|
-
'BackOrder',
|
|
55
|
-
];
|
|
56
|
-
var normalizeAvailability = function (val) {
|
|
57
|
-
if (!val)
|
|
58
|
-
return undefined;
|
|
59
|
-
try {
|
|
60
|
-
var asUrl = String(val);
|
|
61
|
-
if (asUrl.startsWith('http')) {
|
|
62
|
-
var token = asUrl.replace(/https?:\/\/schema\.org\//i, '');
|
|
63
|
-
if (AVAILABILITIES.includes(token))
|
|
64
|
-
return "https://schema.org/".concat(token);
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
if (AVAILABILITIES.includes(asUrl))
|
|
68
|
-
return "https://schema.org/".concat(asUrl);
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
catch (_a) {
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var generateShoppingVariantsSchema = function (_a) {
|
|
76
|
-
var name = _a.name, productGroupId = _a.productGroupId, variants = _a.variants, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
77
|
-
var mappedVariants = variants.map(function (v) {
|
|
78
|
-
var product = {
|
|
79
|
-
'@type': 'Product',
|
|
80
|
-
name: v.name,
|
|
81
|
-
};
|
|
82
|
-
if (v.id)
|
|
83
|
-
product['@id'] = v.id;
|
|
84
|
-
if (v.url)
|
|
85
|
-
product.url = v.url;
|
|
86
|
-
if (v.sku)
|
|
87
|
-
product.sku = v.sku;
|
|
88
|
-
if (v.description)
|
|
89
|
-
product.description = v.description;
|
|
90
|
-
var img = formatImage(v.image);
|
|
91
|
-
if (img)
|
|
92
|
-
product.image = img;
|
|
93
|
-
var b = formatBrand(v.brand);
|
|
94
|
-
if (b)
|
|
95
|
-
product.brand = b;
|
|
96
|
-
if (v.offers) {
|
|
97
|
-
var offs = Array.isArray(v.offers) ? v.offers : [v.offers];
|
|
98
|
-
var mapped = offs
|
|
99
|
-
.map(function (o) {
|
|
100
|
-
if (o.priceCurrency && !isValidCurrency(o.priceCurrency))
|
|
101
|
-
return { __invalidCurrency: o.priceCurrency };
|
|
102
|
-
var of = { '@type': 'Offer' };
|
|
103
|
-
if (o.price != null)
|
|
104
|
-
of.price = o.price;
|
|
105
|
-
if (o.priceCurrency)
|
|
106
|
-
of.priceCurrency = o.priceCurrency;
|
|
107
|
-
if (o.availability) {
|
|
108
|
-
var n = normalizeAvailability(o.availability);
|
|
109
|
-
if (n)
|
|
110
|
-
of.availability = n;
|
|
111
|
-
}
|
|
112
|
-
if (o.url)
|
|
113
|
-
of.url = o.url;
|
|
114
|
-
if (o.priceValidUntil)
|
|
115
|
-
of.priceValidUntil = o.priceValidUntil;
|
|
116
|
-
if (o.itemCondition)
|
|
117
|
-
of.itemCondition = o.itemCondition;
|
|
118
|
-
return of;
|
|
119
|
-
})
|
|
120
|
-
.filter(function (x) { return x && !('__invalidCurrency' in x); });
|
|
121
|
-
var hadInvalid = offs.some(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
122
|
-
if (hadInvalid && !skipInvalidCurrency) {
|
|
123
|
-
var bad = offs.find(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
124
|
-
throw new Error("Invalid currency code: ".concat(bad === null || bad === void 0 ? void 0 : bad.priceCurrency));
|
|
125
|
-
}
|
|
126
|
-
if (mapped.length === 1)
|
|
127
|
-
product.offers = mapped[0];
|
|
128
|
-
else if (mapped.length > 1)
|
|
129
|
-
product.offers = mapped;
|
|
130
|
-
}
|
|
131
|
-
return product;
|
|
132
|
-
});
|
|
133
|
-
var schema = {
|
|
134
|
-
'@context': 'https://schema.org',
|
|
135
|
-
'@type': 'ProductGroup',
|
|
136
|
-
name: name,
|
|
137
|
-
hasVariant: mappedVariants,
|
|
138
|
-
};
|
|
139
|
-
if (productGroupId)
|
|
140
|
-
schema['@id'] = productGroupId;
|
|
141
|
-
return schema;
|
|
142
|
-
};
|
|
143
|
-
exports.generateShoppingVariantsSchema = generateShoppingVariantsSchema;
|
|
1
|
+
var l=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var b=(r,n)=>{for(var a in n)l(r,a,{get:n[a],enumerable:!0})},V=(r,n,a,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of I(n))!O.call(r,c)&&c!==a&&l(r,c,{get:()=>n[c],enumerable:!(u=C(n,c))||u.enumerable});return r};var k=r=>V(l({},"__esModule",{value:!0}),r);var P={};b(P,{generateShoppingVariantsSchema:()=>w});module.exports=k(P);const A=r=>{if(r)return typeof r=="string"?r:{"@type":"ImageObject",url:r.url,...r.width&&{width:r.width},...r.height&&{height:r.height}}},B=r=>{if(r)return typeof r=="string"?{"@type":"Brand",name:r}:{"@type":"Brand",name:r.name,...r.url&&{url:r.url}}},o=r=>r?/^[A-Z]{3}$/.test(r):!1,m=["InStock","OutOfStock","PreOrder","PreSale","Discontinued","OnlineOnly","InStoreOnly","LimitedAvailability","BackOrder"],S=r=>{if(r)try{const n=String(r);if(n.startsWith("http")){const a=n.replace(/https?:\/\/schema\.org\//i,"");return m.includes(a)?`https://schema.org/${a}`:void 0}return m.includes(n)?`https://schema.org/${n}`:void 0}catch{return}},w=({name:r,productGroupId:n,variants:a,skipInvalidCurrency:u=!1})=>{const c=a.map(e=>{const s={"@type":"Product",name:e.name};e.id&&(s["@id"]=e.id),e.url&&(s.url=e.url),e.sku&&(s.sku=e.sku),e.description&&(s.description=e.description);const y=A(e.image);y&&(s.image=y);const g=B(e.brand);if(g&&(s.brand=g),e.offers){const d=Array.isArray(e.offers)?e.offers:[e.offers],f=d.map(i=>{if(i.priceCurrency&&!o(i.priceCurrency))return{__invalidCurrency:i.priceCurrency};const t={"@type":"Offer"};if(i.price!=null&&(t.price=i.price),i.priceCurrency&&(t.priceCurrency=i.priceCurrency),i.availability){const h=S(i.availability);h&&(t.availability=h)}return i.url&&(t.url=i.url),i.priceValidUntil&&(t.priceValidUntil=i.priceValidUntil),i.itemCondition&&(t.itemCondition=i.itemCondition),t}).filter(i=>i&&!("__invalidCurrency"in i));if(d.some(i=>i.priceCurrency&&!o(i.priceCurrency))&&!u){const i=d.find(t=>t.priceCurrency&&!o(t.priceCurrency));throw new Error(`Invalid currency code: ${i?.priceCurrency}`)}f.length===1?s.offers=f[0]:f.length>1&&(s.offers=f)}return s}),p={"@context":"https://schema.org","@type":"ProductGroup",name:r,hasVariant:c};return n&&(p["@id"]=n),p};0&&(module.exports={generateShoppingVariantsSchema});
|
|
@@ -57,5 +57,6 @@ interface SoftwareAppOptions {
|
|
|
57
57
|
reviews?: ReviewItem[];
|
|
58
58
|
aggregateRating?: AggregateRatingOptions;
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
declare const generateSoftwareAppSchema: ({ name, description, image, url, softwareVersion, operatingSystem, applicationCategory, downloadUrl, author, publisher, reviews, aggregateRating, }: SoftwareAppOptions) => any;
|
|
61
|
+
|
|
62
|
+
export { generateSoftwareAppSchema as default, generateSoftwareAppSchema };
|
|
@@ -1,143 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Generate schema.org `SoftwareApplication` JSON-LD, optionally including
|
|
4
|
-
* `Review` and `AggregateRating` data.
|
|
5
|
-
*
|
|
6
|
-
* Accepts application metadata (platforms, versions, downloads), images,
|
|
7
|
-
* author/publisher references, reviews and an aggregate rating. Only
|
|
8
|
-
* provided fields are emitted in the returned object.
|
|
9
|
-
*
|
|
10
|
-
* See `SoftwareAppOptions` below for the input shape.
|
|
11
|
-
* @returns A JSON-LD compatible `SoftwareApplication` 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.generateSoftwareAppSchema = 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.name)
|
|
62
|
-
out.name = r.name;
|
|
63
|
-
if (r.url)
|
|
64
|
-
out.url = r.url;
|
|
65
|
-
if (r.publisher)
|
|
66
|
-
out.publisher = formatOrganization(r.publisher);
|
|
67
|
-
if (r.reviewRating) {
|
|
68
|
-
out.reviewRating = __assign(__assign({ '@type': 'Rating', ratingValue: r.reviewRating.ratingValue }, (r.reviewRating.bestRating != null && {
|
|
69
|
-
bestRating: r.reviewRating.bestRating,
|
|
70
|
-
})), (r.reviewRating.worstRating != null && {
|
|
71
|
-
worstRating: r.reviewRating.worstRating,
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
return out;
|
|
75
|
-
};
|
|
76
|
-
var generateSoftwareAppSchema = function (_a) {
|
|
77
|
-
var name = _a.name, description = _a.description, image = _a.image, url = _a.url, softwareVersion = _a.softwareVersion, operatingSystem = _a.operatingSystem, applicationCategory = _a.applicationCategory, downloadUrl = _a.downloadUrl, author = _a.author, publisher = _a.publisher, reviews = _a.reviews, aggregateRating = _a.aggregateRating;
|
|
78
|
-
var schema = {
|
|
79
|
-
'@context': 'https://schema.org',
|
|
80
|
-
'@type': 'SoftwareApplication',
|
|
81
|
-
name: name,
|
|
82
|
-
};
|
|
83
|
-
if (description)
|
|
84
|
-
schema.description = description;
|
|
85
|
-
var img = formatImage(image);
|
|
86
|
-
if (img)
|
|
87
|
-
schema.image = img;
|
|
88
|
-
if (url)
|
|
89
|
-
schema.url = url;
|
|
90
|
-
if (softwareVersion)
|
|
91
|
-
schema.softwareVersion = softwareVersion;
|
|
92
|
-
if (operatingSystem)
|
|
93
|
-
schema.operatingSystem = Array.isArray(operatingSystem)
|
|
94
|
-
? operatingSystem.join(', ')
|
|
95
|
-
: operatingSystem;
|
|
96
|
-
if (applicationCategory)
|
|
97
|
-
schema.applicationCategory = Array.isArray(applicationCategory)
|
|
98
|
-
? applicationCategory.join(', ')
|
|
99
|
-
: applicationCategory;
|
|
100
|
-
if (downloadUrl)
|
|
101
|
-
schema.downloadUrl = downloadUrl;
|
|
102
|
-
var a = formatPerson(author);
|
|
103
|
-
if (a)
|
|
104
|
-
schema.author = a;
|
|
105
|
-
var p = formatOrganization(publisher);
|
|
106
|
-
if (p)
|
|
107
|
-
schema.publisher = p;
|
|
108
|
-
// Reviews
|
|
109
|
-
if (reviews && reviews.length > 0) {
|
|
110
|
-
var mapped = reviews.map(formatReview);
|
|
111
|
-
schema.review = mapped;
|
|
112
|
-
// compute aggregate rating if not explicitly provided
|
|
113
|
-
if (!aggregateRating) {
|
|
114
|
-
var ratings = reviews
|
|
115
|
-
.map(function (r) { return (r.reviewRating ? Number(r.reviewRating.ratingValue) : NaN); })
|
|
116
|
-
.filter(function (n) { return !Number.isNaN(n); });
|
|
117
|
-
if (ratings.length > 0) {
|
|
118
|
-
var sum = ratings.reduce(function (a, b) { return a + b; }, 0);
|
|
119
|
-
schema.aggregateRating = {
|
|
120
|
-
'@type': 'AggregateRating',
|
|
121
|
-
ratingValue: sum / ratings.length,
|
|
122
|
-
reviewCount: reviews.length,
|
|
123
|
-
ratingCount: ratings.length,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// explicit aggregateRating provided
|
|
129
|
-
if (aggregateRating) {
|
|
130
|
-
schema.aggregateRating = __assign(__assign(__assign(__assign({ '@type': 'AggregateRating', ratingValue: aggregateRating.ratingValue }, (aggregateRating.reviewCount != null && {
|
|
131
|
-
reviewCount: aggregateRating.reviewCount,
|
|
132
|
-
})), (aggregateRating.ratingCount != null && {
|
|
133
|
-
ratingCount: aggregateRating.ratingCount,
|
|
134
|
-
})), (aggregateRating.bestRating != null && {
|
|
135
|
-
bestRating: aggregateRating.bestRating,
|
|
136
|
-
})), (aggregateRating.worstRating != null && {
|
|
137
|
-
worstRating: aggregateRating.worstRating,
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
return schema;
|
|
141
|
-
};
|
|
142
|
-
exports.generateSoftwareAppSchema = generateSoftwareAppSchema;
|
|
143
|
-
exports.default = exports.generateSoftwareAppSchema;
|
|
1
|
+
var R=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var N=(t,n)=>{for(var a in n)R(t,a,{get:n[a],enumerable:!0})},B=(t,n,a,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of C(n))!V.call(t,r)&&r!==a&&R(t,r,{get:()=>n[r],enumerable:!(u=I(n,r))||u.enumerable});return t};var S=t=>B(R({},"__esModule",{value:!0}),t);var U={};N(U,{default:()=>z,generateSoftwareAppSchema:()=>d});module.exports=S(U);const j=t=>{if(t)return typeof t=="string"?t:{"@type":"ImageObject",url:t.url,...t.width&&{width:t.width},...t.height&&{height:t.height}}},b=t=>{if(!t)return;if(typeof t=="string")return{"@type":"Person",name:t};const n={"@type":"Person",name:t.name};return t.url&&(n.url=t.url),n},c=t=>{if(!t)return;if(typeof t=="string")return{"@type":"Organization",name:t};const n={"@type":"Organization",name:t.name};return t.url&&(n.url=t.url),n},x=t=>{const n={"@type":"Review"};return t.author&&(n.author=b(t.author)),t.datePublished&&(n.datePublished=t.datePublished),t.reviewBody&&(n.reviewBody=t.reviewBody),t.name&&(n.name=t.name),t.url&&(n.url=t.url),t.publisher&&(n.publisher=c(t.publisher)),t.reviewRating&&(n.reviewRating={"@type":"Rating",ratingValue:t.reviewRating.ratingValue,...t.reviewRating.bestRating!=null&&{bestRating:t.reviewRating.bestRating},...t.reviewRating.worstRating!=null&&{worstRating:t.reviewRating.worstRating}}),n},d=({name:t,description:n,image:a,url:u,softwareVersion:r,operatingSystem:o,applicationCategory:f,downloadUrl:m,author:y,publisher:v,reviews:g,aggregateRating:i})=>{const e={"@context":"https://schema.org","@type":"SoftwareApplication",name:t};n&&(e.description=n);const w=j(a);w&&(e.image=w),u&&(e.url=u),r&&(e.softwareVersion=r),o&&(e.operatingSystem=Array.isArray(o)?o.join(", "):o),f&&(e.applicationCategory=Array.isArray(f)?f.join(", "):f),m&&(e.downloadUrl=m);const h=b(y);h&&(e.author=h);const p=c(v);if(p&&(e.publisher=p),g&&g.length>0){const A=g.map(x);if(e.review=A,!i){const l=g.map(s=>s.reviewRating?Number(s.reviewRating.ratingValue):NaN).filter(s=>!Number.isNaN(s));if(l.length>0){const s=l.reduce((O,P)=>O+P,0);e.aggregateRating={"@type":"AggregateRating",ratingValue:s/l.length,reviewCount:g.length,ratingCount:l.length}}}}return i&&(e.aggregateRating={"@type":"AggregateRating",ratingValue:i.ratingValue,...i.reviewCount!=null&&{reviewCount:i.reviewCount},...i.ratingCount!=null&&{ratingCount:i.ratingCount},...i.bestRating!=null&&{bestRating:i.bestRating},...i.worstRating!=null&&{worstRating:i.worstRating}}),e};var z=d;0&&(module.exports={generateSoftwareAppSchema});
|
|
@@ -59,5 +59,6 @@ interface SpeakableOptions {
|
|
|
59
59
|
aggregateRating?: AggregateRatingOptions;
|
|
60
60
|
keywords?: string[];
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
declare const generateSpeakableSchema: ({ type, headline, name, description, url, author, publisher, speakable, reviews, aggregateRating, keywords, }: SpeakableOptions) => any;
|
|
63
|
+
|
|
64
|
+
export { generateSpeakableSchema as default, generateSpeakableSchema };
|
|
@@ -1,139 +1 @@
|
|
|
1
|
-
"
|
|
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;
|
|
1
|
+
var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var a in t)f(e,a,{get:t[a],enumerable:!0})},A=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of k(t))!C.call(e,r)&&r!==a&&f(e,r,{get:()=>t[r],enumerable:!(s=S(t,r))||s.enumerable});return e};var I=e=>A(f({},"__esModule",{value:!0}),e);var W={};x(W,{default:()=>B,generateSpeakableSchema:()=>p});module.exports=I(W);const R=e=>{if(!e)return;if(typeof e=="string")return{"@type":"Person",name:e};const t={"@type":"Person",name:e.name};return e.url&&(t.url=e.url),t},V=e=>{if(!e)return;const t={"@type":"Organization",name:e.name};return e.url&&(t.url=e.url),e.logo&&(t.logo={"@type":"ImageObject",url:e.logo.url,...e.logo.width&&{width:e.logo.width},...e.logo.height&&{height:e.logo.height}}),t},O=e=>{if(!e)return;const t={"@type":"SpeakableSpecification"};return Array.isArray(e)?(t.xpath=e,t):(e.xpath&&e.xpath.length>0&&(t.xpath=e.xpath),e.cssSelector&&e.cssSelector.length>0&&(t.cssSelector=e.cssSelector),t)},N=e=>{const t={"@type":"Review"};return e.author&&(t.author=R(e.author)),e.datePublished&&(t.datePublished=e.datePublished),e.reviewBody&&(t.reviewBody=e.reviewBody),e.reviewRating&&(t.reviewRating={"@type":"Rating",ratingValue:e.reviewRating.ratingValue,...e.reviewRating.bestRating!=null&&{bestRating:e.reviewRating.bestRating},...e.reviewRating.worstRating!=null&&{worstRating:e.reviewRating.worstRating}}),t},p=({type:e="Article",headline:t,name:a,description:s,url:r,author:m,publisher:w,speakable:y,reviews:u,aggregateRating:i,keywords:l})=>{const n={"@context":"https://schema.org","@type":e};e==="Article"&&t&&(n.headline=t),e==="WebPage"&&a&&(n.name=a),s&&(n.description=s),r&&(n.mainEntityOfPage={"@type":"WebPage","@id":r});const h=R(m);h&&(n.author=h);const b=V(w);b&&(n.publisher=b);const c=O(y);if(c&&(n.speakable=c),u&&u.length>0){const d=u.map(N);if(n.review=d,!i){const g=u.map(o=>o.reviewRating?Number(o.reviewRating.ratingValue):NaN).filter(o=>!Number.isNaN(o));if(g.length>0){const o=g.reduce((v,P)=>v+P,0);n.aggregateRating={"@type":"AggregateRating",ratingValue:o/g.length,reviewCount:u.length,ratingCount:g.length}}}}return i&&(n.aggregateRating={"@type":"AggregateRating",ratingValue:i.ratingValue,...i.reviewCount!=null&&{reviewCount:i.reviewCount},...i.ratingCount!=null&&{ratingCount:i.ratingCount},...i.bestRating!=null&&{bestRating:i.bestRating},...i.worstRating!=null&&{worstRating:i.worstRating}}),l&&l.length>0&&(n.keywords=l.join(", ")),n};var B=p;0&&(module.exports={generateSpeakableSchema});
|
|
@@ -55,5 +55,6 @@ interface SubscriptionOptions {
|
|
|
55
55
|
reviews?: ReviewItem[];
|
|
56
56
|
aggregateRating?: AggregateRatingOptions;
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
declare const generateSubscriptionSchema: ({ name, description, image, url, author, publisher, datePublished, dateModified, isAccessibleForFree, genre, keywords, reviews, aggregateRating, }: SubscriptionOptions) => any;
|
|
59
|
+
|
|
60
|
+
export { generateSubscriptionSchema as default, generateSubscriptionSchema };
|