vibra 1.0.2 → 1.0.4

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 CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## 🚀 Features
8
8
  - **Type-safe**: Full TypeScript support out of the box
9
- - **Minimal API**: Only `get`, `set`, and `subscribe`
9
+ - **Minimal API**: Only `get`, `getStrict`, `set`, and `subscribe`
10
10
  - **Reactive**: Efficient observer pattern for instant updates
11
11
  - **Memory safe**: Automatic cleanup of subscriptions
12
12
  - **Zero dependencies**: Lightweight and fast
@@ -57,6 +57,19 @@ const store = vibra<string | null>(null);
57
57
  store.set('Ready!');
58
58
  ```
59
59
 
60
+ ### Strict Reads (Non-Nullable)
61
+ Use `getStrict()` when you want a non-nullable read. It throws if the value is `null` or `undefined`.
62
+
63
+ ```typescript
64
+ const store = vibra<string | null>(null);
65
+
66
+ // Throws if value is null/undefined
67
+ store.getStrict();
68
+
69
+ store.set('Ready!');
70
+ const value: string = store.getStrict(); // value is string
71
+ ```
72
+
60
73
  ### Multiple Subscribers
61
74
  ```typescript
62
75
  const store = vibra(0);
@@ -92,6 +105,7 @@ userStore.subscribe(
92
105
  ### `vibra<T>(initialValue: T)`
93
106
  Returns a store object with:
94
107
  - `get(): T` — Get the current value
108
+ - `getStrict(): NonNullableDefined<T>` — Get the current value strictly (throws if value is `null` or `undefined`)
95
109
  - `set(value: T): void` — Set a new value (notifies subscribers if changed)
96
110
  - `subscribe(callback: (value: T) => void, options?: SubscribeOptions): () => void` — Subscribe to changes. Returns an unsubscribe function.
97
111
 
@@ -102,6 +116,16 @@ interface SubscribeOptions {
102
116
  }
103
117
  ```
104
118
 
119
+ ## ⚛️ React Integration
120
+
121
+ For React applications, we provide a dedicated package `vibra-react` that offers React hooks and components for seamless integration with Vibra stores. Check out the [vibra-react documentation](https://www.npmjs.com/package/vibra-react) for more details.
122
+
123
+ ```bash
124
+ npm install vibra-react
125
+ # or
126
+ bun add vibra-react
127
+ ```
128
+
105
129
  ## 💡 Why Vibra?
106
130
  - **Ultra-lightweight**: No bloat, just state
107
131
  - **Predictable**: No magic, no proxies, no hidden behaviors
package/dist/index.d.mts CHANGED
@@ -24,6 +24,11 @@ interface Store<T> {
24
24
  * Get the current value of the store
25
25
  */
26
26
  get(): T;
27
+ /**
28
+ * Get the current value of the store strictly
29
+ * @returns The current value of the store
30
+ */
31
+ getStrict(): NonNullableDefined<T>;
27
32
  /**
28
33
  * Set a new value for the store
29
34
  * @param value - The new value to set
@@ -37,6 +42,11 @@ interface Store<T> {
37
42
  */
38
43
  subscribe(callback: Subscriber<T>, options?: SubscribeOptions): Unsubscribe;
39
44
  }
45
+ /**
46
+ * Generic utility type that ensures a type is neither null nor undefined.
47
+ * Usage: NonNullableDefined<T>
48
+ */
49
+ type NonNullableDefined<T> = T extends null | undefined ? never : T;
40
50
 
41
51
  /**
42
52
  * Vibra - A Simple Yet Powerful State Management Solution
@@ -76,6 +86,10 @@ interface Store<T> {
76
86
  * unsubscribe();
77
87
  * ```
78
88
  */
89
+ /**
90
+ * Generic utility type that ensures a type is neither null nor undefined.
91
+ * Usage: NonNullableDefined<T>
92
+ */
79
93
  declare function vibra<T>(initialValue: T): Store<T>;
80
94
  type Vibra<T> = Store<T>;
81
95
 
@@ -83,4 +97,4 @@ declare class VibraError extends Error {
83
97
  constructor(message: string);
84
98
  }
85
99
 
86
- export { type Store, type SubscribeOptions, type Subscriber, type Unsubscribe, type Vibra, VibraError, vibra as default };
100
+ export { type NonNullableDefined, type Store, type SubscribeOptions, type Subscriber, type Unsubscribe, type Vibra, VibraError, vibra as default };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,11 @@ interface Store<T> {
24
24
  * Get the current value of the store
25
25
  */
26
26
  get(): T;
27
+ /**
28
+ * Get the current value of the store strictly
29
+ * @returns The current value of the store
30
+ */
31
+ getStrict(): NonNullableDefined<T>;
27
32
  /**
28
33
  * Set a new value for the store
29
34
  * @param value - The new value to set
@@ -37,6 +42,11 @@ interface Store<T> {
37
42
  */
38
43
  subscribe(callback: Subscriber<T>, options?: SubscribeOptions): Unsubscribe;
39
44
  }
45
+ /**
46
+ * Generic utility type that ensures a type is neither null nor undefined.
47
+ * Usage: NonNullableDefined<T>
48
+ */
49
+ type NonNullableDefined<T> = T extends null | undefined ? never : T;
40
50
 
41
51
  /**
42
52
  * Vibra - A Simple Yet Powerful State Management Solution
@@ -76,6 +86,10 @@ interface Store<T> {
76
86
  * unsubscribe();
77
87
  * ```
78
88
  */
89
+ /**
90
+ * Generic utility type that ensures a type is neither null nor undefined.
91
+ * Usage: NonNullableDefined<T>
92
+ */
79
93
  declare function vibra<T>(initialValue: T): Store<T>;
80
94
  type Vibra<T> = Store<T>;
81
95
 
@@ -83,4 +97,4 @@ declare class VibraError extends Error {
83
97
  constructor(message: string);
84
98
  }
85
99
 
86
- export { type Store, type SubscribeOptions, type Subscriber, type Unsubscribe, type Vibra, VibraError, vibra as default };
100
+ export { type NonNullableDefined, type Store, type SubscribeOptions, type Subscriber, type Unsubscribe, type Vibra, VibraError, vibra as default };
package/dist/index.js CHANGED
@@ -25,6 +25,15 @@ __export(index_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
27
 
28
+ // src/vibra-error.ts
29
+ var VibraError = class extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = "VibraError";
33
+ }
34
+ };
35
+ var vibra_error_default = VibraError;
36
+
28
37
  // src/vibra.ts
