Skip to content

a script for recursively wildcard searching keys and string elements in the javascript window object

Notifications You must be signed in to change notification settings

JustinLawrenceMS/somewhat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Somewhat

Somewhat is a lightweight utility package that simplifies wildcard searches in JavaScript objects, DOM elements, and JSON. This package is ideal for developers who need quick and effective searching capabilities in their applications.

npm version MIT License

Features

  • Wildcard Search: Supports flexible pattern matching.
  • Cross-Context Support: Works with objects, JSON, and the DOM.
  • Lightweight: Minimal dependencies for faster performance.

Installation

Install the package via npm:

npm install --save-dev https://github.com/JustinLawrenceMS/somewhat 

Quick Start

import Somewhat from "somewhat";

const obj = { a: "apple", b: "banana" };
const searcher = new Somewhat();
const results = searcher.searchObject(obj, "a*");

console.log(results); // Output: [ { path: "a", value: "apple" } ]

Usage

Searching Objects

You can use Somewhat to search JavaScript objects:

const obj = {
  a: "apple",
  b: "banana",
  c: "cherry",
};

const results = searcher.searchObject(obj, "a*");
console.log(results);
// Output: [ { path: "a", value: "apple" } ]

Searching the DOM

Search the DOM for elements matching a wildcard pattern:

const results = searcher.searchDOM(document.body, "data-*");
console.log(results);
// Output: [ { path: ".children[0].children[1]@data-attr", value: "test" } ]

Searching JSON

You can search JSON data using the same method as objects:

const jsonData = {
  a: "apple",
  b: "banana",
  nested: {
    c: "cherry",
  },
};

const results = searcher.searchObject(jsonData, "*erry");
console.log(results);
// Output: [ { path: "nested.c", value: "cherry" } ]

Searching the Entire Document

Search the entire document for text content matching a pattern:

const results = searcher.searchDocument("*world*");
console.log(results);
// Output: [ { path: ".children[0].textContent", value: "Hello, world!" } ]

Testing

Run the tests using Jest:

npm test

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

Support

If you encounter issues, please open an issue on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

a script for recursively wildcard searching keys and string elements in the javascript window object

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published