Skip to content

Commit

Permalink
New function getConstants() + upgrade @nexssp/stack
Browse files Browse the repository at this point in the history
  • Loading branch information
mapoart committed May 7, 2021
1 parent 1e0f379 commit 1c67dde
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 64 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @nexssp/const

- **NEW 1.0.13** - function which list the defined constants: **getConstants()**
- **NEW 1.0.11** - now 2 functions **nConst** and **hConst**. hConst will be hidden. So when the for example `Object.keys` will be used will not be displayed however constant is there.
- **NEW 1.0.10** - now with stack display..

Expand Down Expand Up @@ -35,6 +36,8 @@ nConst("MYCONST2", "OLD CONSTANT VALUE");

hConst("MYCONST3_HIDDEN", "Hidden Constant", myConfig); // NEW! hConst-> Will to been seen on Object.keys etc.

console.log(getConstants()); // Will display defined constants

const myConfig = {};
nConst("MyObjectCONST", "My old object const", myConfig);

Expand Down
2 changes: 1 addition & 1 deletion dist/const.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 5 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@nexssp/const",
"version": "1.0.12",
"version": "1.0.13",
"description": "Global and Object constants the easy way. NEW: hidden constant.",
"main": "dist/const.js",
"main": "src/const.js",
"files": [
"dist/const.js"
"src/const.js"
],
"homepage": "https://nexss.com",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,7 @@
"license": "MIT",
"dependencies": {
"@nexssp/ansi": "^1.1.1",
"@nexssp/stack": "^1.0.8"
"@nexssp/stack": "^1.0.9"
},
"funding": [
{
Expand Down
13 changes: 11 additions & 2 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const { red, bold, green, yellow } = require("@nexssp/ansi");
const { stack } = require("@nexssp/stack");
const nContants = Symbol("nConstants");

// We create object to keep all constants
// (Just to list them if needed)
if (!global[nContants]) global[nContants] = [];

const handler = (displayName, value, hidden = false) => ({
set: function (v) {
stack(bold("PROGRAM TERMINATED:"), 1, 2);
Expand All @@ -21,13 +27,16 @@ const handler = (displayName, value, hidden = false) => ({
configurable: false,
});

const nConst = (name, value, where = global, hidden) => {
const nConst = (name, value, where = global, hidden = false) => {
global[nContants].push({ name, value, hidden, where: typeof where });
Object.defineProperty(where, name, handler(`${name}`, value, hidden));
return { name: value };
};

const getConstants = () => global[nContants];

const hConst = (name, value, where = global) => {
return nConst(name, value, where, true);
};

module.exports = { nConst, hConst };
module.exports = { nConst, hConst, getConstants };
4 changes: 2 additions & 2 deletions tests/index-const.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { myConfig } = require("./config");

console.log(myConfig);
const { getConstants } = require("../src/const");
console.log(getConstants());

process.MYCONST = 369;
myConfig.MyObjectCONST = 999999;
Expand Down

0 comments on commit 1c67dde

Please sign in to comment.