Skip to content

Add an isNode module #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/is-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js
*.js.map
*.d.ts
18 changes: 18 additions & 0 deletions packages/is-node/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {isNode} from '../';

describe('isNode', () => {
it('should return true when running in a Node.JS environment', () => {
// jest only runs in node, so this will always be true
expect(isNode()).toBe(true);
});

it('should return false when the global process object does not exist', () => {
const process = global.process;
try {
delete global.process;
expect(isNode()).toBe(false);
} finally {
global.process = process;
}
});
});
3 changes: 3 additions & 0 deletions packages/is-node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isNode(): boolean {
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
}
19 changes: 19 additions & 0 deletions packages/is-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@aws/is-node",
"private": true,
"version": "0.0.1",
"description": "Provides a function for detecting if the host environment is Node.JS",
"scripts": {
"pretest": "tsc",
"test": "jest"
},
"author": "[email protected]",
"license": "UNLICENSED",
"main": "index.js",
"devDependencies": {
"@types/jest": "^19.2.2",
"@types/node": "^7.0.12",
"jest": "^19.0.2",
"typescript": "^2.3"
}
}
8 changes: 8 additions & 0 deletions packages/is-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"strict": true
}
}