mathiasbynens / jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.
https://mths.be/jsesc
MIT License
716 stars 53 forks source link

feat: check for Buffer existence #64

Closed isidrok closed 3 years ago

isidrok commented 3 years ago

Check for existence of Buffer so it doesn't throw in environments that don't implement it.

Closes https://github.com/mathiasbynens/jsesc/issues/63

I didn't add any test since testing this is pretty awkward but could add something like this if needed:

it('does not throw when Buffer is not defined', function() {
  assert.doesNotThrow(function() {
    const _Buffer = global.Buffer;
    global.Buffer = undefined;
    delete require.cache[require.resolve('../jsesc.js')];
    require('../jsesc.js');
    global.Buffer = _Buffer;
  });
});