From d42a85dd5fdf96202b5d79b1c3fbf5d0946c9842 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 18 Mar 2019 15:06:10 -0400 Subject: [PATCH] Enable Web Worker support This commit allows for this library to be imported within the context of a web worker. When a script is imported via a Worker the `self` should be a sub-type of the `WorkerGlobalScope` object. Registering the library to `self.cssbeautify` allows workers to access it via `this.cssbeautify`. --- cssbeautify.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cssbeautify.js b/cssbeautify.js index b4ae096..e5a7dfb 100644 --- a/cssbeautify.js +++ b/cssbeautify.js @@ -464,6 +464,9 @@ } else if (typeof window === 'object') { // Browser loading. window.cssbeautify = cssbeautify; + } else if (self instanceof WorkerGlobalScope) { + // Web worker. + self.cssbeautify = cssbeautify; } }());