@pistachiojs/react 0.1.0-dev.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pistachio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # @pistachiojs/react
2
+
3
+ A collection React hooks library for reactive programming tasks. Built on top of @pistachiojs/core packages.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@pistachiojs/react)](https://www.npmjs.com/package/@pistachiojs/react)
6
+ [![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](../../coverage)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ## Key features
10
+
11
+ - **Full type safety** - TypeScript-first with complete inference
12
+ - **React optimized** - Built specifically for React 17+
13
+ - **Tree shakeable** - Modular imports for minimal bundle size
14
+ - **Well tested** - Comprehensive test coverage
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ # npm
20
+ npm install @pistachiojs/core @pistachiojs/react
21
+
22
+ # pnpm
23
+ pnpm add @pistachiojs/core @pistachiojs/react
24
+
25
+ # yarn
26
+ yarn add @pistachiojs/core @pistachiojs/react
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```jsx
32
+ import { useCounter } from '@pistachiojs/react'
33
+
34
+ function Counter() {
35
+ const [count, handlers] = useCounter(0, {
36
+ min: 0,
37
+ max: 10,
38
+ })
39
+
40
+ return (
41
+ <div>
42
+ <p>Count: {count}</p>
43
+ <button onClick={handlers.increment}>+</button>
44
+ <button onClick={handlers.decrement}>-</button>
45
+ <button onClick={() => handlers.set(5)}>Set to 5</button>
46
+ <button onClick={handlers.reset}>Reset</button>
47
+ </div>
48
+ )
49
+ }
50
+ ```
51
+
52
+ ## Type safety
53
+
54
+ This package is written in TypeScript and includes type definitions out of the box.
55
+
56
+ ```typescript
57
+ import { useCounter } from '@pistachiojs/react'
58
+
59
+ function TypeSafeCounter() {
60
+ // Full type inference
61
+ const [count, handlers] = useCounter(0, { min: 0, max: 100 })
62
+ // count: number
63
+ // handlers: UseCounterHandler
64
+
65
+ // All handlers are fully typed
66
+ handlers.increment() // () => void
67
+ handlers.set(50) // (value: number) => void
68
+ }
69
+ ```
70
+
71
+ ## License
72
+
73
+ MIT © [Dirga Prakesha](https://github.com/dirgaprksha)
@@ -0,0 +1,21 @@
1
+ type UseCounterOptions = {
2
+ min?: number;
3
+ max?: number;
4
+ };
5
+ type UseCounterHandler = {
6
+ increment: () => void;
7
+ decrement: () => void;
8
+ set: (value: number) => void;
9
+ reset: () => void;
10
+ };
11
+ type UseCounterReturn = [number, UseCounterHandler];
12
+ /**
13
+ * React hook to manage counter state with optional min and max bounds.
14
+ * @param initialValue - Number value for initial.
15
+ * @param options - Configuration object.
16
+ * @returns Tuple containing current count and handler object.
17
+ */
18
+ declare function useCounter(initialValue?: number, options?: UseCounterOptions): UseCounterReturn;
19
+
20
+ export { useCounter };
21
+ export type { UseCounterHandler, UseCounterOptions, UseCounterReturn };
@@ -0,0 +1 @@
1
+ import{useState as x,useCallback as a}from"react";function m(n,c,e){return Math.min(Math.max(n,c),e)}function C(n=0,c={}){const{min:e=-1/0,max:t=1/0}=c,[i,o]=x(m(n,e,t)),s=a(()=>{o(r=>m(r+1,e,t))},[e,t]),u=a(()=>{o(r=>m(r-1,e,t))},[e,t]),f=a(r=>{o(m(r,e,t))},[e,t]),p=a(()=>{o(m(n,e,t))},[n,e,t]);return[i,{increment:s,decrement:u,set:f,reset:p}]}export{C as useCounter};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var r=require("react");function u(a,s,e){return Math.min(Math.max(a,s),e)}function b(a=0,s={}){const{min:e=-1/0,max:t=1/0}=s,[i,c]=r.useState(u(a,e,t)),l=r.useCallback(()=>{c(n=>u(n+1,e,t))},[e,t]),C=r.useCallback(()=>{c(n=>u(n-1,e,t))},[e,t]),m=r.useCallback(n=>{c(u(n,e,t))},[e,t]),o=r.useCallback(()=>{c(u(a,e,t))},[a,e,t]);return[i,{increment:l,decrement:C,set:m,reset:o}]}exports.useCounter=b;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@pistachiojs/react",
3
+ "description": "A React hooks library for reactive programming tasks",
4
+ "version": "0.1.0-dev.0",
5
+ "author": "Dirga Prakesha <dirga.prakesha@gmail.com>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dirgaprksha/pistachio.git",
10
+ "directory": "packages/react"
11
+ },
12
+ "keywords": [
13
+ "utility",
14
+ "typescript",
15
+ "javascript",
16
+ "helpers",
17
+ "functional",
18
+ "react",
19
+ "type-safe",
20
+ "tree-shakeable"
21
+ ],
22
+ "sideEffects": false,
23
+ "main": "dist/index.js",
24
+ "module": "dist/index.esm.js",
25
+ "types": "dist/index.d.ts",
26
+ "files": [
27
+ "dist/index.js",
28
+ "dist/index.esm.js",
29
+ "dist/index.d.ts"
30
+ ],
31
+ "peerDependencies": {
32
+ "react": ">=17"
33
+ },
34
+ "dependencies": {
35
+ "@types/react": "^17.0.0",
36
+ "@pistachiojs/core": "0.3.0-dev.0"
37
+ },
38
+ "scripts": {
39
+ "build": "rollup -c ../../rollup.config.mjs --environment TARGET:react",
40
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
41
+ "clean": "rimraf node_modules dist"
42
+ }
43
+ }