vibra 1.0.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 +85 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +53 -0
- package/dist/index.mjs +30 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Vibra
|
|
2
|
+
|
|
3
|
+
> A blazing fast, type-safe, and minimal state management library for TypeScript and JavaScript. Effortless reactivity, subscriptions, and memory safety in a tiny package.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
- **Type-safe**: Full TypeScript support out of the box
|
|
7
|
+
- **Minimal API**: Only `get`, `set`, and `subscribe`
|
|
8
|
+
- **Reactive**: Efficient observer pattern for instant updates
|
|
9
|
+
- **Memory safe**: Automatic cleanup of subscriptions
|
|
10
|
+
- **Zero dependencies**: Lightweight and fast
|
|
11
|
+
- **Framework agnostic**: Works with any JS/TS project
|
|
12
|
+
|
|
13
|
+
## 📦 Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install vibra
|
|
17
|
+
# o
|
|
18
|
+
bun add vibra
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 🛠️ Basic Usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import vibra from 'vibra';
|
|
25
|
+
|
|
26
|
+
const counter = vibra(0);
|
|
27
|
+
|
|
28
|
+
// Subscribe to changes
|
|
29
|
+
const unsubscribe = counter.subscribe((value) => {
|
|
30
|
+
console.log(`Counter changed to: ${value}`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Update the state
|
|
34
|
+
counter.set(1);
|
|
35
|
+
|
|
36
|
+
// Get current value
|
|
37
|
+
console.log(counter.get()); // 1
|
|
38
|
+
|
|
39
|
+
// Cleanup subscription
|
|
40
|
+
unsubscribe();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ⚡ Advanced Usage
|
|
44
|
+
|
|
45
|
+
### Complex State
|
|
46
|
+
```typescript
|
|
47
|
+
const user = vibra({ name: 'Alice', age: 30 });
|
|
48
|
+
user.subscribe((u) => console.log(u));
|
|
49
|
+
user.set({ name: 'Bob', age: 25 });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Type Safety
|
|
53
|
+
```typescript
|
|
54
|
+
const store = vibra<string | null>(null);
|
|
55
|
+
store.set('Ready!');
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Multiple Subscribers
|
|
59
|
+
```typescript
|
|
60
|
+
const store = vibra(0);
|
|
61
|
+
const unsub1 = store.subscribe(v => console.log('A', v));
|
|
62
|
+
const unsub2 = store.subscribe(v => console.log('B', v));
|
|
63
|
+
store.set(5);
|
|
64
|
+
// Both subscribers are notified
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 🧩 API Reference
|
|
68
|
+
|
|
69
|
+
### `vibra<T>(initialValue: T)`
|
|
70
|
+
Returns a store object with:
|
|
71
|
+
- `get(): T` — Get the current value
|
|
72
|
+
- `set(value: T): void` — Set a new value (notifies subscribers if changed)
|
|
73
|
+
- `subscribe(callback: (value: T) => void): () => void` — Subscribe to changes (immediately calls with current value). Returns an unsubscribe function.
|
|
74
|
+
|
|
75
|
+
## 💡 Why Vibra?
|
|
76
|
+
- **Ultra-lightweight**: No bloat, just state
|
|
77
|
+
- **Predictable**: No magic, no proxies, no hidden behaviors
|
|
78
|
+
- **Easy to test**: Simple, functional API
|
|
79
|
+
- **Perfect for libraries and apps**: Use it anywhere you need reactivity
|
|
80
|
+
|
|
81
|
+
## 🤝 Contributing
|
|
82
|
+
Pull requests and issues are welcome! Please open an issue to discuss your idea or bug before submitting a PR.
|
|
83
|
+
|
|
84
|
+
## 📄 License
|
|
85
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vibra - A Simple Yet Powerful State Management Solution
|
|
3
|
+
*
|
|
4
|
+
* Vibra is a lightweight state management library that provides a simple and efficient
|
|
5
|
+
* way to handle reactive state in your applications.
|
|
6
|
+
* It follows the observer pattern to create a
|
|
7
|
+
* reactive data store that can be used across your application.
|
|
8
|
+
*
|
|
9
|
+
* Key Features:
|
|
10
|
+
* - Type-safe with TypeScript support
|
|
11
|
+
* - Minimal API surface (get, set, subscribe)
|
|
12
|
+
* - Reactive updates through subscription system
|
|
13
|
+
* - Memory efficient with automatic cleanup
|
|
14
|
+
* - Zero dependencies
|
|
15
|
+
*
|
|
16
|
+
* @template T - The type of the state value
|
|
17
|
+
* @param initialValue - The initial value for the state
|
|
18
|
+
* @returns An object containing methods to interact with the state
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const counter = vibra(0);
|
|
23
|
+
*
|
|
24
|
+
* // Subscribe to changes
|
|
25
|
+
* const unsubscribe = counter.subscribe((value) => {
|
|
26
|
+
* console.log(`Counter changed to: ${value}`);
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Update the state
|
|
30
|
+
* counter.set(1);
|
|
31
|
+
*
|
|
32
|
+
* // Get current value
|
|
33
|
+
* console.log(counter.get()); // 1
|
|
34
|
+
*
|
|
35
|
+
* // Cleanup subscription
|
|
36
|
+
* unsubscribe();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function vibra<T>(initialValue: T): {
|
|
40
|
+
get: () => T;
|
|
41
|
+
set: (value: T) => void;
|
|
42
|
+
subscribe: (callback: (value: T) => void) => () => void;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
interface Main {
|
|
46
|
+
test: true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { type Main, vibra as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vibra - A Simple Yet Powerful State Management Solution
|
|
3
|
+
*
|
|
4
|
+
* Vibra is a lightweight state management library that provides a simple and efficient
|
|
5
|
+
* way to handle reactive state in your applications.
|
|
6
|
+
* It follows the observer pattern to create a
|
|
7
|
+
* reactive data store that can be used across your application.
|
|
8
|
+
*
|
|
9
|
+
* Key Features:
|
|
10
|
+
* - Type-safe with TypeScript support
|
|
11
|
+
* - Minimal API surface (get, set, subscribe)
|
|
12
|
+
* - Reactive updates through subscription system
|
|
13
|
+
* - Memory efficient with automatic cleanup
|
|
14
|
+
* - Zero dependencies
|
|
15
|
+
*
|
|
16
|
+
* @template T - The type of the state value
|
|
17
|
+
* @param initialValue - The initial value for the state
|
|
18
|
+
* @returns An object containing methods to interact with the state
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const counter = vibra(0);
|
|
23
|
+
*
|
|
24
|
+
* // Subscribe to changes
|
|
25
|
+
* const unsubscribe = counter.subscribe((value) => {
|
|
26
|
+
* console.log(`Counter changed to: ${value}`);
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Update the state
|
|
30
|
+
* counter.set(1);
|
|
31
|
+
*
|
|
32
|
+
* // Get current value
|
|
33
|
+
* console.log(counter.get()); // 1
|
|
34
|
+
*
|
|
35
|
+
* // Cleanup subscription
|
|
36
|
+
* unsubscribe();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function vibra<T>(initialValue: T): {
|
|
40
|
+
get: () => T;
|
|
41
|
+
set: (value: T) => void;
|
|
42
|
+
subscribe: (callback: (value: T) => void) => () => void;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
interface Main {
|
|
46
|
+
test: true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { type Main, vibra as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
default: () => vibra_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/vibra.ts
|
|
28
|
+
function vibra(initialValue) {
|
|
29
|
+
let data = initialValue;
|
|
30
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
31
|
+
function subscribe(callback) {
|
|
32
|
+
subscribers.add(callback);
|
|
33
|
+
callback(data);
|
|
34
|
+
return () => {
|
|
35
|
+
subscribers.delete(callback);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function set(value) {
|
|
39
|
+
if (data !== value) {
|
|
40
|
+
data = value;
|
|
41
|
+
subscribers.forEach((callback) => callback(data));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function get() {
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
get,
|
|
49
|
+
set,
|
|
50
|
+
subscribe
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var vibra_default = vibra;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/vibra.ts
|
|
2
|
+
function vibra(initialValue) {
|
|
3
|
+
let data = initialValue;
|
|
4
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
5
|
+
function subscribe(callback) {
|
|
6
|
+
subscribers.add(callback);
|
|
7
|
+
callback(data);
|
|
8
|
+
return () => {
|
|
9
|
+
subscribers.delete(callback);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function set(value) {
|
|
13
|
+
if (data !== value) {
|
|
14
|
+
data = value;
|
|
15
|
+
subscribers.forEach((callback) => callback(data));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function get() {
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
get,
|
|
23
|
+
set,
|
|
24
|
+
subscribe
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var vibra_default = vibra;
|
|
28
|
+
export {
|
|
29
|
+
vibra_default as default
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vibra",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vibra: A blazing fast, type-safe, and minimal state management library for TypeScript and JavaScript. Effortless reactivity, subscriptions, and memory safety in a tiny package.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"prepublishOnly": "bun run build",
|
|
15
|
+
"lint": "eslint src"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"state-management",
|
|
19
|
+
"reactive",
|
|
20
|
+
"typescript",
|
|
21
|
+
"javascript",
|
|
22
|
+
"store",
|
|
23
|
+
"observable",
|
|
24
|
+
"minimal",
|
|
25
|
+
"reactivity",
|
|
26
|
+
"vibra",
|
|
27
|
+
"library"
|
|
28
|
+
],
|
|
29
|
+
"author": "Roberto Ríos <roberto@rrios.dev>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/rrios-dev/vibra"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/js": "^9.27.0",
|
|
37
|
+
"@types/bun": "latest",
|
|
38
|
+
"@types/jest": "^29.5.14",
|
|
39
|
+
"eslint": "^9.27.0",
|
|
40
|
+
"globals": "^16.1.0",
|
|
41
|
+
"jest": "^29.7.0",
|
|
42
|
+
"ts-jest": "^29.3.2",
|
|
43
|
+
"tsup": "^8.0.2",
|
|
44
|
+
"typescript": "^5.0.0",
|
|
45
|
+
"typescript-eslint": "^8.32.1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"typescript": "^5.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|