npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-advanced-search

v1.1.7

Published

A search field with advaned options. Made for Angular, with Angular Material components.

Downloads

19

Readme

ng-advanced-search

This is an Angular Component, made with Angular Material input elements that makes advanced filtering easy to use, both by the user and the code.

Example can be seen here

Features

It has two main parts:

  • Basic search
  • Advanced search

The basic search provides a simple text input for the user. With the advanced search the user can add a number of rules, each having the following properties:

  • The column to apply the rule on
  • Whether the rule should be negated
  • The rule criteria (contains, equals, larger than, smaller than)
  • The rule search-term

Additionally, the user can choose if the relationship between the rules should be AND or OR.

If an input array is provided for the component, it will apply the search terms on them, and provide the resulted array as an output array. Additionally, the component also outputs the search term, so a custom filter can be used.

When the filtering is left to the component, it behaves like so:

  • Basic search compares every property value of an array item (as a lowercase string), against the lowercase basic search term. If at least one property includes the search term, the item passes.
  • Advanced search compares the item property of the key chosen in the rule (as a lowercase string), against the rules search term. It compares them based on the criteries choosen for the rule. Depending on the relationship selected, the item passes if all or at least one rule passes.

The component also has some unused space, where custom elements can be used (eg: column-toggle buttons).

Usage

Install

The compoent can be installed from npm

npm install ng-advanced-search

Import

Add the component to your imports in app.module.ts:

import { NgAdvancedSearchModule } from 'ng-advanced-search';

@NgModule({
   imports: [
      ...
      NgAdvancedSearchModule,
      ...
   ],

Include dependency stylesheets

Add these lines to your styles.scss:

@import '../node_modules/bootstrap/scss/bootstrap.scss';
@import '../node_modules/@fortawesome/fontawesome-free/css/all.min.css';

Use

Add the component to your template:

   <ng-advanced-search [headers]="headers" [simpleFieldLabel]="Search items"
      [defaultTerm]="default" (selectedTerm)="termChanged($event)"
      [inputArray]="inputArray" (outputArray)="outputChanged($event)">

      Optional custom content

   </ng-advanced-search>

Inputs |Name|Type|Description|Required?| |----|----|-----------|---------| | headers | NgAsHeader[ ] | An array that defines what columns the user can choose from for advanced rules | Yes | | simpleFieldLabel | string | Placeholder text for the basic search term fiels | No | | defaultTerm | NgAsSearchTerm | Search terms to apply by default | No | | inputArray | any[ ] | Array to perform filtering on | No |

Outputs |Name|Type|Description| |----|----|-----------| | selectedTerm | NgAsSearchTerm | Search term applied by user | | outputArray | any[ ] | If an input array was provided, this will have the search term applied to it

Styling

The input fileds are Angular Material components, refer to that documentation for styling. The rest of the components use two colors, which can be overriden by inculding this in your styles.scss:

:root {
    --ngas-primary-color: [your-color-here];
    --ngas-danger-color: [your-color-here];
}

Types

export interface NgAsSearchTerm {
    searchMode: 'simple' | 'advanced';

    simpleSearchTerm: string;
    
    advancedSearchLink: 'and' | 'or';
    advancedTerms: NgAsAdvancedSearchTerm[];
}

export interface NgAsAdvancedSearchTerm {
    id: number;
    fieldName?: string;
    action?: 'contains' | 'equals' | 'larger than' | 'smaller than';
    searchTerm?: string;
    isNegated?: boolean;
}

export interface NgAsHeader {
    id: string;
    displayText: string;
}