UNPKG

@thiagoprz/fulltext-search-pipe

Version:

Angular pipe with full text search functionality

94 lines (86 loc) 3.42 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('@thiagoprz/fulltext-search-pipe', ['exports', '@angular/core'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.thiagoprz = global.thiagoprz || {}, global.thiagoprz['fulltext-search-pipe'] = {}), global.ng.core)); }(this, (function (exports, core) { 'use strict'; /** * FulltextSearchPipe * @author Thiago Przyczynski <przyczynski@gmail.com> */ var FulltextSearchPipe = /** @class */ (function () { function FulltextSearchPipe() { } /** * Transform method pipe * @param string value * @param string query * @param any field */ FulltextSearchPipe.prototype.transform = function (value, query, field) { var _this = this; return query ? value.reduce(function (prev, next) { if (typeof field == 'string') { query = query.toString(); if (next[field] && _this.removeAccents(next[field].toLowerCase()).includes(_this.removeAccents(query.toLowerCase()))) { prev.push(next); } } else { for (var i in field) { if (next[field[i]] && _this.removeAccents(next[field[i]].toLowerCase()).includes(_this.removeAccents(query.toLowerCase()))) { prev.push(next); break; } } } return prev; }, []) : value; }; /** * Removing accents * @param string value */ FulltextSearchPipe.prototype.removeAccents = function (value) { return value .replace(/á/g, 'a') .replace(/ã/g, 'a') .replace(/à/g, 'a') .replace(/é/g, 'e') .replace(/í/g, 'i') .replace(/ó/g, 'o') .replace(/ô/g, 'o') .replace(/õ/g, 'o') .replace(/ú/g, 'u'); }; return FulltextSearchPipe; }()); FulltextSearchPipe.decorators = [ { type: core.Pipe, args: [{ name: 'FullTextSearch' },] }, { type: core.Injectable } ]; FulltextSearchPipe.ctorParameters = function () { return []; }; var FulltextSearchPipeModule = /** @class */ (function () { function FulltextSearchPipeModule() { } return FulltextSearchPipeModule; }()); FulltextSearchPipeModule.decorators = [ { type: core.NgModule, args: [{ declarations: [FulltextSearchPipe], imports: [], exports: [FulltextSearchPipe] },] } ]; /* * Public API Surface of fulltext-search-pipe */ /** * Generated bundle index. Do not edit. */ exports.FulltextSearchPipe = FulltextSearchPipe; exports.FulltextSearchPipeModule = FulltextSearchPipeModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=thiagoprz-fulltext-search-pipe.umd.js.map