![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@yawaramin/dbc
Advanced tools
This is a small library to help you program in a design-by-contract style in JavaScript and ReasonML (i.e. BuckleScript).
This is a small library to help you program in a design-by-contract style in JavaScript and ReasonML (i.e. BuckleScript).
When targeting JavaScript, even when using a safer language like ReasonML, it's nice to have more guarantees about invariants in your programs. Types provide some of those guarantees, but not all. Design-by- contract style allows you to catch problems as soon as possible–right at the start and end of function bodies.
But this note on defensive programming from the excellent Cornell CS3110 course is worth mentioning here:
Sometimes programmers worry unnecessarily that defensive programming will be too expensive—either in terms of the time it costs them to implement the checks initially, or in the run-time costs that will be paid in checking assertions. These concerns are far too often misplaced. The time and money it costs society to repair faults in software suggests that we could all afford to have programs that run a little more slowly.
For JavaScript, usage is as follows.
contract(body[, pre[, post]])
The body
is the body of the function itself, and is required. pre
is
an array of (array) pairs of string descriptions and boolean
preconditions, and is optional. post
is a function that takes the final
result of the function being contracted, and returns an array of pairs of
postcondition descriptions and booleans.
Throws a TypeError
at the first precondition or postcondition
violation.
pre
, post
These are older APIs; you'll probably want to use contract
instead.
const {contract} = require('@yawaramin/dbc');
const safeDiv = (num, denom) => contract(
num / denom,
/* pre: */ [
['num >= denom', num >= denom],
['denom !== 0', denom !== 0],
],
/* post: */ result => [
['safeDiv(num, denom) * denom === num', result * denom === num],
],
);
const makeUser = (name, age) => contract(
{name, age},
/* pre: */ [['age >= 13', age >= 13]],
// post is optional
);
See the src/Yawaramin__Dbc.mli
file for detailed ReasonML documentation
on the functions, and src/Test.re
for example usage.
ReasonML usage has an extra feature if you need it: all checks can be erased for production use. The idea being that you test thoroughly with all checks turned on during development, and deploy with them turned off (if you need to). See below for the command.
For best results, don't use this library to check types (including 'x
is not null
'). I recommend using a typechecker (like ReasonML or
TypeScript) to do that. Use pre
and post
to check invariants that
can't easily be expressed as types, like 'weight must be 5 kg minimum'.
Development:
npm run build
Production:
NODE_ENV=production npm run build # this turns off all checks
If you actually decide to keep checks on in production (imho a good thing), you can always keep them on explicitly:
NODE_ENV= npm run build
npm test
FAQs
This is a small library to help you program in a design-by-contract style in JavaScript and ReasonML (i.e. BuckleScript).
We found that @yawaramin/dbc 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.