@briannorman9/eli-utils 1.0.0 → 1.0.1
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 +21 -0
- package/README.md +126 -35
- package/index.js +1 -3
- package/package.json +17 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Brian Norman
|
|
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @briannorman9/eli-utils
|
|
2
2
|
|
|
3
|
-
Utility functions for ELI
|
|
3
|
+
Utility functions for web experiments with ELI (Experimentation Local Interface).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,72 +10,163 @@ npm install @briannorman9/eli-utils
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Import the utils in your ELI variant code:
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
16
|
import utils from '@eli/utils';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Note:** ELI's import system automatically resolves `@eli/utils` to `@briannorman9/eli-utils` from your project's `node_modules`.
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
### DOM Utilities
|
|
24
|
+
|
|
25
|
+
#### `waitForElement(selector)`
|
|
26
|
+
Wait for an element to appear in the DOM.
|
|
17
27
|
|
|
18
|
-
|
|
28
|
+
```javascript
|
|
19
29
|
utils.waitForElement('#myElement').then(element => {
|
|
20
30
|
console.log('Element found:', element);
|
|
21
31
|
});
|
|
32
|
+
```
|
|
22
33
|
|
|
23
|
-
|
|
34
|
+
#### `waitUntil(condition, interval)`
|
|
35
|
+
Wait until a condition function returns true.
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
24
38
|
utils.waitUntil(() => document.readyState === 'complete');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### `select(selector, context)`
|
|
42
|
+
Select a single element.
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
const button = utils.select('#myButton');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### `selectAll(selector, context)`
|
|
49
|
+
Select multiple elements.
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
const buttons = utils.selectAll('.button');
|
|
53
|
+
```
|
|
25
54
|
|
|
26
|
-
|
|
55
|
+
### Class Manipulation
|
|
56
|
+
|
|
57
|
+
#### `addClass(element, className)`
|
|
58
|
+
Add a class to an element.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
27
61
|
utils.addClass('#myButton', 'active');
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### `removeClass(element, className)`
|
|
65
|
+
Remove a class from an element.
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
28
68
|
utils.removeClass('#myButton', 'inactive');
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### `toggleClass(element, className)`
|
|
72
|
+
Toggle a class on an element.
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
utils.toggleClass('#myButton', 'active');
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### `hasClass(element, className)`
|
|
79
|
+
Check if an element has a class.
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
if (utils.hasClass('#myButton', 'active')) {
|
|
83
|
+
console.log('Button is active');
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Event Handling
|
|
88
|
+
|
|
89
|
+
#### `on(element, event, handler)`
|
|
90
|
+
Add an event listener.
|
|
29
91
|
|
|
30
|
-
|
|
92
|
+
```javascript
|
|
31
93
|
utils.on('#myButton', 'click', () => console.log('Clicked!'));
|
|
94
|
+
```
|
|
32
95
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
utils.setCookie('userId', '12345', 30);
|
|
96
|
+
#### `off(element, event, handler)`
|
|
97
|
+
Remove an event listener.
|
|
36
98
|
|
|
37
|
-
|
|
38
|
-
|
|
99
|
+
```javascript
|
|
100
|
+
utils.off('#myButton', 'click', handler);
|
|
101
|
+
```
|
|
39
102
|
|
|
40
|
-
|
|
41
|
-
|
|
103
|
+
#### `delegate(parent, selector, event, handler)`
|
|
104
|
+
Event delegation - attach event to parent, handle on children.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
utils.delegate('#container', '.button', 'click', (e) => {
|
|
108
|
+
console.log('Button clicked:', e.target);
|
|
109
|
+
});
|
|
42
110
|
```
|
|
43
111
|
|
|
44
|
-
|
|
112
|
+
#### `triggerEvent(eventName, data, target)`
|
|
113
|
+
Trigger a custom event.
|
|
45
114
|
|
|
46
|
-
|
|
115
|
+
```javascript
|
|
116
|
+
utils.triggerEvent('experimentLoaded', { variant: 'v1' });
|
|
117
|
+
```
|
|
47
118
|
|
|
48
|
-
|
|
49
|
-
- `waitUntil(condition, interval)` - Wait until condition is true (waits indefinitely, checks every `interval` ms, default: 100ms)
|
|
50
|
-
- `select(selector, context)` - Select single element
|
|
51
|
-
- `selectAll(selector, context)` - Select multiple elements
|
|
52
|
-
- `addClass(element, className)` - Add class to element
|
|
53
|
-
- `removeClass(element, className)` - Remove class from element
|
|
54
|
-
- `toggleClass(element, className)` - Toggle class on element
|
|
55
|
-
- `hasClass(element, className)` - Check if element has class
|
|
119
|
+
### Cookies
|
|
56
120
|
|
|
57
|
-
|
|
121
|
+
#### `getCookie(name)`
|
|
122
|
+
Get a cookie value by name.
|
|
58
123
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `triggerEvent(eventName, data, target)` - Trigger custom event
|
|
124
|
+
```javascript
|
|
125
|
+
const userId = utils.getCookie('userId');
|
|
126
|
+
```
|
|
63
127
|
|
|
64
|
-
|
|
128
|
+
#### `setCookie(name, value, days, path)`
|
|
129
|
+
Set a cookie.
|
|
65
130
|
|
|
66
|
-
|
|
67
|
-
|
|
131
|
+
```javascript
|
|
132
|
+
utils.setCookie('userId', '12345', 30);
|
|
133
|
+
```
|
|
68
134
|
|
|
69
135
|
### URL Utilities
|
|
70
136
|
|
|
71
|
-
|
|
137
|
+
#### `getQueryParam(name, url)`
|
|
138
|
+
Get a URL query parameter value.
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const campaign = utils.getQueryParam('campaign');
|
|
142
|
+
```
|
|
72
143
|
|
|
73
144
|
### Viewport Utilities
|
|
74
145
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
146
|
+
#### `getViewport()`
|
|
147
|
+
Get the viewport dimensions.
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
const { width, height } = utils.getViewport();
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### `isInViewport(element, threshold)`
|
|
154
|
+
Check if element is in viewport.
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
if (utils.isInViewport('#myElement')) {
|
|
158
|
+
console.log('Element is visible');
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### `scrollIntoView(element, options)`
|
|
163
|
+
Scroll element into view.
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
utils.scrollIntoView('#myElement', { behavior: 'smooth', block: 'center' });
|
|
167
|
+
```
|
|
78
168
|
|
|
79
169
|
## License
|
|
80
170
|
|
|
81
171
|
MIT
|
|
172
|
+
|
package/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// ELI Utils - Utility functions for web experiments
|
|
2
|
-
// This
|
|
3
|
-
// Then imported in variant code using: import utils from '@eli/utils';
|
|
4
|
-
// (The server automatically resolves @eli/utils to the @briannorman9/eli-utils package)
|
|
2
|
+
// This file can be imported in variant code using: import utils from '@eli/utils';
|
|
5
3
|
|
|
6
4
|
export default {
|
|
7
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@briannorman9/eli-utils",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Utility functions for ELI
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Utility functions for web experiments with ELI (Experimentation Local Interface)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"eli",
|
|
12
12
|
"utils",
|
|
13
|
+
"utilities",
|
|
13
14
|
"web-experiments",
|
|
14
|
-
"
|
|
15
|
+
"dom",
|
|
16
|
+
"helpers"
|
|
15
17
|
],
|
|
16
18
|
"author": "",
|
|
17
19
|
"license": "MIT",
|
|
18
|
-
"engines": {
|
|
19
|
-
"node": ">=12.0.0"
|
|
20
|
-
},
|
|
21
20
|
"repository": {
|
|
22
21
|
"type": "git",
|
|
23
|
-
"url": "
|
|
24
|
-
|
|
22
|
+
"url": "https://github.com/briannorman/eli-utils.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/briannorman/eli-utils/issues"
|
|
25
26
|
},
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
"homepage": "https://github.com/briannorman/eli-utils#readme",
|
|
28
|
+
"files": [
|
|
29
|
+
"index.js",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
]
|
|
29
33
|
}
|
|
30
34
|
|