Gathering detailed insights and metrics for extern-constantify
Gathering detailed insights and metrics for extern-constantify
Gathering detailed insights and metrics for extern-constantify
Gathering detailed insights and metrics for extern-constantify
Transform that does in-place replacement of global constants, without having to declare them or import them at every occurence
npm install extern-constantify
Typescript
Module System
NPM Version
63.6
Supply Chain
91.6
Quality
74.6
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
1,633
Last Day
1
Last Week
2
Last Month
14
Last Year
97
MIT License
12 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Jan 28, 2023
Minified
Minified + Gzipped
Latest Version
0.2.0
Package Id
extern-constantify@0.2.0
Size
3.18 kB
NPM Version
1.4.9
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
-6.7%
14
Compared to previous month
Last Year
36.6%
97
Compared to previous year
1
Browserify transform that allows does in-place replacement of global constants, without having to declare them or import them at every occurence.
1browserify -t extern-constantify entry.js > bundle.js
For example, suppose you have different classes/objects in your project communicating by events/messages:
1var Sender = function () { 2 this.emit('begin'); 3 //do some stuff, reporting progress 4 this.emit('busy', progress); 5 //finalize and report success 6 this.emit('done'); 7}; 8 9var Receiver = function (sender) { 10 sender.on('begin', function(data) { 11 node.innerHTML = 'Starting...'; 12 }); 13 sender.on('busy', function(data) { 14 node.innerHTML = 'Work is ' + data + '% complete'; 15 }); 16 sender.on('done', function(data) { 17 node.innerHTML = 'Work is done'; 18 }); 19};
Now suppose you later decide to change the names of these events to start
, progress
and end
. You would have to look for the various occurences of the original literal strings in your code and replace them accordingly. This introduces a lot of room for error. Instead you could write this:
1var Sender = function () { 2 this.emit(BEGIN_EVENT); 3 //do some stuff, reporting progress 4 this.emit(BUSY_EVENT, progress); 5 //finalize and report success 6 this.emit(END_EVENT); 7}; 8 9var Receiver = function (sender) { 10 sender.on(BEGIN_EVENT, function(data) { 11 node.innerHTML = 'Starting...'; 12 }); 13 sender.on(BUSY_EVENT, function(data) { 14 node.innerHTML = 'Work is ' + data + '% complete'; 15 }); 16 sender.on(END_EVENT, function(data) { 17 node.innerHTML = 'Work is done'; 18 }); 19};
and provide the following configuration in your package.json
file
1{ 2 "extern-constantify": { 3 "BEGIN_EVENT": "begin", 4 "BUSY_EVENT": "busy", 5 "END_EVENT": "done" 6 } 7}
The aforementioned change would then only require one edit in your configuration instead of the multiple edits that were previously required.
The matching happens case-sensitively, so you can avoid naming conflicts by uppercasing all characters of a constant name. This is the recommended coding style, however it is not mandatory.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
project is archived
Details
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More