
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
A compact design-by-contract helper for nodejs and the browser.
$ npm install dbc.js
To use in a browser:
<script src="../releases/dbc.js.min-1.0.js"></script>
!! Be sure to fix the path relative to your static media assets and the referring page.
var dbc = require('dbc.js')
, expect = require('expect.js')
;
// from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
var emailRe = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
function validateEmail(email) {
return emailRe.test(email);
}
function Person(email, handle, last, first) {
dbc([validateEmail(email)], 'email address must appear valid.')
dbc([handle], 'a handle is required');
dbc([typeof first === 'undefined' || typeof last === 'string'],
'if you supply a first name you must also supply a last name');
this.email = email;
this.handle = handle;
this.last = last;
this.first = first;
}
expect(new Person('me@home.me', 'me')).to.be.a(Person);
expect(function() {
// create a Person with a clearly invalid email address...
new Person('it.doesn`t@compute')
}).to.throwError(/email address must appear valid/);
expect(function() {
// create a Person without a handle
new Person('jo@bob.me');
}).to.throwError(/a handle is required/);
Tests use mocha and expect.js, so if you clone the github repository you'll need to run:
npm install
... followed by ...
npm test
... or ...
mocha -R spec
To run the same tests from a browser, open the test/test.html
file directly from your file system.
FAQs
A compact design-by-contract helper for nodejs and the browser.
The npm package dbc.js receives a total of 16 weekly downloads. As such, dbc.js popularity was classified as not popular.
We found that dbc.js 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
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.