@cybearl/cypack 1.1.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) 2024 Cybearl
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,123 @@
1
+ <p align="center">
2
+ <br />
3
+ <a href="https://www.cybearl.com" target="_blank"><img width="100px" src="https://cybearl.com/_next/image?url=%2Fimages%2Flogo.webp&w=640&q=75" /></a>
4
+ <h2 align="center">@cybearl/cypack</h2>
5
+ <p align="center">A set of general utilities for Cybearl projects.</p>
6
+ </p>
7
+
8
+ This package includes multiple centralized utilities for the Cybearl application and API service. It is designed to be a single package that can be used in both the client and server side of the application. It is also designed to be well-optimized and well-documented for easy use.
9
+
10
+ Integration into your project
11
+ -----------------------------
12
+ #### 0. Install the package
13
+ ```typescript
14
+ // With npm
15
+ $ npm install @cybearl/cypack
16
+
17
+ // With yarn
18
+ $ yarn add @cybearl/cypack
19
+ ```
20
+ And... that's it! You can now use the utilities in your project.
21
+
22
+ Categories and utilities
23
+ ------------------------
24
+ Note that the package is divided into three modules:
25
+ - `backend` (`@cybearl/cypack/backend`): Contains utilities that are meant to be used in the backend.
26
+ - `frontend` (`@cybearl/cypack/frontend`): Contains utilities that are meant to be used in the frontend.
27
+ - `main` (`@cybearl/cypack`): Contains utilities that can be used in both the client and server side of the application.
28
+
29
+ Backend utilities
30
+ -----------------
31
+ #### Benchmark utilities
32
+ - `Bench`: A class that provides a simple way to benchmark functions.
33
+
34
+ #### CyBuffer class
35
+ - `CyBuffer`: A class that extends the Uint8Array class with additional methods to read and write data.
36
+
37
+ #### Cybearl General API System
38
+ - `generateCGASStatus`: Generates a Cybearl General API System (CGAS) status object.
39
+
40
+ #### Error utilities
41
+ Contains a set of base error that follows the Cybearl error format, and other error-related utilities.
42
+ - `BaseError`: The base error class that all Cybearl errors inherit from.
43
+ - `formatErrorResponse`: Formats an error response object.
44
+ - `stringifyError`: Stringifies an error object.
45
+
46
+ #### Host-related utilities
47
+ Contains utilities to get the hostname and other host-related information.
48
+ - `getHostname`: Get the name of the host on which the application is running.
49
+
50
+ #### Logger utilities
51
+ Contains a simple multi-level logger that logs to the console based on `Winston`.
52
+ - `logger`: A simple multi-level logger that logs to the console based on `Winston`.
53
+
54
+ #### Next.js utilities
55
+ Contains utilities to get the Next.js server and other Next.js-related information.
56
+ - `NextApiWrapper`: A class that wraps the Next.js API route handler (specifically for page router).
57
+
58
+ Frontend utilities
59
+ ------------------
60
+ #### Cybearl General API System
61
+ - `getCGASStatus`: Returns the current status of the application, or the application marker only if specified,
62
+ in the Cybearl General API System (CGAS) format.
63
+
64
+ #### URLs utilities
65
+ Contains utilities to manipulate URLs.
66
+ - `addParamsToUrl`: Allows to add query parameters to a URL.
67
+ - `currentUrlOrigin`: Get the current URL origin or null if it's not available.
68
+
69
+ Main utilities
70
+ --------------
71
+ #### Checks utilities
72
+ - `isServer`: Check if the code is running on the server.
73
+ - `isClient`: Check if the code is running on the client.
74
+
75
+ #### Configuration utilities
76
+ - `CONSTANTS`: Multiple constants used throughout the application (user password length, etc.).
77
+
78
+ #### Formatting utilities
79
+ Contains a set of utilities to format numbers, time, and other values.
80
+ - `formatUnit`: Format a number with an attached unit + an optional time unit.
81
+ - `formatHRTime`: Format a high-resolution time, into a responsive string with the en-US locale format.
82
+ - `formatTime`: Format a time in milliseconds into a responsive string with the en-US locale format.
83
+ - `formatPercentage`: Formats a number as a percentage.
84
+ - `truncateString`: Truncate a string to a specified length.
85
+
86
+ #### JSON utilities
87
+ Contains utilities to parse and stringify JSON objects.
88
+ - `stringify`: Stringify a JSON object with support for BigInt and functions.
89
+
90
+ #### Math utilities
91
+ Contains utilities to perform mathematical operations.
92
+ - `mapRange`: Maps a number from one range to another.
93
+
94
+ #### Middleware utilities
95
+ Contains utilities to create middleware functions (for Next.js, etc.).
96
+ - `fullyPermissiveCspHeader`: A Content Security Policy (CSP) header that allows everything, used for development.
97
+
98
+ #### String utilities
99
+ Contains utilities to manipulate strings.
100
+ - `convertErrorToString`: Safely converts any error into a string for parsing/searching.
101
+
102
+ #### Styling utilities
103
+ Contains utilities to manipulate CSS styles.
104
+ - `shadeColor`: Shades a color by a percentage.
105
+
106
+ Related types
107
+ -------------
108
+ - `Bit`: A single bit value used by CyBuffer.
109
+ - `BenchmarkResult`: The type of the benchmark function result.
110
+ - `BenchmarkResults`: An object containing multiple benchmark results, ordered by functions.
111
+ - `CGASStatusString`: The type for the CGAS status string (`enabled`, `disabled`, `in-maintenance`, `in-development`).
112
+ - `CGASStatus`: The Cybearl General API System (CGAS) status response.
113
+ - `Endianness`: The endianness (`LE` or `BE`).
114
+ - `ErrorObj`: The type definition for an error object.
115
+ - `StringEncoding`: The available string encoding instruction for the `CyBuffer` string methods.
116
+ - `SuccessfulRequest`: The type for a successful request, containing the data of type T.
117
+ - `FailedRequest`: The type for a failed request, containing the error message and the error object.
118
+ - `RequestResult`: Returns a failed request in case the `success` field is set to `false`,
119
+ otherwise returns a successful request with a data object of type T.
120
+
121
+ Dev notes
122
+ ---------
123
+ *N/A*