dphelper 3.5.5 → 3.7.2
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 +0 -21
- package/docs/README.md +385 -0
- package/docs/SUMMARY.md +83 -0
- package/docs/_config.yml +1 -0
- package/docs/markdown/ai.md +345 -0
- package/docs/markdown/anchor.md +156 -0
- package/docs/markdown/array.md +208 -0
- package/docs/markdown/audio.md +113 -0
- package/docs/markdown/avoid.md +53 -0
- package/docs/markdown/biometric.md +338 -0
- package/docs/markdown/browser.md +203 -0
- package/docs/markdown/check.md +65 -0
- package/docs/markdown/color.md +159 -0
- package/docs/markdown/compress.md +310 -0
- package/docs/markdown/cookie.md +115 -0
- package/docs/markdown/coords.md +127 -0
- package/docs/markdown/credits.md +56 -0
- package/docs/markdown/date.md +260 -0
- package/docs/markdown/disable.md +109 -0
- package/docs/markdown/dispatch.md +108 -0
- package/docs/markdown/element.md +53 -0
- package/docs/markdown/event.md +85 -0
- package/docs/markdown/fetch.md +122 -0
- package/docs/markdown/form.md +302 -0
- package/docs/markdown/format.md +122 -0
- package/docs/markdown/i18n.md +292 -0
- package/docs/markdown/image.md +298 -0
- package/docs/markdown/json.md +269 -0
- package/docs/markdown/load.md +133 -0
- package/docs/markdown/logging.md +99 -0
- package/docs/markdown/math.md +172 -0
- package/docs/markdown/memory.md +85 -0
- package/docs/markdown/navigation.md +152 -0
- package/docs/markdown/net.md +60 -0
- package/docs/markdown/obj.md +242 -0
- package/docs/markdown/path.md +46 -0
- package/docs/markdown/promise.md +94 -0
- package/docs/markdown/sanitize.md +118 -0
- package/docs/markdown/screen.md +78 -0
- package/docs/markdown/scrollbar.md +82 -0
- package/docs/markdown/security.md +289 -0
- package/docs/markdown/shortcut.md +100 -0
- package/docs/markdown/socket.md +134 -0
- package/docs/markdown/sse.md +120 -0
- package/docs/markdown/svg.md +167 -0
- package/docs/markdown/sync.md +147 -0
- package/docs/markdown/system.md +78 -0
- package/docs/markdown/terminal.md +73 -0
- package/docs/markdown/text.md +245 -0
- package/docs/markdown/timer.md +98 -0
- package/docs/markdown/tools.md +111 -0
- package/docs/markdown/translators.md +65 -0
- package/docs/markdown/trigger.md +99 -0
- package/docs/markdown/triggers.md +133 -0
- package/docs/markdown/type.md +109 -0
- package/docs/markdown/types.md +102 -0
- package/docs/markdown/ui.md +45 -0
- package/docs/markdown/window.md +211 -0
- package/docs/markdown/worker.md +223 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +4 -6
- package/types/dphelper.d.ts +0 -15
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# check
|
|
2
|
+
|
|
3
|
+
Validation utilities for version comparison and other checks.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `version` | Compare two version strings | `dphelper.check.version('1.2.0', '1.1.0')` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
Version comparison utilities:
|
|
14
|
+
- **Semantic Versioning** - Compare version numbers
|
|
15
|
+
- **Custom Options** - Lexicographic and zero-pad support
|
|
16
|
+
|
|
17
|
+
## Usage Examples
|
|
18
|
+
|
|
19
|
+
### Version Comparison
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
// Compare versions
|
|
23
|
+
console.log(dphelper.check.version('1.2.0', '1.1.0')); // 1 (v1 > v2)
|
|
24
|
+
console.log(dphelper.check.version('1.1.0', '1.2.0')); // -1 (v1 < v2)
|
|
25
|
+
console.log(dphelper.check.version('1.0.0', '1.0.0')); // 0 (equal)
|
|
26
|
+
|
|
27
|
+
// With zero padding
|
|
28
|
+
console.log(dphelper.check.version('1.2', '1.2.0', { zero: true })); // 0
|
|
29
|
+
|
|
30
|
+
// With lexicographic comparison
|
|
31
|
+
console.log(dphelper.check.version('1.0.0a', '1.0.0b', { lex: true })); // -1
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Software Update Checker
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
function checkForUpdate(currentVersion, latestVersion) {
|
|
38
|
+
const result = dphelper.check.version(currentVersion, latestVersion);
|
|
39
|
+
|
|
40
|
+
if (result === 1) {
|
|
41
|
+
console.log('Update available!');
|
|
42
|
+
return 'Update available';
|
|
43
|
+
} else if (result === 0) {
|
|
44
|
+
console.log('You have the latest version.');
|
|
45
|
+
return 'Up to date';
|
|
46
|
+
} else {
|
|
47
|
+
console.log('You are on a newer version.');
|
|
48
|
+
return 'Ahead';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
checkForUpdate('1.0.0', '1.1.0'); // "Update available!"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Details
|
|
56
|
+
|
|
57
|
+
- **Author:** Dario Passariello
|
|
58
|
+
- **Version:** 0.0.2
|
|
59
|
+
- **Creation Date:** 20240829
|
|
60
|
+
- **Last Modified:** 20240829
|
|
61
|
+
- **Environment:** Works in both client and server environments
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# color
|
|
2
|
+
|
|
3
|
+
Color manipulation utilities for converting between color formats and generating color gradients.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `hex` | Converts a number (0-255) to hexadecimal | `dphelper.color.hex(255)` |
|
|
10
|
+
| `toHex` | Converts RGB array to hex string | `dphelper.color.toHex([255, 128, 0])` |
|
|
11
|
+
| `toRGB` | Converts hex string to RGB array | `dphelper.color.toRGB('#ff8000')` |
|
|
12
|
+
| `oleColor` | Converts hex to OLE color format | `dphelper.color.oleColor('#ffffff')` |
|
|
13
|
+
| `gradient` | Generates gradient between two colors | `dphelper.color.gradient('#ff0000', '#0000ff', 10)` |
|
|
14
|
+
|
|
15
|
+
## Description
|
|
16
|
+
|
|
17
|
+
Comprehensive color manipulation tools:
|
|
18
|
+
- **Format Conversion** - RGB ↔ Hex, OLE color format
|
|
19
|
+
- **Gradient Generation** - Create smooth color transitions
|
|
20
|
+
- **Number Formatting** - Convert color values to hex
|
|
21
|
+
|
|
22
|
+
## Usage Examples
|
|
23
|
+
|
|
24
|
+
### Number to Hex
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// Convert a number to 2-digit hex
|
|
28
|
+
console.log(dphelper.color.hex(0)); // "00"
|
|
29
|
+
console.log(dphelper.color.hex(255)); // "ff"
|
|
30
|
+
console.log(dphelper.color.hex(128)); // "80"
|
|
31
|
+
|
|
32
|
+
// Clamps values outside 0-255
|
|
33
|
+
console.log(dphelper.color.hex(300)); // "ff"
|
|
34
|
+
console.log(dphelper.color.hex(-10)); // "00"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### RGB to Hex Conversion
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// Convert RGB array to hex
|
|
41
|
+
console.log(dphelper.color.toHex([255, 255, 255])); // "ffffff"
|
|
42
|
+
console.log(dphelper.color.toHex([255, 0, 0])); // "ff0000"
|
|
43
|
+
console.log(dphelper.color.toHex([0, 255, 0])); // "00ff00"
|
|
44
|
+
console.log(dphelper.color.toHex([0, 0, 255])); // "0000ff"
|
|
45
|
+
console.log(dphelper.color.toHex([255, 128, 0])); // "ff8000"
|
|
46
|
+
|
|
47
|
+
// Common colors
|
|
48
|
+
const orange = [255, 165, 0];
|
|
49
|
+
console.log('#' + dphelper.color.toHex(orange)); // "#ffa500"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Hex to RGB Conversion
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// Convert hex to RGB array
|
|
56
|
+
console.log(dphelper.color.toRGB('#ffffff')); // [255, 255, 255]
|
|
57
|
+
console.log(dphelper.color.toRGB('#ff0000')); // [255, 0, 0]
|
|
58
|
+
console.log(dphelper.color.toRGB('#00ff00')); // [0, 255, 0]
|
|
59
|
+
console.log(dphelper.color.toRGB('#0000ff')); // [0, 0, 255]
|
|
60
|
+
|
|
61
|
+
// Without hash
|
|
62
|
+
console.log(dphelper.color.toRGB('ff8000')); // [255, 128, 0]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### OLE Color Conversion
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// Convert to OLE color (used in older Windows APIs)
|
|
69
|
+
console.log(dphelper.color.oleColor('#000000')); // "0"
|
|
70
|
+
console.log(dphelper.color.oleColor('#ffffff')); // "16777215"
|
|
71
|
+
console.log(dphelper.color.oleColor('#ff0000')); // "255"
|
|
72
|
+
console.log(dphelper.color.oleColor('#00ff00')); // "65280"
|
|
73
|
+
console.log(dphelper.color.oleColor('#0000ff')); // "16711680"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Gradient Generation
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
// Generate gradient from red to blue
|
|
80
|
+
const gradient = dphelper.color.gradient('#ff0000', '#0000ff', 10);
|
|
81
|
+
console.log(gradient);
|
|
82
|
+
// ["ff0000", "e61b1b", "cc3636", "b35151", "996c6c", "808080", "669696", "4dabab", "33c0c0", "1ad6d6", "0000ff"]
|
|
83
|
+
|
|
84
|
+
// Useful for creating color scales
|
|
85
|
+
const heatmapColors = dphelper.color.gradient('#0000ff', '#ff0000', 20);
|
|
86
|
+
|
|
87
|
+
// Cool to warm gradient
|
|
88
|
+
const sunrise = dphelper.color.gradient('#ff9a9e', '#fecfef', 15);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Advanced Usage
|
|
92
|
+
|
|
93
|
+
### Color Utilities Class
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
class ColorUtils {
|
|
97
|
+
static random() {
|
|
98
|
+
const r = Math.floor(Math.random() * 256);
|
|
99
|
+
const g = Math.floor(Math.random() * 256);
|
|
100
|
+
const b = Math.floor(Math.random() * 256);
|
|
101
|
+
return '#' + dphelper.color.toHex([r, g, b]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static invert(hex) {
|
|
105
|
+
const [r, g, b] = dphelper.color.toRGB(hex);
|
|
106
|
+
return '#' + dphelper.color.toHex([255 - r, 255 - g, 255 - b]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static lighten(hex, percent) {
|
|
110
|
+
const [r, g, b] = dphelper.color.toRGB(hex);
|
|
111
|
+
return '#' + dphelper.color.toHex([
|
|
112
|
+
Math.min(255, Math.floor(r + (255 - r) * percent)),
|
|
113
|
+
Math.min(255, Math.floor(g + (255 - g) * percent)),
|
|
114
|
+
Math.min(255, Math.floor(b + (255 - b) * percent))
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static darken(hex, percent) {
|
|
119
|
+
const [r, g, b] = dphelper.color.toRGB(hex);
|
|
120
|
+
return '#' + dphelper.color.toHex([
|
|
121
|
+
Math.max(0, Math.floor(r * (1 - percent))),
|
|
122
|
+
Math.max(0, Math.floor(g * (1 - percent))),
|
|
123
|
+
Math.max(0, Math.floor(b * (1 - percent)))
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Usage
|
|
129
|
+
console.log(ColorUtils.random()); // "#a3b21c"
|
|
130
|
+
console.log(ColorUtils.invert('#ff0000')); // "#00ffff"
|
|
131
|
+
console.log(ColorUtils.lighten('#888888', 0.2)); // "#adadad"
|
|
132
|
+
console.log(ColorUtils.darken('#888888', 0.2)); // "#636363"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Dynamic Chart Colors
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
function generateChartColors(count) {
|
|
139
|
+
const colors = [];
|
|
140
|
+
for (let i = 0; i < count; i++) {
|
|
141
|
+
const hue = (i * 360 / count) % 360;
|
|
142
|
+
const rgb = this.hslToRgb(hue, 70, 50);
|
|
143
|
+
colors.push('#' + dphelper.color.toHex(rgb));
|
|
144
|
+
}
|
|
145
|
+
return colors;
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Details
|
|
150
|
+
|
|
151
|
+
- **Author:** Dario Passariello
|
|
152
|
+
- **Version:** 0.0.2
|
|
153
|
+
- **Creation Date:** 20210101
|
|
154
|
+
- **Last Modified:** 20260220
|
|
155
|
+
- **Environment:** Client-side only (browser)
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# compress
|
|
2
|
+
|
|
3
|
+
Compression and encoding utilities for data compression, decompression, and various encoding formats including gzip, deflate, LZW, base64, URL, and HTML encoding.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `gzip` | Compress with gzip | `await dphelper.compress.gzip('Hello World')` |
|
|
10
|
+
| `gunzip` | Decompress gzip | `await dphelper.compress.gunzip(compressedBlob)` |
|
|
11
|
+
| `deflate` | Compress with deflate | `await dphelper.compress.deflate('Hello World')` |
|
|
12
|
+
| `inflate` | Decompress deflate | `await dphelper.compress.inflate(compressedBlob)` |
|
|
13
|
+
| `compress` | LZW compress | `dphelper.compress.compress('Hello World')` |
|
|
14
|
+
| `decompress` | LZW decompress | `dphelper.compress.decompress(compressedString)` |
|
|
15
|
+
| `base64Encode` | Encode to base64 | `dphelper.compress.base64Encode('Hello')` |
|
|
16
|
+
| `base64Decode` | Decode from base64 | `dphelper.compress.base64Decode('SGVsbG8=')` |
|
|
17
|
+
| `urlEncode` | URL encode | `dphelper.compress.urlEncode('Hello World!')` |
|
|
18
|
+
| `urlDecode` | URL decode | `dphelper.compress.urlDecode('Hello%20World!')` |
|
|
19
|
+
| `htmlEncode` | HTML encode | `dphelper.compress.htmlEncode('<script>')` |
|
|
20
|
+
| `htmlDecode` | HTML decode | `dphelper.compress.htmlDecode('<script>')` |
|
|
21
|
+
|
|
22
|
+
## Description
|
|
23
|
+
|
|
24
|
+
Comprehensive compression and encoding module providing:
|
|
25
|
+
- **Gzip/Deflate** - Browser-native compression using CompressionStream API
|
|
26
|
+
- **LZW Compression** - JavaScript-compatible compression for data storage
|
|
27
|
+
- **Base64** - Binary-to-text encoding for data transfer
|
|
28
|
+
- **URL Encoding** - Percent-encoding for URLs and query strings
|
|
29
|
+
- **HTML Encoding** - Escape special characters for safe HTML rendering
|
|
30
|
+
- **Universal** - Works in both browser and server environments
|
|
31
|
+
|
|
32
|
+
## Usage Examples
|
|
33
|
+
|
|
34
|
+
### Gzip Compression
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// Compress string with gzip
|
|
38
|
+
const original = 'Hello World! This is a test string for compression.';
|
|
39
|
+
const compressed = await dphelper.compress.gzip(original);
|
|
40
|
+
|
|
41
|
+
console.log('Original size:', original.length);
|
|
42
|
+
console.log('Compressed type:', compressed.type); // "application/gzip"
|
|
43
|
+
|
|
44
|
+
// Decompress
|
|
45
|
+
const decompressed = await dphelper.compress.gunzip(compressed);
|
|
46
|
+
console.log('Decompressed:', decompressed); // "Hello World! This is a test..."
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Deflate Compression
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
// Compress with deflate (smaller than gzip, no header)
|
|
53
|
+
const data = JSON.stringify({ users: [...], metadata: {...} });
|
|
54
|
+
const deflated = await dphelper.compress.deflate(data);
|
|
55
|
+
|
|
56
|
+
// Decompress
|
|
57
|
+
const inflated = await dphelper.compress.inflate(deflated);
|
|
58
|
+
console.log(JSON.parse(inflated));
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### LZW Compression (JavaScript Compatible)
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
// LZW compression - works in both browser and Node.js
|
|
65
|
+
const original = 'ABABABABABABABAB';
|
|
66
|
+
const compressed = dphelper.compress.compress(original);
|
|
67
|
+
|
|
68
|
+
console.log('Original:', original.length, 'chars');
|
|
69
|
+
console.log('Compressed:', compressed.length, 'chars');
|
|
70
|
+
|
|
71
|
+
// Decompress
|
|
72
|
+
const decompressed = dphelper.compress.decompress(compressed);
|
|
73
|
+
console.log('Decompressed:', decompressed); // "ABABABABABABABAB"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Base64 Encoding
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
// Encode string to base64
|
|
80
|
+
const plain = 'Hello, World!';
|
|
81
|
+
const encoded = dphelper.compress.base64Encode(plain);
|
|
82
|
+
console.log(encoded); // "SGVsbG8sIFdvcmxkIQ=="
|
|
83
|
+
|
|
84
|
+
// Decode from base64
|
|
85
|
+
const decoded = dphelper.compress.base64Decode(encoded);
|
|
86
|
+
console.log(decoded); // "Hello, World!"
|
|
87
|
+
|
|
88
|
+
// Encode binary data
|
|
89
|
+
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
|
|
90
|
+
const binaryEncoded = dphelper.compress.base64Encode(String.fromCharCode(...bytes));
|
|
91
|
+
console.log(binaryEncoded); // "SGVsbG8="
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### URL Encoding
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
// URL encode (percent-encoding)
|
|
98
|
+
const url = 'Hello World! Test=1&value=abc';
|
|
99
|
+
const encoded = dphelper.compress.urlEncode(url);
|
|
100
|
+
console.log(encoded); // "Hello%20World!%20Test%3D1%26value%3Dabc"
|
|
101
|
+
|
|
102
|
+
// URL decode
|
|
103
|
+
const decoded = dphelper.compress.urlDecode(encoded);
|
|
104
|
+
console.log(decoded); // "Hello World! Test=1&value=abc"
|
|
105
|
+
|
|
106
|
+
// Encode for query string
|
|
107
|
+
const query = 'name=John Doe&city=New York';
|
|
108
|
+
const queryEncoded = dphelper.compress.urlEncode(query);
|
|
109
|
+
console.log(queryEncoded); // "name%3DJohn%20Doe%26city%3DNew%20York"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### HTML Encoding
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
// HTML encode (escape special characters)
|
|
116
|
+
const unsafe = '<script>alert("XSS!")</script>';
|
|
117
|
+
const encoded = dphelper.compress.htmlEncode(unsafe);
|
|
118
|
+
console.log(encoded);
|
|
119
|
+
// "<script>alert("XSS!")</script>"
|
|
120
|
+
|
|
121
|
+
// HTML decode
|
|
122
|
+
const decoded = dphelper.compress.htmlDecode(encoded);
|
|
123
|
+
console.log(decoded); // '<script>alert("XSS!")</script>'
|
|
124
|
+
|
|
125
|
+
// Encode user input before displaying
|
|
126
|
+
const userInput = '<div onclick="evil()">Click me</div>';
|
|
127
|
+
const safe = dphelper.compress.htmlEncode(userInput);
|
|
128
|
+
// In HTML: <div onclick="evil()">Click me</div>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Advanced Usage
|
|
132
|
+
|
|
133
|
+
### Data Compression for Storage
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
class CompressedStorage {
|
|
137
|
+
async compress(key, data) {
|
|
138
|
+
const json = JSON.stringify(data);
|
|
139
|
+
const compressed = await dphelper.compress.gzip(json);
|
|
140
|
+
localStorage.setItem(key, await compressed.text());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async decompress(key) {
|
|
144
|
+
const stored = localStorage.getItem(key);
|
|
145
|
+
if (!stored) return null;
|
|
146
|
+
|
|
147
|
+
const blob = new Blob([stored], { type: 'application/gzip' });
|
|
148
|
+
const decompressed = await dphelper.compress.gunzip(blob);
|
|
149
|
+
return JSON.parse(decompressed);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Usage
|
|
154
|
+
const storage = new CompressedStorage();
|
|
155
|
+
await storage.compress('cache', { users: [...], timestamp: Date.now() });
|
|
156
|
+
const data = await storage.decompress('cache');
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### API Response Compression
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
// Compress data before sending to server
|
|
163
|
+
async function sendCompressed(url, data) {
|
|
164
|
+
const json = JSON.stringify(data);
|
|
165
|
+
const compressed = await dphelper.compress.gzip(json);
|
|
166
|
+
|
|
167
|
+
return fetch(url, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: {
|
|
170
|
+
'Content-Type': 'application/gzip'
|
|
171
|
+
},
|
|
172
|
+
body: compressed
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Decompress server response
|
|
177
|
+
async function fetchCompressed(url) {
|
|
178
|
+
const response = await fetch(url);
|
|
179
|
+
const compressed = await response.blob();
|
|
180
|
+
const decompressed = await dphelper.compress.gunzip(compressed);
|
|
181
|
+
return JSON.parse(decompressed);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### String Compression for URLs
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
// Compress data for URL-safe storage (using LZW)
|
|
189
|
+
function compressForUrl(data) {
|
|
190
|
+
const compressed = dphelper.compress.compress(JSON.stringify(data));
|
|
191
|
+
return dphelper.compress.base64Encode(compressed)
|
|
192
|
+
.replace(/\+/g, '-')
|
|
193
|
+
.replace(/\//g, '_')
|
|
194
|
+
.replace(/=+$/, '');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Decompress from URL
|
|
198
|
+
function decompressFromUrl(encoded) {
|
|
199
|
+
const base64 = encoded.replace(/-/g, '+').replace(/_/g, '/');
|
|
200
|
+
const padded = base64.padEnd(base64.length + (4 - base64.length % 4) % 4, '=');
|
|
201
|
+
const compressed = dphelper.compress.base64Decode(padded);
|
|
202
|
+
return JSON.parse(dphelper.compress.decompress(compressed));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Usage
|
|
206
|
+
const data = { id: 123, type: 'test', values: [1,2,3] };
|
|
207
|
+
const encoded = compressForUrl(data);
|
|
208
|
+
console.log(encoded); // URL-safe compressed string
|
|
209
|
+
|
|
210
|
+
const decoded = decompressFromUrl(encoded);
|
|
211
|
+
console.log(decoded); // { id: 123, type: 'test', values: [1,2,3] }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Secure Data Transfer
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
// Encode sensitive data for transfer
|
|
218
|
+
function encodeSecure(data) {
|
|
219
|
+
const json = JSON.stringify(data);
|
|
220
|
+
const base64 = dphelper.compress.base64Encode(json);
|
|
221
|
+
return base64;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Decode secure data
|
|
225
|
+
function decodeSecure(encoded) {
|
|
226
|
+
const json = dphelper.compress.base64Decode(encoded);
|
|
227
|
+
return JSON.parse(json);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Sanitize HTML content
|
|
231
|
+
function sanitizeHtml(content) {
|
|
232
|
+
return dphelper.compress.htmlEncode(content);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Build safe query string
|
|
236
|
+
function buildQueryString(params) {
|
|
237
|
+
return Object.entries(params)
|
|
238
|
+
.map(([k, v]) => `${dphelper.compress.urlEncode(k)}=${dphelper.compress.urlEncode(v)}`)
|
|
239
|
+
.join('&');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
console.log(buildQueryString({ name: 'John Doe', age: '30' }));
|
|
243
|
+
// "name=John%20Doe=30"
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Cache with Compression
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
class CacheManager {
|
|
250
|
+
constructor(prefix = 'cache_') {
|
|
251
|
+
this.prefix = prefix;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async set(key, value, maxAge = 3600000) {
|
|
255
|
+
const entry = {
|
|
256
|
+
data: value,
|
|
257
|
+
expires: Date.now() + maxAge
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const compressed = await dphelper.compress.gzip(JSON.stringify(entry));
|
|
261
|
+
localStorage.setItem(
|
|
262
|
+
this.prefix + key,
|
|
263
|
+
await compressed.text()
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async get(key) {
|
|
268
|
+
const stored = localStorage.getItem(this.prefix + key);
|
|
269
|
+
if (!stored) return null;
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
const blob = new Blob([stored], { type: 'application/gzip' });
|
|
273
|
+
const decompressed = await dphelper.compress.gunzip(blob);
|
|
274
|
+
const entry = JSON.parse(decompressed);
|
|
275
|
+
|
|
276
|
+
if (Date.now() > entry.expires) {
|
|
277
|
+
localStorage.removeItem(this.prefix + key);
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return entry.data;
|
|
282
|
+
} catch {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
clear() {
|
|
288
|
+
Object.keys(localStorage)
|
|
289
|
+
.filter(k => k.startsWith(this.prefix))
|
|
290
|
+
.forEach(k => localStorage.removeItem(k));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Usage
|
|
295
|
+
const cache = new CacheManager();
|
|
296
|
+
await cache.set('user_123', { name: 'John', email: 'john@example.com' });
|
|
297
|
+
const user = await cache.get('user_123');
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Details
|
|
301
|
+
|
|
302
|
+
- **Author:** Dario Passariello
|
|
303
|
+
- **Version:** 0.0.1
|
|
304
|
+
- **Creation Date:** 20260313
|
|
305
|
+
- **Last Modified:** 20260313
|
|
306
|
+
- **Environment:** Works in both client and server environments
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# cookie
|
|
2
|
+
|
|
3
|
+
Cookie management utilities with security features.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `set` | Creates a cookie with specified properties | `dphelper.cookie.set({name: 'user', value: 'john', time: 365})` |
|
|
10
|
+
| `get` | Retrieves a cookie value by name | `dphelper.cookie.get('user')` |
|
|
11
|
+
| `delete` | Deletes a cookie by name | `dphelper.cookie.delete('user')` |
|
|
12
|
+
| `removeAll` | Clears all cookies | `dphelper.cookie.removeAll()` |
|
|
13
|
+
|
|
14
|
+
## Description
|
|
15
|
+
|
|
16
|
+
Complete cookie management:
|
|
17
|
+
- **Create** - Set cookies with expiration, path, security
|
|
18
|
+
- **Read** - Get cookie values
|
|
19
|
+
- **Delete** - Remove specific or all cookies
|
|
20
|
+
- **Security** - SameSite, Secure flags for CSRF protection
|
|
21
|
+
|
|
22
|
+
## Usage Examples
|
|
23
|
+
|
|
24
|
+
### Setting Cookies
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// Simple cookie
|
|
28
|
+
dphelper.cookie.set({
|
|
29
|
+
name: 'theme',
|
|
30
|
+
value: 'dark'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Cookie with expiration (days)
|
|
34
|
+
dphelper.cookie.set({
|
|
35
|
+
name: 'user',
|
|
36
|
+
value: 'john@example.com',
|
|
37
|
+
time: 30 // 30 days
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Secure cookie (HTTPS only)
|
|
41
|
+
dphelper.cookie.set({
|
|
42
|
+
name: 'session',
|
|
43
|
+
value: 'abc123',
|
|
44
|
+
secure: true,
|
|
45
|
+
sameSite: 'Strict'
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Reading Cookies
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
// Get cookie value
|
|
53
|
+
const theme = dphelper.cookie.get('theme');
|
|
54
|
+
console.log(theme); // "dark"
|
|
55
|
+
|
|
56
|
+
// Get session
|
|
57
|
+
const session = dphelper.cookie.get('session');
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Deleting Cookies
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
// Delete specific cookie
|
|
64
|
+
dphelper.cookie.delete('theme');
|
|
65
|
+
|
|
66
|
+
// Clear all cookies
|
|
67
|
+
dphelper.cookie.removeAll();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Complete Example
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
class CookieManager {
|
|
74
|
+
constructor() {}
|
|
75
|
+
|
|
76
|
+
// Save user preferences
|
|
77
|
+
savePreferences(prefs) {
|
|
78
|
+
dphelper.cookie.set({
|
|
79
|
+
name: 'preferences',
|
|
80
|
+
value: JSON.stringify(prefs),
|
|
81
|
+
time: 365,
|
|
82
|
+
sameSite: 'Lax'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Load preferences
|
|
87
|
+
loadPreferences() {
|
|
88
|
+
const prefs = dphelper.cookie.get('preferences');
|
|
89
|
+
return prefs ? JSON.parse(prefs) : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Clear all
|
|
93
|
+
clearAll() {
|
|
94
|
+
dphelper.cookie.removeAll();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Security Features
|
|
100
|
+
|
|
101
|
+
- **SameSite** - Default 'Lax' for CSRF protection
|
|
102
|
+
- **Secure** - Automatic on HTTPS
|
|
103
|
+
- **Value Encoding** - URL encoding to prevent injection
|
|
104
|
+
|
|
105
|
+
## Details
|
|
106
|
+
|
|
107
|
+
- **Author:** Dario Passariello
|
|
108
|
+
- **Version:** 0.0.2
|
|
109
|
+
- **Creation Date:** 20210101
|
|
110
|
+
- **Last Modified:** 20240613
|
|
111
|
+
- **Environment:** Client-side only (browser)
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
*Automatically generated document*
|