Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
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 32 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.