
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
master-enumerator
Advanced tools
A JavaScript library for psuedo-enums (enumerators)
Install:
npm install master-enumerator
Use:
This constructor takes in an array which houses the string enum values, it can also optionally be constructed with a custom properties object (as of right now caseSensitive is the only configurable property) - caseSensitive === true will preserve the value of the string in the array - by default the key AND value will always be uppercase - caseSensitive === false then the value is not manipulated in any way (i.e. with toUpperCase() like in the default scenario).
new Enumerator(array[], options?{ caseSensitive: boolean });
Examples:
No custom options are specified - defaulting caseSensitive = false
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'two', 'three' ]);
Enumerator {
getter: ONE() => { return 'ONE' }
getter: TWO() => return 'TWO' }
getter: THREE() => { return 'THREE' }
enumerations: [
{
key: 'ONE',
value: 'ONE'
},
{
key: 'TWO',
value: 'TWO'
},
{
key: 'THREE',
value: 'THREE'
}
]
}
enumerator.ONE // output: 'ONE'
enumerator.TWO // output: 'TWO'
enumerator.THREE // output: 'THREE'
The one custom option is specified - making caseSensitive = true
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'tWo', 'THREE' ], { caseSensitive: true });
Enumerator {
getter: ONE() => { return 'one' }
getter: TWO() => return 'tWo' }
getter: THREE() => { return 'THREE' }
enumerations: [
{
key: 'ONE',
value: 'one'
},
{
key: 'TWO',
value: 'tWo'
},
{
key: 'THREE',
value: 'THREE'
}
]
}
enumerator.ONE // output: 'one'
enumerator.TWO // output: 'tWo'
enumerator.THREE // output: 'THREE'
This method allows you to check a string value against your psude-enumerator data type, returning true if the string value is a correlating type of this enumerator and false if it is not.
const enumerator = new Enumerator(array[], options?{ caseSensitive: boolean });
enumerator.validValue('string/value');
Example:
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'two', 'three' ]);
enumerator.validValue('one'); // output: true
enumerator.validValue('One'); // output: true
enumerator.validValue('ONE'); // output: true
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'tWo', 'THREE' ], { caseSensitive: true });
enumerator.validValue('tWo'); // output: true
enumerator.validValue('TWO'); // output: false
enumerator.validValue('two'); // output: false
This method allows you to check an array of values against your psude-enumerator data type, returning an array with booleans - true if the value in the same exact index location in the passed in array is a correlating type/value of this enumerator and false if it is not.
const enumerator = new Enumerator(array[], options?{ caseSensitive: boolean });
enumerator.validValues(array[]);
Example:
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'two', 'three' ]);
enumerator.validValues(['one', 'One', 'ONE']); // output: [true, true, true]
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'two', 'three' ], { caseSensitive: true });
enumerator.validValues(['one', 'One', 'ONE']); // output: [true, false, false]
This method returns the Enumerator's getter keys/properties that are used to get the values behind its enums.
const enumerator = new Enumerator(array[], options?{ caseSensitive: boolean });
enumerator.enumerationKeys();
Example:
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'two', 'three' ]);
enumerator.enumerationKeys(); // output: [ 'ONE', 'TWO', THREE' ]
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'tWo', 'TRHEE' ], { caseSensitive: true });
enumerator.enumerationValues(); // output: [ 'ONE', 'TWO', THREE' ]
This method returns an array of the Enumerator's values behind its enums/getter keys/properties.
const enumerator = new Enumerator(array[], options?{ caseSensitive: boolean });
enumerator.enumerationValues();
Example:
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'two', 'three' ]);
enumerator.enumerationValues(); // output: [ 'ONE', 'TWO', THREE' ]
const { Enumerator } = require('master-enumerator');
const enumerator = new Enumerator([ 'one', 'tWo', 'TRHEE' ], { caseSensitive: true });
enumerator.enumerationValues(); // output: [ 'one', 'tWo', THREE' ]
test/ contains very thorough TDD and BDD examples/tests.FAQs
Allows users to harness psuedo-enumerator data types
We found that master-enumerator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.