-4

I need to remove double quotes for specific key value:

upload: {
    name: "upload",
    url: "/upload",
    controller: "invoicesCtrl",
    templateUrl: "./views/invoices.html",
    resolve: "resolveUrl('./compiled/invoices_app.js')"
  },
  invoices: {
    name: "invoices",
    url: "/invoices",
    controller: "invoicesCtrl",
    templateUrl: "/invoices/views/invoices.html",
    resolve: "resolveUrl('/invoices/app/js/compiled/invoices_app.js')"
  }

Just for resolve key values, the others have to be strings. Is there any regular expression for this with the replace function? The expected result:

upload: {
    name: "upload",
    url: "/upload",
    controller: "invoicesCtrl",
    templateUrl: "./views/invoices.html",
    resolve: resolveUrl('./compiled/invoices_app.js')
  },
  invoices: {
    name: "invoices",
    url: "/invoices",
    controller: "invoicesCtrl",
    templateUrl: "/invoices/views/invoices.html",
    resolve: resolveUrl('/invoices/app/js/compiled/invoices_app.js')
  }
War10ck
  • 12,387
  • 7
  • 41
  • 54
AndreFontaine
  • 2,334
  • 3
  • 17
  • 30
  • Assuming you are using JavaScript, possible duplicate: http://stackoverflow.com/questions/19156148/i-want-to-remove-double-quotes-from-a-string. – Sean Perkins Dec 15 '15 at 21:13
  • @SeanPerkins thats not what I expected – AndreFontaine Dec 15 '15 at 21:16
  • If I understand your question correctly, you want to assign `resolve` the result of running `eval` on the current value of `resolve`? – ndnenkov Dec 15 '15 at 21:17
  • Side note, that's just a JavaScript object, not JSON. I've edited your title to reflect this and removed the `json` tag... – War10ck Dec 15 '15 at 21:18

1 Answers1

3

When you're saying remove double quotes and the only double quoes in resolve are the string literal terminators, are you saying you want a JavaScript function called resolveUrl to be called at some point, and that resolve should be the result of that call?

In that case, you could do something like:

// iterate through all properties of myObject, assuming it is a flat
// object containing upload and invoices from your code
Object.keys(myObject).forEach(function(key) {

   if(myObject[key].hasOwnProperty('resolve'))
      myObject[key].resolve = eval(myObject[key].resolve);

});

If you know that it will always be a resolveUrl call, it'd be more safe to just let the original property contain the string value - eg. resolve: '/invoices/app/js/compiled/invoices_app.js' - and then call resolveUrl manually:

if(myObject[key].hasOwnProperty('resolve'))
   myObject[key].resolve = resolveUrl(myObject[key].resolve);
David Hedlund
  • 128,221
  • 31
  • 203
  • 222