UNPKG

@ginstone/nga-api

Version:

53 lines (52 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleContent = exports.getExtension = exports.parseBit = exports.getBigIcon = exports.getIcon = exports.clearLinkBreak = void 0; const StrUtils_1 = require("@ginstone/common-utils/dist/src/utils/StrUtils"); /** * 删除干扰的换行符 * @param s 源字符串 */ const clearLinkBreak = (s) => { return s.replace(/\n/g, '').replace(/\r/g, ''); }; exports.clearLinkBreak = clearLinkBreak; const getIcon = (isCol, fid, colTId) => { return isCol ? `https://img4.nga.178.com/proxy/cache_attach/ficon/${colTId}v.png` : `https://img4.nga.178.com/proxy/cache_attach/ficon/${fid}u.png`; }; exports.getIcon = getIcon; const getBigIcon = (id) => { return `https://img4.nga.178.com/ngabbs/nga_classic/f/app/${id}.png`; }; exports.getBigIcon = getBigIcon; /** * 解析bit数据 * @param bit bit */ const parseBit = (bit) => { bit = Number(bit); return bit.toString(2).split("").reverse().join(''); }; exports.parseBit = parseBit; /** * 获取扩展名 * @param name 文件名或url地址 */ const getExtension = (name) => { return name.substring(name.lastIndexOf(".") + 1); }; exports.getExtension = getExtension; /** * 处理正文 ,反转义,再解码unicode * @param text */ const handleContent = (text) => { if (!text) { return ''; } text = (0, StrUtils_1.unEscape)(text) || ''; text = text.replace(/&#(\d+);/g, ($, $1) => String.fromCodePoint($1)); return text; }; exports.handleContent = handleContent;