reactnatively-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.

Potentially problematic release.


This version of reactnatively-utils might be problematic. Click here for more details.

package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Hakizimana Fred
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,61 @@
1
+ import { ElementType, ComponentPropsWithRef, ReactNode } from 'react';
2
+ export { ReactNode } from 'react';
3
+
4
+ declare function deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T;
5
+ declare function shallowMerge<T extends object>(target: T, source: Partial<T>): T;
6
+
7
+ declare const IS_IOS: boolean;
8
+ declare const IS_ANDROID: boolean;
9
+ declare const IS_WEB: boolean;
10
+ declare const IS_NATIVE: boolean;
11
+ declare function getAndroidVersion(): number;
12
+ declare function platformSelect<T>(options: {
13
+ ios?: T;
14
+ android?: T;
15
+ web?: T;
16
+ default: T;
17
+ }): T;
18
+
19
+ declare function defineVariants<V extends string, T>(map: Record<V, T>): (variant: V) => T;
20
+ declare function defineCompoundVariants<Variants extends Record<string, string>, Output>(_variants: Variants, compound: Array<{
21
+ conditions: Partial<Variants>;
22
+ style: Output;
23
+ }>, defaultOutput: Output): (input: Partial<Variants>) => Output;
24
+
25
+ type AsProp<C extends ElementType> = {
26
+ as?: C;
27
+ };
28
+ type PropsToOmit<C extends ElementType, P> = keyof (AsProp<C> & P);
29
+ type PolymorphicComponentProp<C extends ElementType, Props = Record<string, never>> = React.PropsWithChildren<Props & AsProp<C>> & Omit<ComponentPropsWithRef<C>, PropsToOmit<C, Props>>;
30
+ type PolymorphicRef<C extends ElementType> = ComponentPropsWithRef<C>['ref'];
31
+ type PolymorphicComponentPropWithRef<C extends ElementType, Props = Record<string, never>> = PolymorphicComponentProp<C, Props> & {
32
+ ref?: PolymorphicRef<C>;
33
+ };
34
+
35
+ type DeepPartial<T> = T extends object ? {
36
+ [P in keyof T]?: DeepPartial<T[P]>;
37
+ } : T;
38
+ type DeepReadonly<T> = T extends object ? {
39
+ readonly [P in keyof T]: DeepReadonly<T[P]>;
40
+ } : T;
41
+ type ExtractKeys<T, K extends keyof T> = T[K];
42
+ type Prettify<T> = {
43
+ [K in keyof T]: T[K];
44
+ } & {};
45
+
46
+ interface WithChildren {
47
+ children?: ReactNode;
48
+ }
49
+ interface WithTestID {
50
+ testID?: string;
51
+ }
52
+ interface WithClassName {
53
+ className?: string;
54
+ }
55
+ type SizeScale = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
56
+ type ColorScheme = 'light' | 'dark';
57
+ type Orientation = 'horizontal' | 'vertical';
58
+ type Alignment = 'start' | 'center' | 'end' | 'stretch';
59
+ type Justify = 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly';
60
+
61
+ export { type Alignment, type ColorScheme, type DeepPartial, type DeepReadonly, type ExtractKeys, IS_ANDROID, IS_IOS, IS_NATIVE, IS_WEB, type Justify, type Orientation, type PolymorphicComponentProp, type PolymorphicComponentPropWithRef, type PolymorphicRef, type Prettify, type SizeScale, type WithChildren, type WithClassName, type WithTestID, deepMerge, defineCompoundVariants, defineVariants, getAndroidVersion, platformSelect, shallowMerge };
@@ -0,0 +1,61 @@
1
+ import { ElementType, ComponentPropsWithRef, ReactNode } from 'react';
2
+ export { ReactNode } from 'react';
3
+
4
+ declare function deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T;
5
+ declare function shallowMerge<T extends object>(target: T, source: Partial<T>): T;
6
+
7
+ declare const IS_IOS: boolean;
8
+ declare const IS_ANDROID: boolean;
9
+ declare const IS_WEB: boolean;
10
+ declare const IS_NATIVE: boolean;
11
+ declare function getAndroidVersion(): number;
12
+ declare function platformSelect<T>(options: {
13
+ ios?: T;
14
+ android?: T;
15
+ web?: T;
16
+ default: T;
17
+ }): T;
18
+
19
+ declare function defineVariants<V extends string, T>(map: Record<V, T>): (variant: V) => T;
20
+ declare function defineCompoundVariants<Variants extends Record<string, string>, Output>(_variants: Variants, compound: Array<{
21
+ conditions: Partial<Variants>;
22
+ style: Output;
23
+ }>, defaultOutput: Output): (input: Partial<Variants>) => Output;
24
+
25
+ type AsProp<C extends ElementType> = {
26
+ as?: C;
27
+ };
28
+ type PropsToOmit<C extends ElementType, P> = keyof (AsProp<C> & P);
29
+ type PolymorphicComponentProp<C extends ElementType, Props = Record<string, never>> = React.PropsWithChildren<Props & AsProp<C>> & Omit<ComponentPropsWithRef<C>, PropsToOmit<C, Props>>;
30
+ type PolymorphicRef<C extends ElementType> = ComponentPropsWithRef<C>['ref'];
31
+ type PolymorphicComponentPropWithRef<C extends ElementType, Props = Record<string, never>> = PolymorphicComponentProp<C, Props> & {
32
+ ref?: PolymorphicRef<C>;
33
+ };
34
+
35
+ type DeepPartial<T> = T extends object ? {
36
+ [P in keyof T]?: DeepPartial<T[P]>;
37
+ } : T;
38
+ type DeepReadonly<T> = T extends object ? {
39
+ readonly [P in keyof T]: DeepReadonly<T[P]>;
40
+ } : T;
41
+ type ExtractKeys<T, K extends keyof T> = T[K];
42
+ type Prettify<T> = {
43
+ [K in keyof T]: T[K];
44
+ } & {};
45
+
46
+ interface WithChildren {
47
+ children?: ReactNode;
48
+ }
49
+ interface WithTestID {
50
+ testID?: string;
51
+ }
52
+ interface WithClassName {
53
+ className?: string;
54
+ }
55
+ type SizeScale = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
56
+ type ColorScheme = 'light' | 'dark';
57
+ type Orientation = 'horizontal' | 'vertical';
58
+ type Alignment = 'start' | 'center' | 'end' | 'stretch';
59
+ type Justify = 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly';
60
+
61
+ export { type Alignment, type ColorScheme, type DeepPartial, type DeepReadonly, type ExtractKeys, IS_ANDROID, IS_IOS, IS_NATIVE, IS_WEB, type Justify, type Orientation, type PolymorphicComponentProp, type PolymorphicComponentPropWithRef, type PolymorphicRef, type Prettify, type SizeScale, type WithChildren, type WithClassName, type WithTestID, deepMerge, defineCompoundVariants, defineVariants, getAndroidVersion, platformSelect, shallowMerge };
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var reactNative = require('react-native');
4
+
5
+ // src/merge.ts
6
+ function isPlainObject(val) {
7
+ return typeof val === "object" && val !== null && !Array.isArray(val);
8
+ }
9
+ function deepMerge(target, source) {
10
+ const result = { ...target };
11
+ for (const key in source) {
12
+ const sourceVal = source[key];
13
+ const targetVal = result[key];
14
+ if (sourceVal === void 0) continue;
15
+ if (isPlainObject(sourceVal) && isPlainObject(targetVal)) {
16
+ result[key] = deepMerge(
17
+ targetVal,
18
+ sourceVal
19
+ );
20
+ } else {
21
+ result[key] = sourceVal;
22
+ }
23
+ }
24
+ return result;
25
+ }
26
+ function shallowMerge(target, source) {
27
+ return { ...target, ...source };
28
+ }
29
+ var IS_IOS = reactNative.Platform.OS === "ios";
30
+ var IS_ANDROID = reactNative.Platform.OS === "android";
31
+ var IS_WEB = reactNative.Platform.OS === "web";
32
+ var IS_NATIVE = IS_IOS || IS_ANDROID;
33
+ function getAndroidVersion() {
34
+ if (!IS_ANDROID) return 0;
35
+ return typeof reactNative.Platform.Version === "number" ? reactNative.Platform.Version : parseInt(reactNative.Platform.Version, 10);
36
+ }
37
+ function platformSelect(options) {
38
+ if (IS_IOS && options.ios !== void 0) return options.ios;
39
+ if (IS_ANDROID && options.android !== void 0) return options.android;
40
+ if (IS_WEB && options.web !== void 0) return options.web;
41
+ return options.default;
42
+ }
43
+
44
+ // src/variants.ts
45
+ function defineVariants(map) {
46
+ return function resolve(variant) {
47
+ const result = map[variant];
48
+ if (result === void 0) {
49
+ throw new Error(`Unknown variant: "${variant}". Valid variants: ${Object.keys(map).join(", ")}`);
50
+ }
51
+ return result;
52
+ };
53
+ }
54
+ function defineCompoundVariants(_variants, compound, defaultOutput) {
55
+ return (input) => {
56
+ for (const { conditions, style } of compound) {
57
+ const match = Object.entries(conditions).every(
58
+ ([k, v]) => input[k] === v
59
+ );
60
+ if (match) return style;
61
+ }
62
+ return defaultOutput;
63
+ };
64
+ }
65
+
66
+ exports.IS_ANDROID = IS_ANDROID;
67
+ exports.IS_IOS = IS_IOS;
68
+ exports.IS_NATIVE = IS_NATIVE;
69
+ exports.IS_WEB = IS_WEB;
70
+ exports.deepMerge = deepMerge;
71
+ exports.defineCompoundVariants = defineCompoundVariants;
72
+ exports.defineVariants = defineVariants;
73
+ exports.getAndroidVersion = getAndroidVersion;
74
+ exports.platformSelect = platformSelect;
75
+ exports.shallowMerge = shallowMerge;
76
+ //# sourceMappingURL=index.js.map
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/merge.ts","../src/platform.ts","../src/variants.ts"],"names":["Platform"],"mappings":";;;;;AAAA,SAAS,cAAc,GAAA,EAA8C;AACnE,EAAA,OAAO,OAAO,QAAQ,QAAA,IAAY,GAAA,KAAQ,QAAQ,CAAC,KAAA,C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CAAQ,OAAA,KAAY,MAAA,SAAkB,OAAA,CAAQ,OAAA;AAChE,EAAA,IAAI,MAAA,IAAU,OAAA,CAAQ,GAAA,KAAQ,MAAA,SAAkB,OAAA,CAAQ,GAAA;AACxD,EAAA,OAAO,OAAA,CAAQ,OAAA;AACjB;;;ACxBO,SAAS,eAAoC,GAAA,EAAmB;AACrE,EAAA,OAAO,SAAS,QAAQ,OAAA,EAAe;AACrC,IAAA,MAAM,MAAA,GAAS,IAAI,OAAO,CAAA;AAC1B,IAAA,IAAI,WAAW,MAAA,EAAW;AACxB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,OAAO,CAAA,mBAAA,EAAsB,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,IACjG;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;AAEO,SAAS,sBAAA,CAId,SAAA,EACA,QAAA,EACA,aAAA,EACsC;AACtC,EAAA,OAAO,CAAC,KAAA,KAAU;AAChB,IAAA,KAAA,MAAW,EAAE,UAAA,EAAY,KAAA,EAAM,IAAK,QAAA,EAAU;AAC5C,MAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,CAAE,KAAA;AAAA,QACvC,CAAC,CAAC,CAAA,EAAG,CAAC,CAAA,KAAM,KAAA,CAAM,CAAmB,CAAA,KAAM;AAAA,OAC7C;AACA,MAAA,IAAI,OAAO,OAAO,KAAA;AAAA,IACpB;AACA,IAAA,OAAO,aAAA;AAAA,EACT,CAAA;AACF","file":"index.js","sourcesContent":["function isPlainObject(val: unknown): val is Record<string, unknown> {\n return typeof val === 'object' && val !== null && !Array.isArray(val);\n}\n\nexport function deepMerge<T extends Record<string, unknown>>(\n target: T,\n source: Partial<T>,\n): T {\n const result: Record<string, unknown> = { ...target };\n\n for (const key in source) {\n const sourceVal = source[key];\n const targetVal = result[key];\n\n if (sourceVal === undefined) continue;\n\n if (isPlainObject(sourceVal) && isPlainObject(targetVal)) {\n result[key] = deepMerge(\n targetVal as Record<string, unknown>,\n sourceVal as Record<string, unknown>,\n );\n } else {\n result[key] = sourceVal;\n }\n }\n\n return result as T;\n}\n\nexport function shallowMerge<T extends object>(target: T, source: Partial<T>): T {\n return { ...target, ...source };\n}\n","import { Platform } from 'react-native';\n\nexport const IS_IOS = Platform.OS === 'ios';\nexport const IS_ANDROID = Platform.OS === 'android';\nexport const IS_WEB = Platform.OS === 'web';\nexport const IS_NATIVE = IS_IOS || IS_ANDROID;\n\nexport function getAndroidVersion(): number {\n if (!IS_ANDROID) return 0;\n return typeof Platform.Version === 'number'\n ? Platform.Version\n : parseInt(Platform.Version as string, 10);\n}\n\nexport function platformSelect<T>(options: {\n ios?: T;\n android?: T;\n web?: T;\n default: T;\n}): T {\n if (IS_IOS && options.ios !== undefined) return options.ios;\n if (IS_ANDROID && options.android !== undefined) return options.android;\n if (IS_WEB && options.web !== undefined) return options.web;\n return options.default;\n}\n","export function defineVariants<V extends string, T>(map: Record<V, T>) {\n return function resolve(variant: V): T {\n const result = map[variant];\n if (result === undefined) {\n throw new Error(`Unknown variant: \"${variant}\". Valid variants: ${Object.keys(map).join(', ')}`);\n }\n return result;\n };\n}\n\nexport function defineCompoundVariants<\n Variants extends Record<string, string>,\n Output,\n>(\n _variants: Variants,\n compound: Array<{ conditions: Partial<Variants>; style: Output }>,\n defaultOutput: Output,\n): (input: Partial<Variants>) => Output {\n return (input) => {\n for (const { conditions, style } of compound) {\n const match = Object.entries(conditions).every(\n ([k, v]) => input[k as keyof Variants] === v,\n );\n if (match) return style;\n }\n return defaultOutput;\n };\n}\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ // src/merge.ts
4
+ function isPlainObject(val) {
5
+ return typeof val === "object" && val !== null && !Array.isArray(val);
6
+ }
7
+ function deepMerge(target, source) {
8
+ const result = { ...target };
9
+ for (const key in source) {
10
+ const sourceVal = source[key];
11
+ const targetVal = result[key];
12
+ if (sourceVal === void 0) continue;
13
+ if (isPlainObject(sourceVal) && isPlainObject(targetVal)) {
14
+ result[key] = deepMerge(
15
+ targetVal,
16
+ sourceVal
17
+ );
18
+ } else {
19
+ result[key] = sourceVal;
20
+ }
21
+ }
22
+ return result;
23
+ }
24
+ function shallowMerge(target, source) {
25
+ return { ...target, ...source };
26
+ }
27
+ var IS_IOS = Platform.OS === "ios";
28
+ var IS_ANDROID = Platform.OS === "android";
29
+ var IS_WEB = Platform.OS === "web";
30
+ var IS_NATIVE = IS_IOS || IS_ANDROID;
31
+ function getAndroidVersion() {
32
+ if (!IS_ANDROID) return 0;
33
+ return typeof Platform.Version === "number" ? Platform.Version : parseInt(Platform.Version, 10);
34
+ }
35
+ function platformSelect(options) {
36
+ if (IS_IOS && options.ios !== void 0) return options.ios;
37
+ if (IS_ANDROID && options.android !== void 0) return options.android;
38
+ if (IS_WEB && options.web !== void 0) return options.web;
39
+ return options.default;
40
+ }
41
+
42
+ // src/variants.ts
43
+ function defineVariants(map) {
44
+ return function resolve(variant) {
45
+ const result = map[variant];
46
+ if (result === void 0) {
47
+ throw new Error(`Unknown variant: "${variant}". Valid variants: ${Object.keys(map).join(", ")}`);
48
+ }
49
+ return result;
50
+ };
51
+ }
52
+ function defineCompoundVariants(_variants, compound, defaultOutput) {
53
+ return (input) => {
54
+ for (const { conditions, style } of compound) {
55
+ const match = Object.entries(conditions).every(
56
+ ([k, v]) => input[k] === v
57
+ );
58
+ if (match) return style;
59
+ }
60
+ return defaultOutput;
61
+ };
62
+ }
63
+
64
+ export { IS_ANDROID, IS_IOS, IS_NATIVE, IS_WEB, deepMerge, defineCompoundVariants, defineVariants, getAndroidVersion, platformSelect, shallowMerge };
65
+ //# sourceMappingURL=index.mjs.map
66
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/merge.ts","../src/platform.ts","../src/variants.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AA,IAAI,MAAA,IAAU,OAAA,CAAQ,GAAA,KAAQ,MAAA,SAAkB,OAAA,CAAQ,GAAA;AACxD,EAAA,IAAI,UAAA,IAAc,OAAA,CAAQ,OAAA,KAAY,MAAA,SAAkB,OAAA,CAAQ,OAAA;AAChE,EAAA,IAAI,MAAA,IAAU,OAAA,CAAQ,GAAA,KAAQ,MAAA,SAAkB,OAAA,CAAQ,GAAA;AACxD,EAAA,OAAO,OAAA,CAAQ,OAAA;AACjB;;;ACxBO,SAAS,eAAoC,GAAA,EAAmB;AACrE,EAAA,OAAO,SAAS,QAAQ,OAAA,EAAe;AACrC,IAAA,MAAM,MAAA,GAAS,IAAI,OAAO,CAAA;AAC1B,IAAA,IAAI,WAAW,MAAA,EAAW;AACxB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,OAAO,CAAA,mBAAA,EAAsB,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,IACjG;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;AAEO,SAAS,sBAAA,CAId,SAAA,EACA,QAAA,EACA,aAAA,EACsC;AACtC,EAAA,OAAO,CAAC,KAAA,KAAU;AAChB,IAAA,KAAA,MAAW,EAAE,UAAA,EAAY,KAAA,EAAM,IAAK,QAAA,EAAU;AAC5C,MAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,CAAE,KAAA;AAAA,QACvC,CAAC,CAAC,CAAA,EAAG,CAAC,CAAA,KAAM,KAAA,CAAM,CAAmB,CAAA,KAAM;AAAA,OAC7C;AACA,MAAA,IAAI,OAAO,OAAO,KAAA;AAAA,IACpB;AACA,IAAA,OAAO,aAAA;AAAA,EACT,CAAA;AACF","file":"index.mjs","sourcesContent":["function isPlainObject(val: unknown): val is Record<string, unknown> {\n return typeof val === 'object' && val !== null && !Array.isArray(val);\n}\n\nexport function deepMerge<T extends Record<string, unknown>>(\n target: T,\n source: Partial<T>,\n): T {\n const result: Record<string, unknown> = { ...target };\n\n for (const key in source) {\n const sourceVal = source[key];\n const targetVal = result[key];\n\n if (sourceVal === undefined) continue;\n\n if (isPlainObject(sourceVal) && isPlainObject(targetVal)) {\n result[key] = deepMerge(\n targetVal as Record<string, unknown>,\n sourceVal as Record<string, unknown>,\n );\n } else {\n result[key] = sourceVal;\n }\n }\n\n return result as T;\n}\n\nexport function shallowMerge<T extends object>(target: T, source: Partial<T>): T {\n return { ...target, ...source };\n}\n","import { Platform } from 'react-native';\n\nexport const IS_IOS = Platform.OS === 'ios';\nexport const IS_ANDROID = Platform.OS === 'android';\nexport const IS_WEB = Platform.OS === 'web';\nexport const IS_NATIVE = IS_IOS || IS_ANDROID;\n\nexport function getAndroidVersion(): number {\n if (!IS_ANDROID) return 0;\n return typeof Platform.Version === 'number'\n ? Platform.Version\n : parseInt(Platform.Version as string, 10);\n}\n\nexport function platformSelect<T>(options: {\n ios?: T;\n android?: T;\n web?: T;\n default: T;\n}): T {\n if (IS_IOS && options.ios !== undefined) return options.ios;\n if (IS_ANDROID && options.android !== undefined) return options.android;\n if (IS_WEB && options.web !== undefined) return options.web;\n return options.default;\n}\n","export function defineVariants<V extends string, T>(map: Record<V, T>) {\n return function resolve(variant: V): T {\n const result = map[variant];\n if (result === undefined) {\n throw new Error(`Unknown variant: \"${variant}\". Valid variants: ${Object.keys(map).join(', ')}`);\n }\n return result;\n };\n}\n\nexport function defineCompoundVariants<\n Variants extends Record<string, string>,\n Output,\n>(\n _variants: Variants,\n compound: Array<{ conditions: Partial<Variants>; style: Output }>,\n defaultOutput: Output,\n): (input: Partial<Variants>) => Output {\n return (input) => {\n for (const { conditions, style } of compound) {\n const match = Object.entries(conditions).every(\n ([k, v]) => input[k as keyof Variants] === v,\n );\n if (match) return style;\n }\n return defaultOutput;\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "reactnatively-utils",
3
+ "version": "0.1.0",
4
+ "description": "Shared utilities and TypeScript helpers for the Reactnatively framework",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "sideEffects": false,
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "peerDependencies": {
20
+ "react": ">=18.0.0",
21
+ "react-native": ">=0.73.0"
22
+ },
23
+ "devDependencies": {
24
+ "tsup": "^8.2.4",
25
+ "typescript": "^5.5.3",
26
+ "@reactnatively/tsconfig": "0.0.0"
27
+ },
28
+ "keywords": [
29
+ "react-native",
30
+ "expo",
31
+ "utils",
32
+ "helpers",
33
+ "typescript"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/hakizimana-fred/reactnatively.git",
38
+ "directory": "packages/utils"
39
+ },
40
+ "license": "MIT",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "dev": "tsup --watch",
47
+ "lint": "tsc --noEmit",
48
+ "typecheck": "tsc --noEmit",
49
+ "clean": "rm -rf dist"
50
+ }
51
+ }