8000 GitHub - data-pirate/probejs-core
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

data-pirate/probejs-core

Repository files navigation

probejs-core 🔍

npm version Build Status codecov License: MIT

A powerful and precise tool for traversing and investigating nested objects in JavaScript.

Features

  • 🎯 Find values by key in deeply nested objects
  • 📍 Get exact paths to found values
  • 🔄 Case-sensitive and case-insensitive search
  • 🚀 High performance with optional caching
  • 🎮 Simple and intuitive API
  • 📊 Built-in performance monitoring
  • 💪 Written in TypeScript with full type support

Installation

npm install probejs-core
# or
yarn add probejs-core

Quick Start

import { Probe } from 'probejs-core';

const data = {
  users: {
    john: {
      id: 1,
      email: 'john@example.com',
      profile: {
        email: 'john.doe@example.com'
      }
    }
  }
};

// Create a new probe
const probe = new Probe(data);

// Find first email
const result = probe.find('email');
console.log(result);
// { value: 'john@example.com', path: 'users.john.email', key: 'email' }

// Find all emails
const allEmails = probe.find('email', 'all');
// [
//   { value: 'john@example.com', path: 'users.john.email', key: 'email' },
//   { value: 'john.doe@example.com', path: 'users.john.profile.email', key: 'email' }
// ]

API

Creating a Probe

const probe = new Probe(data, {
  caseSensitive: true,    // default: true
  maxDepth: Infinity,     // default: Infinity
  pathDelimiter: '.',     // default: '.'
  caching: true          // default: true
});

Methods

find(key, occurrence?)

Find value(s) by key

probe.find('email');                // Find first occurrence
probe.find('email', 'last');        // Find last occurrence
probe.find('email', 'all');         // Find all occurrences

findByPath(path)

Find value at exact path

probe.findByPath('users.john.email');

findWhere(predicate)

Find values matching a condition

probe.findWhere(value => typeof value === 'number' && value > 10);

Performance Monitoring

// Get performance statistics
const stats = probe.getStatistics();
console.log(stats);
// {
//   searches: number,
//   cacheHits: number,
//   cacheMisses: number,
//   averageSearchTime: number
// }

// Clear the cache
probe.clearCache();

Examples

Check out the examples directory for more use cases.

Documentation

Full documentation is available in the docs directory.

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

MIT © [Damanpreet Singh]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0