MCPcopy Create free account
hub / github.com/Moli-X/Resources / Tools

Function Tools

Script/Parser.js:3568–3603  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3566
3567/***********************************************************************************************/
3568function Tools() {
3569 const filter = (src, ...regex) => {
3570 const initial = [...Array(src.length).keys()].map(() => false);
3571 return regex.reduce((a, expr) => OR(a, src.map(item => expr.test(item))), initial)
3572 }
3573
3574 const rename = {
3575 replace: (src, old, now) => {
3576 return src.map(item => item.replace(old, now));
3577 },
3578
3579 delete: (src, ...args) => {
3580 return src.map(item => args.reduce((now, expr) => now.replace(expr, ''), item));
3581 },
3582
3583 trim: (src) => {
3584 return src.map(item => item.trim().replace(/[^\S\r\n]{2,}/g, ' '));
3585 }
3586 }
3587
3588 const getNodeInfo = servers => {
3589 const nodes = {
3590 names: servers.map(s => s.split("tag=")[1]),
3591 types: servers.map(s => {
3592 const type = s.match(/^(vmess|trojan|shadowsocks|http)=/);
3593 return type ? type[1] : 'unknown';
3594 })
3595 };
3596 return nodes;
3597 }
3598
3599
3600 return {
3601 filter, rename, getNodeInfo
3602 }
3603}
3604
3605function AND(...args) {
3606 return args.reduce((a, b) => a.map((c, i) => b[i] && c));

Callers 2

FilterScriptFunction · 0.85
RenameScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected