Skip to content

Commit 09f0b99

Browse files
committed
corrections, additional type checks/tests, update version
1 parent b304611 commit 09f0b99

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ import {
112112
isBlob, // True if value is a Blob, otherwise false.
113113
isFunction, // True if value is a Function, otherwise false.
114114
isDate, // True if value is a Date, otherwise false.
115-
isStream //True if value is a Stream, otherwise false
115+
isStream, // True if value is a Stream, otherwise false.
116+
isNull, // True if value is a null, otherwise false.
117+
isBool, // True if value is a boolean, otherwise false.
118+
isWindows, // True if platform a Windows OS, otherwise false.
119+
isLinux, // True if platform a Linux OS, otherwise false.
120+
isMac, // True if platform a Apple macOS, otherwise false.
116121
} from 'node-sys';
117122
```
118123

index.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function sysManager() {
7777
*/
7878
export const packager = Sys.packager = function () {
7979
let sys = sysManager();
80-
if (Array.isArray(sys) && sys[0])
80+
if (isArray(sys) && sys[0])
8181
return {
8282
sudo: (sys[0] === 'sudo'),
8383
command: ((!sys[2]) ? sys[0] : sys[1]),
@@ -105,7 +105,7 @@ export const installer = Sys.installer = function (application, progress) {
105105
return new Promise((resolve, reject) => { return reject("No package, application name missing."); });
106106

107107
let manager = sysManager();
108-
if (!Array.isArray(manager))
108+
if (!isArray(manager))
109109
return new Promise((resolve, reject) => { return reject(manager); });
110110
let cmd = manager[0];
111111
let args = null;
@@ -115,7 +115,7 @@ export const installer = Sys.installer = function (application, progress) {
115115
if (manager[2])
116116
install = [manager[2]];
117117

118-
let whatToInstall = (Array.isArray(application)) ? [].concat(application).concat(['-y']) : [].concat([application]).concat(['-y']);
118+
let whatToInstall = isArray(application) ? [].concat(application).concat(['-y']) : [].concat([application]).concat(['-y']);
119119
let system = whatToInstall;
120120
if ((args) && (!install))
121121
system = args.concat(whatToInstall);
@@ -209,7 +209,7 @@ export const spawning = Sys.spawning = function (command, argument, progressOpti
209209

210210
if (sudo) {
211211
argument = [command].concat(argument);
212-
command = (process.platform == 'win32') ? join(__dirname, 'bin', 'sudo.bat') : 'sudo';
212+
command = (isWindows()) ? join(__dirname, 'bin', 'sudo.bat') : 'sudo';
213213
};
214214

215215
const spawned = spawn(command, argument, options);
@@ -405,6 +405,53 @@ export const isStream = Sys.isStream = function (value) {
405405
return isObject(value) && isFunction(value.pipe);
406406
}
407407

408+
/**
409+
* Determine if a value is a boolean
410+
*
411+
* @param {Object} value The value to test
412+
* @returns {boolean} True if value is a boolean, otherwise false
413+
*/
414+
export const isBool = Sys.isBool = function (value) {
415+
return (value === true) || (value === false);
416+
}
417+
418+
/**
419+
* Determine if a value is a null
420+
*
421+
* @param {Object} value The value to test
422+
* @returns {boolean} True if value is a null, otherwise false
423+
*/
424+
export const isNull = Sys.isNull = function (value) {
425+
return value === null;
426+
}
427+
428+
/**
429+
* Determine if platform is Windows
430+
*
431+
* @returns {boolean} True if Windows OS, otherwise false
432+
*/
433+
export const isWindows = Sys.isWindows = function () {
434+
return process.platform === 'win32';
435+
}
436+
437+
/**
438+
* Determine if platform is Linux
439+
*
440+
* @returns {boolean} True if Linux OS, otherwise false
441+
*/
442+
export const isLinux = Sys.isLinux = function () {
443+
return process.platform === 'linux';
444+
}
445+
446+
/**
447+
* Determine if platform is Apple Mac
448+
*
449+
* @returns {boolean} True if Apple macOS, otherwise false
450+
*/
451+
export const isMac = Sys.isMac = function () {
452+
return process.platform === 'darwin';
453+
}
454+
408455
function Sys() { }
409456

410457
export default Sys;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-sys",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Universal package installer, get the command for managing packages, or auto install any package, using one command for all platforms. Automate the installation of macOS Brew, and Windows Chocolatey package managers. A promisify child process of spawn, run as administrator.",
55
"type": "module",
66
"main": "index.js",

test/test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import chai from 'chai';
2-
import Sys from '../index.js';
2+
import Sys, { isLinux, isMac, isWindows } from '../index.js';
33
import {
44
Readable
55
} from 'stream';
@@ -387,7 +387,7 @@ describe('Function: `Sys`', function () {
387387

388388
});
389389

390-
describe('Function: `System` Methods', function () {
390+
describe('Function: `System` Check Methods', function () {
391391
it('should instanced itself like a class', function () {
392392
const system = new System();
393393
expect(system).to.be.an.instanceof(System);
@@ -406,6 +406,11 @@ describe('Function: `System` Methods', function () {
406406
expect(System).itself.to.respondTo('isDate');
407407
expect(System).itself.to.respondTo('isFunction');
408408
expect(System).itself.to.respondTo('isStream');
409+
expect(System).itself.to.respondTo('isNull');
410+
expect(System).itself.to.respondTo('isBool');
411+
expect(System).itself.to.respondTo('isWindows');
412+
expect(System).itself.to.respondTo('isLinux');
413+
expect(System).itself.to.respondTo('isMac');
409414
});
410415

411416
class Blob { };
@@ -487,4 +492,24 @@ describe('Function: `System` Methods', function () {
487492
foo: 'bar'
488493
})).to.equal(false);
489494
});
495+
496+
it('should validate null', function () {
497+
expect(System.isNull(null)).to.equal(true);
498+
expect(System.isNull()).to.equal(false);
499+
expect(System.isNull(false)).to.equal(false);
500+
expect(System.isNull(0)).to.equal(false);
501+
});
502+
503+
it('should validate boolean', function () {
504+
expect(System.isBool(true)).to.equal(true);
505+
expect(System.isBool(false)).to.equal(true);
506+
expect(System.isBool(null)).to.equal(false);
507+
expect(System.isBool()).to.equal(false);
508+
expect(System.isBool('')).to.equal(false);
509+
expect(System.isBool(1)).to.equal(false);
510+
expect(System.isBool(0)).to.equal(false);
511+
expect(System.isBool(isWindows())).to.equal(true);
512+
expect(System.isBool(isLinux())).to.equal(true);
513+
expect(System.isBool(isMac())).to.equal(true);
514+
});
490515
});

0 commit comments

Comments
 (0)