Constructor
new RuntimeEnvChecker()
Create a new instance of a RuntimeEnvChecker class.
Throws:
-
because instancing not allowed for this class
- Type
- Error
Methods
(static) checkBoolean(arg, name) → {boolean}
Ensure that the given argument is a true value.
Parameters:
Name | Type | Description |
---|---|---|
arg |
object | the object to check |
name |
string | the name to use in generated error (if any), empty name as default |
Throws:
-
if it's a false value or it's null or undefined
- Type
- Error
Returns:
- Type
- boolean
(static) checkEnvVarDefined(name) → {boolean}
Ensure that the given environment variable is defined and has a value.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | the name of the variable to check |
Throws:
-
if it's not defined or does not have a value
- Type
- Error
Returns:
- Type
- boolean
(static) checkESModule(filename, foldername) → {boolean}
Ensure that current code is running with JavaScript as ES Module.
Parameters:
Name | Type | Description |
---|---|---|
filename |
string | the name of the file to analyze |
foldername |
string | the name of the folder where to search the project definition file |
Throws:
-
if it's a false value or it's null or undefined
- Type
- Error
Returns:
- Type
- boolean
(static) checkNodeEnvProduction() → {boolean}
Ensure that the current Node.js environment is production.
Throws:
-
if it's not production
- Type
- Error
Returns:
- Type
- boolean
(static) checkStrictMode() → {boolean}
Ensure that current code is running with JavaScript in strict mode (as generally should be now).
Throws:
-
if it's a false value or it's null or undefined
- Type
- Error
Returns:
- Type
- boolean
(static) checkStringNotEmpty(arg, name) → {boolean}
Ensure that the given argument is a not empty string.
Parameters:
Name | Type | Description |
---|---|---|
arg |
object | the object to check |
name |
string | the name to use in generated error (if any), empty name as default |
Throws:
-
if it's an empty string or it's null or undefined
- Type
- Error
Returns:
- Type
- boolean
(static) checkVersion(versionnon-null, expectedVersionnon-null) → {boolean}
Utility method that check if the given version is compatible with the given expected version (using then semver syntax).
Parameters:
Name | Type | Description |
---|---|---|
version |
string | the version to check (as a string) |
expectedVersion |
string | the expected version for the comparison (as a semver string) |
Throws:
-
-
if at least an argument is wrong
- Type
- Error
-
-
-
if versions does not matches
- Type
- Error
-
Returns:
- Type
- boolean
(static) checkVersionOfNode(version, versionExpected) → {boolean}
Utility method that check if the given Node.js version is compatible with the given expected version (using then semver syntax), usually read from a specific field in 'package.json'.
Parameters:
Name | Type | Description |
---|---|---|
version |
string | the version to check (as a string), by default current Node.js version |
versionExpected |
string | the expected version for the comparison (as a semver string), by default current value for 'node', under 'engines' in 'package.json' (if set) |
Throws:
-
-
if at least an argument is wrong
- Type
- Error
-
-
-
if versions are comparable but does not matches
- Type
- Error
-
Returns:
- Type
- boolean
(static) checkVersionOfNpm(version, versionExpected) → {boolean}
Utility method that check if the given NPM version is compatible with the given expected version (using then semver syntax), usually read from a specific field in 'package.json'.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
version |
string | null | the version to check (as a string), default null |
versionExpected |
string | the expected version for the comparison (as a semver string), by default current value for 'npm', under 'engines' in 'package.json' (if set) |
Throws:
-
-
if at least an argument is wrong
- Type
- Error
-
-
-
if versions are comparable but does not matches
- Type
- Error
-
Returns:
- Type
- boolean
(static) getAvailableCpu() → {int}
Utility method that returns the number of total CPU available.
Returns:
- Type
- int
(static) getNodeEnv() → {string}
Utility method that gets the value of Node.js environment variable.
Returns:
- Type
- string
(static) getVersionOfNpm() → {string}
Utility method that gets current NPM version.
Returns:
- Type
- string
(static) isBoolean(arg) → {boolean}
Tell if the given argument is defined and not null, and is a boolean.
Parameters:
Name | Type | Description |
---|---|---|
arg |
object | the object to check |
Returns:
- Type
- boolean
(static) isDefinedAndNotNull(arg) → {boolean}
Tell if the given argument is defined and not null.
Parameters:
Name | Type | Description |
---|---|---|
arg |
object | the object to check |
Returns:
- Type
- boolean
(static) isEnvVarDefined(namenon-null) → {boolean}
Tell if the environment variable with the given name is defined and has a value.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | the name to check |
Returns:
- Type
- boolean
(static) isESModule(filename, foldername) → {boolean}
Utility method that returns if the given source file is running with JavaScript in ES Module.
Parameters:
Name | Type | Description |
---|---|---|
filename |
string | the name of the file to analyze |
foldername |
string | the name of the folder where to search the project definition file |
Throws:
-
if both arguments are undefined, null or empty
- Type
- Error
Returns:
- Type
- boolean
(static) isNodeEnvProduction() → {boolean}
Tell if the current Node.js environment is production.
Returns:
- Type
- boolean
(static) isStrictMode() → {boolean}
Utility method that returns if current code is running with JavaScript in strict mode (as generally should be now).
Returns:
- Type
- boolean
(static) isStringNotEmpty(arg) → {boolean}
Tell if the given argument is defined and not null, is a string and is not empty.
Parameters:
Name | Type | Description |
---|---|---|
arg |
object | the object to check |
Returns:
- Type
- boolean
(static) isVersionCompatible(versionnon-null, expectedVersionnon-null) → {boolean}
Utility method that tell if the given version is compatible with the expected version (using then semver syntax).
Parameters:
Name | Type | Description |
---|---|---|
version |
string | the version to check (as a string) |
expectedVersion |
string | the expected version for the comparison (as a semver string) |
Throws:
-
if at least an argument is wrong
- Type
- Error
Returns:
- Type
- boolean
(static) memoryInfo() → {object}
Utility method that get some info about memory (total, available) and wraps them into an object.
Returns:
- Type
- object
(static) processInfo() → {object}
Utility method that get some process-related info and wraps them into an object.
Returns:
- Type
- object