@rnpack/utils 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +49 -0
  3. package/lib/commonjs/hooks/index.js +28 -0
  4. package/lib/commonjs/hooks/index.js.map +1 -0
  5. package/lib/commonjs/hooks/usePagination.js +29 -0
  6. package/lib/commonjs/hooks/usePagination.js.map +1 -0
  7. package/lib/commonjs/hooks/useTimer.js +44 -0
  8. package/lib/commonjs/hooks/useTimer.js.map +1 -0
  9. package/lib/commonjs/index.js +28 -0
  10. package/lib/commonjs/index.js.map +1 -0
  11. package/lib/commonjs/package.json +1 -0
  12. package/lib/commonjs/utils/index.js +50 -0
  13. package/lib/commonjs/utils/index.js.map +1 -0
  14. package/lib/commonjs/utils/object.js +32 -0
  15. package/lib/commonjs/utils/object.js.map +1 -0
  16. package/lib/commonjs/utils/responsive.js +36 -0
  17. package/lib/commonjs/utils/responsive.js.map +1 -0
  18. package/lib/commonjs/utils/string.js +59 -0
  19. package/lib/commonjs/utils/string.js.map +1 -0
  20. package/lib/commonjs/utils/utils.js +23 -0
  21. package/lib/commonjs/utils/utils.js.map +1 -0
  22. package/lib/module/hooks/index.js +3 -0
  23. package/lib/module/hooks/index.js.map +1 -0
  24. package/lib/module/hooks/usePagination.js +24 -0
  25. package/lib/module/hooks/usePagination.js.map +1 -0
  26. package/lib/module/hooks/useTimer.js +39 -0
  27. package/lib/module/hooks/useTimer.js.map +1 -0
  28. package/lib/module/index.js +3 -0
  29. package/lib/module/index.js.map +1 -0
  30. package/lib/module/package.json +1 -0
  31. package/lib/module/utils/index.js +5 -0
  32. package/lib/module/utils/index.js.map +1 -0
  33. package/lib/module/utils/object.js +25 -0
  34. package/lib/module/utils/object.js.map +1 -0
  35. package/lib/module/utils/responsive.js +31 -0
  36. package/lib/module/utils/responsive.js.map +1 -0
  37. package/lib/module/utils/string.js +46 -0
  38. package/lib/module/utils/string.js.map +1 -0
  39. package/lib/module/utils/utils.js +15 -0
  40. package/lib/module/utils/utils.js.map +1 -0
  41. package/lib/typescript/src/hooks/index.d.ts +3 -0
  42. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  43. package/lib/typescript/src/hooks/usePagination.d.ts +14 -0
  44. package/lib/typescript/src/hooks/usePagination.d.ts.map +1 -0
  45. package/lib/typescript/src/hooks/useTimer.d.ts +14 -0
  46. package/lib/typescript/src/hooks/useTimer.d.ts.map +1 -0
  47. package/lib/typescript/src/index.d.ts +3 -0
  48. package/lib/typescript/src/index.d.ts.map +1 -0
  49. package/lib/typescript/src/utils/index.d.ts +5 -0
  50. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  51. package/lib/typescript/src/utils/object.d.ts +5 -0
  52. package/lib/typescript/src/utils/object.d.ts.map +1 -0
  53. package/lib/typescript/src/utils/responsive.d.ts +8 -0
  54. package/lib/typescript/src/utils/responsive.d.ts.map +1 -0
  55. package/lib/typescript/src/utils/string.d.ts +11 -0
  56. package/lib/typescript/src/utils/string.d.ts.map +1 -0
  57. package/lib/typescript/src/utils/utils.d.ts +8 -0
  58. package/lib/typescript/src/utils/utils.d.ts.map +1 -0
  59. package/package.json +180 -0
  60. package/src/hooks/index.ts +2 -0
  61. package/src/hooks/usePagination.tsx +42 -0
  62. package/src/hooks/useTimer.tsx +63 -0
  63. package/src/index.tsx +2 -0
  64. package/src/utils/index.ts +4 -0
  65. package/src/utils/object.tsx +32 -0
  66. package/src/utils/responsive.tsx +31 -0
  67. package/src/utils/string.tsx +73 -0
  68. package/src/utils/utils.tsx +21 -0
