Skip to content

Selectors API Examples

This page demonstrates usage of some of the selectors provided Quasar.

ProductTagSelector

Definition

typescript
declare class ProductTagSelector {
    comparisonType: 'does' | 'does_not';
    operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with';
    tags: string[];
    returnType: 'ALL' | 'ID';

    constructor(comparisonType: 'does' | 'does_not', operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with', tags: string[], returnType?: string);
    select(lines: any[]): any[];
}

Usage

The ProductTagSelector class is used to select lines based on product tags.

Parameters:

  • comparisonType: Specifies whether the tags should match ('does') or not match ('does_not').
  • operationType: Specifies the type of operation ('match_one', 'contains_one', 'starts_with', 'ends_with').
  • tags: An array of tags to compare against.
  • returnType: Specifies the type of return value ('ALL' for all line items, 'ID' for just the IDs).

Example:

javascript
const selector = new ProductTagSelector('does', 'match_one', ['SALE', 'NEW'], 'ID');
const selectedLines = selector.select(cart.lines);

ProductVendorSelector

Definition

typescript
declare class ProductVendorSelector {
    comparisonType: 'does' | 'does_not';
    operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with';
    productVendors: string[];
    returnType: 'ALL' | 'ID';

    constructor(comparisonType: 'does' | 'does_not', operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with', productVendors: string[], returnType?: string);
    select(lines: any[]): any[];
}

Usage

The ProductVendorSelector class is used to select lines based on product vendors.

Parameters:

  • comparisonType: Specifies whether the vendors should match ('does') or not match ('does_not').
  • operationType: Specifies the type of operation ('match_one', 'contains_one', 'starts_with', 'ends_with').
  • productVendors: An array of vendors to compare against.
  • returnType: Specifies the type of return value ('ALL' for all line items, 'ID' for just the IDs).

Example:

javascript
const selector = new ProductVendorSelector('does', 'contains_one', ['Nike', 'Adidas'], 'ALL');
const selectedLines = selector.select(cart.lines);

ProductTypeSelector

Definition

typescript
declare class ProductTypeSelector {
    comparisonType: 'does' | 'does_not';
    operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with';
    productTypes: string[];
    returnType: 'ALL' | 'ID';

    constructor(comparisonType: 'does' | 'does_not', operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with', productTypes: string[], returnType?: string);
    select(lines: any[]): any[];
}

Usage

The ProductTypeSelector class is used to select lines based on product types.

Parameters:

  • comparisonType: Specifies whether the types should match ('does') or not match ('does_not').
  • operationType: Specifies the type of operation ('match_one', 'contains_one', 'starts_with', 'ends_with').
  • productTypes: An array of product types to compare against.
  • returnType: Specifies the type of return value ('ALL' for all line items, 'ID' for just the IDs).

Example:

javascript
const selector = new ProductTypeSelector('does', 'starts_with', ['Electronics', 'Clothing'], 'ID');
const selectedLines = selector.select(cart.lines);

ReducedItemSelector

Definition

typescript
declare class ReducedItemSelector {
    comparisonType: 'is' | 'is_not';

    constructor(comparisonType: 'is' | 'is_not');
    select(lines: any[]): any[];
}

Usage

The ReducedItemSelector class is used to select lines based on whether the items are reduced in price.

Parameters:

  • comparisonType: Specifies whether the items should be reduced ('is') or not reduced ('is_not').

Example:

javascript
const selector = new ReducedItemSelector('is');
const selectedLines = selector.select(cart.lines);

RatePriceSelector

Definition

typescript
declare class RatePriceSelector {
    comparisonType: 'less_than' | 'greater_than' | 'equal_to';
    amount: number;

    constructor(comparisonType: 'less_than' | 'greater_than' | 'equal_to', amount: number);
    qualifies(rate: any): boolean;
}

Usage

The RatePriceSelector class is used to qualify rates based on their price.

Parameters:

  • comparisonType: Specifies the type of comparison ('less_than', 'greater_than', 'equal_to').
  • amount: The amount to compare against.

Example:

javascript
const selector = new RatePriceSelector('less_than', 50);
const isQualified = selector.qualifies(rate);

RateNameSelector

Definition

typescript
declare class RateNameSelector extends QualifierBase {
    name: string[];

    constructor(comparisonType: 'contains' | 'not_contains' | 'is_one' | 'is_not_one', name: string | string[]);
    qualifies(rate: any): boolean;
}

Usage

The RateNameSelector class is used to qualify rates based on their name.

Parameters:

  • comparisonType: Specifies the type of comparison ('contains', 'not_contains', 'is_one', 'is_not_one').
  • name: A string or array of strings to compare against.

Example:

javascript
const selector = new RateNameSelector('contains', 'Express');
const isQualified = selector.qualifies(rate);

AndSelector

Definition

typescript
declare class AndSelector {
    selectors: any[];

    constructor(selectors: any[]);
    select(lines: any[]): any[];
}

Usage

The AndSelector class is used to combine multiple selectors with AND logic.

Parameters:

  • selectors: An array of selectors to combine.

Example:

javascript
const tagSelector = new ProductTagSelector('does', 'match_one', ['SALE']);
const vendorSelector = new ProductVendorSelector('does', 'contains_one', ['Nike']);
const andSelector = new AndSelector([tagSelector, vendorSelector]);
const selectedLines = andSelector.select(cart.lines);

OrSelector

Definition

typescript
declare class OrSelector {
    selectors: any[];

    constructor(selectors: any[]);
    select(lines: any[]): any[];
}

Usage

The OrSelector class is used to combine multiple selectors with OR logic.

Parameters:

  • selectors: An array of selectors to combine.

Example:

javascript
const tagSelector = new ProductTagSelector('does', 'match_one', ['SALE']);
const vendorSelector = new ProductVendorSelector('does', 'contains_one', ['Nike']);
const orSelector = new OrSelector([tagSelector, vendorSelector]);
const selectedLines = orSelector.select(cart.lines);