@cleartrip/ct-design-common-utils 4.0.0-TEST.3 → 4.0.0-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/HapticFeedback/getHapticPattern.d.ts +4 -0
  2. package/dist/HapticFeedback/getHapticPattern.d.ts.map +1 -0
  3. package/dist/HapticFeedback/index.d.ts +5 -0
  4. package/dist/HapticFeedback/index.d.ts.map +1 -0
  5. package/dist/HapticFeedback/index.native.d.ts +5 -0
  6. package/dist/HapticFeedback/index.native.d.ts.map +1 -0
  7. package/dist/HapticFeedback/type.d.ts +13 -0
  8. package/dist/HapticFeedback/type.d.ts.map +1 -0
  9. package/dist/accessibility.d.ts +4 -0
  10. package/dist/accessibility.d.ts.map +1 -0
  11. package/dist/batchedPromise.d.ts +10 -0
  12. package/dist/batchedPromise.d.ts.map +1 -0
  13. package/dist/common.d.ts +13 -11
  14. package/dist/common.d.ts.map +1 -1
  15. package/dist/ct-design-common-utils.browser.cjs.js +1 -1
  16. package/dist/ct-design-common-utils.browser.cjs.js.map +1 -1
  17. package/dist/ct-design-common-utils.browser.esm.js +1 -1
  18. package/dist/ct-design-common-utils.browser.esm.js.map +1 -1
  19. package/dist/ct-design-common-utils.cjs.js +292 -61
  20. package/dist/ct-design-common-utils.cjs.js.map +1 -1
  21. package/dist/ct-design-common-utils.esm.js +269 -62
  22. package/dist/ct-design-common-utils.esm.js.map +1 -1
  23. package/dist/ct-design-common-utils.umd.js +295 -95
  24. package/dist/ct-design-common-utils.umd.js.map +1 -1
  25. package/dist/dates.d.ts +3 -2
  26. package/dist/dates.d.ts.map +1 -1
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/platform/index.d.ts +27 -0
  30. package/dist/platform/index.d.ts.map +1 -0
  31. package/dist/platform/native-info.d.ts +8 -0
  32. package/dist/platform/native-info.d.ts.map +1 -0
  33. package/dist/platform/native-info.native.d.ts +8 -0
  34. package/dist/platform/native-info.native.d.ts.map +1 -0
  35. package/dist/promiseHandler.d.ts +16 -0
  36. package/dist/promiseHandler.d.ts.map +1 -0
  37. package/dist/{regex/index.d.ts → regex.d.ts} +1 -1
  38. package/dist/regex.d.ts.map +1 -0
  39. package/dist/type.d.ts +62 -0
  40. package/dist/type.d.ts.map +1 -0
  41. package/package.json +11 -6
  42. package/src/HapticFeedback/getHapticPattern.ts +23 -0
  43. package/src/HapticFeedback/index.native.ts +26 -0
  44. package/src/HapticFeedback/index.ts +7 -0
  45. package/src/HapticFeedback/type.ts +35 -0
  46. package/src/accessibility.ts +39 -0
  47. package/src/batchedPromise.ts +43 -0
  48. package/src/common.ts +227 -0
  49. package/src/dates.ts +53 -0
  50. package/src/index.ts +8 -0
  51. package/src/platform/index.ts +70 -0
  52. package/src/platform/native-info.native.ts +17 -0
  53. package/src/platform/native-info.ts +21 -0
  54. package/src/promiseHandler.ts +62 -0
  55. package/src/regex.ts +23 -0
  56. package/src/type.ts +381 -0
  57. package/dist/regex/index.d.ts.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  export * from './common';
2
2
  export * from './dates';
3
3
  export * from './regex';
4
+ export * from './accessibility';
5
+ export * from './HapticFeedback';
6
+ export * from './platform';
7
+ export * from './batchedPromise';
8
+ export * from './promiseHandler';
4
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/utils/common/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/utils/common/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,27 @@
1
+ export declare enum Platform {
2
+ IOS = "iOS",
3
+ PWA = "PWA",
4
+ ANDROID = "Android"
5
+ }
6
+ export declare enum AppAgent {
7
+ PWA = "PWA",
8
+ IOS = "iPhoneApp",
9
+ ANDROID = "AndroidApp",
10
+ H_PWA = "pwa",
11
+ H_IOS = "ios",
12
+ H_ANDROID = "android",
13
+ H_UNKNOWN = "unrecognised"
14
+ }
15
+ export declare const getPlatform: () => Platform;
16
+ export declare const getAppAgent: () => string;
17
+ export declare const getJSVersion: () => string;
18
+ export declare const getDeviceWidth: () => number;
19
+ export declare const getDeviceHeight: () => number;
20
+ export declare const isMobile: () => boolean;
21
+ export declare const isIOS: () => boolean;
22
+ export declare const isAndroid: () => boolean;
23
+ export declare const isAndroid_15: () => boolean;
24
+ export declare const isJSVersionUpdated: (compareVersion: number) => boolean;
25
+ export declare const isPwa: () => boolean;
26
+ export * from './native-info';
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/utils/common/src/platform/index.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,OAAO,YAAY;CACpB;AAED,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,GAAG,cAAc;IACjB,OAAO,eAAe;IACtB,KAAK,QAAQ;IACb,KAAK,QAAQ;IACb,SAAS,YAAY;IACrB,SAAS,iBAAiB;CAC3B;AAID,eAAO,MAAM,WAAW,QAAO,QAc9B,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,MAc9B,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,MAAe,CAAC;AAEhD,eAAO,MAAM,cAAc,QAAO,MAEjC,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,MAElC,CAAC;AAEF,eAAO,MAAM,QAAQ,eAAa,CAAC;AACnC,eAAO,MAAM,KAAK,QAAO,OAAyC,CAAC;AACnE,eAAO,MAAM,SAAS,QAAO,OAA6C,CAAC;AAC3E,eAAO,MAAM,YAAY,QAAO,OAAqE,CAAC;AACtG,eAAO,MAAM,kBAAkB,GAAI,gBAAgB,MAAM,KAAG,OAAqD,CAAC;AAClH,eAAO,MAAM,KAAK,QAAO,OAEmC,CAAC;AAE7D,cAAc,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const isServer: () => boolean;
2
+ export declare const getOS: () => "web" | "ios" | "android";
3
+ export declare const getDimensions: () => {
4
+ width: number;
5
+ height: number;
6
+ };
7
+ export declare const getOSVersion: () => number;
8
+ //# sourceMappingURL=native-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-info.d.ts","sourceRoot":"","sources":["../../packages/utils/common/src/platform/native-info.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,eAEpB,CAAC;AAEF,eAAO,MAAM,KAAK,QAAO,KAAK,GAAG,KAAK,GAAG,SAExC,CAAC;AAKF,eAAO,MAAM,aAAa,QAAO;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAK/D,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,MAE/B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const getOS: () => "web" | "ios" | "android";
2
+ export declare const getDimensions: () => {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export declare const getOSVersion: () => number;
7
+ export declare const isServer: () => boolean;
8
+ //# sourceMappingURL=native-info.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-info.native.d.ts","sourceRoot":"","sources":["../../packages/utils/common/src/platform/native-info.native.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,QAAO,KAAK,GAAG,KAAK,GAAG,SAExC,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAE/D,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,MAE/B,CAAC;AAEF,eAAO,MAAM,QAAQ,eAEpB,CAAC"}
@@ -0,0 +1,16 @@
1
+ interface PromiseHandlerOptions {
2
+ concurrency?: number;
3
+ }
4
+ declare class PromiseHandler {
5
+ private queue;
6
+ private running;
7
+ private concurrency;
8
+ constructor(options?: PromiseHandlerOptions);
9
+ clear: () => void;
10
+ add: (task: () => Promise<void>, ref: unknown) => Promise<void>;
11
+ private processQueue;
12
+ }
13
+ export declare const createPromiseHandler: (options?: PromiseHandlerOptions) => PromiseHandler;
14
+ export declare const promiseHandler: PromiseHandler;
15
+ export {};
16
+ //# sourceMappingURL=promiseHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promiseHandler.d.ts","sourceRoot":"","sources":["../packages/utils/common/src/promiseHandler.ts"],"names":[],"mappings":"AAAA,UAAU,qBAAqB;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,GAAE,qBAA0B;IAI/C,KAAK,aAGH;IAEF,GAAG,GAAU,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC,CAyBlE;IAEF,OAAO,CAAC,YAAY,CASlB;CACH;AAED,eAAO,MAAM,oBAAoB,GAAI,UAAU,qBAAqB,mBAEnE,CAAC;AAEF,eAAO,MAAM,cAAc,gBAAyB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export declare const removeNonNumerals: (data: string) => string;
2
2
  export declare const removeSpace: (data: string) => string;
3
3
  export declare const addSpaceAtInterval: (data: string, interval: number) => string;
4
- //# sourceMappingURL=index.d.ts.map
4
+ //# sourceMappingURL=regex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../packages/utils/common/src/regex.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MAAiC,CAAC;AAOnF,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MAAiC,CAAC;AAO7E,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,KAAG,MAGnE,CAAC"}
package/dist/type.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ export interface AccessibilityProps extends AccessibilityPropsAndroid, AccessibilityPropsIOS {
2
+ accessible?: boolean | undefined;
3
+ accessibilityActions?: ReadonlyArray<AccessibilityActionInfo> | undefined;
4
+ accessibilityLabel?: string | undefined;
5
+ 'aria-label'?: string | undefined;
6
+ accessibilityRole?: AccessibilityRole | undefined;
7
+ accessibilityState?: AccessibilityState | undefined;
8
+ 'aria-busy'?: boolean | undefined;
9
+ 'aria-checked'?: boolean | 'mixed' | undefined;
10
+ 'aria-disabled'?: boolean | undefined;
11
+ 'aria-expanded'?: boolean | undefined;
12
+ 'aria-selected'?: boolean | undefined;
13
+ accessibilityHint?: string | undefined;
14
+ accessibilityValue?: AccessibilityValue | undefined;
15
+ 'aria-valuemax'?: AccessibilityValue['max'] | undefined;
16
+ 'aria-valuemin'?: AccessibilityValue['min'] | undefined;
17
+ 'aria-valuenow'?: AccessibilityValue['now'] | undefined;
18
+ 'aria-valuetext'?: AccessibilityValue['text'] | undefined;
19
+ importantForAccessibility?: ('auto' | 'yes' | 'no' | 'no-hide-descendants') | undefined;
20
+ 'aria-hidden'?: boolean | undefined;
21
+ 'aria-modal'?: boolean | undefined;
22
+ role?: Role | undefined;
23
+ }
24
+ export type AccessibilityActionInfo = Readonly<{
25
+ name: AccessibilityActionName | string;
26
+ label?: string | undefined;
27
+ }>;
28
+ export type AccessibilityActionName = 'activate' | 'increment' | 'decrement' | 'longpress' | 'magicTap' | 'escape';
29
+ export interface AccessibilityState {
30
+ disabled?: boolean | undefined;
31
+ selected?: boolean | undefined;
32
+ checked?: boolean | 'mixed' | undefined;
33
+ busy?: boolean | undefined;
34
+ expanded?: boolean | undefined;
35
+ }
36
+ export interface AccessibilityValue {
37
+ min?: number | undefined;
38
+ max?: number | undefined;
39
+ now?: number | undefined;
40
+ text?: string | undefined;
41
+ }
42
+ export type AccessibilityRole = 'none' | 'button' | 'togglebutton' | 'link' | 'search' | 'image' | 'keyboardkey' | 'text' | 'adjustable' | 'imagebutton' | 'header' | 'summary' | 'alert' | 'checkbox' | 'combobox' | 'menu' | 'menubar' | 'menuitem' | 'progressbar' | 'radio' | 'radiogroup' | 'scrollbar' | 'spinbutton' | 'switch' | 'tab' | 'tabbar' | 'tablist' | 'timer' | 'list' | 'toolbar';
43
+ export interface AccessibilityPropsAndroid {
44
+ accessibilityLabelledBy?: string | string[] | undefined;
45
+ 'aria-labelledby'?: string | undefined;
46
+ accessibilityLiveRegion?: 'none' | 'polite' | 'assertive' | undefined;
47
+ 'aria-live'?: ('polite' | 'assertive' | 'off') | undefined;
48
+ importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants' | undefined;
49
+ }
50
+ export interface AccessibilityPropsIOS {
51
+ accessibilityElementsHidden?: boolean | undefined;
52
+ accessibilityViewIsModal?: boolean | undefined;
53
+ onAccessibilityEscape?: (() => void) | undefined;
54
+ onAccessibilityTap?: (() => void) | undefined;
55
+ onMagicTap?: (() => void) | undefined;
56
+ accessibilityIgnoresInvertColors?: boolean | undefined;
57
+ accessibilityLanguage?: string | undefined;
58
+ accessibilityShowsLargeContentViewer?: boolean | undefined;
59
+ accessibilityLargeContentTitle?: string | undefined;
60
+ }
61
+ export type Role = 'alert' | 'alertdialog' | 'application' | 'article' | 'banner' | 'button' | 'cell' | 'checkbox' | 'columnheader' | 'combobox' | 'complementary' | 'contentinfo' | 'definition' | 'dialog' | 'directory' | 'document' | 'feed' | 'figure' | 'form' | 'grid' | 'group' | 'heading' | 'img' | 'link' | 'list' | 'listitem' | 'log' | 'main' | 'marquee' | 'math' | 'menu' | 'menubar' | 'menuitem' | 'meter' | 'navigation' | 'none' | 'note' | 'option' | 'presentation' | 'progressbar' | 'radio' | 'radiogroup' | 'region' | 'row' | 'rowgroup' | 'rowheader' | 'scrollbar' | 'searchbox' | 'separator' | 'slider' | 'spinbutton' | 'status' | 'summary' | 'switch' | 'tab' | 'table' | 'tablist' | 'tabpanel' | 'term' | 'timer' | 'toolbar' | 'tooltip' | 'tree' | 'treegrid' | 'treeitem';
62
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/utils/common/src/type.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB,EAAE,qBAAqB;IAK1F,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAKjC,oBAAoB,CAAC,EAAE,aAAa,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAAC;IAM1E,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAMxC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAKlC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAIlD,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAOpD,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAC/C,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAKtC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAKvC,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IA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,GAAG,SAAS,CAAC;IAOvD,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAQ3C,oCAAoC,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAO3D,8BAA8B,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrD;AAED,MAAM,MAAM,IAAI,GACZ,OAAO,GACP,aAAa,GACb,aAAa,GACb,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,UAAU,GACV,cAAc,GACd,UAAU,GACV,eAAe,GACf,aAAa,GACb,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,UAAU,GACV,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,KAAK,GACL,MAAM,GACN,MAAM,GACN,UAAU,GACV,KAAK,GACL,MAAM,GACN,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,GACT,UAAU,GACV,OAAO,GACP,YAAY,GACZ,MAAM,GACN,MAAM,GACN,QAAQ,GACR,cAAc,GACd,aAAa,GACb,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,KAAK,GACL,UAAU,GACV,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,KAAK,GACL,OAAO,GACP,SAAS,GACT,UAAU,GACV,MAAM,GACN,OAAO,GACP,SAAS,GACT,SAAS,GACT,MAAM,GACN,UAAU,GACV,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-common-utils",
3
- "version": "4.0.0-TEST.3",
3
+ "version": "4.0.0-rc",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/ct-design-common-utils.cjs.js",
7
+ "react-native": "src/index.ts",
7
8
  "jsnext:main": "dist/ct-design-common-utils.esm.js",
8
9
  "module": "dist/ct-design-common-utils.esm.js",
9
10
  "sideEffects": false,
@@ -12,13 +13,15 @@
12
13
  "./dist/ct-design-common-utils.cjs.js": "./dist/ct-design-common-utils.browser.cjs.js"
13
14
  },
14
15
  "files": [
15
- "dist"
16
+ "dist",
17
+ "src"
16
18
  ],
17
19
  "dependencies": {
20
+ "date-fns": "^2.29.3",
18
21
  "dayjs": "^1.11.7",
19
- "@cleartrip/ct-design-types": "3.20.0",
20
- "@cleartrip/ct-design-theme": "3.20.0",
21
- "@cleartrip/ct-design-common-constants": "3.20.0"
22
+ "@cleartrip/ct-design-theme": "4.0.0-rc",
23
+ "@cleartrip/ct-design-common-constants": "4.0.0-rc",
24
+ "@cleartrip/ct-design-types": "4.0.0-rc"
22
25
  },
23
26
  "publishConfig": {
24
27
  "access": "public"
@@ -28,6 +31,8 @@
28
31
  "scripts": {
29
32
  "watch-package": "rollup -c -w",
30
33
  "build-package": "rollup -c",
31
- "build-package:clean": "rm -rf dist && rollup -c"
34
+ "build-package:clean": "rm -rf dist && rollup -c",
35
+ "publish-package:local": "yalc publish --no-scripts",
36
+ "publish-package:local:registry": "pnpm publish --registry http://localhost:4873 --no-git-checks --access public"
32
37
  }
33
38
  }
