https://github.com/cmtt/konstant
Provides type declarations in the global context and manages custom constants.
https://github.com/cmtt/konstant
Last synced: 11 months ago
JSON representation
Provides type declarations in the global context and manages custom constants.
- Host: GitHub
- URL: https://github.com/cmtt/konstant
- Owner: cmtt
- Created: 2013-02-04T15:39:15.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-02-04T15:52:52.000Z (over 13 years ago)
- Last Synced: 2025-06-26T12:52:43.126Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 105 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Konstant
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).
## Installation
npm install konstant
## Usage
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');
## Functions
### Konstant.define (key, value, inGlobal)
### Konstant.define (object, inGlobal)
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).
### Konstant.defined (key)
Returns true or false, depending on whether a constant has been defined or not.
### Konstant.get (key)
Returns the given constant or throws an error if it hasn't been defined.