Socket
Book a DemoInstallSign in
Socket

@chronicstone/array-query

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chronicstone/array-query

A simple and lightweight array query library

1.0.5
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

Array-Query

npm version npm downloads bundle JSDocs License

Query JavaScript arrays with ORM-like syntax, benefiting from excellent type-safety & developer experience.

Key Features:

  • 🛠 Type-safe Querying: Design your queries with strong typing (typed sort / search / filter keys & output)
  • 📄 Pagination: Easily paginate through large datasets with built-in support.
  • 🔎 Full-text Search: Perform comprehensive searches across multiple fields in your data.
  • 🧭 Advanced Filtering: Apply complex filters with various match modes for precise data retrieval. Supports logical grouping, nested conditions, and array matching.
  • 🔢 Flexible Sorting: Order results based on any field, with support for multiple sort criteria.
  • 🚀 Lightweight and Fast: Queries stay super fast, even with large datasets.
  • 🧩 Zero Dependencies: Completely self-contained with no external dependencies, ensuring a small bundle cost

INSTALLATION

// npm
npm install @chronicstone/array-query

// yarn
yarn add @chronicstone/array-query

// pnpm
pnpm add @chronicstone/array-query

// bun
bun add @chronicstone/array-query

USAGE EXAMPLE

import { query } from '@chronicstone/array-query'

const users = [
  { id: 1, fullName: 'John Doe', email: 'john@example.com', age: 30, status: 'active', roles: ['admin'], createdAt: '2023-01-01' },
  { id: 2, fullName: 'Jane Smith', email: 'jane@example.com', age: 28, status: 'inactive', roles: ['user'], createdAt: '2023-02-15' },
  { id: 3, fullName: 'Bob Johnson', email: 'bob@example.com', age: 35, status: 'active', roles: ['user', 'manager'], createdAt: '2023-03-20' },
  // ... more users
]

const { totalRows, totalPages, rows } = query(users, {
  // Pagination
  page: 1,
  limit: 10,

  // Sorting
  sort: [
    { key: 'age', dir: 'desc' },
    { key: 'fullName', dir: 'asc' }
  ],

  // Searching
  search: {
    value: 'john',
    keys: ['fullName', 'email']
  },

  // Filtering
  filter: [
    { key: 'status', matchMode: 'equals', value: 'active' },
    { key: 'age', matchMode: 'greaterThan', value: 25 },
  ]
})

This example demonstrates pagination, multi-field sorting, full-text searching, and complex filtering with nested conditions and array field matching.

License

MIT License © 2023-PRESENT Cyprien THAO

FAQs

Package last updated on 09 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.