https://github.com/asterics/node-utils
https://github.com/asterics/node-utils
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/asterics/node-utils
- Owner: asterics
- License: gpl-3.0
- Created: 2019-01-27T00:51:40.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-14T22:57:50.000Z (almost 7 years ago)
- Last Synced: 2025-04-27T06:49:16.318Z (11 months ago)
- Language: JavaScript
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-utils
`node-utils` is a collection of methods tools for node.js, with the purpose of ensuring cross-platform support (Windows/Linux/OS X).
## Install
Install with npm:
npm install --save-dev @asterics/node-utils
Install with yarn:
yarn add @asterics/node-utils --dev
## Introduction
This package uses [`shelljs`](https://www.npmjs.com/package/shelljs), a portable implementation of the Unix shell for Windows, Linux and OS X.
## API Reference
### execute( { cmd, success, error, env, fatal, verbose } )
Execute `cmd`.
Available properties:
* `cmd`: Command to execute.
* `success`: Message on success.
* `error`: Message on error.
* `[env]`: Additional environment variables.
* `[fatal]`: Abort on error (default: false).
* `[verbose]`: Verbose logging (default: false).
#### Example
```javascript
const { execute } = require("@asterics/node-utils");
// -> bar
execute({
cmd: "echo $FOO"
success: "success!",
error: "failure!",
env: { FOO: "bar" },
verbose: true
});
```
### mkdirp(path[, ...])
Create directory at `path` and required parent directories.
Available parameters:
* `path`: Absolute path to directory to create.
**Note**: `path` must be an absolute path.
#### Example
````javascript
const { mkdirp } = require("@asterics/node-utils");
// Single directory
mkdirp("/home/admin/temp/foo");
// Multiple directories
mkdirp("/home/admin/temp/foo","/home/admin/temp/bar");
````
### hasShellCommand(command[, ...])
Check if `command` exists on the system.
Available properties:
* `command`: Shell command.
Returns:
`true` if provided `command` exist, `false` otherwise.
#### Example
```javascript
const { hasCommand } = require("@asterics/node-utils");
// Single command
hasCommand("git");
// Multiple commands
hasCommand("git","less","nano");
```