Skip to main content

isomorphy

import { isomorphy } from '@dr.pogodin/react-utils';

The isomorphy module is a collection of helpers for dealing with isomorphic aspects of code (mostly environment checks: client- or server-side, development or production, etc.). All constants and methods documented below are exposed as key values of isomorphy object.

Beware

This module relies on Babel and Webpack configurations provided by react-utils library being used by the host code, along with provided mechanics for server creation and client-side app initialization. It won't work correctly with a different app setup.

Constants

  • isomorphy.IS_CLIENT_SIDE - boolean - equals true within the client-side (browser) environment, and equals false at the server-side (NodeJS).
  • isomorphy.IS_SERVER_SIDE - boolean - equals true within the server-side (NodeJS) environment, and equals false at the client-side (browser).
INFO

For the purpose of .IS_CLIENT_SIDE and .IS_SERVER_SIDE constants the client- and server-side are distinguished based on the presence in the environment of the process object with Node version stored at its process.versions.node path.

For the test purposes the library provides JU.mockClientSide() and JU.unmockClientSide() functions, which enforce client side values of these constants by removing / restoring process.versions.node value.

Alternatively, the client-side may be enforced by setting true the global REACT_UTILS_FORCE_CLIENT_SIDE variable.

Methods

buildTimestamp()

isomorphy.buildTimestamp() => string

Returns string: the build timestamp of the frontend JS bundle in ISO format.

getBuildInfo()

isomorphy.getBuildInfo() => object

Returns object: the build info object.

isDevBuild()

isomorphy.isDevBuild() => boolean

Returns boolean: true if the development version of code is running, false otherwise.

isProdBuild()

isomorphy.isProdBuild() => boolean

Returns boolean: true if the production version of code is running, false otherwise.