probejs-core
v1.0.0
Published
A powerful tool for traversing and investigating nested objects
Downloads
78
Maintainers
Readme
probejs-core 🔍
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: '[email protected]',
profile: {
email: '[email protected]'
}
}
}
};
// Create a new probe
const probe = new Probe(data);
// Find first email
const result = probe.find('email');
console.log(result);
// { value: '[email protected]', path: 'users.john.email', key: 'email' }
// Find all emails
const allEmails = probe.find('email', 'all');
// [
// { value: '[email protected]', path: 'users.john.email', key: 'email' },
// { value: '[email protected]', 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]