@react-pakistan/util-functions 2.0.2 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants/api-methods.d.mts +13 -0
- package/constants/api-methods.mjs +1 -0
- package/constants/cache-time.d.mts +7 -0
- package/constants/cache-time.mjs +1 -0
- package/constants/countries-timezones.d.mts +8 -0
- package/constants/countries-timezones.mjs +1 -0
- package/constants/currencies.d.mts +14 -0
- package/constants/currencies.mjs +1 -0
- package/constants/dial-codes.d.mts +9 -0
- package/constants/dial-codes.mjs +1 -0
- package/constants/layout-direction.d.mts +6 -0
- package/constants/layout-direction.mjs +1 -0
- package/constants/react-pakistan-meta.d.mts +32 -0
- package/constants/react-pakistan-meta.mjs +1 -0
- package/constants/react-pakistan.d.mts +15 -0
- package/constants/react-pakistan.mjs +12 -0
- package/constants/select-value-delimiter.d.mts +12 -0
- package/constants/select-value-delimiter.mjs +1 -0
- package/constants/social-media-colors.d.mts +40 -0
- package/constants/social-media-colors.mjs +1 -0
- package/constants/social-media-sizes.d.mts +323 -0
- package/constants/social-media-sizes.mjs +1 -0
- package/constants/user-roles.d.mts +7 -0
- package/constants/user-roles.mjs +1 -0
- package/factory/generic-component-factory.d.mts +78 -0
- package/factory/generic-component-factory.mjs +1 -0
- package/factory/generic-module-factory.d.mts +80 -0
- package/factory/generic-module-factory.mjs +1 -0
- package/general/basic-get.d.mts +8 -0
- package/general/basic-get.mjs +1 -0
- package/general/basic-post.d.mts +8 -0
- package/general/basic-post.mjs +1 -0
- package/general/calculate-pages.d.mts +9 -0
- package/general/calculate-pages.mjs +1 -0
- package/general/camel-to-sentence-case.d.mts +12 -0
- package/general/camel-to-sentence-case.mjs +1 -0
- package/general/check-even-odd-length.d.mts +13 -0
- package/general/check-even-odd-length.mjs +1 -0
- package/general/clear-cache.d.mts +10 -0
- package/general/clear-cache.mjs +1 -0
- package/general/cnic-formatter.d.mts +20 -0
- package/general/cnic-formatter.mjs +1 -0
- package/general/convert-url-to-base64.d.mts +57 -0
- package/general/convert-url-to-base64.mjs +1 -0
- package/general/countries.d.mts +268 -0
- package/general/countries.mjs +1 -0
- package/general/create-date.d.mts +12 -0
- package/general/create-date.js +1 -1
- package/general/create-date.mjs +1 -0
- package/general/crypto.d.mts +11 -0
- package/general/crypto.mjs +1 -0
- package/general/currencies.d.mts +2 -0
- package/general/currencies.mjs +0 -0
- package/general/delete-image-from-private-supabase.d.mts +16 -0
- package/general/delete-image-from-private-supabase.mjs +1 -0
- package/general/delete-image-from-public-supabase.d.mts +16 -0
- package/general/delete-image-from-public-supabase.mjs +1 -0
- package/general/download-from-url.d.mts +8 -0
- package/general/download-from-url.mjs +1 -0
- package/general/dynamic-page-limit.d.mts +12 -0
- package/general/dynamic-page-limit.mjs +1 -0
- package/general/enum-to-text.d.mts +8 -0
- package/general/enum-to-text.mjs +1 -0
- package/general/fetch-data.d.mts +25 -0
- package/general/fetch-data.mjs +1 -0
- package/general/fetch-supabase-image.d.mts +16 -0
- package/general/fetch-supabase-image.mjs +1 -0
- package/general/fetch-supabase-private-assets.d.mts +15 -0
- package/general/fetch-supabase-private-assets.mjs +1 -0
- package/general/format-date.d.mts +18 -0
- package/general/format-date.mjs +1 -0
- package/general/format-number.d.mts +16 -0
- package/general/format-number.mjs +1 -0
- package/general/format-phone-display.d.mts +9 -0
- package/general/format-phone-display.js +1 -1
- package/general/format-phone-display.mjs +1 -0
- package/general/format-phone.d.mts +13 -0
- package/general/format-phone.d.ts +1 -3
- package/general/format-phone.js +1 -1
- package/general/format-phone.mjs +1 -0
- package/general/format-pricing.d.mts +8 -0
- package/general/format-pricing.mjs +1 -0
- package/general/format-secs.d.mts +8 -0
- package/general/format-secs.mjs +1 -0
- package/general/format-time.d.mts +11 -0
- package/general/format-time.mjs +1 -0
- package/general/format-value.d.mts +8 -0
- package/general/format-value.mjs +1 -0
- package/general/full-month-range.d.mts +13 -0
- package/general/full-month-range.mjs +1 -0
- package/general/full-year-range.d.mts +12 -0
- package/general/full-year-range.mjs +1 -0
- package/general/generate-article-schema.d.mts +50 -0
- package/general/generate-article-schema.mjs +1 -0
- package/general/generate-blog-schema.d.mts +37 -0
- package/general/generate-blog-schema.mjs +1 -0
- package/general/generate-book-schema.d.mts +58 -0
- package/general/generate-book-schema.mjs +1 -0
- package/general/generate-breadcrumb-schema.d.mts +40 -0
- package/general/generate-breadcrumb-schema.mjs +1 -0
- package/general/generate-carousel-schema.d.mts +52 -0
- package/general/generate-carousel-schema.mjs +1 -0
- package/general/generate-course-schema.d.mts +53 -0
- package/general/generate-course-schema.mjs +1 -0
- package/general/generate-dataset-schema.d.mts +65 -0
- package/general/generate-dataset-schema.mjs +1 -0
- package/general/generate-discussion-forum-schema.d.mts +39 -0
- package/general/generate-discussion-forum-schema.mjs +1 -0
- package/general/generate-education-schema.d.mts +68 -0
- package/general/generate-education-schema.mjs +1 -0
- package/general/generate-employer-aggregate-rating-schema.d.mts +29 -0
- package/general/generate-employer-aggregate-rating-schema.mjs +1 -0
- package/general/generate-event-schema.d.mts +63 -0
- package/general/generate-event-schema.mjs +1 -0
- package/general/generate-faq-schema.d.mts +32 -0
- package/general/generate-faq-schema.mjs +1 -0
- package/general/generate-grid.d.mts +17 -0
- package/general/generate-grid.mjs +1 -0
- package/general/generate-image-metadata-schema.d.mts +36 -0
- package/general/generate-image-metadata-schema.mjs +1 -0
- package/general/generate-job-posting-schema.d.mts +49 -0
- package/general/generate-job-posting-schema.mjs +1 -0
- package/general/generate-local-business-schema.d.mts +42 -0
- package/general/generate-local-business-schema.mjs +1 -0
- package/general/generate-math-solver-schema.d.mts +45 -0
- package/general/generate-math-solver-schema.mjs +1 -0
- package/general/generate-movie-carousel-schema.d.mts +51 -0
- package/general/generate-movie-carousel-schema.mjs +1 -0
- package/general/generate-organization-schema.d.mts +49 -0
- package/general/generate-organization-schema.mjs +1 -0
- package/general/generate-profile-page-schema.d.mts +37 -0
- package/general/generate-profile-page-schema.mjs +1 -0
- package/general/generate-qa-page-schema.d.mts +34 -0
- package/general/generate-qa-page-schema.mjs +1 -0
- package/general/generate-recipe-schema.d.mts +49 -0
- package/general/generate-recipe-schema.mjs +1 -0
- package/general/generate-ref.d.mts +11 -0
- package/general/generate-ref.js +1 -1
- package/general/generate-ref.mjs +1 -0
- package/general/generate-review-snippet-schema.d.mts +52 -0
- package/general/generate-review-snippet-schema.mjs +1 -0
- package/general/generate-shopping-loyalty-program-schema.d.mts +38 -0
- package/general/generate-shopping-loyalty-program-schema.mjs +1 -0
- package/general/generate-shopping-merchant-listing-schema.d.mts +53 -0
- package/general/generate-shopping-merchant-listing-schema.mjs +1 -0
- package/general/generate-shopping-merchant-return-policy-schema.d.mts +32 -0
- package/general/generate-shopping-merchant-return-policy-schema.mjs +1 -0
- package/general/generate-shopping-merchant-shipping-policy-schema.d.mts +36 -0
- package/general/generate-shopping-merchant-shipping-policy-schema.mjs +1 -0
- package/general/generate-shopping-overview-schema.d.mts +52 -0
- package/general/generate-shopping-overview-schema.mjs +1 -0
- package/general/generate-shopping-product-snippet-schema.d.mts +57 -0
- package/general/generate-shopping-product-snippet-schema.mjs +1 -0
- package/general/generate-shopping-variants-schema.d.mts +46 -0
- package/general/generate-shopping-variants-schema.mjs +1 -0
- package/general/generate-software-app-schema.d.mts +62 -0
- package/general/generate-software-app-schema.mjs +1 -0
- package/general/generate-speakable-schema.d.mts +64 -0
- package/general/generate-speakable-schema.mjs +1 -0
- package/general/generate-subscription-schema.d.mts +60 -0
- package/general/generate-subscription-schema.mjs +1 -0
- package/general/generate-vacation-rental-schema.d.mts +67 -0
- package/general/generate-vacation-rental-schema.mjs +1 -0
- package/general/generate-video-schema.d.mts +75 -0
- package/general/generate-video-schema.mjs +1 -0
- package/general/generic-cache.d.mts +193 -0
- package/general/generic-cache.mjs +1 -0
- package/general/get-available-page-limit.d.mts +11 -0
- package/general/get-available-page-limit.mjs +1 -0
- package/general/get-calendar-current-month.d.mts +15 -0
- package/general/get-calendar-current-month.js +1 -1
- package/general/get-calendar-current-month.mjs +1 -0
- package/general/get-calendar-dates.d.mts +15 -0
- package/general/get-calendar-dates.js +1 -1
- package/general/get-calendar-dates.mjs +1 -0
- package/general/get-calendar-next-month.d.mts +17 -0
- package/general/get-calendar-next-month.js +1 -1
- package/general/get-calendar-next-month.mjs +1 -0
- package/general/get-calendar-previous-month.d.mts +17 -0
- package/general/get-calendar-previous-month.js +1 -1
- package/general/get-calendar-previous-month.mjs +1 -0
- package/general/get-current-year.d.mts +7 -0
- package/general/get-current-year.mjs +1 -0
- package/general/get-day-name.d.mts +10 -0
- package/general/get-day-name.mjs +1 -0
- package/general/get-dial-code.d.mts +8 -0
- package/general/get-dial-code.mjs +1 -0
- package/general/get-full-name.d.mts +13 -0
- package/general/get-full-name.mjs +1 -0
- package/general/get-href.d.mts +11 -0
- package/general/get-href.mjs +1 -0
- package/general/get-month-name.d.mts +10 -0
- package/general/get-month-name.mjs +1 -0
- package/general/get-month-number.d.mts +15 -0
- package/general/get-month-number.mjs +1 -0
- package/general/get-number-of-days-in-month.d.mts +13 -0
- package/general/get-number-of-days-in-month.js +1 -1
- package/general/get-number-of-days-in-month.mjs +1 -0
- package/general/get-pathname.d.mts +11 -0
- package/general/get-pathname.mjs +1 -0
- package/general/get-week-day.d.mts +8 -0
- package/general/get-week-day.js +1 -1
- package/general/get-week-day.mjs +1 -0
- package/general/image-url-to-base64.d.mts +9 -0
- package/general/image-url-to-base64.mjs +1 -0
- package/general/is-created-or-updated.d.mts +13 -0
- package/general/is-created-or-updated.mjs +1 -0
- package/general/is-next-button-disabled.d.mts +9 -0
- package/general/is-next-button-disabled.mjs +1 -0
- package/general/is-odd.d.mts +11 -0
- package/general/is-odd.mjs +1 -0
- package/general/is-previous-button-disabled.d.mts +8 -0
- package/general/is-previous-button-disabled.mjs +1 -0
- package/general/linear-gradients.d.mts +14 -0
- package/general/linear-gradients.mjs +1 -0
- package/general/multi-part-search.d.mts +22 -0
- package/general/multi-part-search.mjs +1 -0
- package/general/normalize-phone.d.mts +15 -0
- package/general/normalize-phone.js +1 -1
- package/general/normalize-phone.mjs +1 -0
- package/general/parse-frontmatter.d.mts +36 -0
- package/general/parse-frontmatter.mjs +2 -0
- package/general/remove-data-image-prefix.d.mts +8 -0
- package/general/remove-data-image-prefix.mjs +1 -0
- package/general/repeat-times.d.mts +15 -0
- package/general/repeat-times.mjs +1 -0
- package/general/resolve-anchor-link.d.mts +13 -0
- package/general/resolve-anchor-link.mjs +1 -0
- package/general/resolve-current-date.d.mts +12 -0
- package/general/resolve-current-date.mjs +1 -0
- package/general/resolve-grid.d.mts +14 -0
- package/general/resolve-grid.mjs +1 -0
- package/general/resolve-initials.d.mts +12 -0
- package/general/resolve-initials.mjs +1 -0
- package/general/set-timezone.d.mts +9 -0
- package/general/set-timezone.d.ts +1 -3
- package/general/set-timezone.js +1 -1
- package/general/set-timezone.mjs +1 -0
- package/general/slugify.d.mts +12 -0
- package/general/slugify.mjs +1 -0
- package/general/text-to-enum.d.mts +8 -0
- package/general/text-to-enum.mjs +1 -0
- package/general/text-to-sentence-case.d.mts +12 -0
- package/general/text-to-sentence-case.mjs +1 -0
- package/general/time-out.d.mts +12 -0
- package/general/time-out.mjs +1 -0
- package/general/time-zones.d.mts +11 -0
- package/general/time-zones.mjs +1 -0
- package/general/truncate-text.d.mts +14 -0
- package/general/truncate-text.mjs +1 -0
- package/general/type.d.mts +8 -0
- package/general/type.mjs +0 -0
- package/general/upload-blob-to-private-supabase.d.mts +24 -0
- package/general/upload-blob-to-private-supabase.mjs +1 -0
- package/general/upload-blob-to-public-supabase.d.mts +24 -0
- package/general/upload-blob-to-public-supabase.mjs +1 -0
- package/general/upload-image-to-private-supabase.d.mts +26 -0
- package/general/upload-image-to-private-supabase.mjs +1 -0
- package/general/upload-image-to-public-supabase.d.mts +26 -0
- package/general/upload-image-to-public-supabase.mjs +1 -0
- package/general/url-to-sentence-case.d.mts +12 -0
- package/general/url-to-sentence-case.mjs +1 -0
- package/general/validate-comment.d.mts +14 -0
- package/general/validate-comment.mjs +1 -0
- package/general/validate-email.d.mts +15 -0
- package/general/validate-email.mjs +1 -0
- package/general/validate-form.d.mts +18 -0
- package/general/validate-form.mjs +1 -0
- package/general/validate-name.d.mts +14 -0
- package/general/validate-name.mjs +1 -0
- package/hooks/use-change.d.mts +11 -0
- package/hooks/use-change.mjs +1 -0
- package/hooks/use-debounce.d.mts +10 -0
- package/hooks/use-debounce.mjs +1 -0
- package/hooks/use-fetch.d.mts +42 -0
- package/hooks/use-fetch.mjs +1 -0
- package/hooks/use-force-render.d.mts +14 -0
- package/hooks/use-force-render.mjs +1 -0
- package/hooks/use-ip-geo-location.d.mts +12 -0
- package/hooks/use-ip-geo-location.mjs +1 -0
- package/hooks/use-is-mobile.d.mts +8 -0
- package/hooks/use-is-mobile.mjs +1 -0
- package/hooks/use-module-entity-v2.d.mts +105 -0
- package/hooks/use-module-entity-v2.mjs +1 -0
- package/hooks/use-module-entity.d.mts +98 -0
- package/hooks/use-module-entity.mjs +1 -0
- package/hooks/use-phone-formatter.d.mts +17 -0
- package/hooks/use-phone-formatter.d.ts +1 -3
- package/hooks/use-phone-formatter.js +1 -1
- package/hooks/use-phone-formatter.mjs +1 -0
- package/hooks/use-position.d.mts +29 -0
- package/hooks/use-position.mjs +1 -0
- package/hooks/use-rtl.d.mts +46 -0
- package/hooks/use-rtl.mjs +1 -0
- package/hooks/use-sticky.d.mts +13 -0
- package/hooks/use-sticky.mjs +1 -0
- package/hooks/use-toggle-state.d.mts +14 -0
- package/hooks/use-toggle-state.mjs +1 -0
- package/hooks/use-window-event-listener.d.mts +9 -0
- package/hooks/use-window-event-listener.mjs +1 -0
- package/hooks/with-seo.d.mts +19 -0
- package/hooks/with-seo.mjs +1 -0
- package/local-storage/get-storage-value.d.mts +5 -0
- package/local-storage/get-storage-value.mjs +1 -0
- package/local-storage/remove-storage-value.d.mts +3 -0
- package/local-storage/remove-storage-value.mjs +1 -0
- package/local-storage/set-storage-value.d.mts +3 -0
- package/local-storage/set-storage-value.mjs +1 -0
- package/local-storage/type.d.mts +3 -0
- package/local-storage/type.mjs +0 -0
- package/npm.d.d.mts +2 -0
- package/npm.d.mjs +0 -0
- package/package.json +1 -10
- package/edu-pilot-pro/types/academics.d.ts +0 -2
- package/edu-pilot-pro/types/academics.js +0 -1
- package/edu-pilot-pro/types/admission.d.ts +0 -878
- package/edu-pilot-pro/types/admission.js +0 -1
- package/edu-pilot-pro/types/communication.d.ts +0 -2
- package/edu-pilot-pro/types/communication.js +0 -1
- package/edu-pilot-pro/types/enums.d.ts +0 -413
- package/edu-pilot-pro/types/enums.js +0 -1
- package/edu-pilot-pro/types/finance.d.ts +0 -2
- package/edu-pilot-pro/types/finance.js +0 -1
- package/edu-pilot-pro/types/index.d.ts +0 -2
- package/edu-pilot-pro/types/index.js +0 -1
- package/edu-pilot-pro/types/user-management.d.ts +0 -2
- package/edu-pilot-pro/types/user-management.js +0 -1
- package/stellar-solution/types/common.d.ts +0 -26
- package/stellar-solution/types/common.js +0 -1
- package/stellar-solution/types/erp.d.ts +0 -305
- package/stellar-solution/types/erp.js +0 -1
- package/stellar-solution/types/index.d.ts +0 -3
- package/stellar-solution/types/index.js +0 -1
- package/stellar-solution/types/pos.d.ts +0 -179
- package/stellar-solution/types/pos.js +0 -1
- package/storybook/generate-sitemap.d.ts +0 -16
- package/storybook/generate-sitemap.js +0 -17
- package/storybook/preview.d.ts +0 -148
- package/storybook/preview.js +0 -1
- package/storybook/react-design-story-script.d.ts +0 -12
- package/storybook/react-design-story-script.js +0 -5
- package/storybook/react-emoji-collection.d.ts +0 -13
- package/storybook/react-emoji-collection.js +0 -11
- package/storybook/react-emoji-story-script.d.ts +0 -12
- package/storybook/react-emoji-story-script.js +0 -5
- package/storybook/react-emoji-story-template.d.ts +0 -14
- package/storybook/react-emoji-story-template.js +0 -46
- package/storybook/react-icon-collection.d.ts +0 -13
- package/storybook/react-icon-collection.js +0 -11
- package/storybook/react-icon-story-script.d.ts +0 -12
- package/storybook/react-icon-story-script.js +0 -5
- package/storybook/react-icon-story-template.d.ts +0 -13
- package/storybook/react-icon-story-template.js +0 -46
- package/storybook/react-logo-collection.d.ts +0 -13
- package/storybook/react-logo-collection.js +0 -11
- package/storybook/react-logo-story-script.d.ts +0 -12
- package/storybook/react-logo-story-script.js +0 -5
- package/storybook/react-logo-story-template.d.ts +0 -13
- package/storybook/react-logo-story-template.js +0 -46
- package/storybook/react-pakistan-theme.d.ts +0 -25
- package/storybook/react-pakistan-theme.js +0 -1
- package/storybook/responsive-args.d.ts +0 -22
- package/storybook/responsive-args.js +0 -1
- package/storybook/responsive-component.d.ts +0 -33
- package/storybook/responsive-component.js +0 -37
- package/storybook/responsive-screens.d.ts +0 -108
- package/storybook/responsive-screens.js +0 -1
- package/storybook/theme.d.ts +0 -96
- package/storybook/theme.js +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface UploadImageToPublicSupabaseArgs {
|
|
2
|
+
blob: string;
|
|
3
|
+
cacheControl?: string;
|
|
4
|
+
contentType: string;
|
|
5
|
+
fileRef: string;
|
|
6
|
+
supabase: any;
|
|
7
|
+
upsert: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface PublicReturn {
|
|
10
|
+
fullPath: string;
|
|
11
|
+
id: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Uploads a base64 image to the public Supabase storage bucket.
|
|
16
|
+
* @param params.blob - Base64 image string.
|
|
17
|
+
* @param params.cacheControl - Cache control header value.
|
|
18
|
+
* @param params.contentType - MIME type of the image.
|
|
19
|
+
* @param params.fileRef - File reference/path in storage.
|
|
20
|
+
* @param params.supabase - Supabase client instance.
|
|
21
|
+
* @param params.upsert - Whether to overwrite existing file.
|
|
22
|
+
* @returns The upload result data or error.
|
|
23
|
+
*/
|
|
24
|
+
declare const uploadImageToPublicSupabase: ({ blob, cacheControl, contentType, fileRef, supabase, upsert, }: UploadImageToPublicSupabaseArgs) => Promise<PublicReturn>;
|
|
25
|
+
|
|
26
|
+
export { type PublicReturn, type UploadImageToPublicSupabaseArgs, uploadImageToPublicSupabase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{removeDataImagePrefix as g}from"./remove-data-image-prefix";const l=async({blob:r,cacheControl:t,contentType:a,fileRef:o,supabase:s,upsert:n})=>{const i=g(r),u=Buffer.from(i,"base64"),{data:c,error:e}=await s.storage.from(process.env.NEXT_PUBLIC_SUPABASE_PUBLIC_BUCKET).upload(o,u,{cacheControl:t||process.env.NEXT_PUBLIC_SUPABASE_CACHE_CONTROL,contentType:a,upsert:n});return e||c};export{l as uploadImageToPublicSupabase};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util function to convert url into sentence case
|
|
3
|
+
*
|
|
4
|
+
* @param str - string provided to convert url into sentence case - taimoorKhan
|
|
5
|
+
* @returns string in sentence case - Taimoor Khan
|
|
6
|
+
* @author Taimoor Khan
|
|
7
|
+
* @remarks
|
|
8
|
+
*/
|
|
9
|
+
/** End file docs */
|
|
10
|
+
declare const urlToSentenceCase: (url: string) => string;
|
|
11
|
+
|
|
12
|
+
export { urlToSentenceCase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=n=>{const e=n?.split("/");return e[e.length-1]?.split("-")?.map(t=>t.charAt(0).toUpperCase()+t.slice(1))?.join(" ")};export{r as urlToSentenceCase};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util function to validate the length
|
|
3
|
+
* of the given comment string
|
|
4
|
+
* Acceptable range is from 200 - 1500 chars
|
|
5
|
+
*
|
|
6
|
+
* @param string - string to validate
|
|
7
|
+
* @returns boolean - true or false
|
|
8
|
+
* @author Taimoor Khan
|
|
9
|
+
* @remarks Taimoor Khan Resume 2 & Taimoor Khan Resume 4
|
|
10
|
+
*/
|
|
11
|
+
/** End file docs */
|
|
12
|
+
declare const validateComment: (comment: string) => boolean;
|
|
13
|
+
|
|
14
|
+
export { validateComment };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=e=>e.length>=200&&e.length<1500;export{t as validateComment};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util function to validate the length
|
|
3
|
+
* of the given name email string
|
|
4
|
+
* It should't be an empty string
|
|
5
|
+
* Also it passed the emailRegex
|
|
6
|
+
*
|
|
7
|
+
* @param string - string to validate
|
|
8
|
+
* @returns boolean - true or false
|
|
9
|
+
* @author Taimoor Khan
|
|
10
|
+
* @remarks Taimoor Khan Resume 2 & Taimoor Khan Resume 4
|
|
11
|
+
*/
|
|
12
|
+
/** End file docs */
|
|
13
|
+
declare const validateEmail: (email: string) => boolean;
|
|
14
|
+
|
|
15
|
+
export { validateEmail };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/gi,t=e=>!!e.match(a);export{t as validateEmail};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ZodObject, ZodDiscriminatedUnion } from 'zod';
|
|
2
|
+
|
|
3
|
+
interface Params {
|
|
4
|
+
errorCallback: (e: Record<string, string>) => void;
|
|
5
|
+
params: object;
|
|
6
|
+
schema: ZodObject | ZodDiscriminatedUnion;
|
|
7
|
+
successCallback: () => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Validates form data against a Zod schema and calls the appropriate callback.
|
|
11
|
+
* @param params.schema - The Zod schema to validate against.
|
|
12
|
+
* @param params.params - The form data object to validate.
|
|
13
|
+
* @param params.errorCallback - Callback with validation errors map.
|
|
14
|
+
* @param params.successCallback - Callback on successful validation.
|
|
15
|
+
*/
|
|
16
|
+
declare const validateForm: ({ errorCallback, params, schema, successCallback, }: Params) => void;
|
|
17
|
+
|
|
18
|
+
export { validateForm };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const l=({errorCallback:a,params:i,schema:e,successCallback:t})=>{const r=e?.safeParse({...i});if(r?.error){const o={};r?.error.issues.forEach(s=>{o[s.path.join("-")]=s.message}),a(o)}r?.success&&t()};export{l as validateForm};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util function to validate the length
|
|
3
|
+
* of the given name string
|
|
4
|
+
* Acceptable range is from 3 - 30 chars
|
|
5
|
+
*
|
|
6
|
+
* @param string - string to validate
|
|
7
|
+
* @returns boolean - true or false
|
|
8
|
+
* @author Taimoor Khan
|
|
9
|
+
* @remarks Taimoor Khan Resume 2 & Taimoor Khan Resume 4
|
|
10
|
+
*/
|
|
11
|
+
/** End file docs */
|
|
12
|
+
declare const validateName: (str: string) => boolean;
|
|
13
|
+
|
|
14
|
+
export { validateName };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=e=>e.length>=3&&e.length<30;export{t as validateName};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EffectCallback, DependencyList } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs a callback only when dependencies change, skipping the initial mount.
|
|
5
|
+
*
|
|
6
|
+
* @param callback - The effect callback to run on dependency changes.
|
|
7
|
+
* @param deps - The dependency list that triggers the callback.
|
|
8
|
+
*/
|
|
9
|
+
declare const useChange: (callback: EffectCallback, deps: DependencyList) => void;
|
|
10
|
+
|
|
11
|
+
export { useChange };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as n,useRef as f}from"react";const s=(t,c)=>{const e=f(!1);n(()=>{e.current&&t(),e.current=!0},[e,...c])};export{s as useChange};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounces a string value by the specified delay.
|
|
3
|
+
*
|
|
4
|
+
* @param value - The value to debounce.
|
|
5
|
+
* @param timeout - The debounce delay in milliseconds (default 500).
|
|
6
|
+
* @returns The debounced value after the delay has elapsed without change.
|
|
7
|
+
*/
|
|
8
|
+
declare const useDebounce: (value: string, timeout?: number) => string;
|
|
9
|
+
|
|
10
|
+
export { useDebounce };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as o,useEffect as c}from"react";const i=(t,e=500)=>{const[r,s]=o(t);return c(()=>{const n=setTimeout(()=>s(t),e);return()=>clearTimeout(n)},[t,e]),r};export{i as useDebounce};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface FetchResult {
|
|
2
|
+
data: any;
|
|
3
|
+
error: any;
|
|
4
|
+
status?: number;
|
|
5
|
+
ok?: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface FetchConfig extends Omit<RequestInit, 'credentials'> {
|
|
8
|
+
autoFetch?: boolean;
|
|
9
|
+
callback?: (result: FetchResult) => void;
|
|
10
|
+
/**
|
|
11
|
+
* If `true`, the fetch will be invoked with `credentials: 'include'`.
|
|
12
|
+
* String values from the standard `RequestCredentials` are also supported
|
|
13
|
+
* (e.g. 'omit' | 'same-origin' | 'include').
|
|
14
|
+
*/
|
|
15
|
+
credentials?: boolean | RequestCredentials;
|
|
16
|
+
/**
|
|
17
|
+
* Query parameters to append to GET requests.
|
|
18
|
+
* Supports strings, numbers, booleans, arrays, and objects.
|
|
19
|
+
* - Primitives (string, number, boolean) are converted to strings
|
|
20
|
+
* - Arrays are repeated as multiple params with the same key
|
|
21
|
+
* - Objects are JSON-stringified
|
|
22
|
+
* - null and undefined values are skipped
|
|
23
|
+
*
|
|
24
|
+
* Example: { active: true, page: 1, tags: ['a', 'b'] }
|
|
25
|
+
* Results in: ?active=true&page=1&tags=a&tags=b
|
|
26
|
+
*/
|
|
27
|
+
params?: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
interface Return {
|
|
30
|
+
apiResult: API_RESULT | undefined;
|
|
31
|
+
data: any;
|
|
32
|
+
error: any;
|
|
33
|
+
fetchNow: (url?: string, config?: FetchConfig) => void;
|
|
34
|
+
loading: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare enum API_RESULT {
|
|
37
|
+
SUCCESS = "SUCCESS",
|
|
38
|
+
ERROR = "ERROR"
|
|
39
|
+
}
|
|
40
|
+
declare const useFetch: (url: string, config?: FetchConfig, deps?: Array<string> | Array<any>) => Return;
|
|
41
|
+
|
|
42
|
+
export { API_RESULT, type FetchConfig, type FetchResult, type Return, useFetch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as h,useRef as C,useCallback as z,useEffect as I}from"react";var B=(c=>(c.SUCCESS="SUCCESS",c.ERROR="ERROR",c))(B||{});const Q=(O,T={},c=[])=>{const{callback:l,autoFetch:x=!1,...A}=T,[L,i]=h(null),[j,u]=h(null),[q,F]=h(!1),[D,y]=h(void 0),P=C(null),o=C(!0),U=C(!1);I(()=>(o.current=!0,()=>{o.current=!1,P.current?.abort()}),[]);const p=z(async(N,_)=>{let a=N||O;const{params:G,...R}=A||{},{params:$,...g}=_||{},S={...G||{},...$||{}},n={...R,...g,headers:{...R.headers||{},...g.headers||{}}},H=(n.method||"GET").toString().toUpperCase(),b=g.credentials,m=R.credentials;if(typeof b=="string"?n.credentials=b:b===!0?n.credentials="include":typeof m=="string"?n.credentials=m:m===!0&&(n.credentials="include"),H==="GET"&&S&&Object.keys(S).length){const e=a.indexOf("#"),t=e>=0?a.slice(e):"",r=e>=0?a.slice(0,e):a,f=r.indexOf("?"),J=f>=0?r.slice(0,f):r,M=f>=0?r.slice(f+1):"",d=new URLSearchParams(M);Object.entries(S).forEach(([E,s])=>{s!=null&&(Array.isArray(s)?s.forEach(v=>d.append(E,String(v))):typeof s=="object"?d.append(E,JSON.stringify(s)):d.append(E,String(s)))});const k=d.toString();a=J+(k?`?${k}`:"")+t}F(!0),u(null),i(null);const w=new AbortController;P.current=w,n.signal=w.signal;try{const e=await fetch(a,n);let t=null;try{t=await e.json()}catch{t=null}if(o.current)if(e.ok)i(t),u(null),y("SUCCESS"),l?.({data:t,error:null,status:e.status,ok:!0});else{const r=new Error(`HTTP error! status: ${e.status}`);u(r),i(t),y("ERROR"),l?.({data:t,error:r,status:e.status,ok:!1})}}catch(e){o.current&&(u(e),i(null),y("ERROR"),l?.({data:null,error:e,status:void 0,ok:!1}))}finally{o.current&&F(!1)}},[O,A,l,...c]);return I(()=>{x&&!U.current&&(U.current=!0,p())},[p,x]),{apiResult:D,data:L,error:j,fetchNow:p,loading:q}};export{B as API_RESULT,Q as useFetch};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DispatchWithoutAction } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A util hook to enable force renders.
|
|
5
|
+
*
|
|
6
|
+
* @returns dispatch without action
|
|
7
|
+
* @author Taimoor Khan
|
|
8
|
+
* @remarks
|
|
9
|
+
*/
|
|
10
|
+
/** End file docs */
|
|
11
|
+
|
|
12
|
+
declare const useForceRender: () => DispatchWithoutAction;
|
|
13
|
+
|
|
14
|
+
export { useForceRender };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useReducer as o}from"react";const i=()=>{const[,t]=o(e=>e+1,0);return t};export{i as useForceRender};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches the user's country based on their IP address via api.country.is.
|
|
3
|
+
*
|
|
4
|
+
* @returns An object with the detected country (or null), any error, and a loading flag.
|
|
5
|
+
*/
|
|
6
|
+
declare const useIPGeoLocation: () => {
|
|
7
|
+
country: string | null;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { useIPGeoLocation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as r,useEffect as a}from"react";const y=()=>{const[o,i]=r(null),[e,u]=r(null),[s,n]=r(!0),c="https://api.country.is";return a(()=>{if(o)return;async function l(){n(!0),await fetch(c).then(t=>{if(!t.ok)throw Error(t.statusText);return t.json()}).then(t=>{t&&t.country&&i(t.country)}).catch(t=>u(t)).finally(()=>n(!1))}l()},[o]),{country:o,error:e,isLoading:s}};export{y as useIPGeoLocation};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as i,useState as n}from"react";const r=()=>{const[s,o]=n(!1),e=()=>{window.innerWidth<767?o(!0):o(!1)};return i(()=>(window.addEventListener("resize",e),e(),()=>window.removeEventListener("resize",e)),[]),s};export{r as useIsMobile};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { FetchConfig } from './use-fetch.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* useModuleEntityV2
|
|
5
|
+
*
|
|
6
|
+
* Summary
|
|
7
|
+
* - A convenience hook that manages common module/entity operations: list, get-by-id,
|
|
8
|
+
* create/update, and delete. It composes `useFetch` for HTTP calls and `useDebounce`
|
|
9
|
+
* for debouncing search queries.
|
|
10
|
+
*
|
|
11
|
+
* Main features
|
|
12
|
+
* - List: performs a GET to `listUrl` with `listParams`. The hook listens to
|
|
13
|
+
* `searchQuery` (debounced) and `listDeps` to re-run the list fetch.
|
|
14
|
+
* - Get by ID: performs a GET to `unitByIdUrl` with `byIdParams` and returns
|
|
15
|
+
* `byIdFetchNow`, `byIdLoading`, and `byIdError`.
|
|
16
|
+
* - Create/Update: performs a PUT to `unitUrl` with a JSON body `updateParams`.
|
|
17
|
+
* On successful create/update the hook triggers a coalesced list refresh.
|
|
18
|
+
* - Delete: performs a DELETE to `unitUrl` with a JSON body `deleteParams` and
|
|
19
|
+
* triggers a coalesced list refresh when the operation succeeds.
|
|
20
|
+
* - Refresh batching: `refreshList(delay)` coalesces multiple rapid updates/deletes
|
|
21
|
+
* using a short timeout (default 300ms) to avoid unnecessary list reloads.
|
|
22
|
+
*
|
|
23
|
+
* Parameters (object)
|
|
24
|
+
* - `byIdCallback(data)`, `byIdDeps`, `byIdParams` — params for GET by ID request
|
|
25
|
+
* - `deleteCallback(data)`, `deleteDeps`, `deleteParams` — body for DELETE request
|
|
26
|
+
* - `listCallback(data)`, `listDeps`, `listParams`, `listUrl` — params for GET list
|
|
27
|
+
* - `searchQuery` (string) — debounced before influencing the list fetch
|
|
28
|
+
* - `unitByIdUrl`, `unitUrl`
|
|
29
|
+
* - `updateCallback(data)`, `updateDeps`, `updateParams` — body for PUT request
|
|
30
|
+
*
|
|
31
|
+
* Parameter types
|
|
32
|
+
* - `listParams` and `byIdParams` support all primitive types including booleans.
|
|
33
|
+
* They are appended as URL query parameters for GET requests.
|
|
34
|
+
* Example: { active: true, page: 1 } → ?active=true&page=1
|
|
35
|
+
* - `updateParams` and `deleteParams` are sent as JSON in request body.
|
|
36
|
+
*
|
|
37
|
+
* Return values
|
|
38
|
+
* - `byIdFetchNow(url?, config?)`, `byIdLoading`, `byIdError`
|
|
39
|
+
* - `listFetchNow(url?, config?)`, `listLoading`, `listError`
|
|
40
|
+
* - `updateFetchNow(url?, config?)`, `updateLoading`, `updateError`
|
|
41
|
+
* - `deleteFetchNow(url?, config?)`, `deleteLoading`, `deleteError`
|
|
42
|
+
*
|
|
43
|
+
* Behavior notes
|
|
44
|
+
* - All callbacks receive an object `{ data, error, status, ok }` from `useFetch`.
|
|
45
|
+
* - Callbacks are wrapped so that any errors they throw are swallowed; this
|
|
46
|
+
* ensures the hook's refresh logic still runs reliably.
|
|
47
|
+
* - `refreshList()` calls `listFetchNow(undefined, { method: 'POST', params: listParams })`
|
|
48
|
+
* to explicitly re-query the list endpoint with the current `listParams`.
|
|
49
|
+
* - Network calls are delegated to `useFetch`; callers can call the returned
|
|
50
|
+
* `*FetchNow` functions directly with an override URL or config.
|
|
51
|
+
*
|
|
52
|
+
* Example
|
|
53
|
+
* const { listFetchNow, updateFetchNow } = useModuleEntityV2({
|
|
54
|
+
* listUrl: '/items',
|
|
55
|
+
* listParams: { page: 1, active: true },
|
|
56
|
+
* listCallback: (res) => console.log(res),
|
|
57
|
+
* unitUrl: '/items',
|
|
58
|
+
* updateCallback: () => {},
|
|
59
|
+
* updateParams: {}
|
|
60
|
+
* });
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
interface CallbackParamsV2 {
|
|
64
|
+
data: any;
|
|
65
|
+
error: any;
|
|
66
|
+
status?: number;
|
|
67
|
+
ok?: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface Params {
|
|
70
|
+
byIdCallback: (d: CallbackParamsV2) => void;
|
|
71
|
+
byIdDeps?: Array<any> | Array<string>;
|
|
72
|
+
byIdParams: object;
|
|
73
|
+
deleteCallback?: (d: CallbackParamsV2) => void;
|
|
74
|
+
deleteDeps?: Array<any> | Array<string>;
|
|
75
|
+
deleteParams?: object;
|
|
76
|
+
listCallback: (d: CallbackParamsV2) => void;
|
|
77
|
+
listDeps?: Array<any> | Array<string>;
|
|
78
|
+
listParams: object;
|
|
79
|
+
listUrl: string;
|
|
80
|
+
/** Optional headers to include on every fetch made by this hook */
|
|
81
|
+
headers?: Record<string, string>;
|
|
82
|
+
searchQuery: string;
|
|
83
|
+
unitByIdUrl: string;
|
|
84
|
+
unitUrl: string;
|
|
85
|
+
updateCallback: (d: CallbackParamsV2) => void;
|
|
86
|
+
updateDeps?: Array<any> | Array<string>;
|
|
87
|
+
updateParams: object;
|
|
88
|
+
}
|
|
89
|
+
interface Return {
|
|
90
|
+
byIdError?: Error;
|
|
91
|
+
byIdFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
92
|
+
byIdLoading: boolean;
|
|
93
|
+
deleteError?: Error;
|
|
94
|
+
deleteFetchNow?: (url?: string, config?: FetchConfig) => void;
|
|
95
|
+
deleteLoading: boolean;
|
|
96
|
+
listError?: Error;
|
|
97
|
+
listFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
98
|
+
listLoading: boolean;
|
|
99
|
+
updateError?: Error;
|
|
100
|
+
updateFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
101
|
+
updateLoading: boolean;
|
|
102
|
+
}
|
|
103
|
+
declare const useModuleEntityV2: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, headers, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
|
|
104
|
+
|
|
105
|
+
export { type CallbackParamsV2, useModuleEntityV2 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useRef as G,useEffect as O}from"react";import{API_METHODS as o}from"../constants/api-methods";import{useFetch as a}from"./use-fetch";import{useDebounce as S}from"./use-debounce";const B=({byIdCallback:u,byIdDeps:g=[],byIdParams:b,deleteCallback:n,deleteDeps:y=[],deleteParams:f,listCallback:m,listDeps:h=[],listParams:i,listUrl:p,headers:t,searchQuery:E,unitByIdUrl:k,unitUrl:c,updateCallback:l,updateDeps:T=[],updateParams:C})=>{const F=S(E,800),e=G(null);O(()=>()=>{e.current&&(globalThis.clearTimeout(e.current),e.current=null)},[]);const{error:N,fetchNow:s,loading:P}=a(p,{method:o.GET,params:i,headers:t,callback:m,credentials:!0},[F,i,...h]),d=(r=300)=>{e.current&&globalThis.clearTimeout(e.current),e.current=globalThis.setTimeout(()=>{try{s(void 0,{method:o.GET,params:i,headers:t})}catch{}e.current=null},r)},{error:w,loading:I,fetchNow:L}=a(c,{method:o.PUT,body:JSON.stringify(C),headers:t,callback:r=>{if(l)try{l(r)}catch{}try{r&&r.ok&&d()}catch{}}},[...T]),{error:v,loading:A,fetchNow:V}=a(k,{method:o.GET,params:b,headers:t,callback:u},[...g]),{error:D,loading:R,fetchNow:j}=a(c,{method:o.DELETE,body:JSON.stringify(f),headers:t,callback:r=>{if(n)try{n(r)}catch{}try{r&&r.ok&&d()}catch{}}},[...y]);return{byIdError:v,byIdFetchNow:V,byIdLoading:A,deleteError:D,deleteFetchNow:j,deleteLoading:R,listError:N,listFetchNow:s,listLoading:P,updateError:w,updateFetchNow:L,updateLoading:I}};export{B as useModuleEntityV2};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { FetchConfig } from './use-fetch.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* useModuleEntity
|
|
5
|
+
*
|
|
6
|
+
* Summary
|
|
7
|
+
* - A convenience hook that manages common module/entity operations: list, get-by-id,
|
|
8
|
+
* create/update, and delete. It composes `useFetch` for HTTP calls and `useDebounce`
|
|
9
|
+
* for debouncing search queries.
|
|
10
|
+
*
|
|
11
|
+
* Main features
|
|
12
|
+
* - List: performs a POST to `listUrl` with a JSON body `listParams` and re-runs
|
|
13
|
+
* when `searchQuery` (debounced) or `listDeps` change.
|
|
14
|
+
* - Get by ID: performs a POST to `unitByIdUrl` with `byIdParams` in the JSON body
|
|
15
|
+
* and exposes `byIdFetchNow`, `byIdLoading`, and `byIdError`.
|
|
16
|
+
* - Create/Update: performs a POST to `unitUrl` with a JSON body `updateParams`.
|
|
17
|
+
* On successful create/update the hook triggers a coalesced list refresh.
|
|
18
|
+
* - Delete: performs a DELETE to `unitUrl` with a JSON body `deleteParams` and
|
|
19
|
+
* triggers a coalesced list refresh when the operation succeeds.
|
|
20
|
+
* - Refresh batching: `refreshList(delay)` coalesces multiple rapid updates/deletes
|
|
21
|
+
* using a short timeout (default 300ms) to avoid unnecessary list reloads.
|
|
22
|
+
*
|
|
23
|
+
* Parameters (object)
|
|
24
|
+
* - `byIdCallback(data)`, `byIdDeps`, `byIdParams`
|
|
25
|
+
* - `deleteCallback(data)`, `deleteDeps`, `deleteParams`
|
|
26
|
+
* - `listCallback(data)`, `listDeps`, `listParams`, `listUrl`
|
|
27
|
+
* - `searchQuery` (string) — debounced before influencing the list fetch
|
|
28
|
+
* - `unitByIdUrl`, `unitUrl`
|
|
29
|
+
* - `updateCallback(data)`, `updateDeps`, `updateParams`
|
|
30
|
+
*
|
|
31
|
+
* Return values
|
|
32
|
+
* - `byIdFetchNow(url?, config?)`, `byIdLoading`, `byIdError`
|
|
33
|
+
* - `listFetchNow(url?, config?)`, `listLoading`, `listError`
|
|
34
|
+
* - `updateFetchNow(url?, config?)`, `updateLoading`, `updateError`
|
|
35
|
+
* - `deleteFetchNow(url?, config?)`, `deleteLoading`, `deleteError`
|
|
36
|
+
*
|
|
37
|
+
* Behavior notes
|
|
38
|
+
* - All requests that accept parameters send them in the JSON request body (stringified).
|
|
39
|
+
* - All callbacks receive an object `{ data, error, status, ok }` from `useFetch`.
|
|
40
|
+
* - Callbacks are wrapped so thrown errors are swallowed to ensure refresh logic
|
|
41
|
+
* still runs reliably.
|
|
42
|
+
* - `refreshList()` calls `listFetchNow(undefined, { method: 'POST', body: JSON.stringify(listParams) })`
|
|
43
|
+
* to explicitly re-query the list endpoint with the current `listParams`.
|
|
44
|
+
* - Network calls are delegated to `useFetch`; callers can invoke the returned
|
|
45
|
+
* `*FetchNow` functions directly with an override URL or config.
|
|
46
|
+
*
|
|
47
|
+
* Example
|
|
48
|
+
* const { listFetchNow, updateFetchNow } = useModuleEntity({
|
|
49
|
+
* listUrl: '/items',
|
|
50
|
+
* listParams: { page: 1 },
|
|
51
|
+
* listCallback: (res) => console.log(res),
|
|
52
|
+
* unitUrl: '/items',
|
|
53
|
+
* updateCallback: () => {},
|
|
54
|
+
* updateParams: {}
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
interface CallbackParams {
|
|
59
|
+
data: any;
|
|
60
|
+
error: any;
|
|
61
|
+
status?: number;
|
|
62
|
+
ok?: boolean;
|
|
63
|
+
}
|
|
64
|
+
interface Params {
|
|
65
|
+
byIdCallback: (d: CallbackParams) => void;
|
|
66
|
+
byIdDeps?: Array<any> | Array<string>;
|
|
67
|
+
byIdParams: object;
|
|
68
|
+
deleteCallback?: (d: CallbackParams) => void;
|
|
69
|
+
deleteDeps?: Array<any> | Array<string>;
|
|
70
|
+
deleteParams?: object;
|
|
71
|
+
listCallback: (d: CallbackParams) => void;
|
|
72
|
+
listDeps?: Array<any> | Array<string>;
|
|
73
|
+
listParams: object;
|
|
74
|
+
listUrl: string;
|
|
75
|
+
searchQuery: string;
|
|
76
|
+
unitByIdUrl: string;
|
|
77
|
+
unitUrl: string;
|
|
78
|
+
updateCallback: (d: CallbackParams) => void;
|
|
79
|
+
updateDeps?: Array<any> | Array<string>;
|
|
80
|
+
updateParams: object;
|
|
81
|
+
}
|
|
82
|
+
interface Return {
|
|
83
|
+
byIdError?: Error;
|
|
84
|
+
byIdFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
85
|
+
byIdLoading: boolean;
|
|
86
|
+
deleteError?: Error;
|
|
87
|
+
deleteFetchNow?: (url?: string, config?: FetchConfig) => void;
|
|
88
|
+
deleteLoading: boolean;
|
|
89
|
+
listError?: Error;
|
|
90
|
+
listFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
91
|
+
listLoading: boolean;
|
|
92
|
+
updateError?: Error;
|
|
93
|
+
updateFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
94
|
+
updateLoading: boolean;
|
|
95
|
+
}
|
|
96
|
+
declare const useModuleEntity: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
|
|
97
|
+
|
|
98
|
+
export { type CallbackParams, useModuleEntity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useRef as J,useEffect as R}from"react";import{API_METHODS as t}from"../constants/api-methods";import{useFetch as o}from"./use-fetch";import{useDebounce as j}from"./use-debounce";const H=({byIdCallback:d,byIdDeps:u=[],byIdParams:y,deleteCallback:i,deleteDeps:b=[],deleteParams:g,listCallback:f,listDeps:h=[],listParams:a,listUrl:m,searchQuery:p,unitByIdUrl:E,unitUrl:n,updateCallback:c,updateDeps:N=[],updateParams:k})=>{const P=j(p,800),e=J(null);R(()=>()=>{e.current&&(globalThis.clearTimeout(e.current),e.current=null)},[]);const{error:T,fetchNow:l,loading:C}=o(m,{method:t.POST,body:JSON.stringify(a),callback:f},[P,JSON.stringify(a),...h]),s=(r=300)=>{e.current&&globalThis.clearTimeout(e.current),e.current=globalThis.setTimeout(()=>{try{l(void 0,{method:t.POST,body:JSON.stringify(a)})}catch{}e.current=null},r)},{error:F,loading:w,fetchNow:I}=o(n,{method:t.POST,body:JSON.stringify(k),callback:r=>{if(c)try{c(r)}catch{}try{r&&r.ok&&s()}catch{}}},[...N]),{error:O,loading:S,fetchNow:L}=o(E,{method:t.POST,body:JSON.stringify(y),callback:d},[...u]),{error:v,loading:A,fetchNow:D}=o(n,{method:t.DELETE,body:JSON.stringify(g),callback:r=>{if(i)try{i(r)}catch{}try{r&&r.ok&&s()}catch{}}},[...b]);return{byIdError:O,byIdFetchNow:L,byIdLoading:S,deleteError:v,deleteFetchNow:D,deleteLoading:A,listError:T,listFetchNow:l,listLoading:C,updateError:F,updateFetchNow:I,updateLoading:w}};export{H as useModuleEntity};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface FormattedPhoneNumber {
|
|
2
|
+
e164: string;
|
|
3
|
+
international: string;
|
|
4
|
+
}
|
|
5
|
+
interface Return {
|
|
6
|
+
formatted: FormattedPhoneNumber | null;
|
|
7
|
+
formatNumber: (v: string) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parses and formats phone numbers into E.164 and international formats.
|
|
11
|
+
*
|
|
12
|
+
* @param defaultCountry - The default country code to use when parsing (default 'US').
|
|
13
|
+
* @returns An object containing the formatted phone number (or null) and a setter function.
|
|
14
|
+
*/
|
|
15
|
+
declare const usePhoneFormatter: (defaultCountry?: string) => Return;
|
|
16
|
+
|
|
17
|
+
export { usePhoneFormatter };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { CountryCode } from 'libphonenumber-js';
|
|
2
|
-
|
|
3
1
|
interface FormattedPhoneNumber {
|
|
4
2
|
e164: string;
|
|
5
3
|
international: string;
|
|
@@ -14,6 +12,6 @@ interface Return {
|
|
|
14
12
|
* @param defaultCountry - The default country code to use when parsing (default 'US').
|
|
15
13
|
* @returns An object containing the formatted phone number (or null) and a setter function.
|
|
16
14
|
*/
|
|
17
|
-
declare const usePhoneFormatter: (defaultCountry?:
|
|
15
|
+
declare const usePhoneFormatter: (defaultCountry?: string) => Return;
|
|
18
16
|
|
|
19
17
|
export { usePhoneFormatter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},b=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of l(t))!f.call(e,n)&&n!==r&&m(e,n,{get:()=>t[n],enumerable:!(a=s(t,n))||a.enumerable});return e};var N=e=>b(m({},"__esModule",{value:!0}),e);var g={};d(g,{usePhoneFormatter:()=>c});module.exports=N(g);var i=require("react");const c=(e="US")=>{const[t,r]=(0,i.useState)(null);return{formatted:t,formatNumber:n=>{const{parsePhoneNumberFromString:u}=require("libphonenumber-js"),o=u(n,e);r(o?{e164:o.isValid()?o.format("E.164"):"",international:o.formatInternational()}:null)}}};0&&(module.exports={usePhoneFormatter});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as m}from"react";const s=(r="US")=>{const[n,e]=m(null);return{formatted:n,formatNumber:o=>{const{parsePhoneNumberFromString:a}=require("libphonenumber-js"),t=a(o,r);e(t?{e164:t.isValid()?t.format("E.164"):"",international:t.formatInternational()}:null)}}};export{s as usePhoneFormatter};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A util hook to get element positioning.
|
|
5
|
+
*
|
|
6
|
+
* @param elementRef as an element ref for it's position
|
|
7
|
+
* @returns [x, y]
|
|
8
|
+
* @author Taimoor Khan
|
|
9
|
+
* @remarks
|
|
10
|
+
*/
|
|
11
|
+
/** End file docs */
|
|
12
|
+
|
|
13
|
+
type PositionRef = {
|
|
14
|
+
offsetLeft: 0 | null;
|
|
15
|
+
offsetRight: 0 | null;
|
|
16
|
+
offsetTop: 0 | null;
|
|
17
|
+
offsetBottom: 0 | null;
|
|
18
|
+
};
|
|
19
|
+
type StateX = {
|
|
20
|
+
xLeft: 0 | null;
|
|
21
|
+
xRight: 0 | null;
|
|
22
|
+
};
|
|
23
|
+
type StateY = {
|
|
24
|
+
yTop: 0 | null;
|
|
25
|
+
yBottom: 0 | null;
|
|
26
|
+
};
|
|
27
|
+
declare const usePosition: (elementRef: RefObject<PositionRef>) => [StateX, StateY];
|
|
28
|
+
|
|
29
|
+
export { usePosition };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as p,useEffect as y,useState as n}from"react";const S=t=>{const[f,o]=n({xLeft:0,xRight:0}),[l,e]=n({yTop:0,yBottom:0}),s=p(()=>{const u=t?.current?.offsetLeft||null,c=t?.current?.offsetRight||null,i=t?.current?.offsetTop||null,r=t?.current?.offsetBottom||null;o({xLeft:u,xRight:c}),e({yTop:i,yBottom:r})},[t,o,e]);return y(()=>{s()},[s]),[f,l]};export{S as usePosition};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to detect RTL (Right-to-Left) layout based on current locale
|
|
3
|
+
* @returns {boolean} true if current locale requires RTL layout (Urdu), false otherwise
|
|
4
|
+
*/
|
|
5
|
+
declare const useRTL: (forcedLocale?: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Hook to get RTL-aware CSS classes
|
|
8
|
+
*
|
|
9
|
+
* @returns Object containing common RTL-aware class combinations
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const rtlClasses = useRTLClasses();
|
|
14
|
+
*
|
|
15
|
+
* // For icon buttons (ensures proper centering in RTL)
|
|
16
|
+
* <Button size="icon" className={`h-8 w-8 ${rtlClasses.iconButton}`}>
|
|
17
|
+
* <Icon />
|
|
18
|
+
* </Button>
|
|
19
|
+
*
|
|
20
|
+
* // For buttons with icon and text
|
|
21
|
+
* <Button className={rtlClasses.iconWithText("left")}>
|
|
22
|
+
* <Icon />
|
|
23
|
+
* <span>Button Text</span>
|
|
24
|
+
* </Button>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const useRTLClasses: (forcedLocale?: string) => {
|
|
28
|
+
isRTL: boolean;
|
|
29
|
+
container: string;
|
|
30
|
+
direction: string;
|
|
31
|
+
flexRow: string;
|
|
32
|
+
flexRowReverse: string;
|
|
33
|
+
textAlign: string;
|
|
34
|
+
textAlignReverse: string;
|
|
35
|
+
marginLeft: string;
|
|
36
|
+
marginRight: string;
|
|
37
|
+
paddingLeft: (size: string) => string;
|
|
38
|
+
paddingRight: (size: string) => string;
|
|
39
|
+
gap: (size: string) => string;
|
|
40
|
+
roundedLeft: string;
|
|
41
|
+
roundedRight: string;
|
|
42
|
+
iconButton: string;
|
|
43
|
+
iconWithText: (iconPosition?: "left" | "right") => "flex items-center flex-row-reverse gap-2" | "flex items-center gap-2";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { useRTL, useRTLClasses };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=r=>{if(r)return r==="ur";try{const{useLocale:e}=require("next-intl");return e()==="ur"}catch{return!1}},l=r=>{const e=n(r);return{isRTL:e,container:e?"rtl":"ltr",direction:e?"rtl":"ltr",flexRow:e?"flex-row-reverse":"flex-row",flexRowReverse:e?"flex-row":"flex-row-reverse",textAlign:e?"text-right":"text-left",textAlignReverse:e?"text-left":"text-right",marginLeft:e?"mr-auto":"ml-auto",marginRight:e?"ml-auto":"mr-auto",paddingLeft:t=>e?`pr-${t}`:`pl-${t}`,paddingRight:t=>e?`pl-${t}`:`pr-${t}`,gap:t=>`gap-${t}`,roundedLeft:e?"rounded-r":"rounded-l",roundedRight:e?"rounded-l":"rounded-r",iconButton:"flex items-center justify-center border",iconWithText:(t="left")=>t==="left"?e?"flex items-center flex-row-reverse gap-2":"flex items-center gap-2":e?"flex items-center gap-2":"flex items-center flex-row-reverse gap-2"}};export{n as useRTL,l as useRTLClasses};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util hook to stickyness in the app.
|
|
3
|
+
*
|
|
4
|
+
* @param offset - number of pixel which is offset
|
|
5
|
+
* @default offset = 0
|
|
6
|
+
* @returns isSticky as boolean
|
|
7
|
+
* @author Taimoor Khan
|
|
8
|
+
* @remarks
|
|
9
|
+
*/
|
|
10
|
+
/** End file docs */
|
|
11
|
+
declare const useSticky: (offset?: number) => boolean;
|
|
12
|
+
|
|
13
|
+
export { useSticky };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useLayoutEffect as r}from"react";import{useToggleState as s}from"./use-toggle-state";const w=(e=0)=>{const[n,o,t]=s();return r(()=>{const i=()=>{window.requestAnimationFrame(()=>{window.pageYOffset>e?o():t()})};if(window)return window.addEventListener("scroll",i),()=>{window.removeEventListener("scroll",i)}},[o,e,t]),n};export{w as useSticky};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A util hook to enable toggle state.
|
|
3
|
+
*
|
|
4
|
+
* @param defaultValue as an initial state toggle value
|
|
5
|
+
* @default defaultValue as false
|
|
6
|
+
* @returns [state, toggleOn, toggleOff]
|
|
7
|
+
* @author Taimoor Khan
|
|
8
|
+
* @remarks
|
|
9
|
+
*/
|
|
10
|
+
/** End file docs */
|
|
11
|
+
type ReturnType = [boolean, () => void, () => void];
|
|
12
|
+
declare const useToggleState: (defaultValue?: boolean) => ReturnType;
|
|
13
|
+
|
|
14
|
+
export { useToggleState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as t,useState as l}from"react";const u=(o=!1)=>{const[s,e]=l(o),a=t(()=>{e(!0)},[e]),n=t(()=>{e(!1)},[e]);return[s,a,n]};export{u as useToggleState};
|