cacheman-file icon indicating copy to clipboard operation
cacheman-file copied to clipboard

String.replace() works only with the first occurence

Open Sweetchuck opened this issue 9 years ago • 0 comments

The following lines might cause problems in certain cases.

  • https://github.com/anaptfox/cacheman-file/blob/8fcf3f8087790b9a0830d37951c06c991cc286a2/index.js#L20
  • https://github.com/anaptfox/cacheman-file/blob/8fcf3f8087790b9a0830d37951c06c991cc286a2/index.js#L35
  • https://github.com/anaptfox/cacheman-file/blob/8fcf3f8087790b9a0830d37951c06c991cc286a2/index.js#L93
  • https://github.com/anaptfox/cacheman-file/blob/8fcf3f8087790b9a0830d37951c06c991cc286a2/index.js#L112
file = file.replace('.json', '').replace('_', ':');
file = file.replace(/\.json$/, '').replace(/_/g, ':');

Other widely used pattern is 'foo:foo'.split('foo').join('bar'); // bar:bar

Sweetchuck avatar Jan 23 '16 23:01 Sweetchuck