UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

43 lines (41 loc) 991 B
/** * 匹配正则,获取匹配到的列表 * @param {string} content 输入内容 * @param {RegExp} reg 正则 * @returns 匹配列表 * * @example * ```ts * getMatchListFromReg(content, /emit\('([^',]+)'/g); * * // ['start', 'end'] * ``` */ function getMatchListFromReg(content, reg) { var match = reg.exec(content); var result = []; while (match === null || match === void 0 ? void 0 : match[1]) { result.push(match[1]); match = reg.exec(content); } return result; } var PRE_RELEASE_VERSION = /\d+\.\d+\.\d+-(\w+).\d+/; /** * 获取预发布版本标签,比如 alpha, beta * @param {string} version 版本号 * @returns 标签 * @example * ```ts * getPreReleaseTag('1.2.2-beta.0') * // beta * ``` */ function getPreReleaseTag(version) { var match = version.match(PRE_RELEASE_VERSION); if (!(match === null || match === void 0 ? void 0 : match[1])) { return ''; } return match[1]; } export { getMatchListFromReg, getPreReleaseTag };