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
npm install extern-constantify
Typescript
Module System
NPM Version
58.5
Supply Chain
91.6
Quality
74.6
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
1,577
Last Day
2
Last Week
2
Last Month
4
Last Year
65
12 Commits
2 Watching
2 Branches
1 Contributors
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%
2
Compared to previous day
Last week
0%
2
Compared to previous week
Last month
-20%
4
Compared to previous month
Last year
-33%
65
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
Found 0/5 approved changesets -- score normalized to 0
Reason
project is archived
Details
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 2024-12-30
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