В моем коде мне нужно регулярное выражение, чтобы найти динамический ключ первого параметра во всех следующих случаях:
x => x.id // should return 'id'
x => x.a.biggerThan(5) // should return 'a'
x=>x.b.biggerThan(5) // should return 'b'
test => test.c.biggerThan(5) // should return 'c'
(x, y) => x.d.biggerThan(5) // should return 'd'
x => { return x.e.biggerThan(5); } // should return 'e'
(x, y) => { y = test.description; return x.f.biggerThan(y); } // should return 'f'
function (x) { return x.g.biggerThan(5); } // should return 'g'
function test(x) { return x.h.biggerThan(5); } // should return 'h'
function(x) { return x.i.biggerThan(5); } // should return 'i'
function(x){ return x.j.biggerThan(5); } // should return 'j'
function (x, y) { return x.l.biggerThan(5); } // should return 'l'
- Расширение причин, по которым мне это нужно -
Это функции, строковые с методом toString()
, и мне нужно создать динамический объект, который имеет этот ключ для вставки в эту функцию, например:
// get the key used by the function
const key = getkeyInFunc(func.toString());
// construct a dynamic object using that key
const builder = {
[key]: {
biggerThan: // biggerThan function
// others methods
}
};
// call the function with the dynamic key as parameter
const result = func(builder);
Пожалуйста, помогите мне, потому что я ужасен срегулярное выражение = (