JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q27478F
  • License MIT

Regular expression builder for JavaScript with search mode options.

Package Exports

  • cstffx-search
  • cstffx-search/lib/TextSearch.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cstffx-search) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Description

Regular expression builder for JavaScript with search mode options.

Why?

Sometimes we need to filter an string collection, but we want to configure position, match case and if only complete words will count. In spanish is convenient for better user experience that some characters like a and á to be considered equal.

This is easy with regular expressions. For example: the regular expression /jon/ will match if the secuencejon is at any position in the target string, but /jon$/ will only at the end. search-builder provide a method to dinamically generate this regular expresions, you only need to pass the query and options.

Example

TextSearchRegex.build("jon doe", {
    ignoreCase: true
})

// Will output /jon doe/i

To reuse the same regular expresion we can use the class TextSearch.

    const items = [
        // ... string collection
    ];

    let search = new TextSearch("doe", {
        word: true,
        ignoreCase: true,
        position: TextSearchPosition.End
    });
    
    const result = items.filter( item => search.match(item) )

The result is a collection with strings that contains doe at the end, with any upper/lower case combination and only if doe is a complete word.