Nukem's Possible Manifestation
    Wondering what’s next for npm?Check out our public roadmap! »

    @writetome51/abstract-search-service
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.2 • Public • Published

    AbstractSearchService

    An abstract TypeScript/JavaScript class that provides a results property,
    and an abstract _searchAlgorithm method. results is read-only, and when
    accessed returns the result of _searchAlgorithm().
    _searchAlgorithm must be defined in a subclass.

    Example

    view example
    // Create a subclass...
    export class UserSearchService extends AbstractSearchService {
     
        searchText = '';
     
        constructor(private __users){
        }
     
        protected _searchAlgorithm() {
            // If no searchText, return all users:
            if (this.searchText.length === 0) return this.__users;
                        
            // Else, check if searchText found in user's name:
            else return this.__users.filter((user) => {
                if (user.name === undefined) return false;
                else return (user.name.includes(this.searchText));
            });
        }
     
    }
     
    let userSearch = new UserSearchService(getUsersSomehow());
    userSearch.searchText = 'Jane Fonda';
     
    console.log(userSearch.results);
    // logs array of users whose names match 'Jane Fonda'

    Properties

    resultsany // read-only

    Methods

    protected abstract _searchAlgorithm(): any
    

    Installation

    npm i @writetome51/abstract-search-service

    Loading

    // if using TypeScript:
    import { AbstractSearchService } from '@writetome51/abstract-search-service';
    // if using ES5 JavaScript:
    var AbstractSearchService = 
        require('@writetome51/abstract-search-service').AbstractSearchService;

    License

    MIT

    Install

    npm i @writetome51/abstract-search-service

    DownloadsWeekly Downloads

    17

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    4.51 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar