@react-pakistan/util-functions 1.25.90 → 2.0.2
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 +21 -19
- package/{api/stellar-solutions → stellar-solution}/types/common.d.ts +4 -2
- package/stellar-solution/types/common.js +1 -0
- package/{api/stellar-solutions → stellar-solution}/types/erp.d.ts +36 -33
- package/stellar-solution/types/erp.js +1 -0
- package/stellar-solution/types/index.d.ts +3 -0
- package/stellar-solution/types/index.js +1 -0
- package/{api/stellar-solutions → stellar-solution}/types/pos.d.ts +27 -24
- package/stellar-solution/types/pos.js +1 -0
- 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.js +0 -22
- 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.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,153 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Generate a merchant product listing as schema.org structured data.
|
|
4
|
-
*
|
|
5
|
-
* Returns an `ItemList` where each `ListItem.item` is a `Product` with
|
|
6
|
-
* optional `Offer` entries. Supports brand, seller, images, and basic
|
|
7
|
-
* offer normalization; pass `skipInvalidCurrency` to ignore currency
|
|
8
|
-
* validation for price fields.
|
|
9
|
-
*
|
|
10
|
-
* See `MerchantListingOptions` and `MerchantProduct` types for accepted
|
|
11
|
-
* fields.
|
|
12
|
-
* @returns A JSON-LD compatible `ItemList` of Products
|
|
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.generateShoppingMerchantListingSchema = void 0;
|
|
27
|
-
var formatImage = function (image) {
|
|
28
|
-
if (!image)
|
|
29
|
-
return undefined;
|
|
30
|
-
if (typeof image === 'string')
|
|
31
|
-
return image;
|
|
32
|
-
return __assign(__assign({ '@type': 'ImageObject', url: image.url }, (image.width && { width: image.width })), (image.height && { height: image.height }));
|
|
33
|
-
};
|
|
34
|
-
var formatBrand = function (b) {
|
|
35
|
-
if (!b)
|
|
36
|
-
return undefined;
|
|
37
|
-
if (typeof b === 'string')
|
|
38
|
-
return { '@type': 'Brand', name: b };
|
|
39
|
-
return __assign({ '@type': 'Brand', name: b.name }, (b.url && { url: b.url }));
|
|
40
|
-
};
|
|
41
|
-
var isValidCurrency = function (code) {
|
|
42
|
-
if (!code)
|
|
43
|
-
return false;
|
|
44
|
-
return /^[A-Z]{3}$/.test(code);
|
|
45
|
-
};
|
|
46
|
-
var AVAILABILITIES = [
|
|
47
|
-
'InStock',
|
|
48
|
-
'OutOfStock',
|
|
49
|
-
'PreOrder',
|
|
50
|
-
'PreSale',
|
|
51
|
-
'Discontinued',
|
|
52
|
-
'OnlineOnly',
|
|
53
|
-
'InStoreOnly',
|
|
54
|
-
'LimitedAvailability',
|
|
55
|
-
'BackOrder',
|
|
56
|
-
];
|
|
57
|
-
var normalizeAvailability = function (val) {
|
|
58
|
-
if (!val)
|
|
59
|
-
return undefined;
|
|
60
|
-
try {
|
|
61
|
-
var asUrl = String(val);
|
|
62
|
-
if (asUrl.startsWith('http')) {
|
|
63
|
-
var token = asUrl.replace(/https?:\/\/schema\.org\//i, '');
|
|
64
|
-
if (AVAILABILITIES.includes(token))
|
|
65
|
-
return "https://schema.org/".concat(token);
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
if (AVAILABILITIES.includes(asUrl))
|
|
69
|
-
return "https://schema.org/".concat(asUrl);
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
catch (_a) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var generateShoppingMerchantListingSchema = function (_a) {
|
|
77
|
-
var merchant = _a.merchant, name = _a.name, url = _a.url, products = _a.products, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
78
|
-
var itemList = products.map(function (p, i) {
|
|
79
|
-
var product = {
|
|
80
|
-
'@type': 'Product',
|
|
81
|
-
name: p.name,
|
|
82
|
-
};
|
|
83
|
-
if (p.id)
|
|
84
|
-
product['@id'] = p.id;
|
|
85
|
-
if (p.url)
|
|
86
|
-
product.url = p.url;
|
|
87
|
-
var img = formatImage(p.image);
|
|
88
|
-
if (img)
|
|
89
|
-
product.image = img;
|
|
90
|
-
if (p.description)
|
|
91
|
-
product.description = p.description;
|
|
92
|
-
var brand = formatBrand(p.brand);
|
|
93
|
-
if (brand)
|
|
94
|
-
product.brand = brand;
|
|
95
|
-
if (p.sku)
|
|
96
|
-
product.sku = p.sku;
|
|
97
|
-
if (p.offers) {
|
|
98
|
-
var offs = Array.isArray(p.offers) ? p.offers : [p.offers];
|
|
99
|
-
var mapped = offs
|
|
100
|
-
.map(function (o) {
|
|
101
|
-
if (o.priceCurrency && !isValidCurrency(o.priceCurrency))
|
|
102
|
-
return { __invalidCurrency: o.priceCurrency };
|
|
103
|
-
var of = { '@type': 'Offer' };
|
|
104
|
-
if (o.price != null)
|
|
105
|
-
of.price = o.price;
|
|
106
|
-
if (o.priceCurrency)
|
|
107
|
-
of.priceCurrency = o.priceCurrency;
|
|
108
|
-
if (o.availability) {
|
|
109
|
-
var n = normalizeAvailability(o.availability);
|
|
110
|
-
if (n)
|
|
111
|
-
of.availability = n;
|
|
112
|
-
}
|
|
113
|
-
if (o.url)
|
|
114
|
-
of.url = o.url;
|
|
115
|
-
if (o.seller)
|
|
116
|
-
of.seller = __assign(__assign({ '@type': 'Organization' }, (o.seller.name && { name: o.seller.name })), (o.seller.url && { url: o.seller.url }));
|
|
117
|
-
if (o.priceValidUntil)
|
|
118
|
-
of.priceValidUntil = o.priceValidUntil;
|
|
119
|
-
if (o.itemCondition)
|
|
120
|
-
of.itemCondition = o.itemCondition;
|
|
121
|
-
return of;
|
|
122
|
-
})
|
|
123
|
-
.filter(function (x) { return x && !('__invalidCurrency' in x); });
|
|
124
|
-
var hadInvalid = offs.some(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
125
|
-
if (hadInvalid && !skipInvalidCurrency) {
|
|
126
|
-
var bad = offs.find(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
127
|
-
throw new Error("Invalid currency code: ".concat(bad === null || bad === void 0 ? void 0 : bad.priceCurrency));
|
|
128
|
-
}
|
|
129
|
-
if (mapped.length === 1)
|
|
130
|
-
product.offers = mapped[0];
|
|
131
|
-
else if (mapped.length > 1)
|
|
132
|
-
product.offers = mapped;
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
'@type': 'ListItem',
|
|
136
|
-
position: i + 1,
|
|
137
|
-
item: product,
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
var schema = {
|
|
141
|
-
'@context': 'https://schema.org',
|
|
142
|
-
'@type': 'ItemList',
|
|
143
|
-
itemListElement: itemList,
|
|
144
|
-
};
|
|
145
|
-
if (name)
|
|
146
|
-
schema.name = name;
|
|
147
|
-
if (url)
|
|
148
|
-
schema.mainEntityOfPage = { '@type': 'WebPage', '@id': url };
|
|
149
|
-
if (merchant)
|
|
150
|
-
schema.provider = __assign({ '@type': 'Organization', name: merchant.name }, (merchant.url && { url: merchant.url }));
|
|
151
|
-
return schema;
|
|
152
|
-
};
|
|
153
|
-
exports.generateShoppingMerchantListingSchema = generateShoppingMerchantListingSchema;
|
|
1
|
+
var o=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(r,i)=>{for(var s in i)o(r,s,{get:i[s],enumerable:!0})},L=(r,i,s,f)=>{if(i&&typeof i=="object"||typeof i=="function")for(let c of O(i))!b.call(r,c)&&c!==s&&o(r,c,{get:()=>i[c],enumerable:!(f=I(i,c))||f.enumerable});return r};var k=r=>L(o({},"__esModule",{value:!0}),r);var w={};v(w,{generateShoppingMerchantListingSchema:()=>S});module.exports=k(w);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}}},g=r=>r?/^[A-Z]{3}$/.test(r):!1,h=["InStock","OutOfStock","PreOrder","PreSale","Discontinued","OnlineOnly","InStoreOnly","LimitedAvailability","BackOrder"],M=r=>{if(r)try{const i=String(r);if(i.startsWith("http")){const s=i.replace(/https?:\/\/schema\.org\//i,"");return h.includes(s)?`https://schema.org/${s}`:void 0}return h.includes(i)?`https://schema.org/${i}`:void 0}catch{return}},S=({merchant:r,name:i,url:s,products:f,skipInvalidCurrency:c=!1})=>{const u={"@context":"https://schema.org","@type":"ItemList",itemListElement:f.map((n,C)=>{const a={"@type":"Product",name:n.name};n.id&&(a["@id"]=n.id),n.url&&(a.url=n.url);const m=A(n.image);m&&(a.image=m),n.description&&(a.description=n.description);const y=B(n.brand);if(y&&(a.brand=y),n.sku&&(a.sku=n.sku),n.offers){const d=Array.isArray(n.offers)?n.offers:[n.offers],l=d.map(e=>{if(e.priceCurrency&&!g(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 p=M(e.availability);p&&(t.availability=p)}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&&!g(e.priceCurrency))&&!c){const e=d.find(t=>t.priceCurrency&&!g(t.priceCurrency));throw new Error(`Invalid currency code: ${e?.priceCurrency}`)}l.length===1?a.offers=l[0]:l.length>1&&(a.offers=l)}return{"@type":"ListItem",position:C+1,item:a}})};return i&&(u.name=i),s&&(u.mainEntityOfPage={"@type":"WebPage","@id":s}),r&&(u.provider={"@type":"Organization",name:r.name,...r.url&&{url:r.url}}),u};0&&(module.exports={generateShoppingMerchantListingSchema});
|
|
@@ -27,5 +27,6 @@ interface ReturnPolicyOptions {
|
|
|
27
27
|
returnFees?: ReturnFees;
|
|
28
28
|
skipInvalidCurrency?: boolean;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
declare const generateShoppingReturnPolicySchema: ({ name, description, merchant, returnPolicyCategory, returnMethods, inStoreReturns, returnFees, skipInvalidCurrency, }: ReturnPolicyOptions) => any;
|
|
31
|
+
|
|
32
|
+
export { generateShoppingReturnPolicySchema };
|
|
@@ -1,68 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Generate schema.org structured data for a merchant return policy
|
|
4
|
-
* (`MerchantReturnPolicy`).
|
|
5
|
-
*
|
|
6
|
-
* The utility supports normalizing the `returnPolicyCategory` token or
|
|
7
|
-
* URL and optionally validates currency codes for `returnFees`. Set
|
|
8
|
-
* `skipInvalidCurrency` to true to ignore currency validation.
|
|
9
|
-
*
|
|
10
|
-
* See `ReturnPolicyOptions` for available fields.
|
|
11
|
-
* @returns A JSON-LD compatible `MerchantReturnPolicy` 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.generateShoppingReturnPolicySchema = void 0;
|
|
26
|
-
var isValidCurrency = function (code) {
|
|
27
|
-
if (!code)
|
|
28
|
-
return false;
|
|
29
|
-
return /^[A-Z]{3}$/.test(code);
|
|
30
|
-
};
|
|
31
|
-
var normalizePolicyCategory = function (val) {
|
|
32
|
-
if (!val)
|
|
33
|
-
return undefined;
|
|
34
|
-
var s = String(val);
|
|
35
|
-
if (s.startsWith('http'))
|
|
36
|
-
return s;
|
|
37
|
-
return "https://schema.org/".concat(s);
|
|
38
|
-
};
|
|
39
|
-
var generateShoppingReturnPolicySchema = function (_a) {
|
|
40
|
-
var name = _a.name, description = _a.description, merchant = _a.merchant, returnPolicyCategory = _a.returnPolicyCategory, returnMethods = _a.returnMethods, inStoreReturns = _a.inStoreReturns, returnFees = _a.returnFees, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
41
|
-
var schema = {
|
|
42
|
-
'@context': 'https://schema.org',
|
|
43
|
-
'@type': 'MerchantReturnPolicy',
|
|
44
|
-
name: name,
|
|
45
|
-
};
|
|
46
|
-
if (description)
|
|
47
|
-
schema.description = description;
|
|
48
|
-
if (merchant)
|
|
49
|
-
schema.merchant = __assign({ '@type': 'Organization', name: merchant.name }, (merchant.url && { url: merchant.url }));
|
|
50
|
-
var cat = normalizePolicyCategory(returnPolicyCategory);
|
|
51
|
-
if (cat)
|
|
52
|
-
schema.returnPolicyCategory = cat;
|
|
53
|
-
if (returnMethods && returnMethods.length > 0)
|
|
54
|
-
schema.returnMethods = returnMethods;
|
|
55
|
-
if (typeof inStoreReturns === 'boolean')
|
|
56
|
-
schema.inStoreReturns = inStoreReturns;
|
|
57
|
-
if (returnFees) {
|
|
58
|
-
if (returnFees.currency && !isValidCurrency(returnFees.currency)) {
|
|
59
|
-
if (!skipInvalidCurrency)
|
|
60
|
-
throw new Error("Invalid currency code: ".concat(returnFees.currency));
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
schema.returnShippingFees = __assign({ '@type': 'MonetaryAmount', value: returnFees.amount }, (returnFees.currency && { currency: returnFees.currency }));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return schema;
|
|
67
|
-
};
|
|
68
|
-
exports.generateShoppingReturnPolicySchema = generateShoppingReturnPolicySchema;
|
|
1
|
+
var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var p=(r,n)=>{for(var t in n)a(r,t,{get:n[t],enumerable:!0})},h=(r,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of g(n))!f.call(r,e)&&e!==t&&a(r,e,{get:()=>n[e],enumerable:!(o=l(n,e))||o.enumerable});return r};var m=r=>h(a({},"__esModule",{value:!0}),r);var C={};p(C,{generateShoppingReturnPolicySchema:()=>d});module.exports=m(C);const R=r=>r?/^[A-Z]{3}$/.test(r):!1,P=r=>{if(!r)return;const n=String(r);return n.startsWith("http")?n:`https://schema.org/${n}`},d=({name:r,description:n,merchant:t,returnPolicyCategory:o,returnMethods:e,inStoreReturns:s,returnFees:i,skipInvalidCurrency:y=!1})=>{const c={"@context":"https://schema.org","@type":"MerchantReturnPolicy",name:r};n&&(c.description=n),t&&(c.merchant={"@type":"Organization",name:t.name,...t.url&&{url:t.url}});const u=P(o);if(u&&(c.returnPolicyCategory=u),e&&e.length>0&&(c.returnMethods=e),typeof s=="boolean"&&(c.inStoreReturns=s),i)if(i.currency&&!R(i.currency)){if(!y)throw new Error(`Invalid currency code: ${i.currency}`)}else c.returnShippingFees={"@type":"MonetaryAmount",value:i.amount,...i.currency&&{currency:i.currency}};return c};0&&(module.exports={generateShoppingReturnPolicySchema});
|
|
@@ -31,5 +31,6 @@ interface ShippingPolicyOptions {
|
|
|
31
31
|
freeShippingThreshold?: number | string;
|
|
32
32
|
skipInvalidCurrency?: boolean;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
declare const generateShoppingShippingPolicySchema: ({ name, provider, description, shippingDestination, transitTimeMinDays, transitTimeMaxDays, shippingRate, shippingSettingsLink, freeShippingThreshold, skipInvalidCurrency, }: ShippingPolicyOptions) => any;
|
|
35
|
+
|
|
36
|
+
export { generateShoppingShippingPolicySchema };
|
|
@@ -1,74 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Generate schema.org JSON-LD for a merchant shipping policy or service
|
|
4
|
-
* (`ShippingService`).
|
|
5
|
-
*
|
|
6
|
-
* Supports provider information, shipping rates (with currency
|
|
7
|
-
* validation), transit time ranges, free shipping thresholds, and an
|
|
8
|
-
* optional `shippingSettingsLink`.
|
|
9
|
-
*
|
|
10
|
-
* See `ShippingPolicyOptions` for supported fields and the
|
|
11
|
-
* `skipInvalidCurrency` flag behaviour.
|
|
12
|
-
* @returns A JSON-LD compatible `ShippingService` object
|
|
13
|
-
*/
|
|
14
|
-
var __assign = (this && this.__assign) || function () {
|
|
15
|
-
__assign = Object.assign || function(t) {
|
|
16
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
17
|
-
s = arguments[i];
|
|
18
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
19
|
-
t[p] = s[p];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
return __assign.apply(this, arguments);
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.generateShoppingShippingPolicySchema = void 0;
|
|
27
|
-
var isValidCurrency = function (code) {
|
|
28
|
-
if (!code)
|
|
29
|
-
return false;
|
|
30
|
-
return /^[A-Z]{3}$/.test(code);
|
|
31
|
-
};
|
|
32
|
-
var normalizeDestination = function (val) {
|
|
33
|
-
if (!val)
|
|
34
|
-
return undefined;
|
|
35
|
-
var s = String(val);
|
|
36
|
-
if (s.startsWith('http'))
|
|
37
|
-
return s;
|
|
38
|
-
return s;
|
|
39
|
-
};
|
|
40
|
-
var generateShoppingShippingPolicySchema = function (_a) {
|
|
41
|
-
var name = _a.name, provider = _a.provider, description = _a.description, shippingDestination = _a.shippingDestination, transitTimeMinDays = _a.transitTimeMinDays, transitTimeMaxDays = _a.transitTimeMaxDays, shippingRate = _a.shippingRate, shippingSettingsLink = _a.shippingSettingsLink, freeShippingThreshold = _a.freeShippingThreshold, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
42
|
-
var schema = {
|
|
43
|
-
'@context': 'https://schema.org',
|
|
44
|
-
'@type': 'ShippingService',
|
|
45
|
-
name: name,
|
|
46
|
-
};
|
|
47
|
-
if (provider)
|
|
48
|
-
schema.provider = __assign({ '@type': 'Organization', name: provider.name }, (provider.url && { url: provider.url }));
|
|
49
|
-
if (description)
|
|
50
|
-
schema.description = description;
|
|
51
|
-
var dest = normalizeDestination(shippingDestination);
|
|
52
|
-
if (dest)
|
|
53
|
-
schema.shippingDestination = dest;
|
|
54
|
-
if (transitTimeMinDays != null || transitTimeMaxDays != null) {
|
|
55
|
-
schema.shippingDeliveryTime = __assign(__assign(__assign({ '@type': 'ShippingDeliveryTime' }, (transitTimeMinDays != null && {
|
|
56
|
-
transitTimeLabel: "".concat(transitTimeMinDays),
|
|
57
|
-
})), (transitTimeMinDays != null && { transitTimeMin: transitTimeMinDays })), (transitTimeMaxDays != null && { transitTimeMax: transitTimeMaxDays }));
|
|
58
|
-
}
|
|
59
|
-
if (shippingRate) {
|
|
60
|
-
if (shippingRate.currency && !isValidCurrency(shippingRate.currency)) {
|
|
61
|
-
if (!skipInvalidCurrency)
|
|
62
|
-
throw new Error("Invalid currency code: ".concat(shippingRate.currency));
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
schema.shippingRate = __assign(__assign({ '@type': 'MonetaryAmount', value: shippingRate.price }, (shippingRate.currency && { currency: shippingRate.currency })), (shippingRate.shippingLabel && { name: shippingRate.shippingLabel }));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (shippingSettingsLink)
|
|
69
|
-
schema.shippingSettingsLink = shippingSettingsLink;
|
|
70
|
-
if (freeShippingThreshold != null)
|
|
71
|
-
schema.freeShippingThreshold = freeShippingThreshold;
|
|
72
|
-
return schema;
|
|
73
|
-
};
|
|
74
|
-
exports.generateShoppingShippingPolicySchema = generateShoppingShippingPolicySchema;
|
|
1
|
+
var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var m=(e,n)=>{for(var c in n)u(e,c,{get:n[c],enumerable:!0})},S=(e,n,c,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of h(n))!y.call(e,i)&&i!==c&&u(e,i,{get:()=>n[i],enumerable:!(s=f(n,i))||s.enumerable});return e};var b=e=>S(u({},"__esModule",{value:!0}),e);var O={};m(O,{generateShoppingShippingPolicySchema:()=>v});module.exports=b(O);const d=e=>e?/^[A-Z]{3}$/.test(e):!1,L=e=>{if(!e)return;const n=String(e);return n.startsWith("http"),n},v=({name:e,provider:n,description:c,shippingDestination:s,transitTimeMinDays:i,transitTimeMaxDays:l,shippingRate:r,shippingSettingsLink:p,freeShippingThreshold:g,skipInvalidCurrency:a=!1})=>{const t={"@context":"https://schema.org","@type":"ShippingService",name:e};n&&(t.provider={"@type":"Organization",name:n.name,...n.url&&{url:n.url}}),c&&(t.description=c);const o=L(s);if(o&&(t.shippingDestination=o),(i!=null||l!=null)&&(t.shippingDeliveryTime={"@type":"ShippingDeliveryTime",...i!=null&&{transitTimeLabel:`${i}`},...i!=null&&{transitTimeMin:i},...l!=null&&{transitTimeMax:l}}),r)if(r.currency&&!d(r.currency)){if(!a)throw new Error(`Invalid currency code: ${r.currency}`)}else t.shippingRate={"@type":"MonetaryAmount",value:r.price,...r.currency&&{currency:r.currency},...r.shippingLabel&&{name:r.shippingLabel}};return p&&(t.shippingSettingsLink=p),g!=null&&(t.freeShippingThreshold=g),t};0&&(module.exports={generateShoppingShippingPolicySchema});
|
|
@@ -47,5 +47,6 @@ interface ShoppingOverviewOptions {
|
|
|
47
47
|
products: ProductItem[];
|
|
48
48
|
skipInvalidCurrency?: boolean;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
declare const generateShoppingOverviewSchema: ({ name, url, products, skipInvalidCurrency, }: ShoppingOverviewOptions) => any;
|
|
51
|
+
|
|
52
|
+
export { generateShoppingOverviewSchema };
|
|
@@ -1,157 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* Generate schema.org `ItemList` JSON-LD for a shopping overview (Products).
|
|
4
|
-
*
|
|
5
|
-
* The function emits an `ItemList` where each `ListItem.item` is a
|
|
6
|
-
* `Product` object with optional `offers` and `aggregateRating`. Use
|
|
7
|
-
* `skipInvalidCurrency` to ignore invalid currency codes in offers.
|
|
8
|
-
*
|
|
9
|
-
* See `ShoppingOverviewOptions` and `ProductItem` for accepted fields.
|
|
10
|
-
* @returns A JSON-LD compatible `ItemList` of Product objects
|
|
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.generateShoppingOverviewSchema = 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 formatBrand = function (b) {
|
|
33
|
-
if (!b)
|
|
34
|
-
return undefined;
|
|
35
|
-
if (typeof b === 'string')
|
|
36
|
-
return { '@type': 'Brand', name: b };
|
|
37
|
-
return __assign({ '@type': 'Brand', name: b.name }, (b.url && { url: b.url }));
|
|
38
|
-
};
|
|
39
|
-
var isValidCurrency = function (code) {
|
|
40
|
-
if (!code)
|
|
41
|
-
return false;
|
|
42
|
-
return /^[A-Z]{3}$/.test(code);
|
|
43
|
-
};
|
|
44
|
-
var AVAILABILITIES = [
|
|
45
|
-
'InStock',
|
|
46
|
-
'OutOfStock',
|
|
47
|
-
'PreOrder',
|
|
48
|
-
'PreSale',
|
|
49
|
-
'Discontinued',
|
|
50
|
-
'OnlineOnly',
|
|
51
|
-
'InStoreOnly',
|
|
52
|
-
'LimitedAvailability',
|
|
53
|
-
'BackOrder',
|
|
54
|
-
];
|
|
55
|
-
var normalizeAvailability = function (val) {
|
|
56
|
-
if (!val)
|
|
57
|
-
return undefined;
|
|
58
|
-
try {
|
|
59
|
-
var asUrl = String(val);
|
|
60
|
-
if (asUrl.startsWith('http')) {
|
|
61
|
-
var token = asUrl.replace(/https?:\/\/schema\.org\//i, '');
|
|
62
|
-
if (AVAILABILITIES.includes(token))
|
|
63
|
-
return "https://schema.org/".concat(token);
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
if (AVAILABILITIES.includes(asUrl))
|
|
67
|
-
return "https://schema.org/".concat(asUrl);
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
catch (_a) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var generateShoppingOverviewSchema = function (_a) {
|
|
75
|
-
var name = _a.name, url = _a.url, products = _a.products, _b = _a.skipInvalidCurrency, skipInvalidCurrency = _b === void 0 ? false : _b;
|
|
76
|
-
var itemList = products.map(function (p, i) {
|
|
77
|
-
var _a;
|
|
78
|
-
var product = {
|
|
79
|
-
'@type': 'Product',
|
|
80
|
-
name: p.name,
|
|
81
|
-
};
|
|
82
|
-
if (p.id)
|
|
83
|
-
product['@id'] = p.id;
|
|
84
|
-
if (p.url)
|
|
85
|
-
product.url = p.url;
|
|
86
|
-
var img = formatImage(p.image);
|
|
87
|
-
if (img)
|
|
88
|
-
product.image = img;
|
|
89
|
-
if (p.description)
|
|
90
|
-
product.description = p.description;
|
|
91
|
-
var brand = formatBrand(p.brand);
|
|
92
|
-
if (brand)
|
|
93
|
-
product.brand = brand;
|
|
94
|
-
if (p.sku)
|
|
95
|
-
product.sku = p.sku;
|
|
96
|
-
if (p.category)
|
|
97
|
-
product.category = Array.isArray(p.category)
|
|
98
|
-
? p.category.join(', ')
|
|
99
|
-
: p.category;
|
|
100
|
-
if (p.aggregateRating) {
|
|
101
|
-
product.aggregateRating = __assign({ '@type': 'AggregateRating', ratingValue: p.aggregateRating.ratingValue }, (p.aggregateRating.reviewCount != null && {
|
|
102
|
-
reviewCount: p.aggregateRating.reviewCount,
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
if (p.priceRange) {
|
|
106
|
-
product.priceRange =
|
|
107
|
-
"".concat((_a = p.priceRange.low) !== null && _a !== void 0 ? _a : '').concat(p.priceRange.low != null && p.priceRange.high != null ? " - ".concat(p.priceRange.high) : '').trim();
|
|
108
|
-
}
|
|
109
|
-
if (p.offers) {
|
|
110
|
-
var offs = Array.isArray(p.offers) ? p.offers : [p.offers];
|
|
111
|
-
var mapped = offs
|
|
112
|
-
.map(function (o) {
|
|
113
|
-
if (o.priceCurrency && !isValidCurrency(o.priceCurrency))
|
|
114
|
-
return { __invalidCurrency: o.priceCurrency };
|
|
115
|
-
var of = { '@type': 'Offer' };
|
|
116
|
-
if (o.price != null)
|
|
117
|
-
of.price = o.price;
|
|
118
|
-
if (o.priceCurrency)
|
|
119
|
-
of.priceCurrency = o.priceCurrency;
|
|
120
|
-
if (o.availability) {
|
|
121
|
-
var n = normalizeAvailability(o.availability);
|
|
122
|
-
if (n)
|
|
123
|
-
of.availability = n;
|
|
124
|
-
}
|
|
125
|
-
if (o.url)
|
|
126
|
-
of.url = o.url;
|
|
127
|
-
return of;
|
|
128
|
-
})
|
|
129
|
-
.filter(function (x) { return x && !('__invalidCurrency' in x); });
|
|
130
|
-
var hadInvalid = offs.some(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
131
|
-
if (hadInvalid && !skipInvalidCurrency) {
|
|
132
|
-
var bad = offs.find(function (o) { return o.priceCurrency && !isValidCurrency(o.priceCurrency); });
|
|
133
|
-
throw new Error("Invalid currency code: ".concat(bad === null || bad === void 0 ? void 0 : bad.priceCurrency));
|
|
134
|
-
}
|
|
135
|
-
if (mapped.length === 1)
|
|
136
|
-
product.offers = mapped[0];
|
|
137
|
-
else if (mapped.length > 1)
|
|
138
|
-
product.offers = mapped;
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
'@type': 'ListItem',
|
|
142
|
-
position: i + 1,
|
|
143
|
-
item: product,
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
var schema = {
|
|
147
|
-
'@context': 'https://schema.org',
|
|
148
|
-
'@type': 'ItemList',
|
|
149
|
-
itemListElement: itemList,
|
|
150
|
-
};
|
|
151
|
-
if (name)
|
|
152
|
-
schema.name = name;
|
|
153
|
-
if (url)
|
|
154
|
-
schema.mainEntityOfPage = { '@type': 'WebPage', '@id': url };
|
|
155
|
-
return schema;
|
|
156
|
-
};
|
|
157
|
-
exports.generateShoppingOverviewSchema = generateShoppingOverviewSchema;
|
|
1
|
+
var l=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var w=(r,n)=>{for(var a in n)l(r,a,{get:n[a],enumerable:!0})},R=(r,n,a,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of b(n))!O.call(r,s)&&s!==a&&l(r,s,{get:()=>n[s],enumerable:!(u=C(n,s))||u.enumerable});return r};var I=r=>R(l({},"__esModule",{value:!0}),r);var B={};w(B,{generateShoppingOverviewSchema:()=>k});module.exports=I(B);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}}},P=r=>{if(r)return typeof r=="string"?{"@type":"Brand",name:r}:{"@type":"Brand",name:r.name,...r.url&&{url:r.url}}},d=r=>r?/^[A-Z]{3}$/.test(r):!1,p=["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 p.includes(a)?`https://schema.org/${a}`:void 0}return p.includes(n)?`https://schema.org/${n}`:void 0}catch{return}},k=({name:r,url:n,products:a,skipInvalidCurrency:u=!1})=>{const f={"@context":"https://schema.org","@type":"ItemList",itemListElement:a.map((e,v)=>{const t={"@type":"Product",name:e.name};e.id&&(t["@id"]=e.id),e.url&&(t.url=e.url);const y=A(e.image);y&&(t.image=y),e.description&&(t.description=e.description);const h=P(e.brand);if(h&&(t.brand=h),e.sku&&(t.sku=e.sku),e.category&&(t.category=Array.isArray(e.category)?e.category.join(", "):e.category),e.aggregateRating&&(t.aggregateRating={"@type":"AggregateRating",ratingValue:e.aggregateRating.ratingValue,...e.aggregateRating.reviewCount!=null&&{reviewCount:e.aggregateRating.reviewCount}}),e.priceRange&&(t.priceRange=`${e.priceRange.low??""}${e.priceRange.low!=null&&e.priceRange.high!=null?` - ${e.priceRange.high}`:""}`.trim()),e.offers){const o=Array.isArray(e.offers)?e.offers:[e.offers],g=o.map(i=>{if(i.priceCurrency&&!d(i.priceCurrency))return{__invalidCurrency:i.priceCurrency};const c={"@type":"Offer"};if(i.price!=null&&(c.price=i.price),i.priceCurrency&&(c.priceCurrency=i.priceCurrency),i.availability){const m=S(i.availability);m&&(c.availability=m)}return i.url&&(c.url=i.url),c}).filter(i=>i&&!("__invalidCurrency"in i));if(o.some(i=>i.priceCurrency&&!d(i.priceCurrency))&&!u){const i=o.find(c=>c.priceCurrency&&!d(c.priceCurrency));throw new Error(`Invalid currency code: ${i?.priceCurrency}`)}g.length===1?t.offers=g[0]:g.length>1&&(t.offers=g)}return{"@type":"ListItem",position:v+1,item:t}})};return r&&(f.name=r),n&&(f.mainEntityOfPage={"@type":"WebPage","@id":n}),f};0&&(module.exports={generateShoppingOverviewSchema});
|
|
@@ -52,5 +52,6 @@ interface ProductSnippetOptions {
|
|
|
52
52
|
offers?: OfferItem | OfferItem[];
|
|
53
53
|
skipInvalidCurrency?: boolean;
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
declare const generateShoppingProductSnippetSchema: ({ name, description, image, sku, brand, reviews, offers, skipInvalidCurrency, }: ProductSnippetOptions) => any;
|
|
56
|
+
|
|
57
|
+
export { generateShoppingProductSnippetSchema };
|