JSFiddle - React, Tailwind, and code Playground
by Darby Rathbone
JavaScript
var selectors, actions;
var a = ' $(selector).action("crazy(); content((())); here"); myotherfunction(); $(more).crazy("jQuery"); ';
var takeout = function (a) {
var _a = [];
while (/\(([^()]*)\)/gim.test(a)) {
a = a.replace(/\(([^()]*)\)/gim, function () {
_a.push(arguments[0]);
return "~~" + (_a.length - 1) + "~~";
});
}
return {
array: _a,
string: a
};
};
var putin = function (a) {
var _a = this;
while (/[~]{2}(\d+)[~]{2}/gim.test(a)) {
a = a.replace(/[~]{2}(\d+)[~]{2}/gim, function (e, i) {
return _a[i];
});
}
return a;
};
b = takeout(a).string.split(/(\$|\;|\.)/gim);
console.log(b);
selectors = b.filter(function (e, i) {
return b[i - 1] && b[i - 1] === '$';
});
actions = b.filter(function (e, i) {
return b[i - 1] && b[i - 1] === '.';
});
console.log(takeout(a));
//b = b.map(putin,takeout(a));
selectors = selectors.map(putin, takeout(a).array);
actions = actions.map(putin, takeout(a).array);
console.log('selectors:', selectors, 'actions:', actions);