@@ -0,0 +1,46 @@
1
+ function isEmpty(text) {
2
+ if (!text) {
3
+ return true;
4
+ }
5
+ const value = text;
6
+ return /^\s*$/.test(value);
7
+ }
8
+ function isNotEmpty(text) {
9
+ return !isEmpty(text);
10
+ }
11
+ function byteArrayToString(byteArray) {
12
+ let result = '';
13
+ for (let i = 0; i < byteArray.length; i++) {
14
+ if (!byteArray[i]) {
15
+ continue;
16
+ }
17
+ result += String.fromCharCode(byteArray[i]);
18
+ }
19
+ return result;
20
+ }
21
+ function stringToByteArray(data) {
22
+ const arrayBuffer = new ArrayBuffer(data.length * 1);
23
+ const newUint = new Uint8Array(arrayBuffer);
24
+ newUint.forEach((_, i) => {
25
+ newUint[i] = data.charCodeAt(i);
26
+ });
27
+ return newUint;
28
+ }
29
+ function base64ToString(input) {
30
+ return Buffer?.from(input, 'base64').toString('utf8');
31
+ }
32
+ function stringToBase64(input) {
33
+ return Buffer?.from(input, 'utf8').toString('base64');
34
+ }
35
+ function removeNullCharactorsFromText(text) {
36
+ const alphaNumericRegex = new RegExp(/[^a-z0-9]/gi);
37
+ return text?.replaceAll('\0', '')?.replaceAll('%s', '')?.replace(alphaNumericRegex, '');
38
+ }
39
+ function convertStringToNumber(value) {
40
+ return !isEmpty(value) ? parseFloat(value) : undefined;
41
+ }
42
+ function splitString(text, splitBy) {
43
+ return text.split(splitBy);
44
+ }
45
+ export { isEmpty, isNotEmpty, byteArrayToString, stringToByteArray, base64ToString, stringToBase64, removeNullCharactorsFromText, convertStringToNumber, splitString };
46
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isEmpty","text","value","test","isNotEmpty","byteArrayToString","byteArray","result","i","length","String","fromCharCode","stringToByteArray","data","arrayBuffer","ArrayBuffer","newUint","Uint8Array","forEach","_","charCodeAt","base64ToString","input","Buffer","from","toString","stringToBase64","removeNullCharactorsFromText","alphaNumericRegex","RegExp","replaceAll","replace","convertStringToNumber","parseFloat","undefined","splitString","splitBy","split"],"sourceRoot":"../../../src","sources":["utils/string.tsx"],"mappings":"AAAA,SAASA,OAAOA,CAACC,IAAa,EAAW;EACvC,IAAI,CAACA,IAAI,EAAE;IACT,OAAO,IAAI;EACb;EAEA,MAAMC,KAAa,GAAGD,IAAc;EAEpC,OAAO,OAAO,CAACE,IAAI,CAACD,KAAK,CAAC;AAC5B;AAEA,SAASE,UAAUA,CAACH,IAAa,EAAW;EAC1C,OAAO,CAACD,OAAO,CAACC,IAAI,CAAC;AACvB;AAEA,SAASI,iBAAiBA,CAACC,SAAwB,EAAU;EAC3D,IAAIC,MAAM,GAAG,EAAE;EAEf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,SAAS,CAACG,MAAM,EAAED,CAAC,EAAE,EAAE;IACzC,IAAI,CAACF,SAAS,CAACE,CAAC,CAAC,EAAE;MACjB;IACF;IAEAD,MAAM,IAAIG,MAAM,CAACC,YAAY,CAACL,SAAS,CAACE,CAAC,CAAW,CAAC;EACvD;EAEA,OAAOD,MAAM;AACf;AAEA,SAASK,iBAAiBA,CAACC,IAAY,EAAc;EACnD,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAACF,IAAI,CAACJ,MAAM,GAAG,CAAC,CAAC;EACpD,MAAMO,OAAO,GAAG,IAAIC,UAAU,CAACH,WAAW,CAAC;EAC3CE,OAAO,CAACE,OAAO,CAAC,CAACC,CAAC,EAAEX,CAAC,KAAK;IACxBQ,OAAO,CAACR,CAAC,CAAC,GAAGK,IAAI,CAACO,UAAU,CAACZ,CAAC,CAAC;EACjC,CAAC,CAAC;EAEF,OAAOQ,OAAO;AAChB;AAEA,SAASK,cAAcA,CAACC,KAAa,EAAU;EAC7C,OAAOC,MAAM,EAAEC,IAAI,CAACF,KAAK,EAAE,QAAQ,CAAC,CAACG,QAAQ,CAAC,MAAM,CAAC;AACvD;AAEA,SAASC,cAAcA,CAACJ,KAAa,EAAU;EAC7C,OAAOC,MAAM,EAAEC,IAAI,CAACF,KAAK,EAAE,MAAM,CAAC,CAACG,QAAQ,CAAC,QAAQ,CAAC;AACvD;AAEA,SAASE,4BAA4BA,CAAC1B,IAAY,EAAE;EAClD,MAAM2B,iBAAiB,GAAG,IAAIC,MAAM,CAAC,aAAa,CAAC;EACnD,OAAO5B,IAAI,EACP6B,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EACpBA,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EACpBC,OAAO,CAACH,iBAAiB,EAAE,EAAE,CAAC;AACpC;AAEA,SAASI,qBAAqBA,CAAC9B,KAAa,EAAsB;EAChE,OAAO,CAACF,OAAO,CAACE,KAAK,CAAC,GAAG+B,UAAU,CAAC/B,KAAK,CAAC,GAAGgC,SAAS;AACxD;AAEA,SAASC,WAAWA,CAAClC,IAAY,EAAEmC,OAAe,EAAiB;EACjE,OAAOnC,IAAI,CAACoC,KAAK,CAACD,OAAO,CAAC;AAC5B;AAEA,SACEpC,OAAO,EACPI,UAAU,EACVC,iBAAiB,EACjBO,iBAAiB,EACjBS,cAAc,EACdK,cAAc,EACdC,4BAA4B,EAC5BK,qBAAqB,EACrBG,WAAW","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import { Vibration, Linking } from 'react-native';
2
+ function generateRandomNumber(n) {
3
+ return Math.floor(Math.random() * (9 * Math.pow(10, n - 1))) + Math.pow(10, n - 1);
4
+ }
5
+ function sleep(ms) {
6
+ return new Promise(resolve => setTimeout(resolve, ms));
7
+ }
8
+ function makeVibration() {
9
+ Vibration.vibrate();
10
+ }
11
+ async function makeCall(args) {
12
+ await Linking.openURL(`tel:${args?.number}`);
13
+ }
14
+ export { generateRandomNumber, sleep, makeVibration, makeCall };
15
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Vibration","Linking","generateRandomNumber","n","Math","floor","random","pow","sleep","ms","Promise","resolve","setTimeout","makeVibration","vibrate","makeCall","args","openURL","number"],"sourceRoot":"../../../src","sources":["utils/utils.tsx"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,cAAc;AAEjD,SAASC,oBAAoBA,CAACC,CAAS,EAAU;EAC/C,OACEC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAGF,IAAI,CAACG,GAAG,CAAC,EAAE,EAAEJ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAGC,IAAI,CAACG,GAAG,CAAC,EAAE,EAAEJ,CAAC,GAAG,CAAC,CAAC;AAE/E;AAEA,SAASK,KAAKA,CAACC,EAAU,EAAE;EACzB,OAAO,IAAIC,OAAO,CAAEC,OAAO,IAAKC,UAAU,CAACD,OAAO,EAAEF,EAAE,CAAC,CAAC;AAC1D;AAEA,SAASI,aAAaA,CAAA,EAAS;EAC7Bb,SAAS,CAACc,OAAO,CAAC,CAAC;AACrB;AAEA,eAAeC,QAAQA,CAACC,IAAyB,EAAiB;EAChE,MAAMf,OAAO,CAACgB,OAAO,CAAC,OAAOD,IAAI,EAAEE,MAAM,EAAE,CAAC;AAC9C;AAEA,SAAShB,oBAAoB,EAAEM,KAAK,EAAEK,aAAa,EAAEE,QAAQ","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from './usePagination';
2
+ export * from './useTimer';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
@@ -0,0 +1,14 @@
1
+ interface UsePaginationReturns {
2
+ hasMore: boolean;
3
+ nextCursor?: number;
4
+ previousCursor?: number;
5
+ }
6
+ interface UsePaginationProps {
7
+ totalCount: number;
8
+ itemsPerPage: number;
9
+ currentCursor: number;
10
+ }
11
+ declare function usePagination(props: UsePaginationProps): UsePaginationReturns;
12
+ export type { UsePaginationProps, UsePaginationReturns };
13
+ export { usePagination };
14
+ //# sourceMappingURL=usePagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePagination.d.ts","sourceRoot":"","sources":["../../../../src/hooks/usePagination.tsx"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,kBAAkB;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,oBAAoB,CA0BtE;AAED,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ interface UseTimerReturns {
2
+ days: number;
3
+ hours: number;
4
+ minutes: number;
5
+ seconds: number;
6
+ }
7
+ interface UseTimerProps {
8
+ targetDate?: number;
9
+ timeInterval?: number;
10
+ }
11
+ declare function useTimer(props?: UseTimerProps): UseTimerReturns;
12
+ export type { UseTimerProps, UseTimerReturns };
13
+ export { useTimer };
14
+ //# sourceMappingURL=useTimer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTimer.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTimer.tsx"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,iBAAS,QAAQ,CACf,KAAK,GAAE,aAAqC,GAC3C,eAAe,CA2CjB;AAED,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './utils';
2
+ export * from './hooks';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './string';
2
+ export * from './object';
3
+ export * from './utils';
4
+ export * from './responsive';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ declare function mergeObjects(...data: Array<unknown>): unknown;
2
+ declare function structuredClone(object: unknown): unknown;
3
+ declare function trimObjectValues(data: unknown): Record<string, unknown>;
4
+ export { mergeObjects, structuredClone, trimObjectValues };
5
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../src/utils/object.tsx"],"names":[],"mappings":"AAEA,iBAAS,YAAY,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAEtD;AAED,iBAAS,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjD;AAED,iBAAS,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBhE;AAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare function responsiveHeight(size: number): number;
2
+ declare function responsiveSize(size: number): number;
3
+ declare const responsive: {
4
+ height: typeof responsiveHeight;
5
+ size: typeof responsiveSize;
6
+ };
7
+ export { responsive };
8
+ //# sourceMappingURL=responsive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responsive.d.ts","sourceRoot":"","sources":["../../../../src/utils/responsive.tsx"],"names":[],"mappings":"AAoBA,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,QAAA,MAAM,UAAU;;;CAAqD,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ declare function isEmpty(text: unknown): boolean;
2
+ declare function isNotEmpty(text: unknown): boolean;
3
+ declare function byteArrayToString(byteArray: Array<number>): string;
4
+ declare function stringToByteArray(data: string): Uint8Array;
5
+ declare function base64ToString(input: string): string;
6
+ declare function stringToBase64(input: string): string;
7
+ declare function removeNullCharactorsFromText(text: string): string;
8
+ declare function convertStringToNumber(value: string): number | undefined;
9
+ declare function splitString(text: string, splitBy: string): Array<string>;
10
+ export { isEmpty, isNotEmpty, byteArrayToString, stringToByteArray, base64ToString, stringToBase64, removeNullCharactorsFromText, convertStringToNumber, splitString, };
11
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../../src/utils/string.tsx"],"names":[],"mappings":"AAAA,iBAAS,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAQvC;AAED,iBAAS,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAE1C;AAED,iBAAS,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAY3D;AAED,iBAAS,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAQnD;AAED,iBAAS,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,iBAAS,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,iBAAS,4BAA4B,CAAC,IAAI,EAAE,MAAM,UAMjD;AAED,iBAAS,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAEjE;AAED,OAAO,EACL,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,qBAAqB,EACrB,WAAW,GACZ,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare function generateRandomNumber(n: number): number;
2
+ declare function sleep(ms: number): Promise<unknown>;
3
+ declare function makeVibration(): void;
4
+ declare function makeCall(args: {
5
+ number?: string;
6
+ }): Promise<void>;
7
+ export { generateRandomNumber, sleep, makeVibration, makeCall };
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/utils/utils.tsx"],"names":[],"mappings":"AAEA,iBAAS,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED,iBAAS,KAAK,CAAC,EAAE,EAAE,MAAM,oBAExB;AAED,iBAAS,aAAa,IAAI,IAAI,CAE7B;AAED,iBAAe,QAAQ,CAAC,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,180 @@
1
+ {
2
+ "name": "@rnpack/utils",
3
+ "version": "0.1.0",
4
+ "description": "Basic utilities will be available and ready to use",
5
+ "source": "./src/index.tsx",
6
+ "main": "./lib/commonjs/index.js",
7
+ "module": "./lib/module/index.js",
8
+ "types": "./lib/typescript/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/typescript/src/index.d.ts",
12
+ "import": "./lib/module/index.js",
13
+ "require": "./lib/commonjs/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "src",
18
+ "lib",
19
+ "android",
20
+ "ios",
21
+ "cpp",
22
+ "*.podspec",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace @rnpack/utils-example",
36
+ "test": "jest",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "clean": "del-cli lib",
40
+ "prepare": "bob build",
41
+ "release": "release-it"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/rnpack/utils.git"
51
+ },
52
+ "author": "Abiraman K <abiramancit@gmail.com> (https://github.com/AbiramanK)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/rnpack/utils/issues"
56
+ },
57
+ "homepage": "https://github.com/rnpack/utils#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^17.0.2",
63
+ "@evilmartians/lefthook": "^1.5.0",
64
+ "@react-native/eslint-config": "^0.73.1",
65
+ "@release-it/conventional-changelog": "^5.0.0",
66
+ "@types/jest": "^29.5.5",
67
+ "@types/react": "^18.2.44",
68
+ "commitlint": "^17.0.2",
69
+ "del-cli": "^5.1.0",
70
+ "eslint": "^8.51.0",
71
+ "eslint-config-prettier": "^9.0.0",
72
+ "eslint-plugin-prettier": "^5.0.1",
73
+ "jest": "^29.7.0",
74
+ "prettier": "^3.0.3",
75
+ "react": "18.2.0",
76
+ "react-native": "0.74.3",
77
+ "react-native-builder-bob": "^0.26.0",
78
+ "release-it": "^15.0.0",
79
+ "typescript": "^5.2.2"
80
+ },
81
+ "resolutions": {
82
+ "@types/react": "^18.2.44"
83
+ },
84
+ "peerDependencies": {
85
+ "react": "*",
86
+ "react-native": "*"
87
+ },
88
+ "workspaces": [
89
+ "example"
90
+ ],
91
+ "packageManager": "yarn@3.6.1",
92
+ "jest": {
93
+ "preset": "react-native",
94
+ "modulePathIgnorePatterns": [
95
+ "<rootDir>/example/node_modules",
96
+ "<rootDir>/lib/"
97
+ ]
98
+ },
99
+ "commitlint": {
100
+ "extends": [
101
+ "@commitlint/config-conventional"
102
+ ]
103
+ },
104
+ "release-it": {
105
+ "git": {
106
+ "commitMessage": "chore: release ${version}",
107
+ "tagName": "v${version}"
108
+ },
109
+ "npm": {
110
+ "publish": true
111
+ },
112
+ "github": {
113
+ "release": true
114
+ },
115
+ "plugins": {
116
+ "@release-it/conventional-changelog": {
117
+ "preset": "angular"
118
+ }
119
+ }
120
+ },
121
+ "eslintConfig": {
122
+ "root": true,
123
+ "extends": [
124
+ "@react-native",
125
+ "prettier"
126
+ ],
127
+ "rules": {
128
+ "react/react-in-jsx-scope": "off",
129
+ "prettier/prettier": [
130
+ "error",
131
+ {
132
+ "quoteProps": "consistent",
133
+ "singleQuote": true,
134
+ "tabWidth": 2,
135
+ "trailingComma": "es5",
136
+ "useTabs": false
137
+ }
138
+ ]
139
+ }
140
+ },
141
+ "eslintIgnore": [
142
+ "node_modules/",
143
+ "lib/"
144
+ ],
145
+ "prettier": {
146
+ "quoteProps": "consistent",
147
+ "singleQuote": true,
148
+ "tabWidth": 2,
149
+ "trailingComma": "es5",
150
+ "useTabs": false
151
+ },
152
+ "react-native-builder-bob": {
153
+ "source": "src",
154
+ "output": "lib",
155
+ "targets": [
156
+ [
157
+ "commonjs",
158
+ {
159
+ "esm": true
160
+ }
161
+ ],
162
+ [
163
+ "module",
164
+ {
165
+ "esm": true
166
+ }
167
+ ],
168
+ [
169
+ "typescript",
170
+ {
171
+ "project": "tsconfig.build.json"
172
+ }
173
+ ]
174
+ ]
175
+ },
176
+ "create-react-native-library": {
177
+ "type": "library",
178
+ "version": "0.38.2"
179
+ }
180
+ }
@@ -0,0 +1,2 @@
1
+ export * from './usePagination';
2
+ export * from './useTimer';
@@ -0,0 +1,42 @@
1
+ interface UsePaginationReturns {
2
+ hasMore: boolean;
3
+ nextCursor?: number;
4
+ previousCursor?: number;
5
+ }
6
+
7
+ interface UsePaginationProps {
8
+ totalCount: number;
9
+ itemsPerPage: number;
10
+ currentCursor: number;
11
+ }
12
+
13
+ function usePagination(props: UsePaginationProps): UsePaginationReturns {
14
+ let hasMore = false;
15
+ let currentCursor = props?.currentCursor;
16
+ let nextCursor;
17
+ let previousCursor;
18
+
19
+ let totalPages = Math.trunc(props?.totalCount / props?.itemsPerPage);
20
+
21
+ if (props?.totalCount % props?.itemsPerPage > 0) {
22
+ totalPages += 1;
23
+ }
24
+
25
+ if (props?.currentCursor < totalPages) {
26
+ hasMore = true;
27
+ nextCursor = ++currentCursor;
28
+ }
29
+
30
+ if (props?.currentCursor > 1) {
31
+ previousCursor = props?.currentCursor - 1;
32
+ }
33
+
34
+ return {
35
+ hasMore,
36
+ nextCursor,
37
+ previousCursor,
38
+ };
39
+ }
40
+
41
+ export type { UsePaginationProps, UsePaginationReturns };
42
+ export { usePagination };
@@ -0,0 +1,63 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+
3
+ interface UseTimerReturns {
4
+ days: number;
5
+ hours: number;
6
+ minutes: number;
7
+ seconds: number;
8
+ }
9
+
10
+ interface UseTimerProps {
11
+ targetDate?: number;
12
+ timeInterval?: number;
13
+ }
14
+
15
+ function useTimer(
16
+ props: UseTimerProps = { timeInterval: 100 }
17
+ ): UseTimerReturns {
18
+ const today = new Date();
19
+ const todayUnix = today?.getTime();
20
+
21
+ const timeIntervalRef = useRef<NodeJS.Timeout>();
22
+
23
+ const durationDate = useMemo(
24
+ () => (props?.targetDate ? new Date(props?.targetDate) : new Date()),
25
+ [props?.targetDate]
26
+ );
27
+
28
+ const durationDateUnix = durationDate?.getTime();
29
+
30
+ const [timer, setTimer] = useState(durationDateUnix - todayUnix);
31
+
32
+ useEffect(() => {
33
+ const timeDifference = durationDateUnix - todayUnix;
34
+
35
+ if (timeDifference > 0) {
36
+ timeIntervalRef.current = setInterval(() => {
37
+ setTimer(durationDateUnix - todayUnix);
38
+ }, props?.timeInterval);
39
+ } else {
40
+ if (timeIntervalRef?.current) {
41
+ clearInterval(timeIntervalRef?.current);
42
+ }
43
+ }
44
+
45
+ return () => clearInterval(timeIntervalRef?.current);
46
+ }, [durationDateUnix, durationDate, props?.timeInterval, todayUnix]);
47
+
48
+ const getReturnValues = useCallback(() => {
49
+ const days = Math.floor(timer / (1000 * 60 * 60 * 24));
50
+ const hours = Math.floor(
51
+ (timer % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
52
+ );
53
+ const minutes = Math.floor((timer % (1000 * 60 * 60)) / (1000 * 60));
54
+ const seconds = Math.floor((timer % (1000 * 60)) / 1000);
55
+
56
+ return { days, hours, minutes, seconds };
57
+ }, [timer]);
58
+
59
+ return getReturnValues();
60
+ }
61
+
62
+ export type { UseTimerProps, UseTimerReturns };
63
+ export { useTimer };
package/src/index.tsx ADDED
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ export * from './hooks';
@@ -0,0 +1,4 @@
1
+ export * from './string';
2
+ export * from './object';
3
+ export * from './utils';
4
+ export * from './responsive';
@@ -0,0 +1,32 @@
1
+ import { isEmpty } from './string';
2
+
3
+ function mergeObjects(...data: Array<unknown>): unknown {
4
+ return Object.assign({}, ...data);
5
+ }
6
+
7
+ function structuredClone(object: unknown): unknown {
8
+ return JSON.parse(JSON.stringify(object));
9
+ }
10
+
11
+ function trimObjectValues(data: unknown): Record<string, unknown> {
12
+ const value: Record<string, unknown> = data as Record<string, unknown>;
13
+
14
+ Object.keys(value).forEach((key) => {
15
+ switch (typeof value[key]) {
16
+ case 'string':
17
+ value[key] = isEmpty(value[key]) ? '' : value[key]?.trim();
18
+ break;
19
+
20
+ case 'object':
21
+ value[key] = trimObjectValues(value[key]);
22
+ break;
23
+
24
+ default:
25
+ break;
26
+ }
27
+ });
28
+
29
+ return value;
30
+ }
31
+
32
+ export { mergeObjects, structuredClone, trimObjectValues };
@@ -0,0 +1,31 @@
1
+ import { Dimensions, Platform, StatusBar } from 'react-native';
2
+
3
+ const { width, height } = Dimensions.get('window');
4
+ const [shortDimension, longDimension] =
5
+ width < height ? [width, height] : [height, width];
6
+
7
+ // Default guideline sizes are based on standard ~5" screen mobile device (375*812)
8
+ // Dimentions - for a global reference taking iphone 6/6s/7/8 (375*667)
9
+ // Also SSK XD design width is 375*812
10
+
11
+ const guidelineBaseWidth = 375;
12
+ let guidelineBaseHeight = 812;
13
+ if (Platform.OS === 'android') {
14
+ const hgt = StatusBar.currentHeight;
15
+
16
+ if (hgt !== undefined) {
17
+ guidelineBaseHeight = guidelineBaseHeight + hgt;
18
+ }
19
+ }
20
+
21
+ function responsiveHeight(size: number): number {
22
+ return (longDimension / guidelineBaseHeight) * size;
23
+ }
24
+
25
+ function responsiveSize(size: number): number {
26
+ return (shortDimension / guidelineBaseWidth) * size;
27
+ }
28
+
29
+ const responsive = { height: responsiveHeight, size: responsiveSize };
30
+
31
+ export { responsive };
@@ -0,0 +1,73 @@
1
+ function isEmpty(text: unknown): boolean {
2
+ if (!text) {
3
+ return true;
4
+ }
5
+
6
+ const value: string = text as string;
7
+
8
+ return /^\s*$/.test(value);
9
+ }
10
+
11
+ function isNotEmpty(text: unknown): boolean {
12
+ return !isEmpty(text);
13
+ }
14
+
15
+ function byteArrayToString(byteArray: Array<number>): string {
16
+ let result = '';
17
+
18
+ for (let i = 0; i < byteArray.length; i++) {
19
+ if (!byteArray[i]) {
20
+ continue;
21
+ }
22
+
23
+ result += String.fromCharCode(byteArray[i] as number);
24
+ }
25
+
26
+ return result;
27
+ }
28
+
29
+ function stringToByteArray(data: string): Uint8Array {
30
+ const arrayBuffer = new ArrayBuffer(data.length * 1);
31
+ const newUint = new Uint8Array(arrayBuffer);
32
+ newUint.forEach((_, i) => {
33
+ newUint[i] = data.charCodeAt(i);
34
+ });
35
+
36
+ return newUint;
37
+ }
38
+
39
+ function base64ToString(input: string): string {
40
+ return Buffer?.from(input, 'base64').toString('utf8');
41
+ }
42
+
43
+ function stringToBase64(input: string): string {
44
+ return Buffer?.from(input, 'utf8').toString('base64');
45
+ }
46
+
47
+ function removeNullCharactorsFromText(text: string) {
48
+ const alphaNumericRegex = new RegExp(/[^a-z0-9]/gi);
49
+ return text
50
+ ?.replaceAll('\0', '')
51
+ ?.replaceAll('%s', '')
52
+ ?.replace(alphaNumericRegex, '');
53
+ }
54
+
55
+ function convertStringToNumber(value: string): number | undefined {
56
+ return !isEmpty(value) ? parseFloat(value) : undefined;
57
+ }
58
+
59
+ function splitString(text: string, splitBy: string): Array<string> {
60
+ return text.split(splitBy);
61
+ }
62
+
63
+ export {
64
+ isEmpty,
65
+ isNotEmpty,
66
+ byteArrayToString,
67
+ stringToByteArray,
68
+ base64ToString,
69
+ stringToBase64,
70
+ removeNullCharactorsFromText,
71
+ convertStringToNumber,
72
+ splitString,
73
+ };
@@ -0,0 +1,21 @@
1
+ import { Vibration, Linking } from 'react-native';
2
+
3
+ function generateRandomNumber(n: number): number {
4
+ return (
5
+ Math.floor(Math.random() * (9 * Math.pow(10, n - 1))) + Math.pow(10, n - 1)
6
+ );
7
+ }
8
+
9
+ function sleep(ms: number) {
10
+ return new Promise((resolve) => setTimeout(resolve, ms));
11
+ }
12
+
13
+ function makeVibration(): void {
14
+ Vibration.vibrate();
15
+ }
16
+
17
+ async function makeCall(args: { number?: string }): Promise<void> {
18
+ await Linking.openURL(`tel:${args?.number}`);
19
+ }
20
+
21
+ export { generateRandomNumber, sleep, makeVibration, makeCall };