
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
js-helper-functions
Advanced tools
TypeScript utility functions.
A function that recursively counts the number of selected items in a nested data structure. This function is particularly useful when dealing with hierarchical selection states such as those found in tree views, nested checklists, or multi-level category pickers.
type NestedObject = {
[key: string]: Node | string[];
};
Name | Type | Description |
---|---|---|
data | NestedObject Or string[] | A nested object or array representing selected items. |
📤 Returns
{
total: number; // Total count of items in the entire structure
result: {
[key: string]: number | { ...nested_object }
}
}
const selection = {
fruits: ["apple", "banana"],
vegetables: {
root: ["carrot", "beet"],
leafy: ["spinach"],
},
grains: {
rice: ["basmati"],
wheat: [],
},
};
const result = countItemsInMultidimensionalObject(selection);
console.log(result);
{
total: 6,
result: {
fruits: 2,
vegetables: {
root: 2,
leafy: 1
},
grains: {
rice: 1,
wheat: 0
}
}
}
A lightweight utility function that transforms a given string into a valid key name or key by normalizing spaces, removing special characters, and converting to lowercase.
Name | Type | Description |
---|---|---|
query | string | The string to be formatted. |
Type | Description |
---|---|
string | A kebab-cased, sanitized string suitable for use as a CSS class name or identifier. |
formatAsKey("Primary Button"); // "primary-button"
formatAsKey("Save&Continue!"); // "save-continue"
formatAsKey(" Complex--Key!! "); // "complex-key"
formatAsKey("Already-formatted_key"); // "already-formatted-key"
A recursive utility function that removes a specific item from a deeply nested object structure where values can be arrays or further nested objects.
type NestedObject = {
[key: string]: Node | string[];
};
Name | Type | Description |
---|---|---|
obj | NestedObject | The nested object from which to remove the item. |
path | string[] | An array representing the path to the array in the structure. |
itemToRemove | string | The item to be removed from the array at the given path. |
📤 Returns
Type | Description |
---|---|
NestedObject | A new object with the specified item removed. |
const nested = {
category1: {
subcategory1: ["item1", "item2"],
subcategory2: ["item3"],
},
category2: {
subcategory3: ["item4"],
},
};
const result = removeItemFromMultidimensionalObject(
nested,
["category1", "subcategory1"],
"item2"
);
console.log(result);
{
category1: {
subcategory1: ['item1'],
subcategory2: ['item3']
},
category2: {
subcategory3: ['item4']
}
}
FAQs
---
The npm package js-helper-functions receives a total of 4 weekly downloads. As such, js-helper-functions popularity was classified as not popular.
We found that js-helper-functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.