diff --git a/README.md b/README.md index ee4575786..0618ca9fa 100644 --- a/README.md +++ b/README.md @@ -8260,12 +8260,11 @@ Logs: { ### isBrowser -Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) -without throwing errors. +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. +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'); diff --git a/docs/index.html b/docs/index.html index 6d24f7807..948e1eb10 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1990,7 +1990,7 @@ Logs: { "id": 101 } */ -
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.
const isBrowser = () => ![typeof window, typeof document].includes('undefined'); +
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.
const isBrowser = () => ![typeof window, typeof document].includes('undefined');
isBrowser(); // true (browser) isBrowser(); // false (Node)
Returns the index of the function in an array of functions which executed the fastest.
Use Array.map() to generate an array where each value is the total time taken to execute the function after iterations times. Use the difference in performance.now() values before and after to get the total time in milliseconds to a high degree of accuracy. Use Math.min() to find the minimum execution time, and return the index of that shortest time which corresponds to the index of the most performant function. Omit the second argument, iterations, to use a default of 10,000 iterations. The more iterations, the more reliable the result but the longer it will take.
const mostPerformant = (fns, iterations = 10000) => {