react-native-calc-sdk 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.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # react-native-calc-sdk
2
+
3
+ React Native Calculator SDK - Simple arithmetic operations with ready-to-use components and hooks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install react-native-calc-sdk
9
+ # or
10
+ yarn add react-native-calc-sdk
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - Ready-to-use Calculator component
16
+ - `useCalculator` hook for custom UI
17
+ - Utility functions for arithmetic operations
18
+ - Full TypeScript support
19
+
20
+ ## Usage
21
+
22
+ ### Calculator Component
23
+
24
+ ```tsx
25
+ import { Calculator } from 'react-native-calc-sdk';
26
+
27
+ function App() {
28
+ return (
29
+ <Calculator
30
+ onResultChange={(result) => console.log('Result:', result)}
31
+ />
32
+ );
33
+ }
34
+ ```
35
+
36
+ #### Props
37
+
38
+ | Prop | Type | Description |
39
+ |------|------|-------------|
40
+ | `style` | `ViewStyle` | Container style |
41
+ | `buttonStyle` | `ViewStyle` | Operation button style |
42
+ | `buttonTextStyle` | `TextStyle` | Button text style |
43
+ | `inputStyle` | `ViewStyle` | Input field style |
44
+ | `resultStyle` | `TextStyle` | Result text style |
45
+ | `onResultChange` | `(result: number \| null) => void` | Callback when result changes |
46
+
47
+ ### useCalculator Hook
48
+
49
+ ```tsx
50
+ import { useCalculator } from 'react-native-calc-sdk';
51
+
52
+ function CustomCalculator() {
53
+ const calc = useCalculator();
54
+
55
+ return (
56
+ <View>
57
+ <Text>Value 1: {calc.value1}</Text>
58
+ <Text>Value 2: {calc.value2}</Text>
59
+ <Text>Result: {calc.result}</Text>
60
+
61
+ <Button title="Add" onPress={calc.add} />
62
+ <Button title="Subtract" onPress={calc.subtract} />
63
+ <Button title="Multiply" onPress={calc.multiply} />
64
+ <Button title="Divide" onPress={calc.divide} />
65
+ <Button title="Clear" onPress={calc.clear} />
66
+ </View>
67
+ );
68
+ }
69
+ ```
70
+
71
+ #### Returns
72
+
73
+ | Property | Type | Description |
74
+ |----------|------|-------------|
75
+ | `value1` | `number` | First operand |
76
+ | `value2` | `number` | Second operand |
77
+ | `result` | `number \| null` | Calculation result |
78
+ | `error` | `string \| null` | Error message |
79
+ | `setValue1` | `(value: number) => void` | Set first operand |
80
+ | `setValue2` | `(value: number) => void` | Set second operand |
81
+ | `add` | `() => void` | Add values |
82
+ | `subtract` | `() => void` | Subtract values |
83
+ | `multiply` | `() => void` | Multiply values |
84
+ | `divide` | `() => void` | Divide values |
85
+ | `execute` | `(operation: Operation) => void` | Execute operation |
86
+ | `clear` | `() => void` | Reset all values |
87
+
88
+ ### Utility Functions
89
+
90
+ ```tsx
91
+ import { add, subtract, multiply, divide, calculate } from 'react-native-calc-sdk';
92
+
93
+ add(5, 3); // 8
94
+ subtract(10, 4); // 6
95
+ multiply(3, 7); // 21
96
+ divide(20, 5); // 4
97
+
98
+ calculate(10, 2, 'add'); // 12
99
+ calculate(10, 2, 'subtract'); // 8
100
+ calculate(10, 2, 'multiply'); // 20
101
+ calculate(10, 2, 'divide'); // 5
102
+ ```
103
+
104
+ ## Requirements
105
+
106
+ - React >= 18.0.0
107
+ - React Native >= 0.70.0
108
+
109
+ ## License
110
+
111
+ MIT
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ViewStyle, TextStyle } from 'react-native';
3
+ export interface CalculatorProps {
4
+ style?: ViewStyle;
5
+ buttonStyle?: ViewStyle;
6
+ buttonTextStyle?: TextStyle;
7
+ inputStyle?: ViewStyle;
8
+ resultStyle?: TextStyle;
9
+ onResultChange?: (result: number | null) => void;
10
+ }
11
+ export declare function Calculator({ style, buttonStyle, buttonTextStyle, inputStyle, resultStyle, onResultChange, }: CalculatorProps): React.JSX.Element;
12
+ //# sourceMappingURL=Calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Calculator.d.ts","sourceRoot":"","sources":["../../src/components/Calculator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAML,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAClD;AAED,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,WAAW,EACX,eAAe,EACf,UAAU,EACV,WAAW,EACX,cAAc,GACf,EAAE,eAAe,qBAkEjB"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Calculator = Calculator;
7
+ const react_1 = __importDefault(require("react"));
8
+ const react_native_1 = require("react-native");
9
+ const useCalculator_1 = require("../hooks/useCalculator");
10
+ function Calculator({ style, buttonStyle, buttonTextStyle, inputStyle, resultStyle, onResultChange, }) {
11
+ const calc = (0, useCalculator_1.useCalculator)();
12
+ react_1.default.useEffect(() => {
13
+ onResultChange?.(calc.result);
14
+ }, [calc.result, onResultChange]);
15
+ const handleOperation = (op) => {
16
+ op();
17
+ };
18
+ return (<react_native_1.View style={[styles.container, style]}>
19
+ <react_native_1.TextInput style={[styles.input, inputStyle]} keyboardType="numeric" value={String(calc.value1)} onChangeText={(text) => calc.setValue1(Number(text) || 0)} placeholder="First number"/>
20
+
21
+ <react_native_1.TextInput style={[styles.input, inputStyle]} keyboardType="numeric" value={String(calc.value2)} onChangeText={(text) => calc.setValue2(Number(text) || 0)} placeholder="Second number"/>
22
+
23
+ <react_native_1.View style={styles.buttonRow}>
24
+ <react_native_1.TouchableOpacity style={[styles.button, buttonStyle]} onPress={() => handleOperation(calc.add)}>
25
+ <react_native_1.Text style={[styles.buttonText, buttonTextStyle]}>+</react_native_1.Text>
26
+ </react_native_1.TouchableOpacity>
27
+
28
+ <react_native_1.TouchableOpacity style={[styles.button, buttonStyle]} onPress={() => handleOperation(calc.subtract)}>
29
+ <react_native_1.Text style={[styles.buttonText, buttonTextStyle]}>−</react_native_1.Text>
30
+ </react_native_1.TouchableOpacity>
31
+
32
+ <react_native_1.TouchableOpacity style={[styles.button, buttonStyle]} onPress={() => handleOperation(calc.multiply)}>
33
+ <react_native_1.Text style={[styles.buttonText, buttonTextStyle]}>×</react_native_1.Text>
34
+ </react_native_1.TouchableOpacity>
35
+
36
+ <react_native_1.TouchableOpacity style={[styles.button, buttonStyle]} onPress={() => handleOperation(calc.divide)}>
37
+ <react_native_1.Text style={[styles.buttonText, buttonTextStyle]}>÷</react_native_1.Text>
38
+ </react_native_1.TouchableOpacity>
39
+ </react_native_1.View>
40
+
41
+ <react_native_1.TouchableOpacity style={styles.clearButton} onPress={calc.clear}>
42
+ <react_native_1.Text style={styles.clearButtonText}>Clear</react_native_1.Text>
43
+ </react_native_1.TouchableOpacity>
44
+
45
+ {calc.error ? (<react_native_1.Text style={styles.error}>{calc.error}</react_native_1.Text>) : calc.result !== null ? (<react_native_1.Text style={[styles.result, resultStyle]}>Result: {calc.result}</react_native_1.Text>) : null}
46
+ </react_native_1.View>);
47
+ }
48
+ const styles = react_native_1.StyleSheet.create({
49
+ container: {
50
+ padding: 20,
51
+ backgroundColor: '#f5f5f5',
52
+ borderRadius: 12,
53
+ },
54
+ input: {
55
+ backgroundColor: '#fff',
56
+ borderWidth: 1,
57
+ borderColor: '#ddd',
58
+ borderRadius: 8,
59
+ padding: 12,
60
+ marginBottom: 12,
61
+ fontSize: 18,
62
+ },
63
+ buttonRow: {
64
+ flexDirection: 'row',
65
+ justifyContent: 'space-between',
66
+ marginBottom: 12,
67
+ },
68
+ button: {
69
+ flex: 1,
70
+ backgroundColor: '#007AFF',
71
+ padding: 16,
72
+ borderRadius: 8,
73
+ marginHorizontal: 4,
74
+ alignItems: 'center',
75
+ },
76
+ buttonText: {
77
+ color: '#fff',
78
+ fontSize: 24,
79
+ fontWeight: 'bold',
80
+ },
81
+ clearButton: {
82
+ backgroundColor: '#FF3B30',
83
+ padding: 12,
84
+ borderRadius: 8,
85
+ alignItems: 'center',
86
+ },
87
+ clearButtonText: {
88
+ color: '#fff',
89
+ fontSize: 16,
90
+ fontWeight: '600',
91
+ },
92
+ result: {
93
+ marginTop: 16,
94
+ fontSize: 24,
95
+ fontWeight: 'bold',
96
+ textAlign: 'center',
97
+ color: '#333',
98
+ },
99
+ error: {
100
+ marginTop: 16,
101
+ fontSize: 16,
102
+ textAlign: 'center',
103
+ color: '#FF3B30',
104
+ },
105
+ });
106
+ //# sourceMappingURL=Calculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Calculator.js","sourceRoot":"","sources":["../../src/components/Calculator.tsx"],"names":[],"mappings":";;;;;AAqBA,gCAyEC;AA9FD,kDAA0B;AAC1B,+CAQsB;AACtB,0DAAuD;AAWvD,SAAgB,UAAU,CAAC,EACzB,KAAK,EACL,WAAW,EACX,eAAe,EACf,UAAU,EACV,WAAW,EACX,cAAc,GACE;IAChB,MAAM,IAAI,GAAG,IAAA,6BAAa,GAAE,CAAC;IAE7B,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,cAAc,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAElC,MAAM,eAAe,GAAG,CAAC,EAAc,EAAE,EAAE;QACzC,EAAE,EAAE,CAAC;IACP,CAAC,CAAC;IAEF,OAAO,CACL,CAAC,mBAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAA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;IACD,eAAe,EAAE;QACf,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,KAAK;KAClB;IACD,MAAM,EAAE;QACN,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE,QAAQ;QACnB,KAAK,EAAE,MAAM;KACd;IACD,KAAK,EAAE;QACL,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,QAAQ;QACnB,KAAK,EAAE,SAAS;KACjB;CACF,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { Operation } from '../utils/operations';
2
+ export interface UseCalculatorReturn {
3
+ value1: number;
4
+ value2: number;
5
+ result: number | null;
6
+ error: string | null;
7
+ setValue1: (value: number) => void;
8
+ setValue2: (value: number) => void;
9
+ add: () => void;
10
+ subtract: () => void;
11
+ multiply: () => void;
12
+ divide: () => void;
13
+ execute: (operation: Operation) => void;
14
+ clear: () => void;
15
+ }
16
+ export declare function useCalculator(initialValue1?: number, initialValue2?: number): UseCalculatorReturn;
17
+ //# sourceMappingURL=useCalculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCalculator.d.ts","sourceRoot":"","sources":["../../src/hooks/useCalculator.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,aAAa,CAC3B,aAAa,GAAE,MAAU,EACzB,aAAa,GAAE,MAAU,GACxB,mBAAmB,CA8CrB"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCalculator = useCalculator;
4
+ const react_1 = require("react");
5
+ const operations_1 = require("../utils/operations");
6
+ function useCalculator(initialValue1 = 0, initialValue2 = 0) {
7
+ const [value1, setValue1] = (0, react_1.useState)(initialValue1);
8
+ const [value2, setValue2] = (0, react_1.useState)(initialValue2);
9
+ const [result, setResult] = (0, react_1.useState)(null);
10
+ const [error, setError] = (0, react_1.useState)(null);
11
+ const execute = (0, react_1.useCallback)((operation) => {
12
+ try {
13
+ setError(null);
14
+ const calcResult = (0, operations_1.calculate)(value1, value2, operation);
15
+ setResult(calcResult);
16
+ }
17
+ catch (e) {
18
+ setError(e instanceof Error ? e.message : 'Unknown error');
19
+ setResult(null);
20
+ }
21
+ }, [value1, value2]);
22
+ const add = (0, react_1.useCallback)(() => execute('add'), [execute]);
23
+ const subtract = (0, react_1.useCallback)(() => execute('subtract'), [execute]);
24
+ const multiply = (0, react_1.useCallback)(() => execute('multiply'), [execute]);
25
+ const divide = (0, react_1.useCallback)(() => execute('divide'), [execute]);
26
+ const clear = (0, react_1.useCallback)(() => {
27
+ setValue1(0);
28
+ setValue2(0);
29
+ setResult(null);
30
+ setError(null);
31
+ }, []);
32
+ return {
33
+ value1,
34
+ value2,
35
+ result,
36
+ error,
37
+ setValue1,
38
+ setValue2,
39
+ add,
40
+ subtract,
41
+ multiply,
42
+ divide,
43
+ execute,
44
+ clear,
45
+ };
46
+ }
47
+ //# sourceMappingURL=useCalculator.js.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G,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAE/D,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC7B,SAAS,CAAC,CAAC,CAAC,CAAC;QACb,SAAS,CAAC,CAAC,CAAC,CAAC;QACb,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,MAAM;QACN,MAAM;QACN,MAAM;QACN,KAAK;QACL,SAAS;QACT,SAAS;QACT,GAAG;QACH,QAAQ;QACR,QAAQ;QACR,MAAM;QACN,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare const SDK_VERSION = "0.1.0";
2
+ export { add, subtract, multiply, divide, calculate, type Operation, } from './utils/operations';
3
+ export { useCalculator, type UseCalculatorReturn } from './hooks/useCalculator';
4
+ export { Calculator, type CalculatorProps } from './components/Calculator';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,UAAU,CAAC;AAGnC,OAAO,EACL,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAK,SAAS,GACf,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAGhF,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // React Native Calculator SDK
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Calculator = exports.useCalculator = exports.calculate = exports.divide = exports.multiply = exports.subtract = exports.add = exports.SDK_VERSION = void 0;
5
+ exports.SDK_VERSION = '0.1.0';
6
+ // Utils
7
+ var operations_1 = require("./utils/operations");
8
+ Object.defineProperty(exports, "add", { enumerable: true, get: function () { return operations_1.add; } });
9
+ Object.defineProperty(exports, "subtract", { enumerable: true, get: function () { return operations_1.subtract; } });
10
+ Object.defineProperty(exports, "multiply", { enumerable: true, get: function () { return operations_1.multiply; } });
11
+ Object.defineProperty(exports, "divide", { enumerable: true, get: function () { return operations_1.divide; } });
12
+ Object.defineProperty(exports, "calculate", { enumerable: true, get: function () { return operations_1.calculate; } });
13
+ // Hooks
14
+ var useCalculator_1 = require("./hooks/useCalculator");
15
+ Object.defineProperty(exports, "useCalculator", { enumerable: true, get: function () { return useCalculator_1.useCalculator; } });
16
+ // Components
17
+ var Calculator_1 = require("./components/Calculator");
18
+ Object.defineProperty(exports, "Calculator", { enumerable: true, get: function () { return Calculator_1.Calculator; } });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,8BAA8B;;;AAEjB,QAAA,WAAW,GAAG,OAAO,CAAC;AAEnC,QAAQ;AACR,iDAO4B;AAN1B,iGAAA,GAAG,OAAA;AACH,sGAAA,QAAQ,OAAA;AACR,sGAAA,QAAQ,OAAA;AACR,oGAAA,MAAM,OAAA;AACN,uGAAA,SAAS,OAAA;AAIX,QAAQ;AACR,uDAAgF;AAAvE,8GAAA,aAAa,OAAA;AAEtB,aAAa;AACb,sDAA2E;AAAlE,wGAAA,UAAU,OAAA"}
@@ -0,0 +1,7 @@
1
+ export declare function add(a: number, b: number): number;
2
+ export declare function subtract(a: number, b: number): number;
3
+ export declare function multiply(a: number, b: number): number;
4
+ export declare function divide(a: number, b: number): number;
5
+ export type Operation = 'add' | 'subtract' | 'multiply' | 'divide';
6
+ export declare function calculate(a: number, b: number, operation: Operation): number;
7
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/utils/operations.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEnE,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAW5E"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.add = add;
4
+ exports.subtract = subtract;
5
+ exports.multiply = multiply;
6
+ exports.divide = divide;
7
+ exports.calculate = calculate;
8
+ function add(a, b) {
9
+ return a + b;
10
+ }
11
+ function subtract(a, b) {
12
+ return a - b;
13
+ }
14
+ function multiply(a, b) {
15
+ return a * b;
16
+ }
17
+ function divide(a, b) {
18
+ if (b === 0) {
19
+ throw new Error('Division by zero');
20
+ }
21
+ return a / b;
22
+ }
23
+ function calculate(a, b, operation) {
24
+ switch (operation) {
25
+ case 'add':
26
+ return add(a, b);
27
+ case 'subtract':
28
+ return subtract(a, b);
29
+ case 'multiply':
30
+ return multiply(a, b);
31
+ case 'divide':
32
+ return divide(a, b);
33
+ }
34
+ }
35
+ //# sourceMappingURL=operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/utils/operations.ts"],"names":[],"mappings":";;AAAA,kBAEC;AAED,4BAEC;AAED,4BAEC;AAED,wBAKC;AAID,8BAWC;AAhCD,SAAgB,GAAG,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAgB,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAgB,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAgB,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAID,SAAgB,SAAS,CAAC,CAAS,EAAE,CAAS,EAAE,SAAoB;IAClE,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,KAAK;YACR,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnB,KAAK,UAAU;YACb,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,KAAK,UAAU;YACb,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxB,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "react-native-calc-sdk",
3
+ "version": "0.1.0",
4
+ "description": "React Native Calculator SDK - Simple arithmetic operations",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "src"
10
+ ],
11
+ "scripts": {
12
+ "build": "npx tsc",
13
+ "prepare": "npm run build",
14
+ "test": "jest"
15
+ },
16
+ "keywords": [
17
+ "react-native",
18
+ "calculator",
19
+ "arithmetic",
20
+ "math",
21
+ "sdk"
22
+ ],
23
+ "author": "shinseunguk",
24
+ "license": "MIT",
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "react-native": ">=0.70.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^19.2.0",
31
+ "react": "19.2.0",
32
+ "react-native": "0.83.1",
33
+ "typescript": "^5.0.0"
34
+ }
35
+ }
@@ -0,0 +1,154 @@
1
+ import React from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ TextInput,
6
+ TouchableOpacity,
7
+ StyleSheet,
8
+ ViewStyle,
9
+ TextStyle,
10
+ } from 'react-native';
11
+ import { useCalculator } from '../hooks/useCalculator';
12
+
13
+ export interface CalculatorProps {
14
+ style?: ViewStyle;
15
+ buttonStyle?: ViewStyle;
16
+ buttonTextStyle?: TextStyle;
17
+ inputStyle?: ViewStyle;
18
+ resultStyle?: TextStyle;
19
+ onResultChange?: (result: number | null) => void;
20
+ }
21
+
22
+ export function Calculator({
23
+ style,
24
+ buttonStyle,
25
+ buttonTextStyle,
26
+ inputStyle,
27
+ resultStyle,
28
+ onResultChange,
29
+ }: CalculatorProps) {
30
+ const calc = useCalculator();
31
+
32
+ React.useEffect(() => {
33
+ onResultChange?.(calc.result);
34
+ }, [calc.result, onResultChange]);
35
+
36
+ const handleOperation = (op: () => void) => {
37
+ op();
38
+ };
39
+
40
+ return (
41
+ <View style={[styles.container, style]}>
42
+ <TextInput
43
+ style={[styles.input, inputStyle]}
44
+ keyboardType="numeric"
45
+ value={String(calc.value1)}
46
+ onChangeText={(text) => calc.setValue1(Number(text) || 0)}
47
+ placeholder="First number"
48
+ />
49
+
50
+ <TextInput
51
+ style={[styles.input, inputStyle]}
52
+ keyboardType="numeric"
53
+ value={String(calc.value2)}
54
+ onChangeText={(text) => calc.setValue2(Number(text) || 0)}
55
+ placeholder="Second number"
56
+ />
57
+
58
+ <View style={styles.buttonRow}>
59
+ <TouchableOpacity
60
+ style={[styles.button, buttonStyle]}
61
+ onPress={() => handleOperation(calc.add)}>
62
+ <Text style={[styles.buttonText, buttonTextStyle]}>+</Text>
63
+ </TouchableOpacity>
64
+
65
+ <TouchableOpacity
66
+ style={[styles.button, buttonStyle]}
67
+ onPress={() => handleOperation(calc.subtract)}>
68
+ <Text style={[styles.buttonText, buttonTextStyle]}>−</Text>
69
+ </TouchableOpacity>
70
+
71
+ <TouchableOpacity
72
+ style={[styles.button, buttonStyle]}
73
+ onPress={() => handleOperation(calc.multiply)}>
74
+ <Text style={[styles.buttonText, buttonTextStyle]}>×</Text>
75
+ </TouchableOpacity>
76
+
77
+ <TouchableOpacity
78
+ style={[styles.button, buttonStyle]}
79
+ onPress={() => handleOperation(calc.divide)}>
80
+ <Text style={[styles.buttonText, buttonTextStyle]}>÷</Text>
81
+ </TouchableOpacity>
82
+ </View>
83
+
84
+ <TouchableOpacity style={styles.clearButton} onPress={calc.clear}>
85
+ <Text style={styles.clearButtonText}>Clear</Text>
86
+ </TouchableOpacity>
87
+
88
+ {calc.error ? (
89
+ <Text style={styles.error}>{calc.error}</Text>
90
+ ) : calc.result !== null ? (
91
+ <Text style={[styles.result, resultStyle]}>Result: {calc.result}</Text>
92
+ ) : null}
93
+ </View>
94
+ );
95
+ }
96
+
97
+ const styles = StyleSheet.create({
98
+ container: {
99
+ padding: 20,
100
+ backgroundColor: '#f5f5f5',
101
+ borderRadius: 12,
102
+ },
103
+ input: {
104
+ backgroundColor: '#fff',
105
+ borderWidth: 1,
106
+ borderColor: '#ddd',
107
+ borderRadius: 8,
108
+ padding: 12,
109
+ marginBottom: 12,
110
+ fontSize: 18,
111
+ },
112
+ buttonRow: {
113
+ flexDirection: 'row',
114
+ justifyContent: 'space-between',
115
+ marginBottom: 12,
116
+ },
117
+ button: {
118
+ flex: 1,
119
+ backgroundColor: '#007AFF',
120
+ padding: 16,
121
+ borderRadius: 8,
122
+ marginHorizontal: 4,
123
+ alignItems: 'center',
124
+ },
125
+ buttonText: {
126
+ color: '#fff',
127
+ fontSize: 24,
128
+ fontWeight: 'bold',
129
+ },
130
+ clearButton: {
131
+ backgroundColor: '#FF3B30',
132
+ padding: 12,
133
+ borderRadius: 8,
134
+ alignItems: 'center',
135
+ },
136
+ clearButtonText: {
137
+ color: '#fff',
138
+ fontSize: 16,
139
+ fontWeight: '600',
140
+ },
141
+ result: {
142
+ marginTop: 16,
143
+ fontSize: 24,
144
+ fontWeight: 'bold',
145
+ textAlign: 'center',
146
+ color: '#333',
147
+ },
148
+ error: {
149
+ marginTop: 16,
150
+ fontSize: 16,
151
+ textAlign: 'center',
152
+ color: '#FF3B30',
153
+ },
154
+ });
@@ -0,0 +1,68 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { calculate, Operation } from '../utils/operations';
3
+
4
+ export interface UseCalculatorReturn {
5
+ value1: number;
6
+ value2: number;
7
+ result: number | null;
8
+ error: string | null;
9
+ setValue1: (value: number) => void;
10
+ setValue2: (value: number) => void;
11
+ add: () => void;
12
+ subtract: () => void;
13
+ multiply: () => void;
14
+ divide: () => void;
15
+ execute: (operation: Operation) => void;
16
+ clear: () => void;
17
+ }
18
+
19
+ export function useCalculator(
20
+ initialValue1: number = 0,
21
+ initialValue2: number = 0
22
+ ): UseCalculatorReturn {
23
+ const [value1, setValue1] = useState<number>(initialValue1);
24
+ const [value2, setValue2] = useState<number>(initialValue2);
25
+ const [result, setResult] = useState<number | null>(null);
26
+ const [error, setError] = useState<string | null>(null);
27
+
28
+ const execute = useCallback(
29
+ (operation: Operation) => {
30
+ try {
31
+ setError(null);
32
+ const calcResult = calculate(value1, value2, operation);
33
+ setResult(calcResult);
34
+ } catch (e) {
35
+ setError(e instanceof Error ? e.message : 'Unknown error');
36
+ setResult(null);
37
+ }
38
+ },
39
+ [value1, value2]
40
+ );
41
+
42
+ const add = useCallback(() => execute('add'), [execute]);
43
+ const subtract = useCallback(() => execute('subtract'), [execute]);
44
+ const multiply = useCallback(() => execute('multiply'), [execute]);
45
+ const divide = useCallback(() => execute('divide'), [execute]);
46
+
47
+ const clear = useCallback(() => {
48
+ setValue1(0);
49
+ setValue2(0);
50
+ setResult(null);
51
+ setError(null);
52
+ }, []);
53
+
54
+ return {
55
+ value1,
56
+ value2,
57
+ result,
58
+ error,
59
+ setValue1,
60
+ setValue2,
61
+ add,
62
+ subtract,
63
+ multiply,
64
+ divide,
65
+ execute,
66
+ clear,
67
+ };
68
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ // React Native Calculator SDK
2
+
3
+ export const SDK_VERSION = '0.1.0';
4
+
5
+ // Utils
6
+ export {
7
+ add,
8
+ subtract,
9
+ multiply,
10
+ divide,
11
+ calculate,
12
+ type Operation,
13
+ } from './utils/operations';
14
+
15
+ // Hooks
16
+ export { useCalculator, type UseCalculatorReturn } from './hooks/useCalculator';
17
+
18
+ // Components
19
+ export { Calculator, type CalculatorProps } from './components/Calculator';
@@ -0,0 +1,33 @@
1
+ export function add(a: number, b: number): number {
2
+ return a + b;
3
+ }
4
+
5
+ export function subtract(a: number, b: number): number {
6
+ return a - b;
7
+ }
8
+
9
+ export function multiply(a: number, b: number): number {
10
+ return a * b;
11
+ }
12
+
13
+ export function divide(a: number, b: number): number {
14
+ if (b === 0) {
15
+ throw new Error('Division by zero');
16
+ }
17
+ return a / b;
18
+ }
19
+
20
+ export type Operation = 'add' | 'subtract' | 'multiply' | 'divide';
21
+
22
+ export function calculate(a: number, b: number, operation: Operation): number {
23
+ switch (operation) {
24
+ case 'add':
25
+ return add(a, b);
26
+ case 'subtract':
27
+ return subtract(a, b);
28
+ case 'multiply':
29
+ return multiply(a, b);
30
+ case 'divide':
31
+ return divide(a, b);
32
+ }
33
+ }