dphelper 1.8.123 → 1.8.124

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.
Files changed (3) hide show
  1. package/README.md +311 -0
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,311 @@
1
+ # dpHelper
2
+
3
+ ![dpHelper](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dphelper/assets/images/banner.svg)
4
+
5
+ **Manager | DevTools** by [Dario Passariello](https://dario.passariello.ca) (c)
6
+
7
+ [![version](https://img.shields.io/npm/v/dphelper.svg)](https://npmjs.org/package/dphelper)
8
+ [![downloads](https://img.shields.io/npm/dm/dphelper.svg)](https://npmjs.org/package/dphelper)
9
+ ![TypeScript](https://img.shields.io/badge/TypeScript-006b98?logo=TypeScript&logoColor=white)
10
+
11
+ ![dphelper](https://img.shields.io/badge/dphelper-npm-green?logo=dphelper&logoColor=white)
12
+ ![browser extension](https://img.shields.io/badge/browser%20extension-beta-orange.svg)
13
+
14
+ <!--
15
+ [![dphelper](https://snyk.io/advisor/npm-package/dphelper/badge.svg)](https://snyk.io/advisor/npm-package/dphelper)
16
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/dphelper)](https://socket.dev/npm/package/dphelper)
17
+ -->
18
+
19
+ ## About 🔥
20
+
21
+ dpHelper is a precise and complete collection of 190+ tools ready to use in all web/SaaS applications. State and Store Management are now easy, accessible everywhere in your application, including Ajax or React apps, without the need for extra files.
22
+
23
+ 1. __Single Source of Truth__: The application's entire state is held within a single object in one store, ensuring consistent and accessible state management throughout the app.
24
+
25
+ 2. __State is flexible__: State changes are facilitated exclusively through actions. These actions, which are straightforward JavaScript objects, delineate what has occurred. This methodology ensures that state changes remain predictable.
26
+
27
+ 3. __Changes are made with proxy handle function__: To define state changes, dpHelper employs pure functions as intermediaries. These functions accept the current state as input and produce a new state as output, ensuring predictability and ease of testing in the system.
28
+
29
+ ### Example in React
30
+
31
+ ```javascript
32
+ import { useEffect } from 'react';
33
+ import 'dphelper';
34
+
35
+ function App() {
36
+ // Store a value in the state
37
+ state.test = 'Hello, World!';
38
+
39
+ // Use the stored value in a React component
40
+ useEffect(() => {
41
+ console.log("You can recall from all pages: " + state.test); // Output: "Hello, World!"
42
+ }, []);
43
+
44
+ return (
45
+ <div>
46
+ <h1>{state.test}</h1>
47
+ </div>
48
+ );
49
+ }
50
+
51
+ export default App;
52
+ ```
53
+
54
+ ## Live Demo
55
+
56
+ [https://a51.dev/tests/](https://a51.dev/tests/)
57
+
58
+ You can see an HTML version where dpHelper and LayerPro work together seamlessly. dpHelper is compatible with a variety of frontend libraries, including:
59
+ * HTML
60
+ * React
61
+ * Vue
62
+ * And any other frontend library
63
+
64
+ ## Documentation
65
+
66
+ You can see:
67
+ - [State](https://passariello.gitbook.io/dphelper-devtools/general/state)
68
+ - [Store](https://passariello.gitbook.io/dphelper-devtools/general/store)
69
+ - [Observer](https://passariello.gitbook.io/dphelper-devtools/general/observer)
70
+ - [List of functions](https://passariello.gitbook.io/dphelper-devtools/general/tools)
71
+
72
+ You can see more tutorials, information, and examples about **dpHelper** [clicking here](https://passariello.gitbook.io/dphelper-devtools).
73
+
74
+ ## Usage
75
+
76
+ Install dpHelper.
77
+
78
+ ```shell
79
+ npm i dphelper --save-dev
80
+ ```
81
+
82
+ or update:
83
+
84
+ ```shell
85
+ npm i dphelper@latest --save-dev
86
+ ```
87
+
88
+ Use it in the main root file (and only there):
89
+
90
+ ```javascript
91
+ import "dphelper";
92
+ ```
93
+
94
+ or
95
+
96
+ ```javascript
97
+ require("dphelper");
98
+ ```
99
+
100
+ ## Install for EJS or Other Types of Projects (like HTML)
101
+
102
+ Note: You don't need to use npm install in this case, or you will get an error.
103
+
104
+ ```html
105
+ <script src="https://cdn.jsdelivr.net/npm/dphelper@latest"></script>
106
+ ```
107
+
108
+ ## The Best Way To Use State 💥
109
+
110
+ ### Using the "state" Function
111
+
112
+ You can use the state function to store and reuse data throughout your application. Similar to other state managers, you can save state information in JSON format and access it easily in various contexts, including React useEffect and/or dispatch.
113
+
114
+ For example, you can store a value like this: _state.test = 'I am ready'_ and then retrieve it later using state.test.
115
+
116
+ _example:_
117
+
118
+ You can use the browser's devtools console and type " **state.test = 'I am ready'** ". Every time you want to use '**test**' values, you need just recall **state.test**.
119
+
120
+ ```javascript
121
+ // Set a state
122
+ state.test = "I am ready" *
123
+
124
+ // Get the state
125
+ state.test *
126
+
127
+ // List all states
128
+ state.list // or just "state" to see the proxy
129
+
130
+ // Lock a state from edit (Only for Objects or Array)
131
+ state.test.lock() *
132
+
133
+ // Remove a state
134
+ state.remove("test")
135
+
136
+ // Remove all states
137
+ state.removeAll()
138
+
139
+ *["test" is only an example]
140
+
141
+ ```
142
+
143
+ ### Observer 😎 for States
144
+
145
+ **Note**: _Observer works only with states. Stores are excluded at the moment._
146
+
147
+ If you want to run a function every time a state changes, you can use:
148
+
149
+ ```javascript
150
+ /**
151
+ * Observer is a non-cumulative listener,
152
+ * triggered from customEvent / dispatch from state
153
+ * @parameters
154
+ * [ state | store, function ]
155
+ */
156
+ observer( "state.test", () => alert("Test Changes to: " + state.test) )
157
+ |__________| |___________________________________________|
158
+ State: string Function
159
+
160
+ PS: you need to use the name of state | store as string
161
+ ```
162
+
163
+ You can use it everywhere. Works like "useState" in React but with more flexibility (use one observer for each state!).
164
+
165
+ ### Example:
166
+
167
+ ```javascript
168
+ import 'dphelper';
169
+
170
+ // Use the observer to log the changing state value
171
+ observer(
172
+ 'state.count',
173
+ () => console.log("State changed: ", state.count)
174
+ );
175
+
176
+ // Store a value in the state that changes every 5 seconds
177
+ setInterval(() => state.count = Date.now(), 5000);
178
+ ```
179
+
180
+ #### Another Simple Example:
181
+
182
+ ```javascript
183
+ import 'dphelper';
184
+
185
+ // Set a state
186
+ state.myData = 'Hello, world!';
187
+
188
+ // Retrieve the state
189
+ console.log(state.myData); // Output: Hello, world!
190
+
191
+ // Observe state changes
192
+ observer('myData', () => {
193
+ console.log('myData has changed to:', state.myData);
194
+ });
195
+
196
+ // Change the state
197
+ state.myData = 'New value';
198
+ ```
199
+
200
+ ## The Best Way To Use Store 🫙
201
+
202
+ ### Persistent Storage with dpHelper
203
+
204
+ When using dpHelper for permanent storage, you should use the **store**, which stores data persistently across sessions.
205
+
206
+ #### Important Security Note
207
+
208
+ 1. **Use store for persistent storage:** If you want to store data permanently, use store to ensure it is saved in localStorage.
209
+
210
+ 2. **Remove data when necessary:** To maintain security, remove stored data when it is no longer needed, such as during logout.
211
+
212
+ 3. **Remove all stored data:** Use store.removeAll() to securely remove all stored data from your application.
213
+
214
+ ```javascript
215
+ // Set a store:
216
+ store.set("test", { test: "test" })
217
+
218
+ // Get a store:
219
+ store.get("test") // Output: { test: "test" }
220
+
221
+ // Remove a store:
222
+ store.remove("test") // Output: "ok"
223
+
224
+ // Remove all stores:
225
+ store.removeAll() // Output: "ok"
226
+ ```
227
+
228
+ ### Example in React
229
+
230
+ ```javascript
231
+ import { useEffect } from 'react';
232
+ import 'dphelper';
233
+
234
+ function App() {
235
+
236
+ // Store a value in the store (persistent storage)
237
+ store.set(
238
+ 'user',
239
+ {
240
+ name: 'John Doe',
241
+ age: 30
242
+ }
243
+ );
244
+
245
+ // Use the stored value in a React component
246
+ useEffect(
247
+ () => {
248
+ console.log(store.get("user")); // Output: { name: "John Doe", age: 30 }
249
+ $("#name").text(store.get("user").name)
250
+ }, []
251
+ );
252
+
253
+ // Remove all stored data if necessary
254
+ // store.removeAll();
255
+
256
+ return (
257
+ <div>
258
+ <h1 id="name">...</h1>
259
+ </div>
260
+ );
261
+ }
262
+
263
+ export default App;
264
+ ```
265
+
266
+ ## Console It!
267
+
268
+ Type **dphelper** in the devtool console of your browser to have a look at all available tools that you can use! You can call these from everywhere without import (just one time in the main/root page).
269
+
270
+ ## Browser Extension (Chrome/Edge) ♥️
271
+
272
+ ![browser extension](https://img.shields.io/badge/browser%20extension-beta-orange.svg)
273
+
274
+ ![dphelper Banner](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dphelper/assets/images/banner.png)
275
+
276
+ ![dphelper Banner](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dphelper/assets/images/screenshot.png)
277
+
278
+ Chrome: [Download from Google Web Store](https://chrome.google.com/webstore/detail/dphelper-manager-dev-tool/oppppldaoknfddeikfloonnialijngbk)
279
+
280
+ Edge: [Download from Microsoft Addons](https://microsoftedge.microsoft.com/addons/detail/dphelper-manager-dev-to/kphabkbdpaljlfagldhojilhfammepnk)
281
+
282
+ PS: **dpHelper** is compatible with all Chromium-based browsers like **Edge or Brave**!
283
+
284
+ ## dpHelper Browser Extension
285
+
286
+ The dpHelper browser extension allows you to manage your application's dpHelper NPM. Key features include:
287
+
288
+ 1. Simplified API operations: Easily manage and manipulate data with dpHelper's collection of scripts.
289
+ 2. Real-time monitoring: Track memory usage and localStorage to optimize your application's performance.
290
+ 3. Stay up-to-date: Receive updates and tips to improve your daily workflow.
291
+ 4. Easy installation: Simply import 'dphelper' in your project index to get started.
292
+ 5. Global accessibility: All scripts are available globally and can be accessed from anywhere in your application.
293
+
294
+ ## Check
295
+
296
+ [Socket.dev](https://socket.dev/npm/package/dphelper)
297
+
298
+ [Snyk.io](https://security.snyk.io/package/npm/dphelper)
299
+
300
+ ## License
301
+
302
+ [MIT - https://en.wikipedia.org/wiki/MIT_License](https://en.wikipedia.org/wiki/MIT_License)
303
+
304
+ - [LICENCE](https://passariello.gitbook.io/dphelper-devtools/documents/license)
305
+ - [CODE OF CONDUCT](https://passariello.gitbook.io/dphelper-devtools/documents/code_of_conduct)
306
+ - [SECURITY](https://passariello.gitbook.io/dphelper-devtools/documents/security)
307
+ - [CONTRIBUTING](https://passariello.gitbook.io/dphelper-devtools/documents/contributing)
308
+
309
+ ---
310
+
311
+ Dario Passariello - dariopassariello@gmail.com, All rights reserved - Copyright (c) 2019 - 2024