@push.rocks/lik
v6.1.0
Published
Provides a collection of lightweight helpers and utilities for Node.js projects.
Downloads
1,014
Maintainers
Readme
@push.rocks/lik
light little helpers for node
Install
To install @push.rocks/lik
, you can use npm (Node Package Manager). Simply run the following command in your terminal:
npm install @push.rocks/lik --save
This will download @push.rocks/lik
and add it to your project's package.json
dependencies.
Usage
@push.rocks/lik
is a versatile package offering a variety of helper classes designed to simplify common tasks in Node.js development. From managing asynchronous operations to handling collections efficiently, this library provides lightweight solutions to enhance your coding workflow. Below, we explore several key features of @push.rocks/lik
, presenting TypeScript examples to demonstrate their practical application in real-world scenarios.
AsyncExecutionStack
AsyncExecutionStack
allows for managing asynchronous task execution with exclusive and non-exclusive slots, ensuring effective handling of resource-intensive operations.
import { AsyncExecutionStack } from '@push.rocks/lik';
const myAsyncStack = new AsyncExecutionStack();
// Exclusive execution ensures this task doesn't run in parallel with others
await myAsyncStack.getExclusiveExecutionSlot(async () => {
// some asynchronous operation
}, 2500);
// Non-exclusive slots can run in parallel
myAsyncStack.getNonExclusiveExecutionSlot(async () => {
// another asynchronous operation
}, 1500);
FastMap
FastMap
offers a high-performance, key-value map optimized for rapid access and modifications, ideal for scenarios requiring frequent read/write operations.
import { FastMap } from '@push.rocks/lik';
const myFastMap = new FastMap<string>();
// Add items
myFastMap.addToMap('key1', 'value1');
myFastMap.addToMap('key2', 'value2');
// Retrieve item
const value = myFastMap.getByKey('key1'); // 'value1'
LimitedArray
LimitedArray
enforces a maximum size on an array, automatically managing its length to prevent it from exceeding a defined limit.
import { LimitedArray } from '@push.rocks/lik';
const myLimitedArray = new LimitedArray<number>(5); // limit size to 5
myLimitedArray.addMany([1, 2, 3, 4, 5, 6]);
console.log(myLimitedArray.array); // [2, 3, 4, 5, 6]
LoopTracker
LoopTracker
helps detect and prevent infinite loops by tracking object references during iterations.
import { LoopTracker } from '@push.rocks/lik';
const myLoopTracker = new LoopTracker<object>();
const obj1 = {};
if (myLoopTracker.checkAndTrack(obj1)) {
// proceed with operation
} else {
// potential loop detected
}
ObjectMap
ObjectMap
facilitates object management, providing functionalities for adding, finding, and removing objects with ease.
import { ObjectMap } from '@push.rocks/lik';
interface MyObject {
id: number;
name: string;
}
const myObjectMap = new ObjectMap<MyObject>();
const obj: MyObject = { id: 1, name: 'Test Object' };
// Add object
myObjectMap.add(obj);
// Find object
const found = myObjectMap.findSync(item => item.id === 1);
StringMap
StringMap
simplifies string collection management, allowing you to add, remove, and query strings effectively.
import { Stringmap } from '@push.rocks/lik';
const myStringMap = new Stringmap();
// Add strings
myStringMap.addString('hello');
myStringMap.addStringArray(['world', 'example']);
// Check string presence
const exists = myStringMap.checkString('hello'); // true
TimedAggregator
TimedAggregator
batches operations over a specified time interval, useful for aggregating logs, metrics, or any data points over time.
import { TimedAggregtor } from '@push.rocks/lik';
const myAggregator = new TimedAggregtor<string>({
aggregationIntervalInMillis: 5000, // 5 seconds
functionForAggregation: (items) => {
console.log('Aggregated items:', items);
}
});
// Add items
myAggregator.add('item1');
myAggregator.add('item2');
// After 5 seconds, the functionForAggregation will log the aggregated items
InterestMap and Tree
InterestMap
provides a structure for managing subscriptions or interests in certain events or entities, optimizing notification mechanisms.
import { InterestMap } from '@push.rocks/lik';
const myInterestMap = new InterestMap<string, number>((str) => str);
myInterestMap.addInterest('event1').then((interest) => {
interest.fullfillInterest(42);
});
Tree
offers a way to handle hierarchical data structures, allowing for the composition and traversal of tree-like data sets.
import { Tree } from '@push.rocks/lik';
class TreeNode {
constructor(public value: string) {}
}
const myTree = new Tree<TreeNode>();
const rootNode = new TreeNode('root');
myTree.initialize(rootNode);
// Add child nodes
const childNode = new TreeNode('child');
myTree.appendChild(rootNode, childNode);
Utilizing @push.rocks/lik in Your Project
With @push.rocks/lik
, you gain access to a comprehensive set of lightweight utilities that can significantly simplify and expedite the development process in Node.js environments. By leveraging the library's classes and functions, you can implement efficient data structures, manage asynchronous operations gracefully, and streamline complex logic with ease.
By integrating @push.rocks/lik
into your project, you'll benefit from improved code clarity, reduced boilerplate, and enhanced performance, allowing you to focus on developing the core functionalities of your application. Whether you're managing various collections, executing asynchronous tasks in controlled manners, or dealing with hierarchical data, @push.rocks/lik
provides the tools you need to achieve your objectives with minimal overhead.
Remember, continuous exploration of @push.rocks/lik
's capabilities and experimenting with its various components in different scenarios will help you unlock its full potential. As your familiarity with the library grows, you'll discover even more ways to optimize your codebase and streamline your development workflow.
License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at [email protected].
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.