qm-state-simple

0.2.5 • Public • Published

logo-qm

qm-state-simple npm version Build Status code style: prettier

Simple and flexible state contener for simple apps.

Installation

Using npm:

$ npm i -S qm-state-simple

Usage

import { createState, addOptions, returnAPI, getVersion } from 'qm-state-simple'

const state = createState();

Creates default state object:

{
  cwd: ...              // absolute current working directory path
  dryRun: false,        // flag for switching I/O operations
  logger: fales,        // placeholder for external logger 
  exposeState: false, 
  mwd: ...              // absolute module working directory (__dirname) path
  silence: false        // silence all logging
};

Additional state properties

You can add custom properties to state by passing args object:

const args = { feed: true };

const state = createState(args);

Add options

Additional options can be also added by using addOptions() method:

const newState = addOptions(state, { someOption: true});

Return API

At the end of app execution there is possibility of return different forms of state by using returnAPI() method:

const stateToReturn = returnAPI(state, result) // => {result}

When exposeState flag is set on true then:

const stateToReturn = returnAPI(state, result) // => {result, state}

Get version

Use getVersion() method to pull from app version from package.json file. Version number is written to the state in version property.

const updatedState = getVersion(state);

Above method returns Pormise object.

Tests

Run npm script for performing tests:

npm run start:test

License

MIT © qaraluch

Readme

Keywords

none

Package Sidebar

Install

npm i qm-state-simple

Weekly Downloads

1

Version

0.2.5

License

MIT

Last publish

Collaborators

  • qaraluch