Skip to content

Commit

Permalink
Rewrite the library realization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpods committed Feb 12, 2015
1 parent 4563a9c commit b2b46d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ First you need to integrate is-iojs into your application.
var isIojs = require('is-iojs');
```

Then you can call the `isIojs` function to determine whether the runtime is io.js or Node.js. If the function returns `true`, the platform is io.js; otherwise it is Node.js.
Then you can use `isIojs` to determine whether the runtime is io.js or not. If it's `true`, the platform is io.js:

```javascript
if (isIojs()) {
if (isIojs) {
console.log('io.js');
} else {
console.log('Node.js');
console.log('not io.js');
}
```

Expand All @@ -33,7 +33,7 @@ This module can be built using [Grunt](http://gruntjs.com/). Besides running the
## License

The MIT License (MIT)
Copyright (c) 2015 Aleksey Podskrebyshev.
Copyright (c) 2015 Aleksey Podskrebyshev, Golo Roden.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
19 changes: 13 additions & 6 deletions lib/isIojs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
'use strict';

var childProcess = require('child_process');
var cp = require('child_process');

var isIojs = function () {
return /iojs\.org/.test(childProcess.execSync('node -h', { encoding: 'utf8' }));
};

module.exports = isIojs;
module.exports = (function () {
if (!cp.execSync) {
return false;
}
/**
* @TODO: Make some reliable test for v1.0.0 and v1.0.1 versions
*/
if (~[ 'v1.0.0', 'v1.0.1' ].indexOf(process.version)) {
return true;
}
return /iojs\.org/.test(cp.execSync(process.execPath + ' -h', { encoding: 'ascii' }));
})();
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "is-iojs",
"version": "0.3.2",
"version": "1.0.0",
"description": "is-iojs determines if runtime is io.js.",
"contributors": [
{
Expand All @@ -13,9 +13,8 @@
}
],
"main": "lib/isIojs.js",
"dependencies": {},
"devDependencies": {
"assertthat": "0.4.1",
"assertthat": "0.4.2",
"grunt": "0.4.5",
"proxyquire": "1.3.1",
"tourism": "0.13.2"
Expand Down
8 changes: 4 additions & 4 deletions test/isIojsTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ suite('isIojs', function () {

test('is a function.', function (done) {
var isIojs = require('../lib/isIojs');
assert.that(isIojs).is.ofType('function');
assert.that(isIojs).is.ofType('boolean');
done();
});

Expand All @@ -24,11 +24,11 @@ suite('isIojs', function () {
}
/*eslint-enable camelcase*/
});
assert.that(isIojs()).is.true();
assert.that(isIojs).is.true();
done();
});

test('returns false if runtime is Node.js.', function (done) {
test('returns false if runtime is not io.js.', function (done) {
var isIojs = proxyquire('../lib/isIojs', {
/*eslint-disable camelcase*/
child_process: {
Expand All @@ -38,7 +38,7 @@ suite('isIojs', function () {
}
/*eslint-enable camelcase*/
});
assert.that(isIojs()).is.false();
assert.that(isIojs).is.false();
done();
});
});

0 comments on commit b2b46d2

Please sign in to comment.