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

Check for existence of Buffer #63

Closed isidrok closed 3 years ago

isidrok commented 3 years ago

Hi, I'm using this library inside of a service worker and as there is no Buffer implementation I have to polyfill it although it will never be used.

It would be great if isBuffer checked for the existence of Buffer so the library can be used without problems in environments that don't support it:

// current
const isBuffer = Buffer.isBuffer;

// proposal
const isBuffer = (value) => typeof Buffer !== 'undefined' && Buffer.isBuffer(value)

Can submit a PR if interested in the change.

mathiasbynens commented 3 years ago

Yes please submit a PR!