Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@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. It will be True
by default, which means the keys will be included.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: obj });
// 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" }]
Passing a nested array with including keys:
const arr = [
{ name: "John", lastName: "Doe" },
{ name: "Joe", lastName: "Doe" },
[{ name: "Jane", lastName: "Doe" }]
];
Search({ searchText: "jane", searchItems: arr, keys: ['name'] });
// Result: [{ lastName: "Doe", name: "Jane" }]
Passing a nested array with excluding keys:
const arr = [
{ name: "John", lastName: "Doe" },
{ name: "Joe", lastName: "Doe" },
[{ name: "Jane", lastName: "Doe" }]
];
Search({ searchText: "jane", searchItems: arr, keys: ['name'], include: false });
// Result: []
// The result will be an empty array when nothing matches with the provided params
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 0 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.