This is a JavaScript module which provides constants for browser and server environments. Its main purpose is to define the six available types in the global context (TYPE_FUNCTION, TYPE_STRING, TYPE_OBJECT, TYPE_BOOLEAN, TYPE_NUMBER, TYPE_UNDEFINED).
npm install konstant
On the server, a simple
require('konstant');
is sufficient for defining the type declarations. In a browser environment, the script just needs to be included in your DOM.
When additional constants are needed, the module should be initialized on the server as follows:
// Server environment
var Konstant = require('konstant');
With define, a new constant can be defined. You can provide either a hashmap or key-value-pairs. When inGlobal is set to true, the constant will be made available in the global context (which is the window object in a browser environment).
Returns true or false, depending on whether a constant has been defined or not.
Returns the given constant or throws an error if it hasn't been defined.