@@ -0,0 +1,23 @@
1
+ import { HapticVariant } from './type';
2
+
3
+ export const getHapticPatternValue = (variant: HapticVariant) => {
4
+ switch (variant) {
5
+ case 'loud':
6
+ return 80;
7
+ case 'subtle':
8
+ default:
9
+ return 40;
10
+ }
11
+ };
12
+
13
+ export const getIOSHapticPatternValue = (variant: HapticVariant) => {
14
+ switch (variant) {
15
+ case 'loud': {
16
+ return 'rigid';
17
+ }
18
+ case 'subtle':
19
+ default: {
20
+ return 'light';
21
+ }
22
+ }
23
+ };
@@ -0,0 +1,26 @@
1
+ import { NativeModule, NativeModules, Vibration } from 'react-native';
2
+ import { isAndroid } from '../platform';
3
+
4
+ import { getHapticPatternValue, getIOSHapticPatternValue } from './getHapticPattern';
5
+ import { IHapticFeedbackProps } from './type';
6
+
7
+ interface IHapticFeedbackModule extends NativeModule {
8
+ trigger: (variant: 'light' | 'medium' | 'heavy' | 'soft' | 'rigid', intensity?: number) => void;
9
+ }
10
+
11
+ const { HapticFeedback: HapticFeedbackModule } = NativeModules as { HapticFeedback: IHapticFeedbackModule };
12
+
13
+ export class HapticFeedback {
14
+ static vibrate({ pattern, repeat = false, variant = 'subtle' }: IHapticFeedbackProps) {
15
+ if (isAndroid()) {
16
+ Vibration.vibrate(pattern || getHapticPatternValue(variant), repeat);
17
+ } else {
18
+ const hapticVariant = getIOSHapticPatternValue(variant);
19
+
20
+ /**
21
+ * !NOTE: We are not using intensity as of now.
22
+ */
23
+ HapticFeedbackModule.trigger(hapticVariant, -1);
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,7 @@
1
+ import { IHapticFeedbackProps } from './type';
2
+
3
+ export abstract class HapticFeedback {
4
+ static vibrate(_: IHapticFeedbackProps): void {
5
+ // no-op
6
+ }
7
+ }
@@ -0,0 +1,35 @@
1
+ export type HapticVariant = 'subtle' | 'loud';
2
+
3
+ export interface HapticFeedbackProps {
4
+ /**
5
+ * Enables haptic feedback on interaction with the container.
6
+ * When true, the container will trigger haptic feedback on click/tap events.
7
+ * @example
8
+ * <Component hapticEnabled={true} />
9
+ */
10
+ hapticEnabled?: boolean;
11
+
12
+ /**
13
+ * Specifies the intensity of the haptic feedback.
14
+ * - 'light': Light haptic feedback, suitable for most interactions
15
+ * - 'loud': Strong haptic feedback, for more prominent interactions
16
+ * @example
17
+ * <Component hapticEnabled={true} hapticVariant="subtle" />
18
+ */
19
+ hapticVariant?: HapticVariant;
20
+
21
+ /**
22
+ * When enabled, the haptic feedback will repeat continuously while the interaction is active.
23
+ * Useful for long-press or drag interactions.
24
+ * @example
25
+ * <Component hapticEnabled={true} hapticRepeat={true} />
26
+ */
27
+ hapticRepeat?: boolean;
28
+ }
29
+
30
+ export interface IHapticFeedbackProps {
31
+ pattern?: number | number[];
32
+ repeat?: boolean;
33
+ variant: HapticVariant;
34
+ intensity?: number;
35
+ }
@@ -0,0 +1,39 @@
1
+ import type { AccessibilityProps } from './type';
2
+
3
+ export type HTMLElementTagName = keyof HTMLElementTagNameMap;
4
+
5
+ const ACCESSIBILITY_PROPS = {
6
+ main: {
7
+ accessibilityRole: 'main',
8
+ },
9
+ article: {
10
+ accessibilityRole: 'article',
11
+ },
12
+ section: {
13
+ accessibilityRole: 'region',
14
+ },
15
+ h1: {
16
+ accessibilityRole: 'header',
17
+ 'aria-level': 1,
18
+ },
19
+ h2: {
20
+ accessibilityRole: 'header',
21
+ 'aria-level': 2,
22
+ },
23
+ h3: {
24
+ accessibilityRole: 'header',
25
+ 'aria-level': 3,
26
+ },
27
+ h4: {
28
+ accessibilityRole: 'header',
29
+ 'aria-level': 4,
30
+ },
31
+ h5: {
32
+ accessibilityRole: 'header',
33
+ 'aria-level': 5,
34
+ },
35
+ } as const;
36
+
37
+ export const getAccessibilityProps = (componentNode: HTMLElementTagName) => {
38
+ return ACCESSIBILITY_PROPS[componentNode] as AccessibilityProps;
39
+ };
@@ -0,0 +1,43 @@
1
+ export class BatchedPromiseHandler {
2
+ private batchSize: number;
3
+ /**
4
+ * max size 10
5
+ */
6
+ private currentBatch: Array<() => Promise<unknown>> = [];
7
+ private waitingBatch: Array<() => Promise<unknown>> = [];
8
+
9
+ constructor(batchSize: number = 10) {
10
+ this.batchSize = batchSize;
11
+ }
12
+
13
+ private processPromises() {
14
+ /**
15
+ * while (this.currentBatch.length > 0) {
16
+ * remove promise by shift
17
+ * }
18
+ *
19
+ */
20
+ while (this.currentBatch.length > 0) {
21
+ const promise = this.currentBatch.shift();
22
+ promise?.().then(() => {
23
+ const waitingPromise = this.waitingBatch.shift();
24
+ if (waitingPromise) {
25
+ this.currentBatch.push(waitingPromise);
26
+ this.processPromises();
27
+ }
28
+ });
29
+ }
30
+ }
31
+ add<T>(promise: () => Promise<T>) {
32
+ if (this.currentBatch.length < this.batchSize) {
33
+ this.currentBatch.push(promise);
34
+ } else {
35
+ this.waitingBatch.push(promise);
36
+ }
37
+ this.processPromises();
38
+ }
39
+ clearPromises() {
40
+ this.currentBatch = [];
41
+ this.waitingBatch = [];
42
+ }
43
+ }
package/src/common.ts ADDED
@@ -0,0 +1,227 @@
1
+ // Common Utility file
2
+ import { dateFormat, startOfToday, dateFormat_hrental } from './dates';
3
+
4
+ export const isValidDate = (date: Date) => {
5
+ return date && !isNaN(date.getTime());
6
+ };
7
+
8
+ export const _getDate = (date: string | number | Date) => {
9
+ const type = typeof date;
10
+ let departDate;
11
+ if (type === 'number') {
12
+ departDate = new Date(date);
13
+ } else if (typeof date === 'string') {
14
+ departDate = date.split('/');
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
16
+ departDate = new Date(`${departDate[1]}/${departDate[0]}/${departDate[2]}`);
17
+ } else if (date instanceof Date) {
18
+ departDate = date;
19
+ }
20
+ return departDate;
21
+ };
22
+ export const isOldDate = (dateValue: number) => {
23
+ const currDate = new Date();
24
+ currDate.setHours(0, 0, 0, 0);
25
+ return dateValue < currDate.getTime();
26
+ };
27
+
28
+ /** Returns whether the value is a function. Acts as a type guard. */
29
+ export const isFunction = (value: unknown) => {
30
+ return typeof value === 'function';
31
+ };
32
+
33
+ /**
34
+ * Safely invoke the function with the given arguments,
35
+ * if it is indeed a function, and return its value.
36
+ */
37
+ export const safeInvoke = (func: unknown = undefined, ...args: unknown[]) => {
38
+ return isFunction(func) && func(...args);
39
+ };
40
+ export { startOfToday, dateFormat_hrental, dateFormat };
41
+
42
+ export const isEmpty = (obj: unknown) => {
43
+ if (obj instanceof Date) {
44
+ return false;
45
+ }
46
+ // null and undefined are "empty"
47
+ if (obj == null || obj == 'undefined') {
48
+ return true;
49
+ }
50
+
51
+ const isNumber = (value: unknown) => Object.prototype.toString.call(value) === '[object Number]';
52
+ const isNaN = (value: unknown) => isNumber(value) && typeof value === 'number' && isNaN(value);
53
+
54
+ if (isNumber(obj)) {
55
+ return isNaN(obj);
56
+ }
57
+
58
+ /** Assume if it has a length property with a non-zero value
59
+ * that that property is correct.
60
+ */
61
+ if (typeof obj === 'object' && 'length' in obj && typeof obj.length === 'number' && obj.length > 0) {
62
+ return false;
63
+ }
64
+ if (typeof obj === 'object' && 'length' in obj && typeof obj.length === 'number' && obj.length === 0) {
65
+ return true;
66
+ }
67
+
68
+ /** If it isn't an object at this point
69
+ * it is empty, but it can't be anything *but* empty
70
+ * Is it empty? Depends on your application.
71
+ */
72
+ if (typeof obj !== 'object') {
73
+ return true;
74
+ }
75
+
76
+ /** Otherwise, does it have any properties of its own?
77
+ * Note that this doesn't handle
78
+ * toString and valueOf enumeration bugs in IE < 9
79
+ */
80
+ const keys = Object.keys(obj);
81
+ for (let i = 0, key = keys[i]; i < keys.length; i += 1) {
82
+ if (Object.hasOwnProperty.call(obj, key)) {
83
+ return false;
84
+ }
85
+ }
86
+ return true;
87
+ };
88
+
89
+ /**
90
+ *
91
+ * @param callback callback is any function that needs to limit the number of times it executes.
92
+ * @param delay delay is the time (in milliseconds) that needs to elapse before callback can execute again.
93
+ * @returns returns a debounced function
94
+ */
95
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
96
+ export const debounce = (callback: Function, delay = 0) => {
97
+ let clearTimer;
98
+ return function (this: unknown) {
99
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
100
+ const context = this;
101
+ const args = arguments;
102
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
103
+ clearTimeout(clearTimer);
104
+ clearTimer = setTimeout(() => callback.apply(context, args), delay);
105
+ };
106
+ };
107
+
108
+ /**
109
+ *
110
+ * @param obj data that needs to be cloned
111
+ * @returns cloned value of obj
112
+ */
113
+ export function cloneDeep(obj: unknown) {
114
+ if (obj === null || typeof obj !== 'object') {
115
+ return obj;
116
+ }
117
+
118
+ const clonedObj = Array.isArray(obj) ? [] : {};
119
+
120
+ for (const key in obj) {
121
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
122
+ clonedObj[key] = cloneDeep(obj[key]);
123
+ }
124
+ }
125
+
126
+ return clonedObj;
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @param valueA First value
132
+ * @param valueB Second value
133
+ * @returns Returns true if both values are equal otherwise false.
134
+ */
135
+ export function isEqual(valueA: unknown, valueB: unknown) {
136
+ // Check for strict equality first
137
+ if (valueA === valueB) {
138
+ return true;
139
+ }
140
+
141
+ // Check for arrays or objects
142
+ if (Array.isArray(valueA) && Array.isArray(valueB)) {
143
+ if (valueA.length !== valueB.length) {
144
+ return false;
145
+ }
146
+
147
+ for (let i = 0; i < valueA.length; i++) {
148
+ if (!isEqual(valueA[i], valueB[i])) {
149
+ return false;
150
+ }
151
+ }
152
+
153
+ return true;
154
+ }
155
+
156
+ if (typeof valueA === 'object' && typeof valueB === 'object') {
157
+ const keysA = Object.keys(valueA || {});
158
+ const keysB = Object.keys(valueB || {});
159
+
160
+ if (keysA.length !== keysB.length) {
161
+ return false;
162
+ }
163
+
164
+ for (const key of keysA) {
165
+ if (!isEqual(valueA?.[key], valueB?.[key])) {
166
+ return false;
167
+ }
168
+ }
169
+
170
+ return true;
171
+ }
172
+
173
+ // For other primitive types, use strict equality
174
+ return false;
175
+ }
176
+
177
+ /**
178
+ * Parses a JSON string into an object of type `T`, where `T` is a record of strings to unknown values.
179
+ *
180
+ * @param jsonString The JSON string to parse.
181
+ * @returns The parsed object, or an empty object of type `T` if the JSON string is invalid.
182
+ */
183
+ export const parseJSON = <T extends Record<string, unknown>>(jsonString = ''): T => {
184
+ try {
185
+ return JSON.parse(jsonString);
186
+ } catch (_error) {
187
+ return {} as T;
188
+ }
189
+ };
190
+
191
+ /**
192
+ *
193
+ * @param fieldArray Array of string
194
+ * @param objectToTraverse Object from which value needs to be extracted
195
+ * @returns Return field value in a nested object
196
+ */
197
+
198
+ export const getNestedField = (fieldArray: unknown, objectToTraverse: unknown): unknown => {
199
+ const reducerFunction = (accumalator: unknown, current: unknown) => {
200
+ // @ts-ignore
201
+ return accumalator && accumalator[current] ? accumalator[current] : null;
202
+ };
203
+ // @ts-ignore
204
+ return fieldArray.reduce(reducerFunction, objectToTraverse);
205
+ };
206
+ export const getDimensionsFromImageUrl = (url: string, type: 'height' | 'width'): number | undefined => {
207
+ if (!url) {
208
+ return;
209
+ }
210
+
211
+ const regex = {
212
+ // eslint-disable-next-line no-useless-escape
213
+ height: /h_(\d+)[,\/]/,
214
+ // eslint-disable-next-line no-useless-escape
215
+ width: /w_(\d+)[,\/]/,
216
+ };
217
+
218
+ const match = url.match(regex[type]);
219
+
220
+ if (match && match[1]) {
221
+ return parseInt(match[1], 10);
222
+ }
223
+
224
+ return;
225
+ };
226
+
227
+ export const getHeightFromImgUrl = (url: string): number | undefined => getDimensionsFromImageUrl(url, 'height');