通用评论

1
  1. {"version":3,"sources":["../src/helper.js"],"names":["isFunction","isUrl","arrayToObject","htmlEncode","renderContent","functionToCheck","toString","call","userInput","regexp","res","match","array","keyField","reduce","obj","item","str","replace","i","charCodeAt","content","onClick","REGEXP","a","b","src","slice","emojiObejct","emoji","value","prefixUrl","ext"],"mappings":";;;;;QAGgBA,U,GAAAA,U;QAMAC,K,GAAAA,K;QAYAC,a,GAAAA,a;QAYAC,U,GAAAA,U;QAaAC,a,GAAAA,a;;AA9ChB;;AACA;;;;;;AAEO,SAASJ,UAAT,CAAoBK,eAApB,EAAqC;AAC1C,SACEA,mBAAmB,GAAGC,QAAH,CAAYC,IAAZ,CAAiBF,eAAjB,MAAsC,mBAD3D;AAGD;;AAEM,SAASJ,KAAT,CAAeO,SAAf,EAA0B;AAC/B,MAAMC,SAAS,kGAAf;AACA,MAAIC,MAAMF,UAAUG,KAAV,CAAgBF,MAAhB,CAAV;AACA,MAAIC,QAAQ,IAAZ,EAAkB,OAAO,KAAP,CAAlB,KACK,OAAO,IAAP;AACN;;AAED;;;;;AAKO,SAASR,aAAT,CAAuBU,KAAvB,EAA8BC,QAA9B,EAAwC;AAC7C,SAAOD,MAAME,MAAN,CAAa,UAACC,GAAD,EAAMC,IAAN,EAAe;AACjCD,QAAIC,KAAKH,QAAL,CAAJ,IAAsBG,IAAtB;AACA,WAAOD,GAAP;AACD,GAHM,EAGJ,EAHI,CAAP;AAID;;AAED;;;;;AAKO,SAASZ,UAAT,CAAoBc,GAApB,EAAyB;AAC9B,MAAI,CAACA,GAAL,EAAU,OAAO,EAAP;AACV;AACA,SAAOA,IAAIC,OAAJ,CAAY,WAAZ,EAAyB,UAASC,CAAT,EAAY;AAC1C,WAAO,OAAOA,EAAEC,UAAF,CAAa,CAAb,CAAP,GAAyB,GAAhC;AACD,GAFM,CAAP;AAGD;;AAED;;;;;AAKO,SAAShB,aAAT,CAAuBiB,OAAvB,EAAgCC,OAAhC,EAAyC;AAC9C,SAAOnB,WAAWkB,OAAX,EAAoBH,OAApB,CAA4BK,gBAA5B,EAAoC,UAASC,CAAT,EAAYC,CAAZ,EAAe;AACxD,QAAMC,MAAMF,EAAEG,KAAF,CAAQ,CAAR,EAAW,CAAC,CAAZ,CAAZ;AACA,QAAI1B,MAAMyB,GAAN,CAAJ,EAAgB;AACd,6BAAoBA,GAApB,iBAAiCA,GAAjC;AACD;AACD,QAAME,cAAc1B,cAAc2B,eAAd,EAAqB,OAArB,CAApB;AACA,QAAMC,QAAQF,YAAYF,GAAZ,EAAiBI,KAA/B;AACA,2BAAoBC,gBAApB,GAAgCD,KAAhC,SAAyCE,UAAzC,iBAAsDF,KAAtD;AACD,GARM,CAAP;AASD","file":"helper.js","sourcesContent":["import { REGEXP } from \"./constant\";\nimport emoji, { prefixUrl, ext } from \"./emoji\";\n\nexport function isFunction(functionToCheck) {\n return (\n functionToCheck && {}.toString.call(functionToCheck) === \"[object Function]\"\n );\n}\n\nexport function isUrl(userInput) {\n const regexp = /(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\n var res = userInput.match(regexp);\n if (res === null) return false;\n else return true;\n}\n\n/**\n * 将对象数组转换为对象\n * @param {array} array Array of Objects\n * @param {string} keyField string\n */\nexport function arrayToObject(array, keyField) {\n return array.reduce((obj, item) => {\n obj[item[keyField]] = item;\n return obj;\n }, {});\n}\n\n/**\n * HTML 编码\n * 将 < > 等字符串进行编码\n * @param {string} str 文本\n */\nexport function htmlEncode(str) {\n if (!str) return \"\";\n // /[\\u00A0-\\u9999<>\\&]/gim // 中文和 HTML 字符\n return str.replace(/[<>\\&]/gim, function(i) {\n return \"&#\" + i.charCodeAt(0) + \";\";\n });\n}\n\n/**\n * 渲染编辑器\n * [x] => <img src=\"x\" />\n * @param {strig} content\n */\nexport function renderContent(content, onClick) {\n return htmlEncode(content).replace(REGEXP, function(a, b) {\n const src = a.slice(1, -1);\n if (isUrl(src)) {\n return `<img src=\"${src}\" alt=\"${src}\" style=\"max-width: 300px\" />`;\n }\n const emojiObejct = arrayToObject(emoji, \"title\");\n const value = emojiObejct[src].value;\n return `<img src=\"${prefixUrl}${value}.${ext}\" alt=\"${value}\" />`;\n });\n}\n"]}