ng-zorro-antd-yj
Version:
An enterprise-class UI components based on Ant Design and Angular
39 lines • 3.17 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} prefix
* @return {?}
*/
export function getRegExp(prefix) {
/** @type {?} */
var prefixArray = Array.isArray(prefix) ? prefix : [prefix];
/** @type {?} */
var prefixToken = prefixArray.join('').replace(/(\$|\^)/g, '\\$1');
if (prefixArray.length > 1) {
prefixToken = "[" + prefixToken + "]";
}
return new RegExp("(\\s|^)(" + prefixToken + ")[^\\s]*", 'g');
}
/**
* @param {?} value
* @param {?=} prefix
* @return {?}
*/
export function getMentions(value, prefix) {
if (prefix === void 0) { prefix = '@'; }
if (typeof value !== 'string') {
return [];
}
/** @type {?} */
var regex = getRegExp(prefix);
/** @type {?} */
var mentions = value.match(regex);
return mentions !== null ? mentions.map((/**
* @param {?} e
* @return {?}
*/
function (e) { return e.trim(); })) : [];
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0TWVudGlvbnMuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9uZy16b3Jyby1hbnRkLXlqLyIsInNvdXJjZXMiOlsiY29yZS91dGlsL2dldE1lbnRpb25zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7O0FBQUEsTUFBTSxVQUFVLFNBQVMsQ0FBQyxNQUF5Qjs7UUFDM0MsV0FBVyxHQUFHLEtBQUssQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUM7O1FBQ3pELFdBQVcsR0FBRyxXQUFXLENBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxVQUFVLEVBQUUsTUFBTSxDQUFDO0lBRWxFLElBQUksV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