From 43c928295118557e4a95e9a804fde6089306501f Mon Sep 17 00:00:00 2001 From: atomiks Date: Mon, 19 Mar 2018 12:50:55 +1000 Subject: [PATCH 1/3] Create isBrowser.md --- snippets/isBrowser.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 snippets/isBrowser.md diff --git a/snippets/isBrowser.md b/snippets/isBrowser.md new file mode 100644 index 000000000..2145a2331 --- /dev/null +++ b/snippets/isBrowser.md @@ -0,0 +1,19 @@ +### isBrowser + +Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) +without throwing errors. + +Use `Array.includes()` on the `typeof` values of both `window` and `document` (globals usually only available in a +browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`. +`typeof` allows globals to be checked for existence without throwing a ReferenceError. + +If both of them are not `undefined`, then the current environment is assumed to be a browser. + +```js +const isBrowser = () => ![typeof window, typeof document].includes('undefined') +``` + +```js +isBrowser() // true (browser) +isBrowser() // false (Node) +``` From c4a9c0362992ba83f5fedabcb51981cbc162a152 Mon Sep 17 00:00:00 2001 From: atomiks Date: Mon, 19 Mar 2018 12:52:49 +1000 Subject: [PATCH 2/3] Update tag_database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index ebfa9820a..49a8f1be2 100644 --- a/tag_database +++ b/tag_database @@ -119,6 +119,7 @@ isAbsoluteURL:string,utility,browser,url isAnagram:string,regexp isArrayLike:type,array isBoolean:type +isBrowser:utility,browser isDivisible:math isEmpty:type,array,object,string isEven:math From 28856eed5404fbc30c49ee985449c4be681652c4 Mon Sep 17 00:00:00 2001 From: atomiks Date: Mon, 19 Mar 2018 12:54:51 +1000 Subject: [PATCH 3/3] Update isBrowser.md --- snippets/isBrowser.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snippets/isBrowser.md b/snippets/isBrowser.md index 2145a2331..0b41b4bba 100644 --- a/snippets/isBrowser.md +++ b/snippets/isBrowser.md @@ -5,9 +5,7 @@ without throwing errors. Use `Array.includes()` on the `typeof` values of both `window` and `document` (globals usually only available in a browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`. -`typeof` allows globals to be checked for existence without throwing a ReferenceError. - -If both of them are not `undefined`, then the current environment is assumed to be a browser. +`typeof` allows globals to be checked for existence without throwing a ReferenceError. If both of them are not `undefined`, then the current environment is assumed to be a browser. ```js const isBrowser = () => ![typeof window, typeof document].includes('undefined')