UNPKG

cqcode

Version:

CQCode Helper for NodeJS.

38 lines (37 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.find = void 0; const parse_1 = require("./parse"); const regExpStr = '\\[CQ:(.+?)\\]'; /** * @param { string } text 即将被寻找CQCode的字符串。 * @param { FindProps } props 传入函数的参数。 * @return { CQCode[] } 返回寻找到的CQCode对象列表。 */ const find = (text, props) => { const { type, ignoreError } = props || {}; const matchedArr = text.match(new RegExp(regExpStr, 'ig')); const cqCodeArr = []; matchedArr?.forEach((v) => { try { cqCodeArr.push((0, parse_1.parse)(v)); } catch (err) { if (!ignoreError) { throw err; } } }); if (type) { if (typeof type === 'string') { return cqCodeArr.filter((v) => v.type === type); } else { return cqCodeArr.filter((v) => type.includes(v.type)); } } else { return cqCodeArr; } }; exports.find = find;