Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardalan Amini committed Jun 1, 2018
2 parents 7822cab + 836729c commit 61ba9a1
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/globals/intex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** @namespace Global */

import "./isBrowser";
21 changes: 21 additions & 0 deletions lib/globals/isBrowser/index.ts
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;
5 changes: 5 additions & 0 deletions lib/globals/isBrowser/method.ts
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;
13 changes: 13 additions & 0 deletions lib/globals/isBrowser/test.ts
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);
});
});
5 changes: 5 additions & 0 deletions lib/globals/methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as isBrowser from "./isBrowser/method";

export {
isBrowser,
};
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "./array";
import "./boolean";
import "./date";
import "./function";
import "./globals";
import "./math";
import "./number";
import "./object";
Expand Down
2 changes: 2 additions & 0 deletions lib/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as array from "./array/methods";
import * as boolean from "./boolean/methods";
import * as date from "./date/methods";
import * as func from "./function/methods";
import * as globals from "./globals/methods";
import * as math from "./math/methods";
import * as number from "./number/methods";
import * as object from "./object/methods";
Expand All @@ -12,6 +13,7 @@ export {
boolean,
date,
func as function,
globals,
math,
number,
object,
Expand Down
2 changes: 1 addition & 1 deletion lib/object/size/method.ts
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;
2 changes: 1 addition & 1 deletion lib/string/base64/method.ts
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;
2 changes: 1 addition & 1 deletion lib/string/base64Decode/method.ts
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;

0 comments on commit 61ba9a1

Please sign in to comment.