-1

I want to convert the following js code in ts, without using loadish.js.

let claimNames = _.filter<string>(_.keys(decodedToken), o =>
    o.startsWith(ns)
  );      
let claims = <any>(
   _.mapKeys(_.pick(decodedToken, claimNames), (value, key) =>
      key.replace(ns, "").substring(1)
   )
);

or is there a place where I can find some help regarding this situation.

belwood
  • 3,320
  • 11
  • 38
  • 45

1 Answers1

0

So you have an object, with keys starting with a ns-defined substring, let's says it is 'ns'.

Example:

{
  foobar: 'foobar',
  nsfoo: 'foo',
  nsbar: 'bar'
}

And you want to map this to

{
  foo: 'foo',
  bar: 'bar'
}

You can do this:

var ns = 'ns';
var obj = {
  foobar: 'foobar',
  nsfoo: 'foo',
  nsbar: 'bar'
};

var newObj = {};
Object.keys(obj).filter(key => key.startsWith(ns)).forEach(key => newObj[key.replace(ns, '')] = obj[key]);

console.log(newObj);
MoxxiManagarm
  • 8,735
  • 3
  • 14
  • 43