app-defines

Define immutable app-wide constants

Usage no npm install needed!

<script type="module">
  import appDefines from 'https://cdn.skypack.dev/app-defines';
</script>

README

app-defines

npm version npm license travis build

const defines = require('app-defines');

// Set all defines once for the lifetime of the process
defines.someConstant = 42;
defines.someOtherConstant = {luck: 'good'};

// Finalize the defines
defines.freeze();

// Defines are now irreversibly read-only (including nested properties)
defines.someOtherProperty.luck = 'bad'; // Throws TypeError

// The read-only defines object can now be required from anywhere in the app

The object is frozen with the technique used in deep-freeze.

This module is rather trivial, but useful to have as an external module, so that the defines can be required from any file in the project without the need of relative requires.

This module is intended for use in application code only and should not be used in dependencies!