UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

112 lines (106 loc) 3.57 kB
import { Pipe, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: highlight.pipe.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // Regular Expressions for parsing tags and attributes /** @type {?} */ const SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; // ! to ~ is the ASCII range. /** @type {?} */ const NON_ALPHANUMERIC_REGEXP = /([^\#-~ |!])/g; /** * Escapes all potentially dangerous characters, so that the * resulting string can be safely inserted into attribute or * element text. * @param {?} value * @return {?} */ function encodeEntities(value) { return value .replace(/&/g, '&amp;') .replace(SURROGATE_PAIR_REGEXP, (/** * @param {?} match * @return {?} */ (match) => { /** @type {?} */ const hi = match.charCodeAt(0); /** @type {?} */ const low = match.charCodeAt(1); return `&#${(hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000};`; })) .replace(NON_ALPHANUMERIC_REGEXP, (/** * @param {?} match * @return {?} */ (match) => `&#${match.charCodeAt(0)};`)) .replace(/</g, '&lt;') .replace(/>/g, '&gt;'); } class NzHighlightPipe { constructor() { this.UNIQUE_WRAPPERS = ['##==-open_tag-==##', '##==-close_tag-==##']; } /** * @param {?} value * @param {?} highlightValue * @param {?=} flags * @param {?=} klass * @return {?} */ transform(value, highlightValue, flags, klass) { if (!highlightValue) { return value; } // Escapes regex keyword to interpret these characters literally /** @type {?} */ const searchValue = new RegExp(highlightValue.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$&'), flags); /** @type {?} */ const wrapValue = value.replace(searchValue, `${this.UNIQUE_WRAPPERS[0]}$&${this.UNIQUE_WRAPPERS[1]}`); return encodeEntities(wrapValue) .replace(new RegExp(this.UNIQUE_WRAPPERS[0], 'g'), klass ? `<span class="${klass}">` : '<span>') .replace(new RegExp(this.UNIQUE_WRAPPERS[1], 'g'), '</span>'); } } NzHighlightPipe.decorators = [ { type: Pipe, args: [{ name: 'nzHighlight', pure: true },] } ]; if (false) { /** * @type {?} * @private */ NzHighlightPipe.prototype.UNIQUE_WRAPPERS; } /** * @fileoverview added by tsickle * Generated from: highlight.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzHighlightModule { } NzHighlightModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], exports: [NzHighlightPipe], declarations: [NzHighlightPipe] },] } ]; /** * @fileoverview added by tsickle * Generated from: public-api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: ng-zorro-antd-core-highlight.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzHighlightModule, NzHighlightPipe }; //# sourceMappingURL=ng-zorro-antd-core-highlight.js.map