@hyperfrontend/list-utils 0.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/CHANGELOG.md +5 -0
- package/LICENSE.md +21 -0
- package/README.md +175 -0
- package/SECURITY.md +82 -0
- package/bundle/index.iife.js +210 -0
- package/bundle/index.iife.js.map +1 -0
- package/bundle/index.iife.min.js +2 -0
- package/bundle/index.iife.min.js.map +1 -0
- package/bundle/index.umd.js +211 -0
- package/bundle/index.umd.js.map +1 -0
- package/bundle/index.umd.min.js +2 -0
- package/bundle/index.umd.min.js.map +1 -0
- package/create-fifo-list.d.ts +18 -0
- package/create-fifo-list.d.ts.map +1 -0
- package/create-lifo-list.d.ts +18 -0
- package/create-lifo-list.d.ts.map +1 -0
- package/create-range.d.ts +9 -0
- package/create-range.d.ts.map +1 -0
- package/create-value-picker.d.ts +12 -0
- package/create-value-picker.d.ts.map +1 -0
- package/get-last-key-in-map.d.ts +2 -0
- package/get-last-key-in-map.d.ts.map +1 -0
- package/index.cjs.js +182 -0
- package/index.cjs.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.d.ts.map +1 -0
- package/index.esm.js +174 -0
- package/index.esm.js.map +1 -0
- package/non-empty-strings.d.ts +8 -0
- package/non-empty-strings.d.ts.map +1 -0
- package/package.json +60 -0
- package/unique-strings.d.ts +8 -0
- package/unique-strings.d.ts.map +1 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrew Redican
|
|
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,175 @@
|
|
|
1
|
+
# @hyperfrontend/list-utils
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/AndrewRedican/hyperfrontend/actions/workflows/ci-lib-list-utils.yml">
|
|
5
|
+
<img src="https://img.shields.io/github/actions/workflow/status/AndrewRedican/hyperfrontend/ci-lib-list-utils.yml?style=flat-square&logo=github&label=build" alt="Build">
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://codecov.io/gh/AndrewRedican/hyperfrontend/flags?flags%5B0%5D=list-utils">
|
|
8
|
+
<img src="https://codecov.io/gh/AndrewRedican/hyperfrontend/graph/badge.svg?flag=list-utils" alt="Coverage">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@hyperfrontend/list-utils">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@hyperfrontend/list-utils?style=flat-square" alt="npm version">
|
|
12
|
+
</a>
|
|
13
|
+
</p>
|
|
14
|
+
<p align="center">
|
|
15
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
+
<a href="#contributors">
|
|
17
|
+
<img src="https://img.shields.io/github/all-contributors/AndrewRedican/hyperfrontend?color=ee8449&style=flat-square" alt="All Contributors">
|
|
18
|
+
</a>
|
|
19
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
20
|
+
<a href="https://github.com/AndrewRedican/hyperfrontend/blob/main/LICENSE.md">
|
|
21
|
+
<img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://www.npmjs.com/package/@hyperfrontend/list-utils">
|
|
24
|
+
<img src="https://img.shields.io/npm/dm/@hyperfrontend/list-utils?style=flat-square" alt="npm downloads">
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://github.com/AndrewRedican/hyperfrontend">
|
|
27
|
+
<img src="https://img.shields.io/github/stars/AndrewRedican/hyperfrontend?style=flat-square" alt="GitHub stars">
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://bundlephobia.com/package/@hyperfrontend/list-utils">
|
|
30
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@hyperfrontend/list-utils?style=flat-square" alt="Bundle Size">
|
|
31
|
+
</a>
|
|
32
|
+
<img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen?style=flat-square&logo=node.js" alt="Node Version">
|
|
33
|
+
<img src="https://img.shields.io/badge/tree%20shakeable-%E2%9C%93-success?style=flat-square" alt="Tree Shakeable">
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
Purpose-built collection utilities for queue management, filtering, and iteration patterns.
|
|
37
|
+
|
|
38
|
+
## What is @hyperfrontend/list-utils?
|
|
39
|
+
|
|
40
|
+
@hyperfrontend/list-utils provides specialized collection utilities focused on common programming patterns that native JavaScript arrays don't handle elegantly. Rather than replicating lodash, this library targets specific use cases: FIFO/LIFO queue management with object reference tracking, cyclical value iteration, and string array sanitization.
|
|
41
|
+
|
|
42
|
+
The library enforces immutability through frozen interfaces while maintaining high performance. All queue operations (FIFO/LIFO) use native `Set` for O(1) lookups and guaranteed uniqueness, solving the common problem of accidentally adding duplicate items to task queues or event handlers.
|
|
43
|
+
|
|
44
|
+
### Key Features
|
|
45
|
+
|
|
46
|
+
- **FIFO and LIFO queues** with type-safe object tracking
|
|
47
|
+
- **Value picker** for cyclical iteration (ideal for round-robin patterns)
|
|
48
|
+
- **String sanitization** utilities (dedupe, trim, filter empty)
|
|
49
|
+
- **Range generation** for loop-free number sequences
|
|
50
|
+
- **Map utilities** for common Map operations
|
|
51
|
+
- **Zero dependencies** (except sibling @hyperfrontend/data-utils)
|
|
52
|
+
|
|
53
|
+
### Architecture Highlights
|
|
54
|
+
|
|
55
|
+
Queue implementations return frozen objects to prevent external mutation while using native `Set` internally for optimal performance. Object-only restriction on queues prevents reference comparison issues with primitives.
|
|
56
|
+
|
|
57
|
+
## Why Use @hyperfrontend/list-utils?
|
|
58
|
+
|
|
59
|
+
### Prevents Queue Bugs in Event-Driven Systems
|
|
60
|
+
|
|
61
|
+
Native arrays don't enforce uniqueness, making it easy to accidentally register the same event handler, task, or subscription multiple times. FIFO/LIFO lists automatically reject duplicates based on reference equality, eliminating a common source of memory leaks and duplicate processing in event loops, job queues, and observer patterns.
|
|
62
|
+
|
|
63
|
+
### Simplifies Round-Robin and Cyclical Patterns
|
|
64
|
+
|
|
65
|
+
The value picker solves the boilerplate problem of cycling through options (load balancer endpoints, color schemes, retry strategies). No manual index tracking or modulo math—just call `next()`. Particularly useful for testing scenarios where you need predictable value rotation.
|
|
66
|
+
|
|
67
|
+
### Type-Safe String Sanitization
|
|
68
|
+
|
|
69
|
+
`nonEmptyStrings()` and `uniqueStrings()` handle the tedious work of cleaning user input, configuration arrays, or CSV parsing results. Filters null/undefined/empty/whitespace-only values in one call, with full TypeScript type narrowing.
|
|
70
|
+
|
|
71
|
+
### Functional Composition Without Dependencies
|
|
72
|
+
|
|
73
|
+
All utilities return new arrays or frozen objects, never mutate inputs. This makes them safe for use in React hooks dependencies, Redux reducers, or any pure function context. No lodash required for these specific operations.
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install @hyperfrontend/list-utils
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Quick Start
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { createFifoList, createValuePicker, nonEmptyStrings, uniqueStrings } from '@hyperfrontend/list-utils'
|
|
85
|
+
|
|
86
|
+
// FIFO queue for task management
|
|
87
|
+
const taskQueue = createFifoList<{ id: string; execute: () => void }>()
|
|
88
|
+
taskQueue.push({ id: 'task1', execute: () => console.log('Task 1') })
|
|
89
|
+
taskQueue.push({ id: 'task2', execute: () => console.log('Task 2') })
|
|
90
|
+
const nextTask = taskQueue.pull() // Gets task1 (first in)
|
|
91
|
+
|
|
92
|
+
// Round-robin value picker
|
|
93
|
+
const colorPicker = createValuePicker(['red', 'blue', 'green'])
|
|
94
|
+
colorPicker.next() // 'red'
|
|
95
|
+
colorPicker.next() // 'blue'
|
|
96
|
+
colorPicker.next() // 'green'
|
|
97
|
+
colorPicker.next() // 'red' (cycles back)
|
|
98
|
+
|
|
99
|
+
// String sanitization
|
|
100
|
+
const userInputs = [' hello ', '', 'world', null, 'hello', ' ', 'world']
|
|
101
|
+
const cleaned = uniqueStrings(nonEmptyStrings(userInputs)) // ['hello', 'world']
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## API Overview
|
|
105
|
+
|
|
106
|
+
### Queue Management
|
|
107
|
+
|
|
108
|
+
- **`createFifoList<T>()`** - First-in-first-out queue with reference uniqueness
|
|
109
|
+
- **`createLifoList<T>()`** - Last-in-first-out stack with reference uniqueness
|
|
110
|
+
|
|
111
|
+
### Iteration Utilities
|
|
112
|
+
|
|
113
|
+
- **`createValuePicker(values)`** - Cyclical iterator for round-robin patterns
|
|
114
|
+
- **`createRange(start, end)`** - Generate number arrays without loops
|
|
115
|
+
|
|
116
|
+
### String Utilities
|
|
117
|
+
|
|
118
|
+
- **`nonEmptyStrings(values)`** - Filter null/undefined/empty/whitespace strings
|
|
119
|
+
- **`uniqueStrings(values)`** - Remove duplicates while preserving order
|
|
120
|
+
|
|
121
|
+
### Map Helpers
|
|
122
|
+
|
|
123
|
+
- **`getLastKeyInMap(map)`** - Retrieve the last inserted key from a Map
|
|
124
|
+
|
|
125
|
+
## Compatibility
|
|
126
|
+
|
|
127
|
+
| Platform | Support |
|
|
128
|
+
| ----------------------------- | :-----: |
|
|
129
|
+
| Browser | ✅ |
|
|
130
|
+
| Node.js | ✅ |
|
|
131
|
+
| Web Workers | ✅ |
|
|
132
|
+
| Deno, Bun, Cloudflare Workers | ✅ |
|
|
133
|
+
|
|
134
|
+
### Output Formats
|
|
135
|
+
|
|
136
|
+
| Format | File | Tree-Shakeable |
|
|
137
|
+
| ------ | -------------------------- | :------------: |
|
|
138
|
+
| ESM | `index.esm.js` | ✅ |
|
|
139
|
+
| CJS | `index.cjs.js` | ❌ |
|
|
140
|
+
| IIFE | `bundle/index.iife.min.js` | ❌ |
|
|
141
|
+
| UMD | `bundle/index.umd.min.js` | ❌ |
|
|
142
|
+
|
|
143
|
+
**Bundle size:** 1 KB (minified, self-contained)
|
|
144
|
+
|
|
145
|
+
### CDN Usage
|
|
146
|
+
|
|
147
|
+
```html
|
|
148
|
+
<!-- unpkg -->
|
|
149
|
+
<script src="https://unpkg.com/@hyperfrontend/list-utils"></script>
|
|
150
|
+
|
|
151
|
+
<!-- jsDelivr -->
|
|
152
|
+
<script src="https://cdn.jsdelivr.net/npm/@hyperfrontend/list-utils"></script>
|
|
153
|
+
|
|
154
|
+
<script>
|
|
155
|
+
const { createQueue, forEach } = HyperfrontendListUtils
|
|
156
|
+
</script>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Global variable:** `HyperfrontendListUtils`
|
|
160
|
+
|
|
161
|
+
### Dependencies
|
|
162
|
+
|
|
163
|
+
| Package | Type |
|
|
164
|
+
| ------------------------- | -------- |
|
|
165
|
+
| @hyperfrontend/data-utils | Internal |
|
|
166
|
+
|
|
167
|
+
## Part of hyperfrontend
|
|
168
|
+
|
|
169
|
+
This library is part of the [hyperfrontend](https://github.com/AndrewRedican/hyperfrontend) monorepo. [Full documentation](https://hyperfrontend.dev).
|
|
170
|
+
|
|
171
|
+
- Used by [@hyperfrontend/network-protocol](https://github.com/AndrewRedican/hyperfrontend/tree/main/libs/network-protocol) for message queue management
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
We take the security of hyperfrontend seriously. If you discover a security vulnerability, please help us protect our users by following responsible disclosure practices.
|
|
6
|
+
|
|
7
|
+
### How to Report
|
|
8
|
+
|
|
9
|
+
**Please DO NOT report security vulnerabilities through public GitHub issues.**
|
|
10
|
+
|
|
11
|
+
Instead, please report security vulnerabilities directly via email to:
|
|
12
|
+
|
|
13
|
+
**<andrew.redican.mejia@gmail.com>**
|
|
14
|
+
|
|
15
|
+
### What to Include
|
|
16
|
+
|
|
17
|
+
To help us understand and resolve the issue quickly, please include the following information in your report:
|
|
18
|
+
|
|
19
|
+
- **Description**: A clear description of the vulnerability
|
|
20
|
+
- **Impact**: The potential impact and severity of the issue
|
|
21
|
+
- **Reproduction Steps**: Detailed steps to reproduce the vulnerability
|
|
22
|
+
- **Environment**: The version of hyperfrontend affected, browser/Node.js version, operating system, etc.
|
|
23
|
+
- **Proof of Concept**: If possible, include a minimal code example or proof of concept
|
|
24
|
+
- **Suggested Fix**: If you have ideas on how to fix the issue (optional)
|
|
25
|
+
|
|
26
|
+
### Response Timeline
|
|
27
|
+
|
|
28
|
+
- **Acknowledgment**: We will acknowledge receipt of your vulnerability report within 2 business days
|
|
29
|
+
- **Initial Assessment**: We will provide an initial assessment within 5 business days
|
|
30
|
+
- **Patch Development**: We aim to develop and test a patch within 10 days of acknowledgment
|
|
31
|
+
- **Public Disclosure**: Please allow at least **10 days** from the initial report before making the vulnerability publicly known
|
|
32
|
+
|
|
33
|
+
This grace period gives us time to:
|
|
34
|
+
|
|
35
|
+
- Verify and reproduce the issue
|
|
36
|
+
- Develop and test a fix
|
|
37
|
+
- Release a patched version
|
|
38
|
+
- Notify users to update their dependencies
|
|
39
|
+
|
|
40
|
+
### Coordinated Disclosure
|
|
41
|
+
|
|
42
|
+
We believe in coordinated disclosure and appreciate your cooperation in:
|
|
43
|
+
|
|
44
|
+
- Not exploiting the vulnerability beyond what is necessary to demonstrate it
|
|
45
|
+
- Not accessing, modifying, or deleting data that doesn't belong to you
|
|
46
|
+
- Allowing us reasonable time to address the issue before public disclosure
|
|
47
|
+
- Making a good faith effort to avoid privacy violations, data destruction, and service interruption
|
|
48
|
+
|
|
49
|
+
### Recognition
|
|
50
|
+
|
|
51
|
+
Once the vulnerability is patched and publicly disclosed, we will acknowledge your responsible disclosure in:
|
|
52
|
+
|
|
53
|
+
- Our release notes
|
|
54
|
+
- Our security advisories (if applicable)
|
|
55
|
+
- This SECURITY.md file (with your permission)
|
|
56
|
+
|
|
57
|
+
Thank you for helping keep hyperfrontend and its users safe!
|
|
58
|
+
|
|
59
|
+
## Security Best Practices
|
|
60
|
+
|
|
61
|
+
When using hyperfrontend in your applications:
|
|
62
|
+
|
|
63
|
+
1. **Keep Dependencies Updated**: Regularly update to the latest version to receive security patches
|
|
64
|
+
2. **Content Security Policy**: Implement appropriate CSP headers when embedding features
|
|
65
|
+
3. **Input Validation**: Validate and sanitize all data passed between features
|
|
66
|
+
4. **Origin Verification**: Always verify the origin of messages in cross-frame communication
|
|
67
|
+
5. **Authentication**: Implement proper authentication and authorization for sensitive features
|
|
68
|
+
6. **HTTPS**: Always serve hyperfrontend features over HTTPS in production
|
|
69
|
+
|
|
70
|
+
## Security Updates
|
|
71
|
+
|
|
72
|
+
Security updates will be released as patch versions and documented in the [CHANGELOG](https://github.com/AndrewRedican/hyperfrontend/releases) and GitHub Security Advisories.
|
|
73
|
+
|
|
74
|
+
## Supported Versions
|
|
75
|
+
|
|
76
|
+
We currently provide security updates for:
|
|
77
|
+
|
|
78
|
+
| Version | Supported |
|
|
79
|
+
| ------- | ------------------ |
|
|
80
|
+
| 0.0.x | :white_check_mark: |
|
|
81
|
+
|
|
82
|
+
As the project matures, we will update this table to reflect our long-term support policy.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var HyperfrontendListUtils = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const registeredClasses = [];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the data type of the target.
|
|
8
|
+
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
9
|
+
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
10
|
+
*
|
|
11
|
+
* @param target - The target to get the data type of.
|
|
12
|
+
* @returns The data type of the target.
|
|
13
|
+
*/
|
|
14
|
+
const getType = (target) => {
|
|
15
|
+
if (target === null)
|
|
16
|
+
return 'null';
|
|
17
|
+
const nativeDataType = typeof target;
|
|
18
|
+
if (nativeDataType === 'object') {
|
|
19
|
+
if (Array.isArray(target))
|
|
20
|
+
return 'array';
|
|
21
|
+
for (const registeredClass of registeredClasses) {
|
|
22
|
+
if (target instanceof registeredClass)
|
|
23
|
+
return registeredClass.name;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return nativeDataType;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a FIFO (First-In-First-Out) list.
|
|
31
|
+
*
|
|
32
|
+
* @template T The type of elements in the list, must be an object.
|
|
33
|
+
* @returns {FifoList<T>} A FIFO list with methods to manipulate and query the list.
|
|
34
|
+
*/
|
|
35
|
+
function createFifoList() {
|
|
36
|
+
const list = new Set();
|
|
37
|
+
const push = (item) => {
|
|
38
|
+
if (getType(item) !== 'object') {
|
|
39
|
+
throw new Error('A fifo list only non-primitive values');
|
|
40
|
+
}
|
|
41
|
+
if (list.has(item)) {
|
|
42
|
+
throw new Error('Cannot a item that already exists');
|
|
43
|
+
}
|
|
44
|
+
list.add(item);
|
|
45
|
+
};
|
|
46
|
+
const pull = () => {
|
|
47
|
+
const value = list.values().next().value;
|
|
48
|
+
list.delete(value);
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
const map = (callback) => {
|
|
52
|
+
return Array.from(list.values()).map(callback);
|
|
53
|
+
};
|
|
54
|
+
const forEach = (callback) => {
|
|
55
|
+
list.forEach(callback);
|
|
56
|
+
};
|
|
57
|
+
const remove = (item) => list.delete(item);
|
|
58
|
+
const has = (item) => list.has(item);
|
|
59
|
+
const size = () => list.size;
|
|
60
|
+
const clear = () => list.clear();
|
|
61
|
+
const result = {
|
|
62
|
+
push,
|
|
63
|
+
pull,
|
|
64
|
+
map,
|
|
65
|
+
forEach,
|
|
66
|
+
remove,
|
|
67
|
+
has,
|
|
68
|
+
size,
|
|
69
|
+
clear,
|
|
70
|
+
};
|
|
71
|
+
return Object.freeze(result);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates a LIFO (Last-In-First-Out) list.
|
|
76
|
+
*
|
|
77
|
+
* @template T The type of elements in the list, must be an object.
|
|
78
|
+
* @returns {LifoList<T>} A LIFO list with methods to manipulate and query the list.
|
|
79
|
+
*/
|
|
80
|
+
function createLifoList() {
|
|
81
|
+
const list = new Set();
|
|
82
|
+
const push = (item) => {
|
|
83
|
+
if (getType(item) !== 'object') {
|
|
84
|
+
throw new Error('A lifo list only supports non-primitive values');
|
|
85
|
+
}
|
|
86
|
+
list.add(item);
|
|
87
|
+
};
|
|
88
|
+
const pull = () => {
|
|
89
|
+
const lastItem = Array.from(list).pop();
|
|
90
|
+
if (lastItem) {
|
|
91
|
+
list.delete(lastItem);
|
|
92
|
+
}
|
|
93
|
+
return lastItem;
|
|
94
|
+
};
|
|
95
|
+
const map = (callback) => {
|
|
96
|
+
return Array.from(list).map(callback);
|
|
97
|
+
};
|
|
98
|
+
const forEach = (callback) => {
|
|
99
|
+
list.forEach(callback);
|
|
100
|
+
};
|
|
101
|
+
const remove = (item) => list.delete(item);
|
|
102
|
+
const has = (item) => list.has(item);
|
|
103
|
+
const size = () => list.size;
|
|
104
|
+
const clear = () => {
|
|
105
|
+
list.clear();
|
|
106
|
+
};
|
|
107
|
+
const result = {
|
|
108
|
+
push,
|
|
109
|
+
pull,
|
|
110
|
+
map,
|
|
111
|
+
forEach,
|
|
112
|
+
remove,
|
|
113
|
+
has,
|
|
114
|
+
size,
|
|
115
|
+
clear,
|
|
116
|
+
};
|
|
117
|
+
return Object.freeze(result);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Creates an array of numbers within a specified range (inclusive).
|
|
122
|
+
*
|
|
123
|
+
* @param start - The starting number of the range
|
|
124
|
+
* @param end - The ending number of the range (inclusive)
|
|
125
|
+
* @returns An array containing all numbers from start to end
|
|
126
|
+
*/
|
|
127
|
+
function createRange(start, end) {
|
|
128
|
+
const range = [];
|
|
129
|
+
for (let i = start; i <= end; i += 1) {
|
|
130
|
+
range.push(i);
|
|
131
|
+
}
|
|
132
|
+
return range;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Creates a value picker that cycles through a list of string values.
|
|
137
|
+
*
|
|
138
|
+
* @param values - The array of string values to cycle through
|
|
139
|
+
* @returns A ValuePicker instance with current and next methods
|
|
140
|
+
*/
|
|
141
|
+
function createValuePicker(values) {
|
|
142
|
+
if (!values || !values.length) {
|
|
143
|
+
throw new Error('Expected values not to be an empty list.');
|
|
144
|
+
}
|
|
145
|
+
let index = -1;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the current value without advancing the picker.
|
|
148
|
+
*
|
|
149
|
+
* @returns The current value in the list
|
|
150
|
+
*/
|
|
151
|
+
function current() {
|
|
152
|
+
if (index < 0)
|
|
153
|
+
index = 0;
|
|
154
|
+
return values[index];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Advances to and returns the next value, cycling back to the start when reaching the end.
|
|
158
|
+
*
|
|
159
|
+
* @returns The next value in the list
|
|
160
|
+
*/
|
|
161
|
+
function next() {
|
|
162
|
+
if (index < 0)
|
|
163
|
+
return current();
|
|
164
|
+
index = ++index < values.length ? index : 0;
|
|
165
|
+
return values[index];
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
current: current,
|
|
169
|
+
next: next,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
174
|
+
const getLastKeyInMap = (map) => {
|
|
175
|
+
const items = [...map.keys()];
|
|
176
|
+
return items[items.length - 1];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Filters out empty, null, undefined, and whitespace-only strings from an array.
|
|
181
|
+
*
|
|
182
|
+
* @param values - The array of strings to filter
|
|
183
|
+
* @returns A new array containing only non-empty strings with content
|
|
184
|
+
*/
|
|
185
|
+
function nonEmptyStrings(values) {
|
|
186
|
+
return values.filter((value) => ![undefined, null, ''].includes(value) && value.trim() !== '');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Removes duplicate strings from an array, preserving insertion order.
|
|
191
|
+
*
|
|
192
|
+
* @param values - The array of strings to deduplicate
|
|
193
|
+
* @returns A new array containing only unique strings
|
|
194
|
+
*/
|
|
195
|
+
function uniqueStrings(values) {
|
|
196
|
+
return Array.from(new Set(values));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
exports.createFifoList = createFifoList;
|
|
200
|
+
exports.createLifoList = createLifoList;
|
|
201
|
+
exports.createRange = createRange;
|
|
202
|
+
exports.createValuePicker = createValuePicker;
|
|
203
|
+
exports.getLastKeyInMap = getLastKeyInMap;
|
|
204
|
+
exports.nonEmptyStrings = nonEmptyStrings;
|
|
205
|
+
exports.uniqueStrings = uniqueStrings;
|
|
206
|
+
|
|
207
|
+
return exports;
|
|
208
|
+
|
|
209
|
+
})({});
|
|
210
|
+
//# sourceMappingURL=index.iife.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.iife.js","sources":["../../../../../../../../../../libs/utils/data/src/shared/consts.ts","../../../../../../../../../../libs/utils/data/src/get-type.ts","../../../../../../../../../../libs/utils/list/src/create-fifo-list.ts","../../../../../../../../../../libs/utils/list/src/create-lifo-list.ts","../../../../../../../../../../libs/utils/list/src/create-range.ts","../../../../../../../../../../libs/utils/list/src/create-value-picker.ts","../../../../../../../../../../libs/utils/list/src/get-last-key-in-map.ts","../../../../../../../../../../libs/utils/list/src/non-empty-strings.ts","../../../../../../../../../../libs/utils/list/src/unique-strings.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null],"names":[],"mappings":";;;IAGO,MAAM,iBAAiB,GAAmB,EAAE;;ICAnD;;;;;;;IAOG;IACI,MAAM,OAAO,GAAG,CAA8B,MAAe,KAAO;QACzE,IAAI,MAAM,KAAK,IAAI;IAAE,QAAA,OAAU,MAAM;IACrC,IAAA,MAAM,cAAc,GAAG,OAAO,MAAM;IACpC,IAAA,IAAI,cAAc,KAAK,QAAQ,EAAE;IAC/B,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;IAAE,YAAA,OAAU,OAAO;IAC5C,QAAA,KAAK,MAAM,eAAe,IAAI,iBAAiB,EAAE;gBAC/C,IAAI,MAAM,YAAY,eAAe;oBAAE,OAAU,eAAe,CAAC,IAAI;YACvE;QACF;IACA,IAAA,OAAU,cAAc;IAC1B,CAAC;;ICRD;;;;;IAKG;aACa,cAAc,GAAA;IAC5B,IAAA,MAAM,IAAI,GAAW,IAAI,GAAG,EAAE;IAE9B,IAAA,MAAM,IAAI,GAAG,CAAC,IAAO,KAAU;IAC7B,QAA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eAAe,CAAC,MAAgB,EAAA;IAC9C,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;IAChG;;ICRA;;;;;IAKG;IACG,SAAU,aAAa,CAAC,MAAgB,EAAA;QAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var HyperfrontendListUtils=function(e){"use strict";const r=[],t=e=>{if(null===e)return"null";const t=typeof e;if("object"===t){if(Array.isArray(e))return"array";for(const t of r)if(e instanceof t)return t.name}return t};return e.createFifoList=function(){const e=new Set,r={push:r=>{if("object"!==t(r))throw new Error("A fifo list only non-primitive values");if(e.has(r))throw new Error("Cannot a item that already exists");e.add(r)},pull:()=>{const r=e.values().next().value;return e.delete(r),r},map:r=>Array.from(e.values()).map(r),forEach:r=>{e.forEach(r)},remove:r=>e.delete(r),has:r=>e.has(r),size:()=>e.size,clear:()=>e.clear()};return Object.freeze(r)},e.createLifoList=function(){const e=new Set,r={push:r=>{if("object"!==t(r))throw new Error("A lifo list only supports non-primitive values");e.add(r)},pull:()=>{const r=Array.from(e).pop();return r&&e.delete(r),r},map:r=>Array.from(e).map(r),forEach:r=>{e.forEach(r)},remove:r=>e.delete(r),has:r=>e.has(r),size:()=>e.size,clear:()=>{e.clear()}};return Object.freeze(r)},e.createRange=function(e,r){const t=[];for(let n=e;n<=r;n+=1)t.push(n);return t},e.createValuePicker=function(e){if(!e||!e.length)throw new Error("Expected values not to be an empty list.");let r=-1;function t(){return r<0&&(r=0),e[r]}return{current:t,next:function(){return r<0?t():(r=++r<e.length?r:0,e[r])}}},e.getLastKeyInMap=e=>{const r=[...e.keys()];return r[r.length-1]},e.nonEmptyStrings=function(e){return e.filter(e=>![void 0,null,""].includes(e)&&""!==e.trim())},e.uniqueStrings=function(e){return Array.from(new Set(e))},e}({});
|
|
2
|
+
//# sourceMappingURL=index.iife.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.iife.min.js","sources":["../../../../../../../../../../libs/utils/data/src/shared/consts.ts","../../../../../../../../../../libs/utils/data/src/get-type.ts","../../../../../../../../../../libs/utils/list/src/create-fifo-list.ts","../../../../../../../../../../libs/utils/list/src/create-lifo-list.ts","../../../../../../../../../../libs/utils/list/src/create-range.ts","../../../../../../../../../../libs/utils/list/src/create-value-picker.ts","../../../../../../../../../../libs/utils/list/src/get-last-key-in-map.ts","../../../../../../../../../../libs/utils/list/src/non-empty-strings.ts","../../../../../../../../../../libs/utils/list/src/unique-strings.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null],"names":["registeredClasses","getType","target","nativeDataType","Array","isArray","registeredClass","name","list","Set","result","push","item","Error","has","add","pull","value","values","next","delete","map","callback","from","forEach","remove","size","clear","Object","freeze","lastItem","pop","start","end","range","i","length","index","current","items","keys","filter","undefined","includes","trim"],"mappings":"oDAGO,MAAMA,EAAoC,GCQpCC,EAAwCC,IACnD,GAAe,OAAXA,EAAiB,MAAU,OAC/B,MAAMC,SAAwBD,EAC9B,GAAuB,WAAnBC,EAA6B,CAC/B,GAAIC,MAAMC,QAAQH,GAAS,MAAU,QACrC,IAAK,MAAMI,KAAmBN,EAC5B,GAAIE,aAAkBI,EAAiB,OAAUA,EAAgBC,IAErE,CACA,OAAUJ,sCCAV,MAAMK,EAAe,IAAIC,IAkCnBC,EAAsB,CAC1BC,KAjCYC,IACZ,GAAsB,WAAlBX,EAAQW,GACV,MAAM,IAAIC,MAAM,yCAElB,GAAIL,EAAKM,IAAIF,GACX,MAAM,IAAIC,MAAM,qCAElBL,EAAKO,IAAIH,IA2BTI,KAxBW,KACX,MAAMC,EAAQT,EAAKU,SAASC,OAAOF,MA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