
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
js-helper-functions
Advanced tools
TypeScript utility functions.
countItemsInMultidimensionalObject
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. |
{
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
}
}
}
formatAsKey
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"
removeItemFromMultidimensionalObject
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. |
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 50 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.