You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1>SWOOP.JS : simplifying web development with only one library</h1>
30
+
31
+
<p>Tired of juggling with multiple libraries and utilities for your projects? Don't worry, Swoop.js is here to help! A lightweight versatile javascript utility library, containing a ton of useful functions, that simplifies the process of web development.</p>
32
+
33
+
<p>Swoop js has a comprehensive set of features, from common utilities to advanced and more specific utility classes, such as:</p>
34
+
35
+
<ul>
36
+
<li><b>SWOOPHYSIX</b> for making physics calculations and unit conversions.</li>
37
+
<li><b>SWOOP TEST</b> for unit testing, helping you to write test cases for your code.</li>
38
+
<li><b>SWOOP CACHE</b> to store values for use later, with TTL feature.</li>
39
+
</ul>
40
+
41
+
<h3id="ins">INSTALLATION</h3>
42
+
43
+
<p>You can simply include Swoop.js using our <ahref="https://cdn.jsdelivr.net/gh/SomnathDevPro/Swoop.js@main/swoop.min.js">CDN</a> link</p>
44
+
45
+
<p>or <ahref="swoop.min.js" download>download</a> it from here</p>
46
+
47
+
<h3id="usage">USAGE</h3>
48
+
<p>Let's get started with Swoop.js! Include Swoop.js in your source code to get started:</p>
49
+
<h3>The Swoop object</h3>
50
+
51
+
<p>The <code>SWOOP</code> object is the main object which you will be using to access the basic utilities! Available utility functions:</p>
52
+
53
+
<h4id="array">ARR (Array Functions)</h4>
54
+
55
+
<ol>
56
+
<li><code>union(arr1, arr2)</code>: Returns the union of two arrays.</li>
57
+
<li><code>intersection(arr1, arr2)</code>: Returns the intersection of two arrays.</li>
58
+
<li><code>difference(arr1, arr2)</code>: Returns the difference of two arrays.</li>
59
+
<li><code>sum(arr)</code>: Returns the sum of all elements in an array.</li>
60
+
<li><code>mean(arr)</code>: Returns the mean of an array.</li>
61
+
<li><code>standard_deviation(arr)</code>: Returns the standard deviation of an array.</li>
62
+
<li><code>variance(arr)</code>: Returns the variance of an array.</li>
63
+
<li><code>median(arr)</code>: Returns the median of an array.</li>
64
+
<li><code>min(arr)</code>: Returns the minimum value of an array.</li>
65
+
<li><code>max(arr)</code>: Returns the maximum value of an array.</li>
66
+
<li><code>countUnique(arr)</code>: Returns the number of unique values in an array.</li>
67
+
<li><code>countDuplicates(arr)</code>: Returns the number of duplicate values in an array.</li>
68
+
<li><code>merge(arr1, arr2)</code>: Merges two arrays.</li>
69
+
<li><code>freq(arr)</code>: Returns the frequency of elements in an array.</li>
70
+
</ol>
71
+
72
+
<h4id="dom">DOM (Document Object Model Functions)</h4>
73
+
74
+
<ol>
75
+
<li><code>select(selector)</code>: Selects an element by its selector.</li>
76
+
<li><code>selectid(id)</code>: Selects an element by its ID.</li>
77
+
<li><code>selectall(element)</code>: Selects all elements with a matching selector.</li>
78
+
<li><code>addListener(element, event, fn)</code>: Attaches an event listener to an element.</li>
79
+
<li><code>removeListener(element, event, fn)</code>: Removes an event listener from an element.</li>
<li><code>throttle(func, wait)</code>: Throttles a function to prevent excessive calls.</li>
86
+
<li><code>debounce(func, wait)</code>: Debounces a function to prevent excessive calls.</li>
87
+
<li><code>memoize(func)</code>: Memoizes a function to cache its results.</li>
88
+
<li><code>curry(func)</code>: Curries a function to enable partial application.</li>
89
+
<li><code>once(func)</code>: Ensures a function is called only once.</li>
90
+
</ol>
91
+
<h4id="maths">MATHS (Mathematical Functions)</h4>
92
+
<ol>
93
+
<li><code>sin(angle)</code>: Returns the sine of an angle.</li>
94
+
<li><code>cos(angle)</code>: Returns the cosine of an angle.</li>
95
+
<li><code>tan(angle)</code>: Returns the tangent of an angle.</li>
96
+
<li><code>distance(x1, x2, y1, y2)</code>: Returns the distance between two points.</li>
97
+
<li><code>midpoint(x1, x2, y1, y2)</code>: Returns the midpoint between two points.</li>
98
+
<li><code>lerp(a, b, t)</code>: Returns the linear interpolation between two values.</li>
99
+
<li><code>clamp(value, min, max)</code>: Clamps a value within a range.</li>
100
+
<li><code>signum(value)</code>: Returns the sign of a number.</li>
101
+
<li><code>sqrt(value)</code>: Returns the square root of a number.</li>
102
+
<li><code>round(num)</code>: Returns the rounded value of a number.</li>
103
+
<li><code>ceil(num)</code>: Returns the ceiling of a number.</li>
104
+
<li><code>absolute(num)</code>: Returns the absolute value of a number.</li>
105
+
<li><code>gcd(a, b)</code>: Returns the Greatest Common Divisor of two numbers.</li>
106
+
<li><code>lcm(a, b)</code>: Returns the Least Common Multiple of two numbers.</li>
107
+
<li><code>hypot(p, b)</code>: Returns the hypotenuse of a right triangle.</li>
108
+
<li><code>randnum(min, max)</code>: Returns a random number within a range.</li>
109
+
</ol>
110
+
111
+
<h4id="string">STR (String Functions)</h4>
112
+
113
+
<ol>
114
+
<li><code>strip(str)</code>: Removes whitespace from a string.</li>
115
+
<li><code>contains(str, search, position)</code>: Checks if a substring is present in a string.</li>
116
+
<li><code>isBlank(str)</code>: Checks if a string is blank.</li>
117
+
<li><code>isNotBlank(str)</code>: Checks if a string is not blank.</li>
118
+
<li><code>isAlphabet(str)</code>: Checks if a string contains only alphabetic characters.</li>
119
+
<li><code>isNumeric(str)</code>: Checks if a string contains only numeric characters.</li>
120
+
<li><code>echo(str, n)</code>: Repeats a string n times.</li>
121
+
<li><code>capitalise(str)</code>: Capitalizes the first letter of a string.</li>
122
+
</ol>
123
+
<h2id="swoophysix">Swoophysix Class</h2>
124
+
125
+
<p>The Swoophysix class provides a collection of methods for converting between different units of measurement and calculating various physics-related values.</p>
126
+
127
+
<h3>Constructor</h3>
128
+
129
+
<code>constructor(gravity=9.81)</code>
130
+
131
+
<p>Initializes the Swoophysix object with the given gravity value (default is 9.81 m/s^2).</p>
132
+
133
+
<h2>Heat Conversion Methods</h2>
134
+
135
+
<h3>Temperature Conversions</h3>
136
+
137
+
<ul>
138
+
<li><code>convertFtoC(value)</code>: Converts a temperature value from Fahrenheit to Celsius.</li>
139
+
<li><code>convertCtoF(value)</code>: Converts a temperature value from Celsius to Fahrenheit.</li>
140
+
<li><code>convertCtoK(value)</code>: Converts a temperature value from Celsius to Kelvin.</li>
141
+
<li><code>convertKtoC(value)</code>: Converts a temperature value from Kelvin to Celsius.</li>
142
+
<li><code>convertFtoK(value)</code>: Converts a temperature value from Fahrenheit to Kelvin.</li>
143
+
<li><code>convertKtoF(value)</code>: Converts a temperature value from Kelvin to Fahrenheit.</li>
144
+
</ul>
145
+
146
+
<h2>Length Conversion Methods</h2>
147
+
148
+
<h3>Length Conversions</h3>
149
+
150
+
<ul>
151
+
<li><code>convertMtoFT(value)</code>: Converts a length value from meters to feet.</li>
152
+
<li><code>convertFTtoM(value)</code>: Converts a length value from feet to meters.</li>
153
+
<li><code>convertINtoCM(value)</code>: Converts a length value from inches to centimeters.</li>
154
+
<li><code>convertCMtoIN(value)</code>: Converts a length value from centimeters to inches.</li>
155
+
<li><code>convertMtoIN(value)</code>: Converts a length value from meters to inches.</li>
156
+
<li><code>convertINtoM(value)</code>: Converts a length value from inches to meters.</li>
157
+
<li><code>convertCMtoM(value)</code>: Converts a length value from centimeters to meters.</li>
158
+
<li><code>convertMtoCM(value)</code>: Converts a length value from meters to centimeters.</li>
159
+
</ul>
160
+
161
+
<h2>Physics Calculation Methods</h2>
162
+
163
+
<h3>Physics Calculations</h3>
164
+
165
+
<ul>
166
+
<li><code>force(mass, acceleration)</code>: Calculates the force applied to an object.</li>
167
+
<li><code>pressure(force, area)</code>: Calculates the pressure exerted on an object.</li>
168
+
<li><code>energy(mass, velocity)</code>: Calculates the kinetic energy of an object.</li>
169
+
<li><code>momentum(mass, velocity)</code>: Calculates the momentum of an object.</li>
170
+
<li><code>liquid_pressure(area, height, density)</code>: Calculates the pressure exerted by a liquid.</li>
171
+
<li><code>friction(force, coeff)</code>: Calculates the frictional force.</li>
172
+
<li><code>acceleration(velocity, time)</code>: Calculates the acceleration of an object.</li>
173
+
<li><code>potential_energy(mass, height)</code>: Calculates the potential energy of an object.</li>
174
+
<li><code>torque(radii, force)</code>: Calculates the torque applied to an object.</li>
175
+
</ul>
176
+
177
+
<h2id="swooptest">SwoopTest Class</h2>
178
+
179
+
<p>The SwoopTest class provides a simple testing framework for writing and running tests.</p>
180
+
181
+
<h3>Constructor</h3>
182
+
183
+
<code>constructor()</code>
184
+
185
+
<p>Initializes the SwoopTest object with an empty array of tests.</p>
186
+
187
+
<h3>Adding Tests</h3>
188
+
189
+
<code>addTest(name, fn)</code>
190
+
191
+
<p>Adds a new test to the array of tests. The test is defined by a name and a function that contains the test logic.</p>
192
+
193
+
<h3>Running Tests</h3>
194
+
195
+
<code>runTests()</code>
196
+
197
+
<p>Runs all the tests in the array of tests. If a test passes, it logs a success message to the console. If a test fails, it logs an error message to the console.</p>
198
+
199
+
<h3>Assertion Methods</h3>
200
+
201
+
<p>The following assertion methods can be used within tests to verify expected results:</p>
202
+
203
+
<ul>
204
+
<li><code>assertEqual(a, b)</code>: Verifies that two values are equal. If not, throws an error.</li>
205
+
<li><code>assertNotEqual(a, b, message)</code>: Verifies that two values are not equal. If they are, throws an error.</li>
206
+
<li><code>assertGreaterThan(a, b, message)</code>: Verifies that the first value is greater than the second. If not, throws an error.</li>
207
+
<li><code>assertLessThan(a, b, message)</code>: Verifies that the first value is less than the second. If not, throws an error.</li>
208
+
</ul>
209
+
<h2id="swoopcache">SwoopCache Class</h2>
210
+
211
+
<p>The SwoopCache class provides a simple caching mechanism with a time-to-live (TTL) feature.</p>
212
+
213
+
<h3>Constructor</h3>
214
+
215
+
<code>constructor(TTL=60000)</code>
216
+
217
+
<p>Initializes the SwoopCache object with an empty cache object and a default TTL of 60 seconds (60000 milliseconds).</p>
218
+
219
+
<h3>Setting Cache Data</h3>
220
+
221
+
<code>setCacheData(key, value)</code>
222
+
223
+
<p>Sets a new cache entry with the given key and value. The entry will expire after the TTL period.</p>
224
+
225
+
<h3>Getting Cached Data</h3>
226
+
227
+
<code>getCachedData(key)</code>
228
+
229
+
<p>Retrieves the cached value for the given key. If the entry has expired or does not exist, returns null.</p>
230
+
231
+
<h3>Deleting Cached Data</h3>
232
+
233
+
<code>deleteCachedData(key)</code>
234
+
235
+
<p>Deletes the cached entry for the given key.</p>
236
+
237
+
<h3>Clearing Cached Data</h3>
238
+
239
+
<code>clearCachedData()</code>
240
+
241
+
<p>Clears all cached entries.</p>
242
+
243
+
<h3id="examp">Examples</h3>
244
+
<b>Union of two arrays</b>
245
+
<preclass="code">
246
+
<code>const arr1 = [1, 2, 3];
247
+
const arr2 = [3, 4, 5];
248
+
const union = SWOOP.ARR.union(arr1, arr2);
249
+
// [1, 2, 3, 4, 5]</code>
250
+
</pre>
251
+
252
+
<b>Sum of an array</b>
253
+
<preclass="code">
254
+
<code>const arr = [1, 2, 3, 4, 5];
255
+
const sum = SWOOP.ARR.sum(arr);
256
+
// 15</code>
257
+
</pre>
258
+
<b>Median of an array</b>
259
+
<preclass="code">
260
+
<code>const arr = [1, 3, 5, 7, 9];
261
+
const median = SWOOP.ARR.median(arr);
262
+
// 5</code>
263
+
</pre>
264
+
265
+
<b>Throttling A Function</b>
266
+
<preclass="code">
267
+
<code>
268
+
SWOOP.FUNC.throttle(myFunc(),2000)
269
+
/*allows the function to be called once in 2 seconds,i.e,2000 milliseconds*/
270
+
</code>
271
+
</pre>
272
+
273
+
<b>convert metres to centimetres using swoophysix</b>
274
+
<preclass="code">
275
+
<code>
276
+
const physix = new Swoophysix();
277
+
physix.convertMtoCM(20)
278
+
//converts 20 metres to centimetres
279
+
</code>
280
+
</pre>
281
+
<b>using SwoopCache to cache data</b>
282
+
<preclass="code">
283
+
<code>
284
+
const cache = new SwoopCache(TTL=60000)//the cached data resets after 1 minute
285
+
cache.setCacheData("myKey","myValue") //sets a data in the cache
286
+
//obtaining cached data
287
+
cache.getCachedData("myKey")
288
+
//you can delete cache data like this:
289
+
cache.deleteCachedData("myKey")
290
+
</code>
291
+
</pre>
292
+
293
+
<h2>Contributing</h2>
294
+
<p>Swoop.js has just started its journey, and its features may be limited, but we believe that together, we can make it the best JavaScript library in the world. We highly appreciate contributions and look forward to collaborating with you to achieve this goal.</p>
295
+
296
+
<p> If you'd like to contribute, please follow these guidelines:</p>
297
+
298
+
<h3>Code Contributions</h3>
299
+
300
+
<ol>
301
+
<li>Fork the repository on GitHub.</li>
302
+
<li>Create a new branch for your feature or fix.</li>
303
+
<li>Write tests for your changes.</li>
304
+
<li>Make sure your code passes all tests.</li>
305
+
<li>Submit a pull request.</li>
306
+
</ol>
307
+
308
+
<h3>Documentation Contributions</h3>
309
+
310
+
<ol>
311
+
<li>Fork the repository on GitHub.</li>
312
+
<li>Create a new branch for your documentation changes.</li>
313
+
<li>Make your changes to the documentation files.</li>
314
+
<li>Submit a pull request.</li>
315
+
</ol>
316
+
317
+
<h3>Issue Reporting</h3>
318
+
319
+
<p>If you find a bug or have a feature request, please submit an issue on our GitHub page. Make sure to include as much detail as possible, such as:</p>
320
+
321
+
<ul>
322
+
<li>A clear description of the issue or feature request.</li>
323
+
<li>Steps to reproduce the issue (if applicable).</li>
324
+
<li>Any relevant code or screenshots.</li>
325
+
</ul>
326
+
327
+
<h2>Licensing</h2>
328
+
329
+
<p>Swoop.js is licensed under the Apache 2.0 License. This means you can use, modify, and distribute the library freely, as long as you include the original copyright notice and license text in your project.</p>
330
+
331
+
<h2>Versioning</h2>
332
+
333
+
<p>Swoop.js uses semantic versioning. This means that versions are incremented as follows:</p>
334
+
335
+
<ul>
336
+
<li>Major version (e.g., 1.0.0): Breaking changes or significant new features.</li>
337
+
<li>Minor version (e.g., 0.1.0): New features or enhancements.</li>
338
+
<li>Patch version (e.g., 0.0.1): Bug fixes or minor changes.</li>
339
+
</ul>
340
+
341
+
<h2>Acknowledgments</h2>
342
+
343
+
<p>Swoop.js is a standalone project, built from scratch using pure JavaScript.</p>
0 commit comments