-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** @namespace Global */ | ||
|
||
import "./isBrowser"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as method from "./method"; | ||
|
||
declare global { | ||
namespace NodeJS { | ||
interface Global { | ||
isBrowser(): boolean; | ||
} | ||
} | ||
|
||
const isBrowser: () => boolean; | ||
} | ||
|
||
/** | ||
* Determines if the current runtime environment is a browser, | ||
* so that front-end modules can run on the server (Node) without throwing errors | ||
* @memberof Global | ||
* @returns {boolean} | ||
* @example | ||
* isBrowser(); // false | ||
*/ | ||
global.isBrowser = method; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as contains from "../../array/contains/method"; | ||
|
||
const method = () => !contains([typeof window, typeof document], "undefined"); | ||
|
||
export = method; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import "./index"; | ||
|
||
beforeAll(() => { | ||
// Jest creates virtual ones ! | ||
delete (global as any).window; | ||
delete (global as any).document; | ||
}); | ||
|
||
describe("Global.isBrowser", () => { | ||
test("isBrowser() returns false", () => { | ||
expect(isBrowser()).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as isBrowser from "./isBrowser/method"; | ||
|
||
export { | ||
isBrowser, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
const method = (obj: { [key: string]: any }): number => Object.keys(obj).length; | ||
const method = (obj: { [key: string]: any }): number => obj.size || obj.length || Object.keys(obj).length; | ||
|
||
export = method; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
const method = (str: string) => new Buffer(str).toString("base64"); | ||
const method = (str: string) => Buffer.from(str).toString("base64"); | ||
|
||
export = method; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
const method = (str: string) => new Buffer(str, "base64").toString(); | ||
const method = (str: string) => Buffer.from(str, "base64").toString(); | ||
|
||
export = method; |