Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
@smakss/search
Advanced tools
Searching through arrays or objects might be easy these days with array helpers like filter, but what if you have a nested array of object and want to search into every key of your object with a specific keyword? This might be hard or frustrating sometimes, this package will help you to achieve search a keyword through each object key, array elements and/or nested arrays. Also, this package uses ES6+ syntax so if you using older standards for writing JS code you may need a transpiler for it.
To install it you can simply do the following command:
npm i @smakss/search
or
yarn add @smakss/search
to include it with common js module you should do this:
var search = require('@smakss/search');
and to include it with ECMAscript module you can simply do this one:
import search from '@smakss/search';
then to use it within your application you can do it just like below:
The search function will accept 4 input parameter:
searchText
(String
): The string that you want to look for in your element (It will match the whole string without regards to case sensitivity).searchItems
(Object|Array
): Element that you want to perform a search on it.keys
(Array
): Keys to include or exclude in your object items. If you exclude them it will exclude them from search and search won't perform on those specific keys. And if you include them search will only perform on those desired keys and it will ignore others.include
(Boolean
): A flag to determine whether the keys
are included or excluded.Passing an object: If the matching element was in object it will return the whole object.
const obj = { name: "John", lastName: "Doe" };
search({ searchText: "john", searchItems: array });
// Result: [{ lastName: "Doe", name: "John" }]
Passing an array:
const arr = [
{ name: "John", lastName: "Doe" },
{ name: "Joe", lastName: "Doe" }
];
search({ searchText: "john", searchItems: arr });
// Result: [{ lastName: "Doe", name: "John" }]
Passing a nested array:
const arr = [
{ name: "John", lastName: "Doe" },
{ name: "Joe", lastName: "Doe" },
[{ name: "Jane", lastName: "Doe" }]
];
search({ searchText: "jane", searchItems: arr });
// Result: [{ lastName: "Doe", name: "Jane" }]
You can check the working demo in runkit.
FAQs
Enhance your searching capabilities with @smakss/search. Effortlessly find keywords in arrays, nested arrays, and objects, perfect for deep search needs in various data structures.
The npm package @smakss/search receives a total of 64 weekly downloads. As such, @smakss/search popularity was classified as not popular.
We found that @smakss/search 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
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.