29
38
  function vibra(initialValue) {
30
39
  let data = initialValue;
@@ -43,22 +52,20 @@ function vibra(initialValue) {
43
52
  function get() {
44
53
  return data;
45
54
  }
55
+ function getStrict() {
56
+ if (data === null || data === void 0) {
57
+ throw new vibra_error_default("Data is null or undefined");
58
+ }
59
+ return data;
60
+ }
46
61
  return {
47
62
  get,
48
63
  set,
64
+ getStrict,
49
65
  subscribe
50
66
  };
51
67
  }
52
68
  var vibra_default = vibra;
53
-
54
- // src/vibra-error.ts
55
- var VibraError = class extends Error {
56
- constructor(message) {
57
- super(message);
58
- this.name = "VibraError";
59
- }
60
- };
61
- var vibra_error_default = VibraError;
62
69
  // Annotate the CommonJS export names for ESM import in node:
63
70
  0 && (module.exports = {
64
71
  VibraError
package/dist/index.mjs CHANGED
@@ -1,3 +1,12 @@
1
+ // src/vibra-error.ts
2
+ var VibraError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "VibraError";
6
+ }
7
+ };
8
+ var vibra_error_default = VibraError;
9
+
1
10
  // src/vibra.ts
2
11
  function vibra(initialValue) {
3
12
  let data = initialValue;
@@ -16,22 +25,20 @@ function vibra(initialValue) {
16
25
  function get() {
17
26
  return data;
18
27
  }
28
+ function getStrict() {
29
+ if (data === null || data === void 0) {
30
+ throw new vibra_error_default("Data is null or undefined");
31
+ }
32
+ return data;
33
+ }
19
34
  return {
20
35
  get,
21
36
  set,
37
+ getStrict,
22
38
  subscribe
23
39
  };
24
40
  }
25
41
  var vibra_default = vibra;
26
-
27
- // src/vibra-error.ts
28
- var VibraError = class extends Error {
29
- constructor(message) {
30
- super(message);
31
- this.name = "VibraError";
32
- }
33
- };
34
- var vibra_error_default = VibraError;
35
42
  export {
36
43
  vibra_error_default as VibraError,
37
44
  vibra_default as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibra",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
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
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,18 +33,18 @@
33
33
  "url": "https://github.com/rrios-dev/vibra"
34
34
  },
35
35
  "devDependencies": {
36
- "@eslint/js": "^9.27.0",
36
+ "@eslint/js": "^9.39.2",
37
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"
38
+ "@types/jest": "^30.0.0",
39
+ "eslint": "^9.39.2",
40
+ "globals": "^17.0.0",
41
+ "jest": "^30.2.0",
42
+ "ts-jest": "^29.4.6",
43
+ "tsup": "^8.5.1",
44
+ "typescript": "^5.9.3",
45
+ "typescript-eslint": "^8.52.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "typescript": "^5.0.0"
49
49
  }
50
- }
50
+ }